public CustomerRepository() { var connection = Effort.DbConnectionFactory.CreateTransient(); dbContext = new CustomerPortalDbContext(connection); if (!dbContext.Customers.Any()) { dbContext.Seed(); } }
public void ConfigureServices(IServiceCollection services) { services.AddControllersWithViews(); var options = new DbContextOptionsBuilder <CustomerPortalDbContext>() .UseSqlServer(_configuration.GetConnectionString("CustomerPortalDb")) .Options; var context = new CustomerPortalDbContext(options); context.Database.EnsureCreated(); context.Seed(); services.AddSingleton(context); services.AddScoped <ICustomerRepository, CustomerRepository>(); services.AddSingleton(_configuration); }
public void ConfigureServices(IServiceCollection services) { services.AddControllersWithViews(); var connection = new SqliteConnection("DataSource=:memory:"); connection.Open(); var options = new DbContextOptionsBuilder <CustomerPortalDbContext>().UseSqlite(connection).Options; var context = new CustomerPortalDbContext(options); context.Database.EnsureCreated(); context.Seed(); services.AddSingleton(context); services.AddScoped <ICustomerRepository, CustomerRepository>(); services.AddSingleton(config); }
public CustomerRepository(CustomerPortalDbContext dbContext) { this.dbContext = dbContext; }
public CustomerRepository() { dbContext = new CustomerPortalDbContext(); }