public override void PreInitialize()
        {
            Configuration.ReplaceService <IConnectionStringResolver, MyConnectionStringResolver>();
            //使用freeSql模块
            Configuration.Modules.AbpFreeSql().ConnectionString = GetConnectionString();

            if (!SkipDbContextRegistration)
            {
                if (!SkipSqlserverDbContextRegistration)
                {
                    Configuration.Modules.AbpEfCore().AddDbContext <JPGZServiceDbContext>(options =>
                    {
                        if (options.ExistingConnection != null)
                        {
                            JPGZServiceDbContextConfigurer.Configure(options.DbContextOptions, options.ExistingConnection);
                        }
                        else
                        {
                            JPGZServiceDbContextConfigurer.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);
                        }
                    });
                }
            }
        }
示例#2
0
        public JPGZServiceMysqlDbContext CreateDbContext(string[] args)
        {
            var builder       = new DbContextOptionsBuilder <JPGZServiceMysqlDbContext>();
            var configuration = AppConfigurations.Get(WebContentDirectoryFinder.CalculateContentRootFolder());

            JPGZServiceMysqlDbContextConfigurer.Configure(
                builder,
                configuration.GetConnectionString(JPGZServiceConsts.MysqlConnectionStringName)
                );

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