コード例 #1
0
ファイル: EventSourcing.cs プロジェクト: yta1/m-r-core-of
        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));
        }
コード例 #2
0
        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
ファイル: InventoryEvents.cs プロジェクト: yta1/m-r-core-of
        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;
 }