예제 #1
0
 /// <summary>
 /// 注入多个数据库
 /// </summary>
 /// <typeparam name="T"></typeparam>
 private void AddDbContext <T>() where T : AbpDbContext
 {
     Configuration.Modules.AbpEfCore().AddDbContext <T>(options =>
     {
         if (options.ExistingConnection != null)
         {
             MESDbContextConfigurer.Configure <T>(options.DbContextOptions, options.ExistingConnection);
         }
         else
         {
             MESDbContextConfigurer.Configure <T>(options.DbContextOptions, options.ConnectionString);
         }
     });
 }
예제 #2
0
        public MESDbContext CreateDbContext(string[] args)
        {
            var builder = new DbContextOptionsBuilder <MESDbContext>();

            /*
             * You can provide an environmentName parameter to the AppConfigurations.Get method.
             * In this case, AppConfigurations will try to read appsettings.{environmentName}.json.
             * Use Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") method or from string[] args to get environment if necessary.
             * https://docs.microsoft.com/en-us/ef/core/cli/dbcontext-creation?tabs=dotnet-core-cli#args
             */
            var configuration = AppConfigurations.Get(WebContentDirectoryFinder.CalculateContentRootFolder());

            MESDbContextConfigurer.Configure(builder, configuration.GetConnectionString(MESConsts.ConnectionStringName));

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