Browse Source

[CSharp] Migrate `FastEndpoints` to .NET 9 (#9566)

Dĵ ΝιΓΞΗΛψΚ 5 months ago
parent
commit
939321d3a6

+ 1 - 1
frameworks/CSharp/fastendpoints/Benchmarks/Benchmarks.csproj

@@ -1,7 +1,7 @@
 <Project Sdk="Microsoft.NET.Sdk.Web">
 
   <PropertyGroup>
-    <TargetFramework>net8.0</TargetFramework>
+    <TargetFramework>net9.0</TargetFramework>
     <Nullable>enable</Nullable>
     <ImplicitUsings>enable</ImplicitUsings>
     <NoWarn>CA2016;IDE1006</NoWarn>

+ 3 - 2
frameworks/CSharp/fastendpoints/Benchmarks/Endpoints/JsonEndpoint.cs

@@ -1,6 +1,6 @@
 namespace Benchmarks.Endpoints;
 
-public sealed class JsonEndpoint : Endpoint<EmptyRequest, object>
+sealed class JsonEndpoint : Ep.NoReq.Res<object>
 {
     public override void Configure()
     {
@@ -8,9 +8,10 @@ public sealed class JsonEndpoint : Endpoint<EmptyRequest, object>
         AllowAnonymous();
     }
 
-    public override Task HandleAsync(EmptyRequest _, CancellationToken __)
+    public override Task HandleAsync(CancellationToken ct)
     {
         HttpContext.Response.ContentLength = 27;
+
         return SendAsync(new { message = "Hello, World!" });
     }
 }

+ 6 - 5
frameworks/CSharp/fastendpoints/Benchmarks/Endpoints/PlainTextEndpoint.cs

@@ -1,8 +1,8 @@
 namespace Benchmarks.Endpoints;
 
-public sealed class PlainTextEndpoint : Endpoint<EmptyRequest, EmptyResponse>
+sealed class PlainTextEndpoint : Ep.NoReq.Res<byte[]>
 {
-    private static readonly byte[] payload = System.Text.Encoding.UTF8.GetBytes("Hello, World!");
+    static readonly byte[] _payload = "Hello, World!"u8.ToArray();
 
     public override void Configure()
     {
@@ -10,11 +10,12 @@ public sealed class PlainTextEndpoint : Endpoint<EmptyRequest, EmptyResponse>
         AllowAnonymous();
     }
 
-    public override Task HandleAsync(EmptyRequest _, CancellationToken __)
+    public override Task HandleAsync(CancellationToken ct)
     {
         HttpContext.Response.StatusCode = StatusCodes.Status200OK;
         HttpContext.Response.ContentType = "text/plain";
-        HttpContext.Response.ContentLength = payload.Length;
-        return HttpContext.Response.Body.WriteAsync(payload, 0, payload.Length);
+        HttpContext.Response.ContentLength = _payload.Length;
+
+        return HttpContext.Response.Body.WriteAsync(_payload, 0, _payload.Length);
     }
 }

+ 5 - 5
frameworks/CSharp/fastendpoints/Benchmarks/Program.cs

@@ -1,9 +1,9 @@
 global using FastEndpoints;
 
-var builder = WebApplication.CreateBuilder();
-builder.Logging.ClearProviders();
-builder.Services.AddFastEndpoints();
+var bld = WebApplication.CreateBuilder();
+bld.Logging.ClearProviders();
+bld.Services.AddFastEndpoints();
 
-var app = builder.Build();
+var app = bld.Build();
 app.UseFastEndpoints();
-app.Run("http://0.0.0.0:8080");
+app.Run("http://0.0.0.0:8080");

+ 3 - 3
frameworks/CSharp/fastendpoints/README.md

@@ -5,11 +5,11 @@ This includes tests for plaintext and json serialization.
 
 **Language**
 
-* C# 12.0
+* C# 13.0
 
 **Platforms**
 
-* .NET 8 (Windows and Linux)
+* .NET 9 (Windows and Linux)
 
 **Web Servers**
 
@@ -18,7 +18,7 @@ This includes tests for plaintext and json serialization.
 **Web Stack**
 
 * [FastEndpoints](https://fast-endpoints.com/)
-* ASP.NET 8
+* ASP.NET 9
 
 ## Paths & Source for Tests
 

+ 6 - 2
frameworks/CSharp/fastendpoints/fastendpoints.dockerfile

@@ -1,9 +1,13 @@
-FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
+FROM mcr.microsoft.com/dotnet/sdk:9.0 AS build
 WORKDIR /app
 COPY Benchmarks .
 RUN dotnet publish -c Release -o out
 
-FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS runtime
+FROM mcr.microsoft.com/dotnet/aspnet:9.0 AS runtime
+ENV DOTNET_GCDynamicAdaptationMode=0
+ENV DOTNET_ReadyToRun=0
+ENV DOTNET_HillClimbing_Disable=1
+
 WORKDIR /app
 COPY --from=build /app/out ./