One of configuration's in infrastructure layer
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);
this way doesn't working in .net6 i have red warn with IServiceCollection services
instance
exception: the name 'services' does not Exist in the current context
The service collection is available via the WebApplicationBuilder
's Services
property:
CustomerManagementConfigure.Configure(builder.Services, conString);
ProductManagementConfigure.Configure(builder.Services, conString);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.