示例#1
0
        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);
        }
示例#3
0
        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);
        }
示例#4
0
 public CustomerRepository(CustomerPortalDbContext dbContext)
 {
     this.dbContext = dbContext;
 }
示例#5
0
 public CustomerRepository()
 {
     dbContext = new CustomerPortalDbContext();
 }