public static void Services(IServiceCollection services, IConfiguration configuration) { var productConfig = new ProductConfiguration(); configuration.GetSection(nameof(ProductConfiguration)).Bind(productConfig); services.AddScoped(typeof(IProductRepositoryAsync), typeof(ProductRepositoryAsync)); services.AddScoped(typeof(IProductServiceAsync), typeof(ProductServiceAsync)); services.AddScoped(typeof(IUnitOfWork), typeof(ProductContext)); services.AddCustomDbContext(productConfig); }
public static IServiceCollection AddCustomDbContext(this IServiceCollection services, ProductConfiguration configuration) { if (configuration == null) { throw new ArgumentNullException(nameof(configuration)); } services.AddEntityFrameworkSqlServer() .AddDbContext <ProductContext>(options => { options .UseLazyLoadingProxies() .UseSqlServer(configuration.ConnectionString); }); return(services); }