Browse Source

[genhttp] Switch to .NET 6 (#6890)

* Bump GenHTTP to v6

* Fix the database test returning HTTP 500

* Update connection string with the aspcore settings

* Revert DB connection string
Andreas Nägeli 3 years ago
parent
commit
0044e89539

+ 7 - 7
frameworks/CSharp/genhttp/Benchmarks/Benchmarks.csproj

@@ -2,8 +2,8 @@
   
   <PropertyGroup>
     
-    <TargetFramework>net5.0</TargetFramework>
-    <LangVersion>9.0</LangVersion>
+    <TargetFramework>net6.0</TargetFramework>
+    <LangVersion>10.0</LangVersion>
     
     <AssemblyTitle>GenHTTP Benchmarks</AssemblyTitle>
     <Description>Test suite to be executed with TechEmpower FrameworkBenchmarks.</Description>
@@ -26,11 +26,11 @@
   </ItemGroup>
     
   <ItemGroup>
-    <PackageReference Include="GenHTTP.Core" Version="5.2.0" />
-    <PackageReference Include="GenHTTP.Modules.Razor" Version="5.2.0" />
-    <PackageReference Include="GenHTTP.Modules.Webservices" Version="5.2.0" />
-    <PackageReference Include="Microsoft.EntityFrameworkCore" Version="5.0.7" />
-    <PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="5.0.7" />
+    <PackageReference Include="GenHTTP.Core" Version="6.0.0" />
+    <PackageReference Include="GenHTTP.Modules.Razor" Version="6.0.0" />
+    <PackageReference Include="GenHTTP.Modules.Webservices" Version="6.0.0" />
+    <PackageReference Include="Microsoft.EntityFrameworkCore" Version="6.0.0" />
+    <PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="6.0.0" />
   </ItemGroup>
   
 </Project>

+ 17 - 13
frameworks/CSharp/genhttp/Benchmarks/Tests/FortuneHandler.cs

@@ -33,7 +33,7 @@ namespace Benchmarks.Tests
 
     #region Supporting data structures
 
-    public sealed class FortuneModel : PageModel
+    public sealed class FortuneModel : BasicModel
     {
 
         public List<Fortune> Cookies { get; }
@@ -80,18 +80,28 @@ namespace Benchmarks.Tests
 
         #region Functionality
 
-        public ValueTask<IResponse> HandleAsync(IRequest request) => Page.HandleAsync(request);
+        public async ValueTask PrepareAsync()
+        {
+            await Page.PrepareAsync();
+            await Template.PrepareAsync();
+        }
+
+        public ValueTask<ulong> CalculateChecksumAsync() => new(17);
 
         public IEnumerable<ContentElement> GetContent(IRequest request) => Enumerable.Empty<ContentElement>();
 
-        public async ValueTask<IResponseBuilder> RenderAsync(TemplateModel model)
+        public async ValueTask<string> RenderAsync(TemplateModel model) => await Template.RenderAsync(model);
+
+        public async ValueTask<IResponse> HandleAsync(IRequest request)
         {
-            return model.Request.Respond()
-                                .Content(await Template.RenderAsync(model))
-                                .Type(CONTENT_TYPE);
+            var response = await Page.HandleAsync(request);
+
+            response.ContentType = CONTENT_TYPE;
+
+            return response;
         }
 
-        private async ValueTask<FortuneModel> GetFortunes(IRequest request, IHandler handler)
+        private static async ValueTask<FortuneModel> GetFortunes(IRequest request, IHandler handler)
         {
             using var context = DatabaseContext.CreateNoTracking();
 
@@ -104,12 +114,6 @@ namespace Benchmarks.Tests
             return new FortuneModel(request, handler, fortunes);
         }
 
-        public async ValueTask PrepareAsync()
-        {
-            await Page.PrepareAsync();
-            await Template.PrepareAsync();
-        }
-
         #endregion
 
     }

+ 3 - 3
frameworks/CSharp/genhttp/genhttp.dockerfile

@@ -1,4 +1,4 @@
-FROM mcr.microsoft.com/dotnet/sdk:5.0-alpine AS build
+FROM mcr.microsoft.com/dotnet/sdk:6.0-alpine AS build
 WORKDIR /source
 
 # copy csproj and restore as distinct layers
@@ -7,10 +7,10 @@ RUN dotnet restore -r linux-musl-x64
 
 # copy and publish app and libraries
 COPY Benchmarks/ .
-RUN dotnet publish -c release -o /app -r linux-musl-x64 --no-restore 
+RUN dotnet publish -c release -o /app -r linux-musl-x64 --no-restore --self-contained
 
 # final stage/image
-FROM mcr.microsoft.com/dotnet/runtime-deps:5.0-alpine
+FROM mcr.microsoft.com/dotnet/runtime-deps:6.0-alpine
 WORKDIR /app
 COPY --from=build /app .