From 2b0407d986f608c4f17a10c89d2400cd369810f1 Mon Sep 17 00:00:00 2001 From: liangshiwei Date: Fri, 7 May 2021 09:17:31 +0800 Subject: [PATCH] Get attribute before optionsBuilder?.Invoke(options); --- .../AbpEfCoreServiceCollectionExtensions.cs | 7 ++++--- .../AbpMongoDbServiceCollectionExtensions.cs | 3 ++- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/framework/src/Volo.Abp.EntityFrameworkCore/Microsoft/Extensions/DependencyInjection/AbpEfCoreServiceCollectionExtensions.cs b/framework/src/Volo.Abp.EntityFrameworkCore/Microsoft/Extensions/DependencyInjection/AbpEfCoreServiceCollectionExtensions.cs index 07e86cb0e3..956b2937aa 100644 --- a/framework/src/Volo.Abp.EntityFrameworkCore/Microsoft/Extensions/DependencyInjection/AbpEfCoreServiceCollectionExtensions.cs +++ b/framework/src/Volo.Abp.EntityFrameworkCore/Microsoft/Extensions/DependencyInjection/AbpEfCoreServiceCollectionExtensions.cs @@ -17,9 +17,6 @@ namespace Microsoft.Extensions.DependencyInjection services.AddMemoryCache(); var options = new AbpDbContextRegistrationOptions(typeof(TDbContext), services); - optionsBuilder?.Invoke(options); - - services.TryAddTransient(DbContextOptionsFactory.Create); var replaceDbContextAttribute = typeof(TDbContext).GetCustomAttribute(true); if (replaceDbContextAttribute != null) @@ -27,6 +24,10 @@ namespace Microsoft.Extensions.DependencyInjection options.ReplacedDbContextTypes.AddRange(replaceDbContextAttribute.ReplacedDbContextTypes); } + optionsBuilder?.Invoke(options); + + services.TryAddTransient(DbContextOptionsFactory.Create); + foreach (var dbContextType in options.ReplacedDbContextTypes) { services.Replace( diff --git a/framework/src/Volo.Abp.MongoDB/Microsoft/Extensions/DependencyInjection/AbpMongoDbServiceCollectionExtensions.cs b/framework/src/Volo.Abp.MongoDB/Microsoft/Extensions/DependencyInjection/AbpMongoDbServiceCollectionExtensions.cs index 48e3115306..13131718c0 100644 --- a/framework/src/Volo.Abp.MongoDB/Microsoft/Extensions/DependencyInjection/AbpMongoDbServiceCollectionExtensions.cs +++ b/framework/src/Volo.Abp.MongoDB/Microsoft/Extensions/DependencyInjection/AbpMongoDbServiceCollectionExtensions.cs @@ -13,7 +13,6 @@ namespace Microsoft.Extensions.DependencyInjection where TMongoDbContext : AbpMongoDbContext { var options = new AbpMongoDbContextRegistrationOptions(typeof(TMongoDbContext), services); - optionsBuilder?.Invoke(options); var replaceDbContextAttribute = typeof(TMongoDbContext).GetCustomAttribute(true); if (replaceDbContextAttribute != null) @@ -21,6 +20,8 @@ namespace Microsoft.Extensions.DependencyInjection options.ReplacedDbContextTypes.AddRange(replaceDbContextAttribute.ReplacedDbContextTypes); } + optionsBuilder?.Invoke(options); + foreach (var dbContextType in options.ReplacedDbContextTypes) { services.Replace(ServiceDescriptor.Transient(dbContextType, typeof(TMongoDbContext)));