Пример #1
0
        private InventoryEventRepository InvokeInventoryEventRepository()
        {
            var eventsOptions = new DbContextOptionsBuilder <InventoryEventsDbContext>()
                                .UseSqlite(_eventsConnection)
                                .Options;

            // Create the schema in the database
            var dbEventsContext = new InventoryEventsDbContext(eventsOptions);

            dbEventsContext.Database.EnsureCreated();

            return(new InventoryEventRepository(dbEventsContext));
        }
        public static IServiceCollection AddApplicationServices(
            this IServiceCollection services, IConfiguration configuration)
        {
            var itemsOptions = new DbContextOptionsBuilder <InventoryItemsDbContext>()
                               .UseSqlite(new SqliteConnection(configuration.GetConnectionString("InventoryDbContext")))
                               .Options;

            // Create the schema in the database
            using (var dbContext = new InventoryItemsDbContext(itemsOptions))
            {
                dbContext.Database.EnsureCreated();
            }

            var eventsOptions = new DbContextOptionsBuilder <InventoryEventsDbContext>()
                                .UseSqlite(new SqliteConnection(configuration.GetConnectionString("InventoryDbContext")))
                                .Options;

            // Create the schema in the database
            using (var dbContext = new InventoryEventsDbContext(eventsOptions))
            {
                dbContext.Database.EnsureCreated();
            }

            // DbContexts
            services.AddDbContext <InventoryItemsDbContext>(options =>
                                                            options.UseSqlite(configuration.GetConnectionString("InventoryDbContext")));

            services.AddDbContext <InventoryItemsReadDbContext>(options =>
                                                                options.UseSqlite(configuration.GetConnectionString("InventoryDbContext")));
            services.AddDbContext <InventoryItemsWriteDbContext>(options =>
                                                                 options.UseSqlite(configuration.GetConnectionString("InventoryDbContext")));

            services.AddDbContext <InventoryEventsDbContext>(options =>
                                                             options.UseSqlite(configuration.GetConnectionString("InventoryDbContext")));

            // Repositories
            services.AddScoped <IInventoryEventRepository, InventoryEventRepository>();

            services.AddScoped <IInventoryReadRepository, InventoryReadRepository>();
            services.AddScoped <IInventoryWriteRepository, InventoryWriteRepository>();

            services.AddScoped <IInventoryRepository, InventoryRepository>();

            // Services
            services.AddScoped <IInventoryCommandHandler, InventoryCommandHandler>();

            services.AddScoped <IInventoryService, InventoryService>();

            return(services);
        }
Пример #3
0
        public void Initialize()
        {
            // In-memory database only exists while the connection is open
            _connection = new SqliteConnection("DataSource=:memory:");
            _connection.Open();

            var options = new DbContextOptionsBuilder <InventoryEventsDbContext>()
                          .UseSqlite(_connection)
                          .Options;

            // Create the schema in the database
            _dbContext = new InventoryEventsDbContext(options);
            _dbContext.Database.EnsureCreated();
        }
Пример #4
0
 public InventoryEventRepository(InventoryEventsDbContext dbContext)
 {
     _dbContext = dbContext;
 }