From b9c3a536f0548c23b5fe56aa42523c5673894ac9 Mon Sep 17 00:00:00 2001 From: Savorboard Date: Tue, 5 Sep 2017 22:13:11 +0800 Subject: [PATCH] fixed dependency injection bugs. --- src/DotNetCore.CAP.Kafka/CAP.KafkaCapOptionsExtension.cs | 2 +- .../CAP.RabbitMQCapOptionsExtension.cs | 3 +-- src/DotNetCore.CAP.RabbitMQ/PublishQueueExecutor.cs | 9 +++++---- .../RabbitMQConsumerClientFactory.cs | 4 ++-- .../CAP.SqlServerCapOptionsExtension.cs | 4 ++-- 5 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/DotNetCore.CAP.Kafka/CAP.KafkaCapOptionsExtension.cs b/src/DotNetCore.CAP.Kafka/CAP.KafkaCapOptionsExtension.cs index 8d9bf98..5c9b6ba 100644 --- a/src/DotNetCore.CAP.Kafka/CAP.KafkaCapOptionsExtension.cs +++ b/src/DotNetCore.CAP.Kafka/CAP.KafkaCapOptionsExtension.cs @@ -21,7 +21,7 @@ namespace DotNetCore.CAP services.AddSingleton(kafkaOptions); services.AddSingleton(); - services.AddTransient(); + services.AddSingleton(); } } } \ No newline at end of file diff --git a/src/DotNetCore.CAP.RabbitMQ/CAP.RabbitMQCapOptionsExtension.cs b/src/DotNetCore.CAP.RabbitMQ/CAP.RabbitMQCapOptionsExtension.cs index 22e2af2..abc6d2b 100644 --- a/src/DotNetCore.CAP.RabbitMQ/CAP.RabbitMQCapOptionsExtension.cs +++ b/src/DotNetCore.CAP.RabbitMQ/CAP.RabbitMQCapOptionsExtension.cs @@ -23,9 +23,8 @@ namespace DotNetCore.CAP services.AddSingleton(); services.AddSingleton(); - services.AddScoped(x => x.GetService().Rent()); - services.AddTransient(); + services.AddSingleton(); } } } \ No newline at end of file diff --git a/src/DotNetCore.CAP.RabbitMQ/PublishQueueExecutor.cs b/src/DotNetCore.CAP.RabbitMQ/PublishQueueExecutor.cs index 791985d..ee49ce9 100644 --- a/src/DotNetCore.CAP.RabbitMQ/PublishQueueExecutor.cs +++ b/src/DotNetCore.CAP.RabbitMQ/PublishQueueExecutor.cs @@ -10,19 +10,19 @@ namespace DotNetCore.CAP.RabbitMQ internal sealed class PublishQueueExecutor : BasePublishQueueExecutor { private readonly ILogger _logger; - private readonly IConnection _connection; + private readonly ConnectionPool _connectionPool; private readonly RabbitMQOptions _rabbitMQOptions; public PublishQueueExecutor( CapOptions options, IStateChanger stateChanger, - IConnection connection, + ConnectionPool connectionPool, RabbitMQOptions rabbitMQOptions, ILogger logger) : base(options, stateChanger, logger) { _logger = logger; - _connection = connection; + _connectionPool = connectionPool; _rabbitMQOptions = rabbitMQOptions; } @@ -30,7 +30,8 @@ namespace DotNetCore.CAP.RabbitMQ { try { - using (var channel = _connection.CreateModel()) + var connection = _connectionPool.Rent(); + using (var channel = connection.CreateModel()) { var body = Encoding.UTF8.GetBytes(content); diff --git a/src/DotNetCore.CAP.RabbitMQ/RabbitMQConsumerClientFactory.cs b/src/DotNetCore.CAP.RabbitMQ/RabbitMQConsumerClientFactory.cs index 5fc9d8f..252b865 100644 --- a/src/DotNetCore.CAP.RabbitMQ/RabbitMQConsumerClientFactory.cs +++ b/src/DotNetCore.CAP.RabbitMQ/RabbitMQConsumerClientFactory.cs @@ -9,10 +9,10 @@ namespace DotNetCore.CAP.RabbitMQ private readonly IConnection _connection; - public RabbitMQConsumerClientFactory(RabbitMQOptions rabbitMQOptions, IConnection connection) + public RabbitMQConsumerClientFactory(RabbitMQOptions rabbitMQOptions, ConnectionPool pool) { _rabbitMQOptions = rabbitMQOptions; - _connection = connection; + _connection = pool.Rent(); } public IConsumerClient Create(string groupId) diff --git a/src/DotNetCore.CAP.SqlServer/CAP.SqlServerCapOptionsExtension.cs b/src/DotNetCore.CAP.SqlServer/CAP.SqlServerCapOptionsExtension.cs index 7aac2e1..f928031 100644 --- a/src/DotNetCore.CAP.SqlServer/CAP.SqlServerCapOptionsExtension.cs +++ b/src/DotNetCore.CAP.SqlServer/CAP.SqlServerCapOptionsExtension.cs @@ -19,8 +19,8 @@ namespace DotNetCore.CAP public void AddServices(IServiceCollection services) { services.AddSingleton(); - services.AddScoped(); - services.AddScoped(); + services.AddSingleton(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); AddSqlServerOptions(services);