From dbf54b136e237021c6d6aa45c1ac8817e234dd06 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A9=99=E5=AD=90?= <454313500@qq.com> Date: Tue, 23 Nov 2021 03:14:31 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BE=AA=E7=8E=AF=E5=BC=95=E7=94=A8=E6=89=A9?= =?UTF-8?q?=E5=B1=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Yi.Framework.ApiMicroservice/Startup.cs | 3 ++- .../BuilderExtend/JsonExtension.cs | 22 +++++++++++++++++++ .../Yi.Framework.WebCore.csproj | 5 +++++ 3 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 Yi.Framework/Yi.Framework.WebCore/BuilderExtend/JsonExtension.cs diff --git a/Yi.Framework/Yi.Framework.ApiMicroservice/Startup.cs b/Yi.Framework/Yi.Framework.ApiMicroservice/Startup.cs index e7bab1a9..bde35395 100644 --- a/Yi.Framework/Yi.Framework.ApiMicroservice/Startup.cs +++ b/Yi.Framework/Yi.Framework.ApiMicroservice/Startup.cs @@ -6,6 +6,7 @@ using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Yi.Framework.Core; using Yi.Framework.Model.ModelFactory; +using Yi.Framework.WebCore.BuilderExtend; using Yi.Framework.WebCore.MiddlewareExtend; using Yi.Framework.WebCore.Utility; @@ -38,7 +39,7 @@ namespace Yi.Framework.ApiMicroservice #endregion services.AddControllers(optios=> { //optios.Filters.Add(typeof(CustomExceptionFilterAttribute)); - }); + }).AddJsonFileService(); #region //Swagger·þÎñÅäÖà diff --git a/Yi.Framework/Yi.Framework.WebCore/BuilderExtend/JsonExtension.cs b/Yi.Framework/Yi.Framework.WebCore/BuilderExtend/JsonExtension.cs new file mode 100644 index 00000000..ccf52354 --- /dev/null +++ b/Yi.Framework/Yi.Framework.WebCore/BuilderExtend/JsonExtension.cs @@ -0,0 +1,22 @@ +using Microsoft.Extensions.DependencyInjection; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Yi.Framework.WebCore.BuilderExtend +{ + public static class JsonExtension + { + public static void AddJsonFileService(this IMvcBuilder builder) + { + builder.AddNewtonsoftJson(options => + { + options.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore; + options.SerializerSettings.DateFormatString = "yyyy-MM-dd HH:mm"; + }); + + } + } +} diff --git a/Yi.Framework/Yi.Framework.WebCore/Yi.Framework.WebCore.csproj b/Yi.Framework/Yi.Framework.WebCore/Yi.Framework.WebCore.csproj index 396231b7..789419be 100644 --- a/Yi.Framework/Yi.Framework.WebCore/Yi.Framework.WebCore.csproj +++ b/Yi.Framework/Yi.Framework.WebCore/Yi.Framework.WebCore.csproj @@ -9,12 +9,17 @@ + + + + +