using Autofac; using Autofac.Extensions.DependencyInjection; using DS.Module.AutofacModule; using DS.Module.PrintModule; using DS.Module.SqlSugar; using DS.Module.UserModule; using DS.Module.RedisModule; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; namespace Ds.WMS.Test; public class Startup { // 自定义 host 构建 public void ConfigureHost(IHostBuilder hostBuilder) { //hostBuilder.ConfigureAppConfiguration(builder => //{ // // 注册配置 // builder.AddInMemoryCollection(new Dictionary() // { // {"UserName", "Alice"} // }).AddJsonFile("appsettings.json"); //}) //.ConfigureServices((context, services) => //{ // // 注册自定义服务 // services.AddSingleton(); // if (context.Configuration.GetAppSetting("XxxEnabled")) // { // services.AddSingleton(); // } //}); //Autofac注入 hostBuilder .UseServiceProviderFactory(new AutofacServiceProviderFactory()) .ConfigureContainer(builder => { builder.RegisterModule(new AutofacModuleRegister()); }); } /// /// /// 支持的形式: /// ConfigureServices(IServiceCollection services) /// ConfigureServices(IServiceCollection services, HostBuilderContext hostBuilderContext) /// ConfigureServices(HostBuilderContext hostBuilderContext, IServiceCollection services) /// /// /// public void ConfigureServices(IServiceCollection services, HostBuilderContext hostBuilderContext) { // services.AddTransient(); services.AddUserModuleInstall(); //用户服务 services.AddRedisModuleInstall();//redis services.AddSqlSugarInstall(); services.AddSaasDbInstall(); services.AddPrintModuleInstall(); } /// /// 可以添加要用到的方法参数,会自动从注册的服务中获取服务实例,类似于 asp.net core 里 Configure 方法 /// /// public void Configure(IServiceProvider provider) { } }