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<string, Type> EventTypes { get; }
protected IModel ConsumerChannel;
protected IServiceProvider ServiceProvider { get; }
protected IHybridServiceScopeFactory ServiceScopeFactory { get; }
public RabbitMqDistributedEventBus(
IOptions<RabbitMqDistributedEventBusOptions> options,
IConnectionPool connectionPool,
IRabbitMqSerializer serializer,
IServiceProvider serviceProvider,
IHybridServiceScopeFactory serviceScopeFactory,
IOptions<DistributedEventBusOptions> 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));
}
}
}

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
{
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> 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));
}
}
}

8
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<IServiceScopeFactory>()
.CreateScope();
ServiceScope = scopeFactory.CreateScope();
}
/// <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 IServiceProvider ServiceProvider { get; }
protected IHybridServiceScopeFactory ServiceScopeFactory { get; }
public LocalEventBus(
IOptions<LocalEventBusOptions> options,
IServiceProvider serviceProvider)
IHybridServiceScopeFactory serviceScopeFactory)
{
ServiceProvider = serviceProvider;
ServiceScopeFactory = serviceScopeFactory;
Options = options.Value;
Logger = NullLogger<LocalEventBus>.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));
}
}
}

Loading…
Cancel
Save