From cc8d8a6949da242943e61a97e08e507228b56f75 Mon Sep 17 00:00:00 2001 From: Galip Tolga Erdem Date: Tue, 6 Feb 2024 12:03:07 -0500 Subject: [PATCH] Changed JsonSerializer to IJsonSerializer --- .../AppConfigurationRemoteService.cs | 5 ++- .../Base/AggregateRemoteServiceBase.cs | 13 +++--- .../Localization/LocalizationRemoteService.cs | 5 ++- .../ReverseProxyBuilderExtensions.cs | 41 +++++++++---------- 4 files changed, 30 insertions(+), 34 deletions(-) diff --git a/gateways/web/src/EShopOnAbp.WebGateway/Aggregations/ApplicationConfiguration/AppConfigurationRemoteService.cs b/gateways/web/src/EShopOnAbp.WebGateway/Aggregations/ApplicationConfiguration/AppConfigurationRemoteService.cs index 13952340..233e18c2 100644 --- a/gateways/web/src/EShopOnAbp.WebGateway/Aggregations/ApplicationConfiguration/AppConfigurationRemoteService.cs +++ b/gateways/web/src/EShopOnAbp.WebGateway/Aggregations/ApplicationConfiguration/AppConfigurationRemoteService.cs @@ -2,9 +2,10 @@ using Microsoft.Extensions.Logging; using Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations; using Volo.Abp.DependencyInjection; +using Volo.Abp.Json; namespace EShopOnAbp.WebGateway.Aggregations.ApplicationConfiguration; -public class AppConfigurationRemoteService(ILogger> logger) - : AggregateRemoteServiceBase(logger), +public class AppConfigurationRemoteService(ILogger> logger, IJsonSerializer jsonSerializer) + : AggregateRemoteServiceBase(logger, jsonSerializer), IAppConfigurationRemoteService, ITransientDependency; \ No newline at end of file diff --git a/gateways/web/src/EShopOnAbp.WebGateway/Aggregations/Base/AggregateRemoteServiceBase.cs b/gateways/web/src/EShopOnAbp.WebGateway/Aggregations/Base/AggregateRemoteServiceBase.cs index a5cb54b0..b60cf0e9 100644 --- a/gateways/web/src/EShopOnAbp.WebGateway/Aggregations/Base/AggregateRemoteServiceBase.cs +++ b/gateways/web/src/EShopOnAbp.WebGateway/Aggregations/Base/AggregateRemoteServiceBase.cs @@ -2,24 +2,21 @@ using System.Collections.Generic; using System.Linq; using System.Net.Http; -using System.Text.Json; using System.Threading.Tasks; using Microsoft.Extensions.Logging; +using Volo.Abp.Json; namespace EShopOnAbp.WebGateway.Aggregations.Base; public abstract class AggregateRemoteServiceBase : IAggregateRemoteService { private readonly ILogger> _logger; - protected JsonSerializerOptions JsonSerializerOptions { get; } + protected IJsonSerializer JsonSerializer { get; } - protected AggregateRemoteServiceBase(ILogger> logger) + protected AggregateRemoteServiceBase(ILogger> logger, IJsonSerializer jsonSerializer) { _logger = logger; - JsonSerializerOptions = new JsonSerializerOptions() - { - PropertyNamingPolicy = JsonNamingPolicy.CamelCase - }; + JsonSerializer = jsonSerializer; } public async Task> GetMultipleAsync( @@ -71,7 +68,7 @@ public abstract class AggregateRemoteServiceBase : IAggregateRemoteService response.EnsureSuccessStatusCode(); var content = await response.Content.ReadAsStringAsync(); - return JsonSerializer.Deserialize(content, JsonSerializerOptions); + return JsonSerializer.Deserialize(content); } catch (Exception e) { diff --git a/gateways/web/src/EShopOnAbp.WebGateway/Aggregations/Localization/LocalizationRemoteService.cs b/gateways/web/src/EShopOnAbp.WebGateway/Aggregations/Localization/LocalizationRemoteService.cs index 6dc93789..9e582d1f 100644 --- a/gateways/web/src/EShopOnAbp.WebGateway/Aggregations/Localization/LocalizationRemoteService.cs +++ b/gateways/web/src/EShopOnAbp.WebGateway/Aggregations/Localization/LocalizationRemoteService.cs @@ -2,14 +2,15 @@ using Microsoft.Extensions.Logging; using Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations; using Volo.Abp.DependencyInjection; +using Volo.Abp.Json; namespace EShopOnAbp.WebGateway.Aggregations.Localization; public class LocalizationRemoteService : AggregateRemoteServiceBase, ILocalizationRemoteService, ITransientDependency { - public LocalizationRemoteService(ILogger> logger) : - base(logger) + public LocalizationRemoteService(ILogger> logger, IJsonSerializer jsonSerializer) : + base(logger, jsonSerializer) { } } \ No newline at end of file diff --git a/gateways/web/src/EShopOnAbp.WebGateway/ReverseProxyBuilderExtensions.cs b/gateways/web/src/EShopOnAbp.WebGateway/ReverseProxyBuilderExtensions.cs index 71364f11..70be5da1 100644 --- a/gateways/web/src/EShopOnAbp.WebGateway/ReverseProxyBuilderExtensions.cs +++ b/gateways/web/src/EShopOnAbp.WebGateway/ReverseProxyBuilderExtensions.cs @@ -8,18 +8,13 @@ using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Routing; using Microsoft.Extensions.DependencyInjection; +using Volo.Abp.Json; using Yarp.ReverseProxy.Configuration; namespace EShopOnAbp.WebGateway; public static class ReverseProxyBuilderExtensions { - private static readonly JsonSerializerOptions JsonSerializerOptions = new() - { - PropertyNamingPolicy = JsonNamingPolicy.CamelCase, - WriteIndented = true - }; - public static ReverseProxyConventionBuilder MapReverseProxyWithLocalization(this IEndpointRouteBuilder endpoints) { return endpoints.MapReverseProxy(proxyBuilder => @@ -27,34 +22,36 @@ public static class ReverseProxyBuilderExtensions proxyBuilder.Use(async (context, next) => { var endpoint = context.GetEndpoint(); - + var localizationAggregation = context.RequestServices .GetRequiredService(); + var appConfigurationAggregation = context.RequestServices + .GetRequiredService(); + + var jsonSerializer = context.RequestServices.GetRequiredService(); + // The "/api/abp/application-localization" endpoint if (localizationAggregation.LocalizationRouteName == endpoint?.DisplayName) { var localizationRequestInput = CreateLocalizationRequestInput(context, localizationAggregation.LocalizationEndpoint); - + var result = await localizationAggregation.GetLocalizationAsync(localizationRequestInput); - await context.Response.WriteAsync(JsonSerializer.Serialize(result, JsonSerializerOptions)); + await context.Response.WriteAsync(jsonSerializer.Serialize(result)); return; } - - var appConfigurationAggregation = context.RequestServices - .GetRequiredService(); - // The "/api/abp/application-configuration" endpoint - if (appConfigurationAggregation.AppConfigRouteName == endpoint?.DisplayName) - { - var appConfigurationRequestInput = - CreateAppConfigurationRequestInput(context, appConfigurationAggregation.AppConfigEndpoint); - - var result = await appConfigurationAggregation.GetAppConfigurationAsync(appConfigurationRequestInput); - await context.Response.WriteAsync(JsonSerializer.Serialize(result, JsonSerializerOptions)); - return; - } + // // The "/api/abp/application-configuration" endpoint + // if (appConfigurationAggregation.AppConfigRouteName == endpoint?.DisplayName) + // { + // var appConfigurationRequestInput = + // CreateAppConfigurationRequestInput(context, appConfigurationAggregation.AppConfigEndpoint); + // + // var result = await appConfigurationAggregation.GetAppConfigurationAsync(appConfigurationRequestInput); + // await context.Response.WriteAsync(jsonSerializer.Serialize(result)); + // return; + // } await next(); });