基礎設施層的配置之一
客戶管理配置.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實體有紅色警告
例外:
當前背景關系中不存在名稱“服務”
uj5u.com熱心網友回復:
服務集合可通過WebApplicationBuilder的Services屬性獲得:
CustomerManagementConfigure.Configure(builder.Services, conString);
ProductManagementConfigure.Configure(builder.Services, conString);
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/408717.html
標籤:
