/// <summary> /// Configures data access settings. /// </summary> /// <param name="services">The collection of application services.</param> /// <param name="connectionString">The database connection string.</param> public static void ConfigureServices(IServiceCollection services, string connectionString) { services.AddSingleton <IUnitOfWorkFactory, UnitOfWorkFactory>( (provider) => new UnitOfWorkFactory(connectionString)); services.AddScoped <IUnitOfWork, UnitOfWork>((provider) => { var context = ApplicationDatabaseContextFactory.CreateContext(connectionString); return(new UnitOfWork(context)); }); }
/// <summary> /// Initializes database. /// </summary> /// <param name="connectionString">The database connection string.</param> public static void InitializeDatabase(string connectionString) { using (var context = ApplicationDatabaseContextFactory.CreateContext(connectionString)) { #if DEBUG context.Database.EnsureDeleted(); #endif context.Database.Migrate(); InitializeData(context); context.SaveChanges(); } }