在 ASP.NET Core 6 中添加 program.cs 中的配置服务
Add configuration services in program.cs in ASP.NET Core 6
基础设施层的配置之一
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));
}
}
program.cs
var conString = builder.Configuration.GetConnectionString("CustomerDB");
CustomerManagementConfigure.Configure(services, conString);
ProductManagementConfigure.Configure(services, conString);
这种方式在 .NET 6 中不起作用。
我有 IServiceCollection services
个实例的红色警告
异常:
The name 'services' does not Exist in the current context
服务集合可通过 WebApplicationBuilder
的 Services
属性:
CustomerManagementConfigure.Configure(builder.Services, conString);
ProductManagementConfigure.Configure(builder.Services, conString);
基础设施层的配置之一
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));
}
}
program.cs
var conString = builder.Configuration.GetConnectionString("CustomerDB");
CustomerManagementConfigure.Configure(services, conString);
ProductManagementConfigure.Configure(services, conString);
这种方式在 .NET 6 中不起作用。
我有 IServiceCollection services
个实例的红色警告
异常:
The name 'services' does not Exist in the current context
服务集合可通过 WebApplicationBuilder
的 Services
属性:
CustomerManagementConfigure.Configure(builder.Services, conString);
ProductManagementConfigure.Configure(builder.Services, conString);