Browse Source

Use IHybridServiceScopeFactory for IocEventHandlerFactory

pull/625/head
Halil ibrahim Kalkan 8 years ago
parent
commit
dfa3fba82f
  1. 8
      framework/src/Volo.Abp.EventBus.Distributed.RabbitMQ/Volo/Abp/EventBus/Distributed/RabbitMq/RabbitMqDistributedEventBus.cs
  2. 10
      framework/src/Volo.Abp.EventBus/Volo/Abp/EventBus/Distributed/LocalDistributedEventBus.cs
  3. 8
      framework/src/Volo.Abp.EventBus/Volo/Abp/EventBus/IocEventHandlerFactory.cs
  4. 8
      framework/src/Volo.Abp.EventBus/Volo/Abp/EventBus/Local/LocalEventBus.cs

8
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<Type, List<IEventHandlerFactory>> HandlerFactories { get; } //TODO: Accessing to the List<IEventHandlerFactory> may not be thread-safe! protected ConcurrentDictionary<Type, List<IEventHandlerFactory>> HandlerFactories { get; } //TODO: Accessing to the List<IEventHandlerFactory> may not be thread-safe!
protected ConcurrentDictionary<string, Type> EventTypes { get; } protected ConcurrentDictionary<string, Type> EventTypes { get; }
protected IModel ConsumerChannel; protected IModel ConsumerChannel;
protected IServiceProvider ServiceProvider { get; } protected IHybridServiceScopeFactory ServiceScopeFactory { get; }
public RabbitMqDistributedEventBus( public RabbitMqDistributedEventBus(
IOptions<RabbitMqDistributedEventBusOptions> options, IOptions<RabbitMqDistributedEventBusOptions> options,
IConnectionPool connectionPool, IConnectionPool connectionPool,
IRabbitMqSerializer serializer, IRabbitMqSerializer serializer,
IServiceProvider serviceProvider, IHybridServiceScopeFactory serviceScopeFactory,
IOptions<DistributedEventBusOptions> distributedEventBusOptions) IOptions<DistributedEventBusOptions> distributedEventBusOptions)
{ {
ConnectionPool = connectionPool; ConnectionPool = connectionPool;
Serializer = serializer; Serializer = serializer;
ServiceProvider = serviceProvider; ServiceScopeFactory = serviceScopeFactory;
DistributedEventBusOptions = distributedEventBusOptions.Value; DistributedEventBusOptions = distributedEventBusOptions.Value;
RabbitMqDistributedEventBusOptions = options.Value; RabbitMqDistributedEventBusOptions = options.Value;
@ -67,7 +67,7 @@ namespace Volo.Abp.EventBus.Distributed.RabbitMq
var genericArgs = @interface.GetGenericArguments(); var genericArgs = @interface.GetGenericArguments();
if (genericArgs.Length == 1) if (genericArgs.Length == 1)
{ {
Subscribe(genericArgs[0], new IocEventHandlerFactory(ServiceProvider, handler)); Subscribe(genericArgs[0], new IocEventHandlerFactory(ServiceScopeFactory, handler));
} }
} }
} }

10
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 public class LocalDistributedEventBus : IDistributedEventBus, ITransientDependency
{ {
private readonly ILocalEventBus _localEventBus; private readonly ILocalEventBus _localEventBus;
protected IServiceProvider ServiceProvider { get; } protected IHybridServiceScopeFactory ServiceScopeFactory { get; }
protected DistributedEventBusOptions DistributedEventBusOptions { get; } protected DistributedEventBusOptions DistributedEventBusOptions { get; }
public LocalDistributedEventBus( public LocalDistributedEventBus(
ILocalEventBus localEventBus, ILocalEventBus localEventBus,
IServiceProvider serviceProvider, IHybridServiceScopeFactory serviceScopeFactory,
IOptions<DistributedEventBusOptions> distributedEventBusOptions) IOptions<DistributedEventBusOptions> distributedEventBusOptions)
{ {
_localEventBus = localEventBus; _localEventBus = localEventBus;
ServiceProvider = serviceProvider; ServiceScopeFactory = serviceScopeFactory;
DistributedEventBusOptions = distributedEventBusOptions.Value; DistributedEventBusOptions = distributedEventBusOptions.Value;
Subscribe(distributedEventBusOptions.Value.Handlers); Subscribe(distributedEventBusOptions.Value.Handlers);
} }
@ -42,7 +42,7 @@ namespace Volo.Abp.EventBus.Distributed
var genericArgs = @interface.GetGenericArguments(); var genericArgs = @interface.GetGenericArguments();
if (genericArgs.Length == 1) if (genericArgs.Length == 1)
{ {
Subscribe(genericArgs[0], new IocEventHandlerFactory(ServiceProvider, handler)); Subscribe(genericArgs[0], new IocEventHandlerFactory(ServiceScopeFactory, handler));
} }
} }
} }

8
framework/src/Volo.Abp.EventBus/Volo/Abp/EventBus/IocEventHandlerFactory.cs

@ -1,5 +1,6 @@
using System; using System;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Volo.Abp.DependencyInjection;
namespace Volo.Abp.EventBus namespace Volo.Abp.EventBus
{ {
@ -13,13 +14,10 @@ namespace Volo.Abp.EventBus
protected IServiceScope ServiceScope { get; } protected IServiceScope ServiceScope { get; }
//TODO: Consider to inject IServiceScopeFactory instead public IocEventHandlerFactory(IHybridServiceScopeFactory scopeFactory, Type handlerType)
public IocEventHandlerFactory(IServiceProvider serviceProvider, Type handlerType)
{ {
HandlerType = handlerType; HandlerType = handlerType;
ServiceScope = serviceProvider ServiceScope = scopeFactory.CreateScope();
.GetRequiredService<IServiceScopeFactory>()
.CreateScope();
} }
/// <summary> /// <summary>

8
framework/src/Volo.Abp.EventBus/Volo/Abp/EventBus/Local/LocalEventBus.cs

@ -28,13 +28,13 @@ namespace Volo.Abp.EventBus.Local
protected ConcurrentDictionary<Type, List<IEventHandlerFactory>> HandlerFactories { get; } protected ConcurrentDictionary<Type, List<IEventHandlerFactory>> HandlerFactories { get; }
protected IServiceProvider ServiceProvider { get; } protected IHybridServiceScopeFactory ServiceScopeFactory { get; }
public LocalEventBus( public LocalEventBus(
IOptions<LocalEventBusOptions> options, IOptions<LocalEventBusOptions> options,
IServiceProvider serviceProvider) IHybridServiceScopeFactory serviceScopeFactory)
{ {
ServiceProvider = serviceProvider; ServiceScopeFactory = serviceScopeFactory;
Options = options.Value; Options = options.Value;
Logger = NullLogger<LocalEventBus>.Instance; Logger = NullLogger<LocalEventBus>.Instance;
@ -57,7 +57,7 @@ namespace Volo.Abp.EventBus.Local
var genericArgs = @interface.GetGenericArguments(); var genericArgs = @interface.GetGenericArguments();
if (genericArgs.Length == 1) if (genericArgs.Length == 1)
{ {
Subscribe(genericArgs[0], new IocEventHandlerFactory(ServiceProvider, handler)); Subscribe(genericArgs[0], new IocEventHandlerFactory(ServiceScopeFactory, handler));
} }
} }
} }

Loading…
Cancel
Save