diff options
| author | crupest <crupest@outlook.com> | 2022-12-02 13:23:40 +0800 | 
|---|---|---|
| committer | crupest <crupest@outlook.com> | 2022-12-02 13:35:35 +0800 | 
| commit | f0e48b2957d2ff8d66bb8d8a0cec673f8b424558 (patch) | |
| tree | 59f4e3942cc35664993f8bb8b9e4f7bf2ff4f3a3 /docker/crupest-api/CrupestApi/CrupestApi.Commons | |
| parent | 300842e81a99db6da103f146d33eb47f43efc683 (diff) | |
| download | crupest-f0e48b2957d2ff8d66bb8d8a0cec673f8b424558.tar.gz crupest-f0e48b2957d2ff8d66bb8d8a0cec673f8b424558.tar.bz2 crupest-f0e48b2957d2ff8d66bb8d8a0cec673f8b424558.zip  | |
Fix crupest-api bug.
Diffstat (limited to 'docker/crupest-api/CrupestApi/CrupestApi.Commons')
| -rw-r--r-- | docker/crupest-api/CrupestApi/CrupestApi.Commons/CrupestApi.Commons.csproj | 1 | ||||
| -rw-r--r-- | docker/crupest-api/CrupestApi/CrupestApi.Commons/Json.cs | 7 | 
2 files changed, 4 insertions, 4 deletions
diff --git a/docker/crupest-api/CrupestApi/CrupestApi.Commons/CrupestApi.Commons.csproj b/docker/crupest-api/CrupestApi/CrupestApi.Commons/CrupestApi.Commons.csproj index 72a1294..c0cd0c4 100644 --- a/docker/crupest-api/CrupestApi/CrupestApi.Commons/CrupestApi.Commons.csproj +++ b/docker/crupest-api/CrupestApi/CrupestApi.Commons/CrupestApi.Commons.csproj @@ -2,6 +2,7 @@    <PropertyGroup>
      <TargetFramework>net7.0</TargetFramework>
 +    <TargetType>library</TargetType>
      <Nullable>enable</Nullable>
      <ImplicitUsings>enable</ImplicitUsings>
    </PropertyGroup>
 diff --git a/docker/crupest-api/CrupestApi/CrupestApi.Commons/Json.cs b/docker/crupest-api/CrupestApi/CrupestApi.Commons/Json.cs index 0ec3ff0..8409a96 100644 --- a/docker/crupest-api/CrupestApi/CrupestApi.Commons/Json.cs +++ b/docker/crupest-api/CrupestApi/CrupestApi.Commons/Json.cs @@ -1,9 +1,8 @@ -using System.Text;  using System.Text.Json; +using Microsoft.Extensions.Options;  namespace CrupestApi.Commons; -  public static class CrupestApiJsonExtensions  {      public static IServiceCollection AddJsonOptions(this IServiceCollection services) @@ -22,8 +21,8 @@ public static class CrupestApiJsonExtensions      public static async Task WriteJsonAsync<T>(this HttpResponse response, T bodyObject, int statusCode = 200, HttpResponseAction? beforeWriteBody = null, CancellationToken cancellationToken = default)      { -        var jsonOptions = response.HttpContext.RequestServices.GetRequiredService<JsonSerializerOptions>(); -        byte[] json = JsonSerializer.SerializeToUtf8Bytes<T>(bodyObject, jsonOptions); +        var jsonOptions = response.HttpContext.RequestServices.GetRequiredService<IOptionsSnapshot<JsonSerializerOptions>>(); +        byte[] json = JsonSerializer.SerializeToUtf8Bytes<T>(bodyObject, jsonOptions.Value);          var byteCount = json.Length;          response.StatusCode = statusCode;  | 
