Skip to content

Commit 56025a4

Browse files
committed
upgrade Carter to net10
1 parent d5f0a2a commit 56025a4

5 files changed

Lines changed: 40 additions & 68 deletions

File tree

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
<Project Sdk="Microsoft.NET.Sdk.Web">
22
<PropertyGroup>
3-
<TargetFramework>net5.0</TargetFramework>
3+
<TargetFramework>net10.0</TargetFramework>
44
<NoDefaultLaunchSettingsFile>true</NoDefaultLaunchSettingsFile>
55
</PropertyGroup>
66

77
<ItemGroup>
8-
<PackageReference Include="Carter" Version="5.2.0" />
8+
<PackageReference Include="Carter" Version="10.0.0" />
99
<PackageReference Include="Utf8Json" Version="1.3.7" />
1010
</ItemGroup>
1111
</Project>
Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,23 @@
1-
namespace Benchmarks
2-
{
3-
using Carter;
4-
using System.Threading.Tasks;
5-
using Utf8Json;
1+
using Carter;
2+
using Microsoft.AspNetCore.Builder;
3+
using Microsoft.AspNetCore.Http;
4+
using Microsoft.AspNetCore.Routing;
5+
using Utf8Json;
66

7-
public class JsonModule : CarterModule
7+
namespace Benchmarks
8+
{
9+
public class JsonModule : ICarterModule
810
{
911
private const int _bufferSize = 27;
1012

11-
public JsonModule() : base("json")
13+
public struct JsonMessage
14+
{
15+
public string message;
16+
}
17+
18+
public void AddRoutes(IEndpointRouteBuilder app)
1219
{
13-
Get("/", (req, res) =>
20+
app.MapGet("/json", (HttpResponse res) =>
1421
{
1522
res.StatusCode = 200;
1623
res.ContentType = "application/json";
@@ -21,10 +28,5 @@ public JsonModule() : base("json")
2128
return JsonSerializer.SerializeAsync(res.Body, msg);
2229
});
2330
}
24-
25-
public struct JsonMessage
26-
{
27-
public string message;
28-
}
2931
}
30-
}
32+
}
Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
1-
namespace Benchmarks
2-
{
3-
using Carter;
4-
using System.Text;
1+
using System.Text;
2+
using Carter;
3+
using Microsoft.AspNetCore.Builder;
4+
using Microsoft.AspNetCore.Http;
5+
using Microsoft.AspNetCore.Routing;
56

6-
public class PlainModule : CarterModule
7+
namespace Benchmarks
8+
{
9+
public class PlainModule : ICarterModule
710
{
811
private static readonly byte[] _helloWorldPayload = Encoding.UTF8.GetBytes("Hello, World!");
912

10-
public PlainModule() : base("plaintext")
13+
14+
public void AddRoutes(IEndpointRouteBuilder app)
1115
{
12-
Get("/", (req, res) =>
16+
app.MapGet("/plaintext", (HttpResponse res) =>
1317
{
1418
var payloadLength = _helloWorldPayload.Length;
1519
res.StatusCode = 200;
@@ -19,4 +23,4 @@ public PlainModule() : base("plaintext")
1923
});
2024
}
2125
}
22-
}
26+
}
Lines changed: 10 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,13 @@
1-
namespace Benchmarks
2-
{
3-
using System.IO;
4-
using System.Threading.Tasks;
5-
using Microsoft.AspNetCore.Hosting;
6-
using Microsoft.Extensions.Configuration;
1+
using Carter;
2+
using Microsoft.AspNetCore.Builder;
3+
using Microsoft.Extensions.Logging;
74

8-
public class Program
9-
{
10-
public static async Task Main(string[] args)
11-
{
12-
var config = new ConfigurationBuilder()
13-
.AddEnvironmentVariables(prefix: "ASPNETCORE_")
14-
.AddCommandLine(args)
15-
.Build();
5+
var builder = WebApplication.CreateBuilder(args);
166

17-
var webHost = new WebHostBuilder()
18-
.UseContentRoot(Directory.GetCurrentDirectory())
19-
.UseConfiguration(config)
20-
.UseStartup<Startup>()
21-
.UseKestrel()
22-
.Build();
7+
// Disable logging as this is not required for the benchmark
8+
builder.Logging.ClearProviders();
9+
builder.Services.AddCarter();
10+
var app = builder.Build();
2311

24-
await webHost.RunAsync();
25-
}
26-
}
27-
}
12+
app.MapCarter();
13+
app.Run();

frameworks/CSharp/carter/Benchmarks/Startup.cs

Lines changed: 0 additions & 20 deletions
This file was deleted.

0 commit comments

Comments
 (0)