Browse Source

Changed JsonSerializer to IJsonSerializer

pull/235/head
Galip Tolga Erdem 3 years ago
parent
commit
cc8d8a6949
  1. 5
      gateways/web/src/EShopOnAbp.WebGateway/Aggregations/ApplicationConfiguration/AppConfigurationRemoteService.cs
  2. 13
      gateways/web/src/EShopOnAbp.WebGateway/Aggregations/Base/AggregateRemoteServiceBase.cs
  3. 5
      gateways/web/src/EShopOnAbp.WebGateway/Aggregations/Localization/LocalizationRemoteService.cs
  4. 41
      gateways/web/src/EShopOnAbp.WebGateway/ReverseProxyBuilderExtensions.cs

5
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<AggregateRemoteServiceBase<ApplicationConfigurationDto>> logger)
: AggregateRemoteServiceBase<ApplicationConfigurationDto>(logger),
public class AppConfigurationRemoteService(ILogger<AggregateRemoteServiceBase<ApplicationConfigurationDto>> logger, IJsonSerializer jsonSerializer)
: AggregateRemoteServiceBase<ApplicationConfigurationDto>(logger, jsonSerializer),
IAppConfigurationRemoteService, ITransientDependency;

13
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<TDto> : IAggregateRemoteService<TDto>
{
private readonly ILogger<AggregateRemoteServiceBase<TDto>> _logger;
protected JsonSerializerOptions JsonSerializerOptions { get; }
protected IJsonSerializer JsonSerializer { get; }
protected AggregateRemoteServiceBase(ILogger<AggregateRemoteServiceBase<TDto>> logger)
protected AggregateRemoteServiceBase(ILogger<AggregateRemoteServiceBase<TDto>> logger, IJsonSerializer jsonSerializer)
{
_logger = logger;
JsonSerializerOptions = new JsonSerializerOptions()
{
PropertyNamingPolicy = JsonNamingPolicy.CamelCase
};
JsonSerializer = jsonSerializer;
}
public async Task<Dictionary<string, TDto>> GetMultipleAsync(
@ -71,7 +68,7 @@ public abstract class AggregateRemoteServiceBase<TDto> : IAggregateRemoteService
response.EnsureSuccessStatusCode();
var content = await response.Content.ReadAsStringAsync();
return JsonSerializer.Deserialize<T>(content, JsonSerializerOptions);
return JsonSerializer.Deserialize<T>(content);
}
catch (Exception e)
{

5
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<ApplicationLocalizationDto>,
ILocalizationRemoteService, ITransientDependency
{
public LocalizationRemoteService(ILogger<AggregateRemoteServiceBase<ApplicationLocalizationDto>> logger) :
base(logger)
public LocalizationRemoteService(ILogger<AggregateRemoteServiceBase<ApplicationLocalizationDto>> logger, IJsonSerializer jsonSerializer) :
base(logger, jsonSerializer)
{
}
}

41
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<ILocalizationAggregation>();
var appConfigurationAggregation = context.RequestServices
.GetRequiredService<IAppConfigurationAggregation>();
var jsonSerializer = context.RequestServices.GetRequiredService<IJsonSerializer>();
// 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<IAppConfigurationAggregation>();
// 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();
});

Loading…
Cancel
Save