Get attribute before optionsBuilder?.Invoke(options);

pull/8897/head
liangshiwei 5 years ago
parent d13b6c8b0c
commit 2b0407d986

@ -17,9 +17,6 @@ namespace Microsoft.Extensions.DependencyInjection
services.AddMemoryCache(); services.AddMemoryCache();
var options = new AbpDbContextRegistrationOptions(typeof(TDbContext), services); var options = new AbpDbContextRegistrationOptions(typeof(TDbContext), services);
optionsBuilder?.Invoke(options);
services.TryAddTransient(DbContextOptionsFactory.Create<TDbContext>);
var replaceDbContextAttribute = typeof(TDbContext).GetCustomAttribute<ReplaceDbContextAttribute>(true); var replaceDbContextAttribute = typeof(TDbContext).GetCustomAttribute<ReplaceDbContextAttribute>(true);
if (replaceDbContextAttribute != null) if (replaceDbContextAttribute != null)
@ -27,6 +24,10 @@ namespace Microsoft.Extensions.DependencyInjection
options.ReplacedDbContextTypes.AddRange(replaceDbContextAttribute.ReplacedDbContextTypes); options.ReplacedDbContextTypes.AddRange(replaceDbContextAttribute.ReplacedDbContextTypes);
} }
optionsBuilder?.Invoke(options);
services.TryAddTransient(DbContextOptionsFactory.Create<TDbContext>);
foreach (var dbContextType in options.ReplacedDbContextTypes) foreach (var dbContextType in options.ReplacedDbContextTypes)
{ {
services.Replace( services.Replace(

@ -13,7 +13,6 @@ namespace Microsoft.Extensions.DependencyInjection
where TMongoDbContext : AbpMongoDbContext where TMongoDbContext : AbpMongoDbContext
{ {
var options = new AbpMongoDbContextRegistrationOptions(typeof(TMongoDbContext), services); var options = new AbpMongoDbContextRegistrationOptions(typeof(TMongoDbContext), services);
optionsBuilder?.Invoke(options);
var replaceDbContextAttribute = typeof(TMongoDbContext).GetCustomAttribute<ReplaceDbContextAttribute>(true); var replaceDbContextAttribute = typeof(TMongoDbContext).GetCustomAttribute<ReplaceDbContextAttribute>(true);
if (replaceDbContextAttribute != null) if (replaceDbContextAttribute != null)
@ -21,6 +20,8 @@ namespace Microsoft.Extensions.DependencyInjection
options.ReplacedDbContextTypes.AddRange(replaceDbContextAttribute.ReplacedDbContextTypes); options.ReplacedDbContextTypes.AddRange(replaceDbContextAttribute.ReplacedDbContextTypes);
} }
optionsBuilder?.Invoke(options);
foreach (var dbContextType in options.ReplacedDbContextTypes) foreach (var dbContextType in options.ReplacedDbContextTypes)
{ {
services.Replace(ServiceDescriptor.Transient(dbContextType, typeof(TMongoDbContext))); services.Replace(ServiceDescriptor.Transient(dbContextType, typeof(TMongoDbContext)));

Loading…
Cancel
Save