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


            if (!SkipDbContextRegistration)
            {
                Configuration.Modules.AbpEfCore().AddDbContext <TwoContextsDbContext>(options =>
                {
                    if (options.ExistingConnection != null)
                    {
                        TwoContextsDbContextConfigurer.Configure(options.DbContextOptions, options.ExistingConnection);
                    }
                    else
                    {
                        TwoContextsDbContextConfigurer.Configure(options.DbContextOptions, options.ConnectionString);
                    }
                });
            }

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

            TwoContextsDbContextConfigurer.Configure(builder, configuration.GetConnectionString(TwoContextsConsts.ConnectionStringName));

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