using Microsoft.AspNetCore.Builder; using Microsoft.Extensions.DependencyInjection; namespace DS.Module.Core.Modules; public static class AppModuleExtensions { public static IServiceCollection AddApplication(this IServiceCollection services) where T : IDSAppModule { services.AddApplication(typeof(T)); return services; } private static IServiceCollection AddApplication(this IServiceCollection services, Type type) { if (services == null) { throw new ArgumentNullException(nameof(services)); } var obj = new ObjectAccessor(); services.Add(ServiceDescriptor.Singleton(typeof(ObjectAccessor), obj)); services.Add(ServiceDescriptor.Singleton(typeof(IObjectAccessor), obj)); IStartupModuleRunner runner = new StartupModuleRunner(type, services); runner.ConfigureServices(services); return services; } public static IApplicationBuilder InitializeApplication(this IApplicationBuilder builder) { builder.ApplicationServices.GetRequiredService>().Value = builder; var runner = builder.ApplicationServices.GetRequiredService(); runner.Initialize(builder.ApplicationServices); return builder; } }