From dfa3fba82f4dcf8a91a0c7295baf21b9920363eb Mon Sep 17 00:00:00 2001 From: Halil ibrahim Kalkan Date: Mon, 3 Dec 2018 10:01:21 +0300 Subject: [PATCH] Use IHybridServiceScopeFactory for IocEventHandlerFactory --- .../RabbitMq/RabbitMqDistributedEventBus.cs | 8 ++++---- .../EventBus/Distributed/LocalDistributedEventBus.cs | 10 +++++----- .../Volo/Abp/EventBus/IocEventHandlerFactory.cs | 8 +++----- .../Volo/Abp/EventBus/Local/LocalEventBus.cs | 8 ++++---- 4 files changed, 16 insertions(+), 18 deletions(-) diff --git a/framework/src/Volo.Abp.EventBus.Distributed.RabbitMQ/Volo/Abp/EventBus/Distributed/RabbitMq/RabbitMqDistributedEventBus.cs b/framework/src/Volo.Abp.EventBus.Distributed.RabbitMQ/Volo/Abp/EventBus/Distributed/RabbitMq/RabbitMqDistributedEventBus.cs index 3cd7cfbe03..4bf615a998 100644 --- a/framework/src/Volo.Abp.EventBus.Distributed.RabbitMQ/Volo/Abp/EventBus/Distributed/RabbitMq/RabbitMqDistributedEventBus.cs +++ b/framework/src/Volo.Abp.EventBus.Distributed.RabbitMQ/Volo/Abp/EventBus/Distributed/RabbitMq/RabbitMqDistributedEventBus.cs @@ -30,18 +30,18 @@ namespace Volo.Abp.EventBus.Distributed.RabbitMq protected ConcurrentDictionary> HandlerFactories { get; } //TODO: Accessing to the List may not be thread-safe! protected ConcurrentDictionary EventTypes { get; } protected IModel ConsumerChannel; - protected IServiceProvider ServiceProvider { get; } + protected IHybridServiceScopeFactory ServiceScopeFactory { get; } public RabbitMqDistributedEventBus( IOptions options, IConnectionPool connectionPool, IRabbitMqSerializer serializer, - IServiceProvider serviceProvider, + IHybridServiceScopeFactory serviceScopeFactory, IOptions distributedEventBusOptions) { ConnectionPool = connectionPool; Serializer = serializer; - ServiceProvider = serviceProvider; + ServiceScopeFactory = serviceScopeFactory; DistributedEventBusOptions = distributedEventBusOptions.Value; RabbitMqDistributedEventBusOptions = options.Value; @@ -67,7 +67,7 @@ namespace Volo.Abp.EventBus.Distributed.RabbitMq var genericArgs = @interface.GetGenericArguments(); if (genericArgs.Length == 1) { - Subscribe(genericArgs[0], new IocEventHandlerFactory(ServiceProvider, handler)); + Subscribe(genericArgs[0], new IocEventHandlerFactory(ServiceScopeFactory, handler)); } } } diff --git a/framework/src/Volo.Abp.EventBus/Volo/Abp/EventBus/Distributed/LocalDistributedEventBus.cs b/framework/src/Volo.Abp.EventBus/Volo/Abp/EventBus/Distributed/LocalDistributedEventBus.cs index 30278c6b21..0f609c6aaa 100644 --- a/framework/src/Volo.Abp.EventBus/Volo/Abp/EventBus/Distributed/LocalDistributedEventBus.cs +++ b/framework/src/Volo.Abp.EventBus/Volo/Abp/EventBus/Distributed/LocalDistributedEventBus.cs @@ -13,16 +13,16 @@ namespace Volo.Abp.EventBus.Distributed public class LocalDistributedEventBus : IDistributedEventBus, ITransientDependency { private readonly ILocalEventBus _localEventBus; - protected IServiceProvider ServiceProvider { get; } + protected IHybridServiceScopeFactory ServiceScopeFactory { get; } protected DistributedEventBusOptions DistributedEventBusOptions { get; } public LocalDistributedEventBus( - ILocalEventBus localEventBus, - IServiceProvider serviceProvider, + ILocalEventBus localEventBus, + IHybridServiceScopeFactory serviceScopeFactory, IOptions distributedEventBusOptions) { _localEventBus = localEventBus; - ServiceProvider = serviceProvider; + ServiceScopeFactory = serviceScopeFactory; DistributedEventBusOptions = distributedEventBusOptions.Value; Subscribe(distributedEventBusOptions.Value.Handlers); } @@ -42,7 +42,7 @@ namespace Volo.Abp.EventBus.Distributed var genericArgs = @interface.GetGenericArguments(); if (genericArgs.Length == 1) { - Subscribe(genericArgs[0], new IocEventHandlerFactory(ServiceProvider, handler)); + Subscribe(genericArgs[0], new IocEventHandlerFactory(ServiceScopeFactory, handler)); } } } diff --git a/framework/src/Volo.Abp.EventBus/Volo/Abp/EventBus/IocEventHandlerFactory.cs b/framework/src/Volo.Abp.EventBus/Volo/Abp/EventBus/IocEventHandlerFactory.cs index 9d388bae74..d944afae42 100644 --- a/framework/src/Volo.Abp.EventBus/Volo/Abp/EventBus/IocEventHandlerFactory.cs +++ b/framework/src/Volo.Abp.EventBus/Volo/Abp/EventBus/IocEventHandlerFactory.cs @@ -1,5 +1,6 @@ using System; using Microsoft.Extensions.DependencyInjection; +using Volo.Abp.DependencyInjection; namespace Volo.Abp.EventBus { @@ -13,13 +14,10 @@ namespace Volo.Abp.EventBus protected IServiceScope ServiceScope { get; } - //TODO: Consider to inject IServiceScopeFactory instead - public IocEventHandlerFactory(IServiceProvider serviceProvider, Type handlerType) + public IocEventHandlerFactory(IHybridServiceScopeFactory scopeFactory, Type handlerType) { HandlerType = handlerType; - ServiceScope = serviceProvider - .GetRequiredService() - .CreateScope(); + ServiceScope = scopeFactory.CreateScope(); } /// diff --git a/framework/src/Volo.Abp.EventBus/Volo/Abp/EventBus/Local/LocalEventBus.cs b/framework/src/Volo.Abp.EventBus/Volo/Abp/EventBus/Local/LocalEventBus.cs index 07a9e609e5..31238961ae 100644 --- a/framework/src/Volo.Abp.EventBus/Volo/Abp/EventBus/Local/LocalEventBus.cs +++ b/framework/src/Volo.Abp.EventBus/Volo/Abp/EventBus/Local/LocalEventBus.cs @@ -28,13 +28,13 @@ namespace Volo.Abp.EventBus.Local protected ConcurrentDictionary> HandlerFactories { get; } - protected IServiceProvider ServiceProvider { get; } + protected IHybridServiceScopeFactory ServiceScopeFactory { get; } public LocalEventBus( IOptions options, - IServiceProvider serviceProvider) + IHybridServiceScopeFactory serviceScopeFactory) { - ServiceProvider = serviceProvider; + ServiceScopeFactory = serviceScopeFactory; Options = options.Value; Logger = NullLogger.Instance; @@ -57,7 +57,7 @@ namespace Volo.Abp.EventBus.Local var genericArgs = @interface.GetGenericArguments(); if (genericArgs.Length == 1) { - Subscribe(genericArgs[0], new IocEventHandlerFactory(ServiceProvider, handler)); + Subscribe(genericArgs[0], new IocEventHandlerFactory(ServiceScopeFactory, handler)); } } }