From f68ffefaa95b5f6595e02dde765016dd0119f612 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A9=99=E5=AD=90?= <454313500@qq.com> Date: Tue, 17 Jan 2023 17:50:15 +0800 Subject: [PATCH] =?UTF-8?q?BFS+=E5=80=92=E7=BD=AE=E9=81=8D=E5=8E=86?= =?UTF-8?q?=E5=AE=8C=E6=88=90=E6=A8=A1=E5=9D=97=E5=8C=96=E4=BE=9D=E8=B5=96?= =?UTF-8?q?=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../YiFrameworkCoreAutoMapperModule.cs | 5 + .../Extensions/AutoFacModuleExtensions.cs | 1 + .../Attributes/DependsOnAttribute.cs | 25 +++ .../Extensions/ModuleExtensions.cs | 166 +----------------- .../Yi.Framework.Core/Module/ModuleManager.cs | 83 +++++++++ .../Yi.Framework.Core.csproj | 6 - .../Yi.Framework.Ddd/YiFrameworkDddModule.cs | 5 + .../YiFrameworkCachingMemoryCacheModule.cs | 5 + .../YiFrameworkCachingRedisModule.cs | 6 +- .../YiFrameworkOfficeExcelModule.cs | 5 + .../Domain/IPayManager.cs | 2 +- .../Domain/PayManager.cs | 6 +- .../Extensions/PayServiceExtensions.cs | 4 +- .../YiFrameworkWeChatPayModule.cs | 5 + .../YiFrameworkApplicationContractsModule.cs | 5 + .../YiFrameworkApplicationModule.cs | 7 + .../YiFrameworkDomainSharedModule.cs | 7 +- .../YiFrameworkDomainModule.cs | 5 + .../YiFrameworkSqlsugarModule.cs | 5 + .../test/Yi.Framework.Web/Program.cs | 30 +--- .../test/Yi.Framework.Web/TimeTest.txt | 4 + .../Yi.Framework.Web/YiFrameworkWebModule.cs | 8 + 22 files changed, 192 insertions(+), 203 deletions(-) create mode 100644 Yi.Framework.Net6/src/framework/Yi.Framework.Core/Attributes/DependsOnAttribute.cs create mode 100644 Yi.Framework.Net6/src/framework/Yi.Framework.Core/Module/ModuleManager.cs diff --git a/Yi.Framework.Net6/src/framework/Yi.Framework.Core.AutoMapper/YiFrameworkCoreAutoMapperModule.cs b/Yi.Framework.Net6/src/framework/Yi.Framework.Core.AutoMapper/YiFrameworkCoreAutoMapperModule.cs index 8a222cf7..25c819b2 100644 --- a/Yi.Framework.Net6/src/framework/Yi.Framework.Core.AutoMapper/YiFrameworkCoreAutoMapperModule.cs +++ b/Yi.Framework.Net6/src/framework/Yi.Framework.Core.AutoMapper/YiFrameworkCoreAutoMapperModule.cs @@ -2,11 +2,16 @@ using Microsoft.Extensions.DependencyInjection; using StartupModules; using Yi.Framework.Autofac.Extensions; +using Yi.Framework.Core.Attributes; namespace Yi.Framework.Core.AutoMapper { + [DependsOn( + typeof(YiFrameworkCoreModule) + )] public class YiFrameworkCoreAutoMapperModule : IStartupModule { + public void Configure(IApplicationBuilder app, ConfigureMiddlewareContext context) { } diff --git a/Yi.Framework.Net6/src/framework/Yi.Framework.Core.Autofac/Extensions/AutoFacModuleExtensions.cs b/Yi.Framework.Net6/src/framework/Yi.Framework.Core.Autofac/Extensions/AutoFacModuleExtensions.cs index 739f9d2e..266a1b78 100644 --- a/Yi.Framework.Net6/src/framework/Yi.Framework.Core.Autofac/Extensions/AutoFacModuleExtensions.cs +++ b/Yi.Framework.Net6/src/framework/Yi.Framework.Core.Autofac/Extensions/AutoFacModuleExtensions.cs @@ -23,6 +23,7 @@ namespace Yi.Framework.Core.Autofac.Extensions switch (autoFacModuleEnum) { case AutoFacModuleEnum.PropertiesAutowiredModule: + Console.WriteLine($"意框架添加AutoFac模块:{nameof(PropertiesAutowiredModule)}-属性注入模块"); new PropertiesAutowiredModule().Load(builder, assemblies); break; } diff --git a/Yi.Framework.Net6/src/framework/Yi.Framework.Core/Attributes/DependsOnAttribute.cs b/Yi.Framework.Net6/src/framework/Yi.Framework.Core/Attributes/DependsOnAttribute.cs new file mode 100644 index 00000000..085dbcc9 --- /dev/null +++ b/Yi.Framework.Net6/src/framework/Yi.Framework.Core/Attributes/DependsOnAttribute.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Yi.Framework.Core.Attributes +{ + [AttributeUsage(AttributeTargets.Class, AllowMultiple = true)] + public class DependsOnAttribute : Attribute + { + public Type[] DependedTypes { get; } + + public DependsOnAttribute(params Type[] dependedTypes) + { + DependedTypes = dependedTypes ?? new Type[0]; + } + + public virtual Type[] GetDependedTypes() + { + return DependedTypes; + } + } + +} diff --git a/Yi.Framework.Net6/src/framework/Yi.Framework.Core/Extensions/ModuleExtensions.cs b/Yi.Framework.Net6/src/framework/Yi.Framework.Core/Extensions/ModuleExtensions.cs index e991ca57..0f0e3d64 100644 --- a/Yi.Framework.Net6/src/framework/Yi.Framework.Core/Extensions/ModuleExtensions.cs +++ b/Yi.Framework.Net6/src/framework/Yi.Framework.Core/Extensions/ModuleExtensions.cs @@ -10,6 +10,7 @@ using System.Linq; using System.Reflection; using System.Text; using System.Threading.Tasks; +using Yi.Framework.Core.Module; namespace Yi.Framework.Core.Extensions { @@ -19,172 +20,17 @@ namespace Yi.Framework.Core.Extensions /// public static class ModuleExtensions { - // - // 摘要: - // Configures startup modules and automatically discovers StartupModules.IStartupModule's - // from the applications entry assembly. - // - // 参数: - // builder: - // The Microsoft.AspNetCore.Hosting.IWebHostBuilder instance. - // - // 返回结果: - // The Microsoft.AspNetCore.Hosting.IWebHostBuilder instance. - public static IWebHostBuilder UseYiModules(this IWebHostBuilder builder) + public static WebApplicationBuilder UseYiModules(this WebApplicationBuilder builder, Type startType) { - return builder.UseStartupModules(delegate (StartupModulesOptions options) - { - options.DiscoverStartupModules(); - }); - } - - // - // 摘要: - // Configures startup modules and automatically discovers StartupModules.IStartupModule's - // from the specified assemblies. - // - // 参数: - // builder: - // The Microsoft.AspNetCore.Hosting.IWebHostBuilder instance. - // - // assemblies: - // The assemblies to discover startup modules from. - // - // 返回结果: - // The Microsoft.AspNetCore.Hosting.IWebHostBuilder instance. - public static IWebHostBuilder UseYiModules(this IWebHostBuilder builder, params Assembly[] assemblies) - { - Assembly[] assemblies2 = assemblies; + var moduleManager = new ModuleManager(startType); + moduleManager.Invoker(); + + Assembly[] assemblies2 = moduleManager.ToAssemblyArray(); return builder.UseStartupModules(delegate (StartupModulesOptions options) { options.DiscoverStartupModules(assemblies2); }); } - - // - // 摘要: - // Configures startup modules with the specified configuration for StartupModules.StartupModulesOptions. - // - // 参数: - // builder: - // The Microsoft.AspNetCore.Hosting.IWebHostBuilder instance. - // - // configure: - // A callback to configure StartupModules.StartupModulesOptions. - // - // 返回结果: - // The Microsoft.AspNetCore.Hosting.IWebHostBuilder instance. - public static IWebHostBuilder UseYiModules(this IWebHostBuilder builder, Action configure) - { - Action configure2 = configure; - return builder.ConfigureServices(delegate (WebHostBuilderContext hostContext, IServiceCollection services) - { - services.AddStartupModules(hostContext.Configuration, hostContext.HostingEnvironment, configure2); - }); - } - - // - // 摘要: - // Configures startup modules with the specified configuration for StartupModules.StartupModulesOptions. - // - // 参数: - // builder: - // The Microsoft.AspNetCore.Builder.WebApplicationBuilder instance. - // - // 返回结果: - // The Microsoft.AspNetCore.Builder.WebApplicationBuilder instance. - public static WebApplicationBuilder UseYiModules(this WebApplicationBuilder builder) - { - return builder.UseStartupModules(delegate (StartupModulesOptions options) - { - options.DiscoverStartupModules(); - }); - } - - // - // 摘要: - // Configures startup modules with the specified configuration for StartupModules.StartupModulesOptions. - // - // 参数: - // builder: - // The Microsoft.AspNetCore.Builder.WebApplicationBuilder instance. - // - // assemblies: - // The assemblies to discover startup modules from. - // - // 返回结果: - // The Microsoft.AspNetCore.Builder.WebApplicationBuilder instance. - public static WebApplicationBuilder UseYiModules(this WebApplicationBuilder builder, params Assembly[] assemblies) - { - Assembly[] assemblies2 = assemblies; - return builder.UseStartupModules(delegate (StartupModulesOptions options) - { - options.DiscoverStartupModules(assemblies2); - }); - } - - // - // 摘要: - // Configures startup modules with the specified configuration for StartupModules.StartupModulesOptions. - // - // 参数: - // builder: - // The Microsoft.AspNetCore.Builder.WebApplicationBuilder instance. - // - // configure: - // A callback to configure StartupModules.StartupModulesOptions. - // - // 返回结果: - // The Microsoft.AspNetCore.Builder.WebApplicationBuilder instance. - public static WebApplicationBuilder UseYiModules(this WebApplicationBuilder builder, Action configure) - { - builder.Services.AddStartupModules(builder.Configuration, builder.Environment, configure); - return builder; - } - - // - // 摘要: - // Configures startup modules with the specified configuration for StartupModules.StartupModulesOptions. - // - // 参数: - // services: - // The service collection to add the StartupModules services to. - // - // configuration: - // The application's configuration. - // - // environment: - // The application's environment information. - // - // configure: - // A callback to configure StartupModules.StartupModulesOptions. - public static void AddYiModules(this IServiceCollection services, IConfiguration configuration, IWebHostEnvironment environment, Action configure) - { - if (services == null) - { - throw new ArgumentNullException("services"); - } - - if (configuration == null) - { - throw new ArgumentNullException("configuration"); - } - - if (environment == null) - { - throw new ArgumentNullException("environment"); - } - - StartupModulesOptions startupModulesOptions = new StartupModulesOptions(); - configure(startupModulesOptions); - if (startupModulesOptions.StartupModules.Count != 0 || startupModulesOptions.ApplicationInitializers.Count != 0) - { - StartupModuleRunner runner = new StartupModuleRunner(startupModulesOptions); - services.AddSingleton((Func)((IServiceProvider sp) => ActivatorUtilities.CreateInstance(sp, new object[1] { runner }))); - new ConfigureServicesContext(configuration, environment, startupModulesOptions); - runner.ConfigureServices(services, configuration, environment); - } - } } } diff --git a/Yi.Framework.Net6/src/framework/Yi.Framework.Core/Module/ModuleManager.cs b/Yi.Framework.Net6/src/framework/Yi.Framework.Core/Module/ModuleManager.cs new file mode 100644 index 00000000..7886a9b4 --- /dev/null +++ b/Yi.Framework.Net6/src/framework/Yi.Framework.Core/Module/ModuleManager.cs @@ -0,0 +1,83 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; +using System.Text; +using System.Threading.Tasks; +using Yi.Framework.Core.Attributes; + +namespace Yi.Framework.Core.Module +{ + + internal class ModuleManager + { + private List ResultType = new List(); + private Type StartType; + public ModuleManager(Type startType) + { + StartType = startType; + } + + public List Invoker() + { + StartBFSNodes(StartType); + var result= RemoveDuplicate(ResultType); + + foreach (var r in result) + { + + Console.WriteLine($"意框架正在加载模块:{r.Name}"); + } + return result; + } + + private Type[]? GetDependsOnType(Type type) + { + var dependsOnbuild = type.GetCustomAttributes(typeof(DependsOnAttribute), false).FirstOrDefault() as DependsOnAttribute; + if (dependsOnbuild is null) + { + return new Type[0]; + } + return dependsOnbuild.GetDependedTypes(); + + } + + private void StartBFSNodes(Type node) + { + ResultType.Add(node); + var nodes = GetDependsOnType(node); + if (nodes is not null && nodes.Count() != 0) + { + foreach (var n in nodes) + { + StartBFSNodes(n); + } + } + } + + private List RemoveDuplicate(List array) + { + HashSet s = new HashSet(); + List list = new List(); + for (int i = array.Count - 1; i >= 0; i--) + { + if (!s.Contains(array[i])) + { + s.Add(array[i]); + list.Add(array[i]); + } + } + ResultType = list; + return list; + } + + public List ToAssemblyList() + { + return ResultType.Select(a => a.Assembly).ToList(); + } + public Assembly[] ToAssemblyArray() + { + return ResultType.Select(a => a.Assembly).ToArray(); + } + } +} diff --git a/Yi.Framework.Net6/src/framework/Yi.Framework.Core/Yi.Framework.Core.csproj b/Yi.Framework.Net6/src/framework/Yi.Framework.Core/Yi.Framework.Core.csproj index 5905072b..c90edd5b 100644 --- a/Yi.Framework.Net6/src/framework/Yi.Framework.Core/Yi.Framework.Core.csproj +++ b/Yi.Framework.Net6/src/framework/Yi.Framework.Core/Yi.Framework.Core.csproj @@ -6,12 +6,6 @@ enable - - - - - - diff --git a/Yi.Framework.Net6/src/framework/Yi.Framework.Ddd/YiFrameworkDddModule.cs b/Yi.Framework.Net6/src/framework/Yi.Framework.Ddd/YiFrameworkDddModule.cs index 3de4b32e..8f74be6e 100644 --- a/Yi.Framework.Net6/src/framework/Yi.Framework.Ddd/YiFrameworkDddModule.cs +++ b/Yi.Framework.Net6/src/framework/Yi.Framework.Ddd/YiFrameworkDddModule.cs @@ -6,9 +6,14 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using Yi.Framework.Core.Attributes; +using Yi.Framework.Core.AutoMapper; namespace Yi.Framework.Ddd { + [DependsOn( + typeof(YiFrameworkCoreAutoMapperModule) + )] public class YiFrameworkDddModule:IStartupModule { public void Configure(IApplicationBuilder app, ConfigureMiddlewareContext context) diff --git a/Yi.Framework.Net6/src/module/Yi.Framework.Caching.MemoryCache/YiFrameworkCachingMemoryCacheModule.cs b/Yi.Framework.Net6/src/module/Yi.Framework.Caching.MemoryCache/YiFrameworkCachingMemoryCacheModule.cs index d4dc5ea7..83076f1f 100644 --- a/Yi.Framework.Net6/src/module/Yi.Framework.Caching.MemoryCache/YiFrameworkCachingMemoryCacheModule.cs +++ b/Yi.Framework.Net6/src/module/Yi.Framework.Caching.MemoryCache/YiFrameworkCachingMemoryCacheModule.cs @@ -8,9 +8,14 @@ using System.Text; using System.Threading.Tasks; using Yi.Framework.Caching.MemoryCache; using Yi.Framework.Caching; +using Yi.Framework.Core.Attributes; +using Yi.Framework.Core; namespace Yi.Framework.Ddd { + [DependsOn( + typeof(YiFrameworkCoreModule) + )] public class YiFrameworkCachingMemoryCacheModule:IStartupModule { public void Configure(IApplicationBuilder app, ConfigureMiddlewareContext context) diff --git a/Yi.Framework.Net6/src/module/Yi.Framework.Caching.Redis/YiFrameworkCachingRedisModule.cs b/Yi.Framework.Net6/src/module/Yi.Framework.Caching.Redis/YiFrameworkCachingRedisModule.cs index a965ddb9..c576fadb 100644 --- a/Yi.Framework.Net6/src/module/Yi.Framework.Caching.Redis/YiFrameworkCachingRedisModule.cs +++ b/Yi.Framework.Net6/src/module/Yi.Framework.Caching.Redis/YiFrameworkCachingRedisModule.cs @@ -1,11 +1,15 @@ using Microsoft.AspNetCore.Builder; using Microsoft.Extensions.DependencyInjection; using StartupModules; +using Yi.Framework.Core; +using Yi.Framework.Core.Attributes; using Yi.Framework.Core.Configuration; namespace Yi.Framework.Caching.Redis { - + [DependsOn( + typeof(YiFrameworkCoreModule) + )] public class YiFrameworkCachingRedisModule : IStartupModule { public void Configure(IApplicationBuilder app, ConfigureMiddlewareContext context) diff --git a/Yi.Framework.Net6/src/module/Yi.Framework.Office.Excel/YiFrameworkOfficeExcelModule.cs b/Yi.Framework.Net6/src/module/Yi.Framework.Office.Excel/YiFrameworkOfficeExcelModule.cs index 61c93edf..8bf54446 100644 --- a/Yi.Framework.Net6/src/module/Yi.Framework.Office.Excel/YiFrameworkOfficeExcelModule.cs +++ b/Yi.Framework.Net6/src/module/Yi.Framework.Office.Excel/YiFrameworkOfficeExcelModule.cs @@ -6,9 +6,14 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using Yi.Framework.Core; +using Yi.Framework.Core.Attributes; namespace Yi.Framework.Office.Excel { + [DependsOn( + typeof(YiFrameworkCoreModule) + )] public class YiFrameworkOfficeExcelModule : IStartupModule { public void Configure(IApplicationBuilder app, ConfigureMiddlewareContext context) diff --git a/Yi.Framework.Net6/src/module/Yi.Framework.WeChatPay/Domain/IPayManager.cs b/Yi.Framework.Net6/src/module/Yi.Framework.WeChatPay/Domain/IPayManager.cs index 7ae701ad..d4014eeb 100644 --- a/Yi.Framework.Net6/src/module/Yi.Framework.WeChatPay/Domain/IPayManager.cs +++ b/Yi.Framework.Net6/src/module/Yi.Framework.WeChatPay/Domain/IPayManager.cs @@ -8,7 +8,7 @@ using Yi.Framework.WeChatPay.Helper; namespace Yi.Framework.WeChatPay.Domain { - public interface IPayInvoker + public interface IPayManager { /// /// 获取WX支付链接的方法 diff --git a/Yi.Framework.Net6/src/module/Yi.Framework.WeChatPay/Domain/PayManager.cs b/Yi.Framework.Net6/src/module/Yi.Framework.WeChatPay/Domain/PayManager.cs index aceafbde..901e1843 100644 --- a/Yi.Framework.Net6/src/module/Yi.Framework.WeChatPay/Domain/PayManager.cs +++ b/Yi.Framework.Net6/src/module/Yi.Framework.WeChatPay/Domain/PayManager.cs @@ -11,13 +11,13 @@ using Yi.Framework.WeChatPay.Options; namespace Yi.Framework.WeChatPay.Domain { - public class PayInvoker : IPayInvoker + public class PayManager : IPayManager { private readonly PayHelper _payHelper; - private readonly ILogger _logger; + private readonly ILogger _logger; private readonly AbstractNotify _notify; - public PayInvoker(PayHelper payHelper, ILogger logger, AbstractNotify notify) + public PayManager(PayHelper payHelper, ILogger logger, AbstractNotify notify) { _payHelper = payHelper; _logger = logger; diff --git a/Yi.Framework.Net6/src/module/Yi.Framework.WeChatPay/Extensions/PayServiceExtensions.cs b/Yi.Framework.Net6/src/module/Yi.Framework.WeChatPay/Extensions/PayServiceExtensions.cs index 7a6bb2da..f8451a7e 100644 --- a/Yi.Framework.Net6/src/module/Yi.Framework.WeChatPay/Extensions/PayServiceExtensions.cs +++ b/Yi.Framework.Net6/src/module/Yi.Framework.WeChatPay/Extensions/PayServiceExtensions.cs @@ -40,8 +40,8 @@ namespace Yi.Framework.WeChatPay.Extensions throw new PayException("NotifyUrl为空值"); } services.AddSingleton(option); - services.AddTransient(); - services.AddTransient(); + services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); diff --git a/Yi.Framework.Net6/src/module/Yi.Framework.WeChatPay/YiFrameworkWeChatPayModule.cs b/Yi.Framework.Net6/src/module/Yi.Framework.WeChatPay/YiFrameworkWeChatPayModule.cs index 303aa678..1a85048b 100644 --- a/Yi.Framework.Net6/src/module/Yi.Framework.WeChatPay/YiFrameworkWeChatPayModule.cs +++ b/Yi.Framework.Net6/src/module/Yi.Framework.WeChatPay/YiFrameworkWeChatPayModule.cs @@ -1,12 +1,17 @@ using Microsoft.AspNetCore.Builder; using Microsoft.Extensions.DependencyInjection; using StartupModules; +using Yi.Framework.Core; +using Yi.Framework.Core.Attributes; using Yi.Framework.Core.Configuration; using Yi.Framework.WeChatPay.Extensions; using Yi.Framework.WeChatPay.Options; namespace Yi.Framework.WeChatPay { + [DependsOn( + typeof(YiFrameworkCoreModule) + )] public class YiFrameworkWeChatPayModule : IStartupModule { public void Configure(IApplicationBuilder app, ConfigureMiddlewareContext context) diff --git a/Yi.Framework.Net6/test/Yi.Framework.Application.Contracts/YiFrameworkApplicationContractsModule.cs b/Yi.Framework.Net6/test/Yi.Framework.Application.Contracts/YiFrameworkApplicationContractsModule.cs index 74067ff9..c7250f61 100644 --- a/Yi.Framework.Net6/test/Yi.Framework.Application.Contracts/YiFrameworkApplicationContractsModule.cs +++ b/Yi.Framework.Net6/test/Yi.Framework.Application.Contracts/YiFrameworkApplicationContractsModule.cs @@ -6,9 +6,14 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using Yi.Framework.Core.Attributes; +using Yi.Framework.Domain.Shared; namespace Yi.Framework.Application.Contracts { + [DependsOn( + typeof(YiFrameworkDomainSharedModule) + )] public class YiFrameworkApplicationContractsModule : IStartupModule { public void Configure(IApplicationBuilder app, ConfigureMiddlewareContext context) diff --git a/Yi.Framework.Net6/test/Yi.Framework.Application/YiFrameworkApplicationModule.cs b/Yi.Framework.Net6/test/Yi.Framework.Application/YiFrameworkApplicationModule.cs index 3dc3333d..848404ec 100644 --- a/Yi.Framework.Net6/test/Yi.Framework.Application/YiFrameworkApplicationModule.cs +++ b/Yi.Framework.Net6/test/Yi.Framework.Application/YiFrameworkApplicationModule.cs @@ -6,11 +6,18 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using Yi.Framework.Application.Contracts; using Yi.Framework.Application.Contracts.Student; using Yi.Framework.Application.Student; +using Yi.Framework.Core.Attributes; +using Yi.Framework.Domain; namespace Yi.Framework.Application { + [DependsOn( + typeof(YiFrameworkApplicationContractsModule), + typeof(YiFrameworkDomainModule) + )] public class YiFrameworkApplicationModule : IStartupModule { public void Configure(IApplicationBuilder app, ConfigureMiddlewareContext context) diff --git a/Yi.Framework.Net6/test/Yi.Framework.Domain.Shared/YiFrameworkDomainSharedModule.cs b/Yi.Framework.Net6/test/Yi.Framework.Domain.Shared/YiFrameworkDomainSharedModule.cs index 437b87fa..c7dc7f45 100644 --- a/Yi.Framework.Net6/test/Yi.Framework.Domain.Shared/YiFrameworkDomainSharedModule.cs +++ b/Yi.Framework.Net6/test/Yi.Framework.Domain.Shared/YiFrameworkDomainSharedModule.cs @@ -6,10 +6,15 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using Yi.Framework.Core.Attributes; +using Yi.Framework.Ddd; namespace Yi.Framework.Domain.Shared { - public class YiFrameworkDomainSharedModule : IStartupModule + [DependsOn( + typeof(YiFrameworkDddModule) + )] + public class YiFrameworkDomainSharedModule : IStartupModule { public void Configure(IApplicationBuilder app, ConfigureMiddlewareContext context) { diff --git a/Yi.Framework.Net6/test/Yi.Framework.Domain/YiFrameworkDomainModule.cs b/Yi.Framework.Net6/test/Yi.Framework.Domain/YiFrameworkDomainModule.cs index 7e8ee6e5..40eab39a 100644 --- a/Yi.Framework.Net6/test/Yi.Framework.Domain/YiFrameworkDomainModule.cs +++ b/Yi.Framework.Net6/test/Yi.Framework.Domain/YiFrameworkDomainModule.cs @@ -6,10 +6,15 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using Yi.Framework.Core.Attributes; +using Yi.Framework.Domain.Shared; using Yi.Framework.Domain.Student; namespace Yi.Framework.Domain { + [DependsOn( + typeof(YiFrameworkDomainSharedModule) + )] public class YiFrameworkDomainModule : IStartupModule { public void Configure(IApplicationBuilder app, ConfigureMiddlewareContext context) diff --git a/Yi.Framework.Net6/test/Yi.Framework.Sqlsugar/YiFrameworkSqlsugarModule.cs b/Yi.Framework.Net6/test/Yi.Framework.Sqlsugar/YiFrameworkSqlsugarModule.cs index 169c09fc..68cc8bc9 100644 --- a/Yi.Framework.Net6/test/Yi.Framework.Sqlsugar/YiFrameworkSqlsugarModule.cs +++ b/Yi.Framework.Net6/test/Yi.Framework.Sqlsugar/YiFrameworkSqlsugarModule.cs @@ -6,11 +6,16 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using Yi.Framework.Core.Attributes; +using Yi.Framework.Core.Sqlsugar; +using Yi.Framework.Domain; using Yi.Framework.Domain.Student.IRepository; using Yi.Framework.Sqlsugar.Student; namespace Yi.Framework.Sqlsugar { + [DependsOn(typeof(YiFrameworkCoreSqlsugarModule), + typeof(YiFrameworkDomainModule))] public class YiFrameworkSqlsugarModule : IStartupModule { public void Configure(IApplicationBuilder app, ConfigureMiddlewareContext context) diff --git a/Yi.Framework.Net6/test/Yi.Framework.Web/Program.cs b/Yi.Framework.Net6/test/Yi.Framework.Web/Program.cs index 5000369f..00002dfa 100644 --- a/Yi.Framework.Net6/test/Yi.Framework.Web/Program.cs +++ b/Yi.Framework.Net6/test/Yi.Framework.Web/Program.cs @@ -1,15 +1,6 @@ -using Yi.Framework.Application; -using Yi.Framework.Application.Contracts; -using Yi.Framework.Core; using Yi.Framework.Core.Autofac.Extensions; using Yi.Framework.Core.Autofac.Modules; -using Yi.Framework.Core.AutoMapper; using Yi.Framework.Core.Extensions; -using Yi.Framework.Core.Sqlsugar; -using Yi.Framework.Ddd; -using Yi.Framework.Domain; -using Yi.Framework.Domain.Shared; -using Yi.Framework.Sqlsugar; using Yi.Framework.Web; TimeTest.Start(); @@ -18,21 +9,7 @@ var builder = WebApplication.CreateBuilder(args); builder.WebHost.UseUrls(builder.Configuration.GetValue("StartUrl")); //ģ -builder.UseYiModules( - typeof(YiFrameworkCoreModule).Assembly, - typeof(YiFrameworkCoreAutoMapperModule).Assembly, - typeof(YiFrameworkDddModule).Assembly, - typeof(YiFrameworkCoreSqlsugarModule).Assembly, - - typeof(YiFrameworkSqlsugarModule).Assembly, - typeof(YiFrameworkDomainSharedModule).Assembly, - typeof(YiFrameworkDomainModule).Assembly, - typeof(YiFrameworkApplicationContractsModule).Assembly, - typeof(YiFrameworkApplicationModule).Assembly, - typeof(YiFrameworkWebModule).Assembly - - ); - +builder.UseYiModules(typeof(YiFrameworkWebModule)); //autofacģ,Ҫģ builder.Host.ConfigureAutoFacContainer(container => @@ -46,9 +23,4 @@ var app = builder.Build(); var t = app.Services.GetService(); app.MapControllers(); - - - - - app.Run(); diff --git a/Yi.Framework.Net6/test/Yi.Framework.Web/TimeTest.txt b/Yi.Framework.Net6/test/Yi.Framework.Web/TimeTest.txt index 9a4b2259..630f37ef 100644 --- a/Yi.Framework.Net6/test/Yi.Framework.Web/TimeTest.txt +++ b/Yi.Framework.Net6/test/Yi.Framework.Web/TimeTest.txt @@ -7,3 +7,7 @@ 2023:01:16-22:42:05本次运行启动时间为:2008毫秒 2023:01:16-22:43:22本次运行启动时间为:1910毫秒 2023:01:16-22:44:33本次运行启动时间为:2017毫秒 +2023:01:17-17:30:46本次运行启动时间为:23171毫秒 +2023:01:17-17:45:11本次运行启动时间为:4771毫秒 +2023:01:17-17:45:54本次运行启动时间为:1917毫秒 +2023:01:17-17:48:04本次运行启动时间为:2138毫秒 diff --git a/Yi.Framework.Net6/test/Yi.Framework.Web/YiFrameworkWebModule.cs b/Yi.Framework.Net6/test/Yi.Framework.Web/YiFrameworkWebModule.cs index 7e8267f7..44163f67 100644 --- a/Yi.Framework.Net6/test/Yi.Framework.Web/YiFrameworkWebModule.cs +++ b/Yi.Framework.Net6/test/Yi.Framework.Web/YiFrameworkWebModule.cs @@ -1,12 +1,20 @@ using AspNetCore.Microsoft.AspNetCore.Builder; using StartupModules; using Yi.Framework.Application; +using Yi.Framework.Core; +using Yi.Framework.Core.Attributes; +using Yi.Framework.Sqlsugar; namespace Yi.Framework.Web { /// /// 这里是最后执行的模块 /// + [DependsOn( + typeof(YiFrameworkCoreModule), + typeof(YiFrameworkSqlsugarModule), + typeof(YiFrameworkApplicationModule) + )] public class YiFrameworkWebModule : IStartupModule { public void ConfigureServices(IServiceCollection services, ConfigureServicesContext context)