public static void Services(IServiceCollection services, IConfiguration configuration) { var marketListConfig = new MarketListConfiguration(); configuration.GetSection(nameof(MarketListConfiguration)).Bind(marketListConfig); services.AddScoped(typeof(IMarketListRepositoryAsync), typeof(MarketListRepositoryAsync)); services.AddScoped(typeof(IMarketListServiceAsync), typeof(MarketListServiceAsync)); services.AddScoped(typeof(IUnitOfWork), typeof(MarketListContext)); services.AddCustomDbContext(marketListConfig); }
public static IServiceCollection AddCustomDbContext(this IServiceCollection services, MarketListConfiguration configuration) { if (configuration == null) { throw new ArgumentNullException(nameof(configuration)); } services.AddEntityFrameworkSqlServer() .AddDbContext <MarketListContext>(options => { options .UseLazyLoadingProxies() .UseSqlServer(configuration.ConnectionString); }); return(services); }