Skip to content

Commit a213ea0

Browse files
committed
update
1 parent 711e0f0 commit a213ea0

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

src/Benchmarks/Middleware/JsonMiddleware.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,8 @@
1010
using Benchmarks.Configuration;
1111
using Microsoft.AspNetCore.Builder;
1212
using Microsoft.AspNetCore.Http;
13-
using Microsoft.AspNetCore.Http.Features;
14-
using System.Text.Json;
15-
using System.Text.Json.Serialization;
13+
using Microsoft.Extensions.Options;
14+
using Microsoft.AspNetCore.Http.Json;
1615

1716
namespace Benchmarks.Middleware
1817
{
@@ -36,7 +35,7 @@ public Task Invoke(HttpContext httpContext)
3635
httpContext.Response.StatusCode = 200;
3736
httpContext.Response.ContentLength = _bufferSize;
3837

39-
return httpContext.Response.WriteAsJsonAsync<JsonMessage>(new JsonMessage { message = "Hello, World!" }, _jsonOptions, httpContext.RequestAborted);
38+
return httpContext.Response.WriteAsJsonAsync(new JsonMessage { message = "Hello, World!" }, _jsonOptions, httpContext.RequestAborted);
4039
}
4140

4241
return _next(httpContext);

src/Benchmarks/Program.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,11 @@ public static void Main(string[] args)
8383
.ConfigureHttpJsonOptions(jsonOptions =>
8484
{
8585
jsonOptions.SerializerOptions.Encoder = null;
86+
#if NET7_0
8687
jsonOptions.SerializerOptions.AddContext<Middleware.CustomJsonContext>();
88+
#elif NET8_0_OR_GREATER
89+
jsonOptions.SerializerOptions.TypeInfoResolverChain.Insert(0, Middleware.CustomJsonContext.Default);
90+
#endif
8791
})
8892
)
8993
.UseDefaultServiceProvider(
@@ -125,9 +129,9 @@ public static void Main(string[] args)
125129
else if (String.Equals(Server, "HttpSys", StringComparison.OrdinalIgnoreCase))
126130
{
127131
// Disable cross-platform warning
128-
#pragma warning disable CA1416
132+
#pragma warning disable CA1416
129133
webHostBuilder = webHostBuilder.UseHttpSys();
130-
#pragma warning restore CA1416
134+
#pragma warning restore CA1416
131135
}
132136
else if (String.Equals(Server, "IISInProcess", StringComparison.OrdinalIgnoreCase))
133137
{

0 commit comments

Comments
 (0)