public MySuperStatsDbContext CreateDbContext(string[] args)
        {
            var builder = new DbContextOptionsBuilder <MySuperStatsDbContext>();

            /*
             * You can provide an environmentName parameter to the AppConfigurations.Get method.
             * In this case, AppConfigurations will try to read appsettings.{environmentName}.json.
             * Use Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") method or from string[] args to get environment if necessary.
             * https://docs.microsoft.com/en-us/ef/core/cli/dbcontext-creation?tabs=dotnet-core-cli#args
             */
            var configuration = AppConfigurations.Get(WebContentDirectoryFinder.CalculateContentRootFolder());

            MySuperStatsDbContextConfigurer.Configure(builder, configuration.GetConnectionString(MySuperStatsConsts.ConnectionStringName));

            return(new MySuperStatsDbContext(builder.Options));
        }
Exemple #2
0
 public override void PreInitialize()
 {
     if (!SkipDbContextRegistration)
     {
         Configuration.Modules.AbpEfCore().AddDbContext <MySuperStatsDbContext>(options =>
         {
             if (options.ExistingConnection != null)
             {
                 MySuperStatsDbContextConfigurer.Configure(options.DbContextOptions, options.ExistingConnection);
             }
             else
             {
                 MySuperStatsDbContextConfigurer.Configure(options.DbContextOptions, options.ConnectionString);
             }
         });
     }
 }