diff --git a/frameworks/CSharp/carter/Benchmarks/Benchmarks.csproj b/frameworks/CSharp/carter/Benchmarks/Benchmarks.csproj index 633df583883..90e7a92548e 100644 --- a/frameworks/CSharp/carter/Benchmarks/Benchmarks.csproj +++ b/frameworks/CSharp/carter/Benchmarks/Benchmarks.csproj @@ -1,11 +1,11 @@  - net5.0 + net10.0 true - + diff --git a/frameworks/CSharp/carter/Benchmarks/JsonModule.cs b/frameworks/CSharp/carter/Benchmarks/JsonModule.cs index 3d5e9392a78..45a0775e4d8 100644 --- a/frameworks/CSharp/carter/Benchmarks/JsonModule.cs +++ b/frameworks/CSharp/carter/Benchmarks/JsonModule.cs @@ -1,16 +1,23 @@ -namespace Benchmarks -{ - using Carter; - using System.Threading.Tasks; - using Utf8Json; +using Carter; +using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Routing; +using Utf8Json; - public class JsonModule : CarterModule +namespace Benchmarks +{ + public class JsonModule : ICarterModule { private const int _bufferSize = 27; - public JsonModule() : base("json") + public struct JsonMessage + { + public string message; + } + + public void AddRoutes(IEndpointRouteBuilder app) { - Get("/", (req, res) => + app.MapGet("/json", (HttpResponse res) => { res.StatusCode = 200; res.ContentType = "application/json"; @@ -21,10 +28,5 @@ public JsonModule() : base("json") return JsonSerializer.SerializeAsync(res.Body, msg); }); } - - public struct JsonMessage - { - public string message; - } } -} +} \ No newline at end of file diff --git a/frameworks/CSharp/carter/Benchmarks/PlainModule.cs b/frameworks/CSharp/carter/Benchmarks/PlainModule.cs index 7cf6e360b70..1f78a6eb49f 100644 --- a/frameworks/CSharp/carter/Benchmarks/PlainModule.cs +++ b/frameworks/CSharp/carter/Benchmarks/PlainModule.cs @@ -1,15 +1,19 @@ -namespace Benchmarks -{ - using Carter; - using System.Text; +using System.Text; +using Carter; +using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Routing; - public class PlainModule : CarterModule +namespace Benchmarks +{ + public class PlainModule : ICarterModule { private static readonly byte[] _helloWorldPayload = Encoding.UTF8.GetBytes("Hello, World!"); - public PlainModule() : base("plaintext") + + public void AddRoutes(IEndpointRouteBuilder app) { - Get("/", (req, res) => + app.MapGet("/plaintext", (HttpResponse res) => { var payloadLength = _helloWorldPayload.Length; res.StatusCode = 200; @@ -19,4 +23,4 @@ public PlainModule() : base("plaintext") }); } } -} +} \ No newline at end of file diff --git a/frameworks/CSharp/carter/Benchmarks/Program.cs b/frameworks/CSharp/carter/Benchmarks/Program.cs index 6b935fd6038..ce34af0d2a0 100644 --- a/frameworks/CSharp/carter/Benchmarks/Program.cs +++ b/frameworks/CSharp/carter/Benchmarks/Program.cs @@ -1,27 +1,13 @@ -namespace Benchmarks -{ - using System.IO; - using System.Threading.Tasks; - using Microsoft.AspNetCore.Hosting; - using Microsoft.Extensions.Configuration; +using Carter; +using Microsoft.AspNetCore.Builder; +using Microsoft.Extensions.Logging; - public class Program - { - public static async Task Main(string[] args) - { - var config = new ConfigurationBuilder() - .AddEnvironmentVariables(prefix: "ASPNETCORE_") - .AddCommandLine(args) - .Build(); +var builder = WebApplication.CreateBuilder(args); - var webHost = new WebHostBuilder() - .UseContentRoot(Directory.GetCurrentDirectory()) - .UseConfiguration(config) - .UseStartup() - .UseKestrel() - .Build(); +// Disable logging as this is not required for the benchmark +builder.Logging.ClearProviders(); +builder.Services.AddCarter(); +var app = builder.Build(); - await webHost.RunAsync(); - } - } -} +app.MapCarter(); +app.Run(); \ No newline at end of file diff --git a/frameworks/CSharp/carter/Benchmarks/Startup.cs b/frameworks/CSharp/carter/Benchmarks/Startup.cs deleted file mode 100644 index 2b985b66fa4..00000000000 --- a/frameworks/CSharp/carter/Benchmarks/Startup.cs +++ /dev/null @@ -1,20 +0,0 @@ -namespace Benchmarks -{ - using Carter; - using Microsoft.AspNetCore.Builder; - using Microsoft.Extensions.DependencyInjection; - - public class Startup - { - public void ConfigureServices(IServiceCollection services) - { - services.AddCarter(); - } - - public void Configure(IApplicationBuilder app) - { - app.UseRouting(); - app.UseEndpoints(builder => builder.MapCarter()); - } - } -} diff --git a/frameworks/CSharp/carter/README.md b/frameworks/CSharp/carter/README.md index bd309d88db7..8ae0a91653f 100644 --- a/frameworks/CSharp/carter/README.md +++ b/frameworks/CSharp/carter/README.md @@ -5,7 +5,7 @@ This includes tests for plaintext and json serialization. **Language** -* C# 7.0 +* C# 14.0 **Platforms** diff --git a/frameworks/CSharp/carter/carter.dockerfile b/frameworks/CSharp/carter/carter.dockerfile index b120fb7ea05..2275abd81c2 100644 --- a/frameworks/CSharp/carter/carter.dockerfile +++ b/frameworks/CSharp/carter/carter.dockerfile @@ -1,9 +1,9 @@ -FROM mcr.microsoft.com/dotnet/sdk:5.0 AS build +FROM mcr.microsoft.com/dotnet/sdk:10.0 AS build WORKDIR /app COPY Benchmarks . RUN dotnet publish -c Release -o out -FROM mcr.microsoft.com/dotnet/aspnet:5.0 AS runtime +FROM mcr.microsoft.com/dotnet/aspnet:10.0 AS runtime ENV ASPNETCORE_URLS http://+:8080 WORKDIR /app COPY --from=build /app/out ./