Пример #1
0
        public DatabaseContext CreateDbContext(string[] args)
        {
            DbContextOptionsBuilder optionsBuilder = new DbContextOptionsBuilder();

            optionsBuilder.ConfigureCorrectDatabase();

            return(new DatabaseContext(optionsBuilder.Options));
        }
Пример #2
0
        public static IDatabase GetDatabase()
        {
            DbContextOptionsBuilder optionsBuilder = new DbContextOptionsBuilder();

            optionsBuilder.ConfigureCorrectDatabase();
            DatabaseContext databaseContext = new DatabaseContext(optionsBuilder.Options);

            return(new Database(databaseContext));
        }
Пример #3
0
        public DatabaseContext CreateDbContext(string[] args)
        {
            DbContextOptionsBuilder optionsBuilder = new DbContextOptionsBuilder();
            var dbConfig = ConfigurationHelper.Load <DatabaseConfiguration>("config/database.json");

            optionsBuilder.ConfigureCorrectDatabase(dbConfig);

            return(new DatabaseContext(optionsBuilder.Options));
        }
Пример #4
0
        /// <summary>
        /// Creates a database on the given database configuration.
        /// Lifetime should be managed by IOC framework if using any!
        /// </summary>
        /// <param name="configuration">The database configuration to use</param>
        /// <returns>A new instance of an IDatabase implementation</returns>
        public IDatabase GetDatabase(DatabaseConfiguration configuration)
        {
            var optionsBuilder = new DbContextOptionsBuilder();

            optionsBuilder.ConfigureCorrectDatabase(configuration);
            var databaseContext = new DatabaseContext(optionsBuilder.Options, configuration);

            return(new Database(databaseContext));
        }
Пример #5
0
        public static IDatabase GetDatabase()
        {
            DbContextOptionsBuilder optionsBuilder = new DbContextOptionsBuilder();
            var dbConfig = ConfigurationHelper.Load <DatabaseConfiguration>("config/database.json");

            optionsBuilder.ConfigureCorrectDatabase(dbConfig);
            DatabaseContext databaseContext = new DatabaseContext(optionsBuilder.Options);

            return(new Database(databaseContext));
        }
Пример #6
0
        /// <inheritdoc />
        public DatabaseContext CreateDbContext(string[] args)
        {
            var configurationPath = Environment.GetEnvironmentVariable(MigrationConfigurationEnv);
            var configuration     = ConfigurationHelper.Load <DatabaseConfiguration>(configurationPath);

            if (configuration == null)
            {
                throw new InvalidOperationException($"Cannot find database configuration path: '{configurationPath}'.");
            }

            DbContextOptionsBuilder optionsBuilder = new DbContextOptionsBuilder();

            optionsBuilder.ConfigureCorrectDatabase(configuration);
            return(new DatabaseContext(optionsBuilder.Options, configuration));
        }
Пример #7
0
        public DatabaseContext CreateDbContext(string[] args)
        {
            var configuration = new ConfigurationBuilder()
                                .SetBasePath(Directory.GetParent(AppContext.BaseDirectory).FullName)
                                .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
#if DEBUG
                                .AddJsonFile($"appsettings.Development.json", optional: true)
#else
                                .AddJsonFile($"appsettings.Release.json", optional: true)
#endif
                                .Build();

            var dbConfig = new DatabaseConfiguration();

            configuration.Bind("Database", dbConfig);

            var optionsBuilder = new DbContextOptionsBuilder();

            optionsBuilder.ConfigureCorrectDatabase(dbConfig);

            return(new DatabaseContext(optionsBuilder.Options));
        }