/// <summary> /// Add Configuration DbContext to the DI system. /// </summary> /// <typeparam name="TContext">The IConfigurationDbContext to use.</typeparam> /// <param name="services"></param> /// <param name="storeOptionsAction">The store options action.</param> /// <returns></returns> public static IServiceCollection AddConfigurationDbContext <TContext>(this IServiceCollection services, Action <ApplicationStoreOptions> storeOptionsAction = null) where TContext : DbContext, IApplicationDbContext { var options = new ApplicationStoreOptions(); services.AddSingleton(options); storeOptionsAction?.Invoke(options); if (options.ResolveDbContextOptions != null) { services.AddDbContext <TContext>(options.ResolveDbContextOptions); } else { services.AddDbContext <TContext>(dbCtxBuilder => { options.ConfigureDbContext?.Invoke(dbCtxBuilder); }); } services.AddScoped <IApplicationDbContext, TContext>(); return(services); }
/// <summary> /// Initializes a new instance of the <see cref="ConfigurationDbContext"/> class. /// </summary> /// <param name="options">The options.</param> /// <param name="storeOptions">The store options.</param> /// <exception cref="ArgumentNullException">storeOptions</exception> public ApplicationDbContext(DbContextOptions <ApplicationDbContext> options, ApplicationStoreOptions storeOptions) : base(options, storeOptions) { }