From 4ecc17510e5104f5ddc297a709341ebd53a2f485 Mon Sep 17 00:00:00 2001 From: zpc Date: Sat, 24 Aug 2024 11:25:08 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E4=BA=A4=E7=89=88=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AppExtend/AppConfigExtendServer.cs | 31 ++++++++++++++++++ .../AppExtend/AppConfigurationExtend.cs | 1 + .../SysDictionary/DictionaryInfoExtend.cs | 32 +++++++++---------- src/2-api/HuanMeng.MiaoYu.WebApi/Program.cs | 12 ++----- .../HuanMeng.MiaoYu.WebPayApi.csproj | 3 ++ 5 files changed, 53 insertions(+), 26 deletions(-) create mode 100644 src/0-core/HuanMeng.MiaoYu.Code/AppExtend/AppConfigExtendServer.cs diff --git a/src/0-core/HuanMeng.MiaoYu.Code/AppExtend/AppConfigExtendServer.cs b/src/0-core/HuanMeng.MiaoYu.Code/AppExtend/AppConfigExtendServer.cs new file mode 100644 index 0000000..e45abb2 --- /dev/null +++ b/src/0-core/HuanMeng.MiaoYu.Code/AppExtend/AppConfigExtendServer.cs @@ -0,0 +1,31 @@ +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Hosting; + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace HuanMeng.MiaoYu.Code.AppExtend +{ + /// + /// + /// + /// + /// + public class AppConfigExtendServer(IDictionaryInfoServer dictionaryInfoServer, IServiceProvider serviceProvider) : IHostedService + { + public async Task StartAsync(CancellationToken cancellationToken) + { + //var x = serviceProvider.CreateScope(); + //注入数据字典 + await dictionaryInfoServer.Initialization(); + } + + public Task StopAsync(CancellationToken cancellationToken) + { + return Task.CompletedTask; + } + } +} diff --git a/src/0-core/HuanMeng.MiaoYu.Code/AppExtend/AppConfigurationExtend.cs b/src/0-core/HuanMeng.MiaoYu.Code/AppExtend/AppConfigurationExtend.cs index cf60873..f8da067 100644 --- a/src/0-core/HuanMeng.MiaoYu.Code/AppExtend/AppConfigurationExtend.cs +++ b/src/0-core/HuanMeng.MiaoYu.Code/AppExtend/AppConfigurationExtend.cs @@ -100,6 +100,7 @@ namespace HuanMeng.MiaoYu.Code.AppExtend ConfigurationManager = builder.Configuration; AppConfigInit(builder.Configuration); builder.Services.AddScoped(); + builder.Services.AddHostedService(); return builder; } diff --git a/src/0-core/HuanMeng.MiaoYu.Code/SysDictionary/DictionaryInfoExtend.cs b/src/0-core/HuanMeng.MiaoYu.Code/SysDictionary/DictionaryInfoExtend.cs index 184287a..a59871d 100644 --- a/src/0-core/HuanMeng.MiaoYu.Code/SysDictionary/DictionaryInfoExtend.cs +++ b/src/0-core/HuanMeng.MiaoYu.Code/SysDictionary/DictionaryInfoExtend.cs @@ -24,7 +24,7 @@ namespace HuanMeng.MiaoYu.Code.SysDictionary builder.Services.AddSingleton(); builder.Services.AddScoped(); - builder.Services.AddHostedService(); + //builder.Services.AddHostedService(); } @@ -62,21 +62,21 @@ namespace HuanMeng.MiaoYu.Code.SysDictionary } - /// - /// - /// - /// - public class DictionaryInfoExtendServer(IDictionaryInfoServer dictionaryInfoServer) : IHostedService - { - public async Task StartAsync(CancellationToken cancellationToken) - { - await dictionaryInfoServer.Initialization(); + ///// + ///// + ///// + ///// + //public class DictionaryInfoExtendServer(IDictionaryInfoServer dictionaryInfoServer) : IHostedService + //{ + // public async Task StartAsync(CancellationToken cancellationToken) + // { + // await dictionaryInfoServer.Initialization(); - } + // } - public Task StopAsync(CancellationToken cancellationToken) - { - return Task.CompletedTask; - } - } + // public Task StopAsync(CancellationToken cancellationToken) + // { + // return Task.CompletedTask; + // } + //} } diff --git a/src/2-api/HuanMeng.MiaoYu.WebApi/Program.cs b/src/2-api/HuanMeng.MiaoYu.WebApi/Program.cs index 2f32781..277b30b 100644 --- a/src/2-api/HuanMeng.MiaoYu.WebApi/Program.cs +++ b/src/2-api/HuanMeng.MiaoYu.WebApi/Program.cs @@ -89,16 +89,8 @@ builder.Services.AddControllers() #endif //options.SerializerSettings.Converters.Add() // 其他配置... -}) - ; -// .AddJsonOptions(options => -//{ -// //options.JsonSerializerOptions.ReferenceHandler = ReferenceHandler.Preserve; -// //options.JsonSerializerOptions.WriteIndented = true; -// options.JsonSerializerOptions.Converters.Add(new JsonStringEnumConverter()); -// //options.JsonSerializerOptions.PropertyNamingPolicy = null; -// options.JsonSerializerOptions.Converters.Add(new CustomDateTimeConverter("yyyy-MM-dd HH:mm:ss")); -//}); +}); + // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle builder.Services.AddEndpointsApiExplorer(); builder.Services.AddSwaggerGen(c => diff --git a/src/2-api/HuanMeng.MiaoYu.WebPayApi/HuanMeng.MiaoYu.WebPayApi.csproj b/src/2-api/HuanMeng.MiaoYu.WebPayApi/HuanMeng.MiaoYu.WebPayApi.csproj index 98fb5df..3171938 100644 --- a/src/2-api/HuanMeng.MiaoYu.WebPayApi/HuanMeng.MiaoYu.WebPayApi.csproj +++ b/src/2-api/HuanMeng.MiaoYu.WebPayApi/HuanMeng.MiaoYu.WebPayApi.csproj @@ -9,6 +9,9 @@ + + +