Пример #1
0
        public static IServiceCollection AddAppDbContext <TDbContext>(this IServiceCollection services, Action <DatabaseConfigOptions> configOptions)
            where TDbContext : DbContext
        {
            var dbOptions = new DatabaseConfigOptions();

            configOptions?.Invoke(dbOptions);

            if (!dbOptions.IsValid())
            {
                throw new ArgumentException("Database configuration is invalid");
            }

            services.AddDbContext <TDbContext>(options =>
                                               options.UseSqlServer(
                                                   dbOptions.BuildConnectionString(),
                                                   x => x.MigrationsHistoryTable("_EFMigrationsHistory", dbOptions.Schema)
                                                   )
                                               .EnableSensitiveDataLogging(dbOptions.IsSensitiveDataLoggingEnabled));

            return(services);
        }
Пример #2
0
        public static IServiceCollection AddAppDbContext <TDbContext>(this IServiceCollection services, Action <DatabaseConfigOptions> configOptions)
            where TDbContext : DbContext
        {
            var dbOptions = new DatabaseConfigOptions();

            configOptions?.Invoke(dbOptions);

            if (!dbOptions.IsValid())
            {
                throw new ArgumentException("Database configuration is invalid");
            }

            services.AddDbContext <TDbContext>(options =>
                                               options.UseMySQL(
                                                   dbOptions.BuildConnectionString()
                                                   // TODO check if mysql support that
                                                   //x => x.MigrationsHistoryTable("_EFMigrationsHistory", dbOptions.EntitySchema)
                                                   )
                                               );

            return(services);
        }