基础设施层的配置之一
客户管理配置.cs
public class CustomerManagementConfigure
{
public static void Configure(IServiceCollection services,string conString)
{
services.AddTransient<ICustomerApplication, CustomerApplication>();
services.AddTransient<ICustomerRepository, CustomerRepository>();
services.AddDbContext<DiscountContext>(x => x.UseSqlServer(conString));
}
}
程序.cs
var conString = builder.Configuration.GetConnectionString("CustomerDB");
CustomerManagementConfigure.Configure(services, conString);
ProductManagementConfigure.Configure(services, conString);
这种方式在 .NET 6 中不起作用。
IServiceCollection services
我对实例有红色警告
例外:
当前上下文中不存在名称“服务”