@@ -28,24 +28,17 @@ namespace DotNetCore.CAP | |||||
if (mysqlOptions.DbContextType != null) | if (mysqlOptions.DbContextType != null) | ||||
{ | { | ||||
var provider = TempBuildService(services); | |||||
var dbContextObj = provider.GetService(mysqlOptions.DbContextType); | |||||
var dbContext = (DbContext)dbContextObj; | |||||
mysqlOptions.ConnectionString = dbContext.Database.GetDbConnection().ConnectionString; | |||||
services.AddSingleton(x => | |||||
{ | |||||
var dbContext = (DbContext)x.GetService(mysqlOptions.DbContextType); | |||||
mysqlOptions.ConnectionString = dbContext.Database.GetDbConnection().ConnectionString; | |||||
return mysqlOptions; | |||||
}); | |||||
} | |||||
else | |||||
{ | |||||
services.AddSingleton(mysqlOptions); | |||||
} | } | ||||
services.AddSingleton(mysqlOptions); | |||||
} | |||||
#if NETSTANDARD1_6 | |||||
private IServiceProvider TempBuildService(IServiceCollection services) | |||||
{ | |||||
return services.BuildServiceProvider(); | |||||
} | |||||
#else | |||||
private ServiceProvider TempBuildService(IServiceCollection services) | |||||
{ | |||||
return services.BuildServiceProvider(); | |||||
} | } | ||||
#endif | |||||
} | } | ||||
} | } |
@@ -28,24 +28,17 @@ namespace DotNetCore.CAP | |||||
if (postgreSqlOptions.DbContextType != null) | if (postgreSqlOptions.DbContextType != null) | ||||
{ | { | ||||
var provider = TempBuildService(services); | |||||
var dbContextObj = provider.GetService(postgreSqlOptions.DbContextType); | |||||
var dbContext = (DbContext)dbContextObj; | |||||
postgreSqlOptions.ConnectionString = dbContext.Database.GetDbConnection().ConnectionString; | |||||
services.AddSingleton(x => | |||||
{ | |||||
var dbContext = (DbContext)x.GetService(postgreSqlOptions.DbContextType); | |||||
postgreSqlOptions.ConnectionString = dbContext.Database.GetDbConnection().ConnectionString; | |||||
return postgreSqlOptions; | |||||
}); | |||||
} | |||||
else | |||||
{ | |||||
services.AddSingleton(postgreSqlOptions); | |||||
} | } | ||||
services.AddSingleton(postgreSqlOptions); | |||||
} | |||||
#if NETSTANDARD1_6 | |||||
private IServiceProvider TempBuildService(IServiceCollection services) | |||||
{ | |||||
return services.BuildServiceProvider(); | |||||
} | |||||
#else | |||||
private ServiceProvider TempBuildService(IServiceCollection services) | |||||
{ | |||||
return services.BuildServiceProvider(); | |||||
} | } | ||||
#endif | |||||
} | } | ||||
} | } |
@@ -21,6 +21,10 @@ namespace DotNetCore.CAP | |||||
services.AddSingleton(options); | services.AddSingleton(options); | ||||
services.AddSingleton<IConsumerClientFactory, RabbitMQConsumerClientFactory>(); | services.AddSingleton<IConsumerClientFactory, RabbitMQConsumerClientFactory>(); | ||||
services.AddSingleton<ConnectionPool>(); | |||||
services.AddScoped(x => x.GetService<ConnectionPool>().Rent()); | |||||
services.AddTransient<IQueueExecutor, PublishQueueExecutor>(); | services.AddTransient<IQueueExecutor, PublishQueueExecutor>(); | ||||
} | } | ||||
} | } |