From 8fc277be57be8a1da98521a89ad642428253a70f Mon Sep 17 00:00:00 2001 From: Halil ibrahim Kalkan Date: Thu, 24 Jan 2019 10:46:13 +0300 Subject: [PATCH] AbpRabbitMqModule should get configuration from appsettings file if available. --- .../ServiceCollectionCommonExtensions.cs | 10 ++++++++++ .../Volo/Abp/RabbitMQ/AbpRabbitMqModule.cs | 6 ++++++ .../Volo/Abp/RabbitMQ/AbpRabbitMqOptions.cs | 4 ++-- .../Volo/Abp/RabbitMQ/ConnectionPool.cs | 2 +- 4 files changed, 19 insertions(+), 3 deletions(-) diff --git a/framework/src/Volo.Abp.Core/Microsoft/Extensions/DependencyInjection/ServiceCollectionCommonExtensions.cs b/framework/src/Volo.Abp.Core/Microsoft/Extensions/DependencyInjection/ServiceCollectionCommonExtensions.cs index 240513a5ce..1b2d2c4652 100644 --- a/framework/src/Volo.Abp.Core/Microsoft/Extensions/DependencyInjection/ServiceCollectionCommonExtensions.cs +++ b/framework/src/Volo.Abp.Core/Microsoft/Extensions/DependencyInjection/ServiceCollectionCommonExtensions.cs @@ -8,6 +8,16 @@ namespace Microsoft.Extensions.DependencyInjection { public static class ServiceCollectionCommonExtensions { + public static bool IsAdded(this IServiceCollection services) + { + return services.IsAdded(typeof(T)); + } + + public static bool IsAdded(this IServiceCollection services, Type type) + { + return services.Any(d => d.ServiceType == type); + } + public static T GetSingletonInstanceOrNull(this IServiceCollection services) { return (T)services diff --git a/framework/src/Volo.Abp.RabbitMQ/Volo/Abp/RabbitMQ/AbpRabbitMqModule.cs b/framework/src/Volo.Abp.RabbitMQ/Volo/Abp/RabbitMQ/AbpRabbitMqModule.cs index b030e2f5c2..a96309a1a8 100644 --- a/framework/src/Volo.Abp.RabbitMQ/Volo/Abp/RabbitMQ/AbpRabbitMqModule.cs +++ b/framework/src/Volo.Abp.RabbitMQ/Volo/Abp/RabbitMQ/AbpRabbitMqModule.cs @@ -11,6 +11,12 @@ namespace Volo.Abp.RabbitMQ )] public class AbpRabbitMqModule : AbpModule { + public override void ConfigureServices(ServiceConfigurationContext context) + { + var configuration = context.Services.GetConfiguration(); + Configure(configuration.GetSection("RabbitMQ")); + } + public override void OnApplicationShutdown(ApplicationShutdownContext context) { context.ServiceProvider diff --git a/framework/src/Volo.Abp.RabbitMQ/Volo/Abp/RabbitMQ/AbpRabbitMqOptions.cs b/framework/src/Volo.Abp.RabbitMQ/Volo/Abp/RabbitMQ/AbpRabbitMqOptions.cs index da10ab7e06..a971b85d5e 100644 --- a/framework/src/Volo.Abp.RabbitMQ/Volo/Abp/RabbitMQ/AbpRabbitMqOptions.cs +++ b/framework/src/Volo.Abp.RabbitMQ/Volo/Abp/RabbitMQ/AbpRabbitMqOptions.cs @@ -2,11 +2,11 @@ { public class AbpRabbitMqOptions { - public RabbitMqConnections ConnectionFactories { get; } + public RabbitMqConnections Connections { get; } public AbpRabbitMqOptions() { - ConnectionFactories = new RabbitMqConnections(); + Connections = new RabbitMqConnections(); } } } diff --git a/framework/src/Volo.Abp.RabbitMQ/Volo/Abp/RabbitMQ/ConnectionPool.cs b/framework/src/Volo.Abp.RabbitMQ/Volo/Abp/RabbitMQ/ConnectionPool.cs index 883eaa6ba3..08d9d48036 100644 --- a/framework/src/Volo.Abp.RabbitMQ/Volo/Abp/RabbitMQ/ConnectionPool.cs +++ b/framework/src/Volo.Abp.RabbitMQ/Volo/Abp/RabbitMQ/ConnectionPool.cs @@ -28,7 +28,7 @@ namespace Volo.Abp.RabbitMQ return Connections.GetOrAdd( connectionName, () => Options - .ConnectionFactories + .Connections .GetOrDefault(connectionName) .CreateConnection() );