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);
                        }
                    });
                }
            }
        }
Example #2
0
        public JPGZServiceMysqlDbContext CreateDbContext(string[] args)
        {
            var builder = new DbContextOptionsBuilder <JPGZServiceMysqlDbContext>();

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

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