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


            JPGZServicePostgreSqlDbContextConfigurer.Configure(builder, _appConfiguration[$"ConnectionStrings:{WebApiConsts.PostgreSqlConnectionStringName}"]);

            return(new JPGZServicePostgreSqlDbContext(builder.Options));
        }
        public override void PreInitialize()
        {
            //Configuration.ReplaceService(typeof(IConnectionStringResolver), () => {
            //    IocManager.RegisterIfNot<IConnectionStringResolver, MyConnectionStringResolver>();
            //});
            Configuration.ReplaceService <IConnectionStringResolver, MyConnectionStringResolver>();

            if (!SkipDbContextRegistration)
            {
                if (!SkipSqlserverDbContextRegistration)
                {
                    Configuration.Modules.AbpEfCore().AddDbContext <WebApiDbContext>(options =>
                    {
                        if (options.ExistingConnection != null)
                        {
                            WebApiDbContextConfigurer.Configure(options.DbContextOptions, options.ExistingConnection);
                        }
                        else
                        {
                            WebApiDbContextConfigurer.Configure(options.DbContextOptions, options.ConnectionString);
                        }
                    });
                }
                if (!SkipMysqlDbContextRegistration)
                {
                    //配置mysql数据库
                    Configuration.Modules.AbpEfCore().AddDbContext <JPGZServiceMysqlDbContext>(options =>
                    {
                        if (options.ExistingConnection != null)
                        {
                            JPGZServiceMysqlDbContextConfigurer.Configure(options.DbContextOptions, options.ExistingConnection);
                        }
                        else
                        {
                            JPGZServiceMysqlDbContextConfigurer.Configure(options.DbContextOptions, options.ConnectionString);
                        }
                    });
                }

                if (!SkipPostgreSqlDbContextRegistration)
                {
                    //配置PostgreSql数据库
                    Configuration.Modules.AbpEfCore().AddDbContext <JPGZServicePostgreSqlDbContext>(options =>
                    {
                        if (options.ExistingConnection != null)
                        {
                            JPGZServicePostgreSqlDbContextConfigurer.Configure(options.DbContextOptions, options.ExistingConnection);
                        }
                        else
                        {
                            JPGZServicePostgreSqlDbContextConfigurer.Configure(options.DbContextOptions, options.ConnectionString);
                        }
                    });
                }
            }
        }