public override void PreInitialize()
        {
            Configuration.ReplaceService <IConnectionStringResolver, MyConnectionStringResolver>();

            // Configure first DbContext
            Configuration.Modules.AbpEfCore().AddDbContext <MultipleDbContextEfCoreDemoDbContext>(options =>
            {
                if (options.ExistingConnection != null)
                {
                    DbContextOptionsConfigurer.Configure(options.DbContextOptions, options.ExistingConnection);
                }
                else
                {
                    DbContextOptionsConfigurer.Configure(options.DbContextOptions, options.ConnectionString);
                }
            });

            // Configure second DbContext
            Configuration.Modules.AbpEfCore().AddDbContext <MultipleDbContextEfCoreDemoSecondDbContext>(options =>
            {
                if (options.ExistingConnection != null)
                {
                    SecondDbContextOptionsConfigurer.Configure(options.DbContextOptions, options.ExistingConnection);
                }
                else
                {
                    SecondDbContextOptionsConfigurer.Configure(options.DbContextOptions, options.ConnectionString);
                }
            });
        }
Exemple #2
0
        public MultipleDbContextEfCoreDemoSecondDbContext CreateDbContext(string[] args)
        {
            var builder       = new DbContextOptionsBuilder <MultipleDbContextEfCoreDemoSecondDbContext>();
            var configuration = AppConfigurations.Get(WebContentDirectoryFinder.CalculateContentRootFolder());

            SecondDbContextOptionsConfigurer.Configure(
                builder,
                configuration.GetConnectionString(MultipleDbContextEfCoreDemoConsts.SecondDbConnectionStringName)
                );

            return(new MultipleDbContextEfCoreDemoSecondDbContext(builder.Options));
        }