diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/Json/AbpHybridJsonInputFormatter.cs b/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/Json/AbpHybridJsonInputFormatter.cs index 52cd0c8d63..ce6036f71f 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/Json/AbpHybridJsonInputFormatter.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/Json/AbpHybridJsonInputFormatter.cs @@ -23,7 +23,7 @@ namespace Volo.Abp.AspNetCore.Mvc.Json return await GetTextInputFormatter(context).ReadRequestBodyAsync(context, encoding); } - private TextInputFormatter GetTextInputFormatter(InputFormatterContext context) + protected virtual TextInputFormatter GetTextInputFormatter(InputFormatterContext context) { var typesMatcher = context.HttpContext.RequestServices.GetRequiredService(); if (typesMatcher.Match(context.ModelType)) @@ -34,6 +34,6 @@ namespace Volo.Abp.AspNetCore.Mvc.Json return context.HttpContext.RequestServices.GetRequiredService(); } - public InputFormatterExceptionPolicy ExceptionPolicy => InputFormatterExceptionPolicy.MalformedInputExceptions; + public virtual InputFormatterExceptionPolicy ExceptionPolicy => InputFormatterExceptionPolicy.MalformedInputExceptions; } } diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/Json/AbpHybridJsonOutputFormatter.cs b/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/Json/AbpHybridJsonOutputFormatter.cs index e0537664da..d4f1d67f22 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/Json/AbpHybridJsonOutputFormatter.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/Json/AbpHybridJsonOutputFormatter.cs @@ -23,7 +23,7 @@ namespace Volo.Abp.AspNetCore.Mvc.Json await GetTextInputFormatter(context).WriteResponseBodyAsync(context, selectedEncoding); } - private TextOutputFormatter GetTextInputFormatter(OutputFormatterWriteContext context) + protected virtual TextOutputFormatter GetTextInputFormatter(OutputFormatterWriteContext context) { var typesMatcher = context.HttpContext.RequestServices.GetRequiredService(); if (typesMatcher.Match(context.ObjectType)) diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/Json/AbpMvcJsonContractResolver.cs b/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/Json/AbpMvcJsonContractResolver.cs index 2db8bc3f06..2021afd492 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/Json/AbpMvcJsonContractResolver.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/Json/AbpMvcJsonContractResolver.cs @@ -1,5 +1,6 @@ using System; using System.Reflection; +using Microsoft.Extensions.DependencyInjection; using Newtonsoft.Json; using Newtonsoft.Json.Serialization; using Volo.Abp.DependencyInjection; @@ -11,11 +12,14 @@ namespace Volo.Abp.AspNetCore.Mvc.Json { public class AbpMvcJsonContractResolver : DefaultContractResolver, ITransientDependency { - private readonly AbpJsonIsoDateTimeConverter _dateTimeConverter; + private readonly Lazy _dateTimeConverter; - public AbpMvcJsonContractResolver(AbpJsonIsoDateTimeConverter dateTimeConverter) + public AbpMvcJsonContractResolver(IServiceProvider serviceProvider) { - _dateTimeConverter = dateTimeConverter; + _dateTimeConverter = new Lazy( + serviceProvider.GetRequiredService, + true + ); NamingStrategy = new CamelCaseNamingStrategy(); } @@ -38,7 +42,7 @@ namespace Volo.Abp.AspNetCore.Mvc.Json if (ReflectionHelper.GetSingleAttributeOfMemberOrDeclaringTypeOrDefault(member) == null) { - property.Converter = _dateTimeConverter; + property.Converter = _dateTimeConverter.Value; } } } diff --git a/framework/src/Volo.Abp.Json/Volo/Abp/Json/AbpJsonModule.cs b/framework/src/Volo.Abp.Json/Volo/Abp/Json/AbpJsonModule.cs index 21d5b67241..8eb683c515 100644 --- a/framework/src/Volo.Abp.Json/Volo/Abp/Json/AbpJsonModule.cs +++ b/framework/src/Volo.Abp.Json/Volo/Abp/Json/AbpJsonModule.cs @@ -27,6 +27,11 @@ namespace Volo.Abp.Json { options.UnsupportedAttributes.Add(); }); + + Configure(options => + { + options.Converters.Add(); + }); } } }