【发布时间】:2022-01-12 02:02:19
【问题描述】:
基础设施层的配置之一
CustomerManagementConfigure.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 实例有红色警告
例外:
名称“服务”在当前上下文中不存在
【问题讨论】:
标签: c# asp.net-core razor-pages asp.net-core-6.0