Exemplo n.º 1
0
        public PersonalFinanceDbContext CreateDbContext(string[] args)
        {
            var builder = new DbContextOptionsBuilder <PersonalFinanceDbContext>();

            /*
             * 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());

            PersonalFinanceDbContextConfigurer.Configure(builder, configuration.GetConnectionString(PersonalFinanceConsts.ConnectionStringName));

            return(new PersonalFinanceDbContext(builder.Options));
        }
Exemplo n.º 2
0
 public override void PreInitialize()
 {
     if (!SkipDbContextRegistration)
     {
         Configuration.Modules.AbpEfCore().AddDbContext <PersonalFinanceDbContext>(options =>
         {
             if (options.ExistingConnection != null)
             {
                 PersonalFinanceDbContextConfigurer.Configure(options.DbContextOptions, options.ExistingConnection);
             }
             else
             {
                 PersonalFinanceDbContextConfigurer.Configure(options.DbContextOptions, options.ConnectionString);
             }
         });
     }
 }