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

                // Configure first DbContext
                Configuration.Modules.AbpEfCore().AddDbContext <TemplateDbContext>(options =>
                {
                    if (options.ExistingConnection != null)
                    {
                        TemplateDbContextConfigurer.Configure(options.DbContextOptions, options.ExistingConnection);
                    }
                    else
                    {
                        TemplateDbContextConfigurer.Configure(options.DbContextOptions, options.ConnectionString);
                    }
                });
                // Configure second DbContext
                Configuration.Modules.AbpEfCore().AddDbContext <TemplateSecondDbContext>(options =>
                {
                    if (options.ExistingConnection != null)
                    {
                        TemplateDbContextConfigurer.Configure(options.DbContextOptions, options.ExistingConnection);
                    }
                    else
                    {
                        TemplateDbContextConfigurer.Configure(options.DbContextOptions, options.ConnectionString);
                    }
                });
            }
        }
Exemplo n.º 2
0
        public T CreateDbContext(string[] args)
        {
            var builder       = new DbContextOptionsBuilder <T>();
            var configuration = AppConfigurations.Get(WebContentDirectoryFinder.CalculateContentRootFolder());

            TemplateDbContextConfigurer.Configure(builder, configuration.GetConnectionString(ConnectionStringName));

            return(this.CreateDbContext(builder.Options));
        }