Browse Source

Support a handler to implement both `Local` and `Distribute`.

Resolve #19484
pull/19642/head
maliming 2 years ago
parent
commit
95261e9d00
No known key found for this signature in database GPG Key ID: A646B9CB645ECEA4
  1. 3
      framework/src/Volo.Abp.EventBus/Volo/Abp/EventBus/AbpEventBusModule.cs
  2. 40
      framework/test/Volo.Abp.EventBus.Tests/Volo/Abp/EventBus/LocalAndDistributeEventHandlerRegister_Tests.cs

3
framework/src/Volo.Abp.EventBus/Volo/Abp/EventBus/AbpEventBusModule.cs

@ -53,7 +53,8 @@ public class AbpEventBusModule : AbpModule
{
localHandlers.Add(context.ImplementationType);
}
else if (ReflectionHelper.IsAssignableToGenericType(context.ImplementationType, typeof(IDistributedEventHandler<>)))
if (ReflectionHelper.IsAssignableToGenericType(context.ImplementationType, typeof(IDistributedEventHandler<>)))
{
distributedHandlers.Add(context.ImplementationType);
}

40
framework/test/Volo.Abp.EventBus.Tests/Volo/Abp/EventBus/LocalAndDistributeEventHandlerRegister_Tests.cs

@ -0,0 +1,40 @@
using System.Threading.Tasks;
using Microsoft.Extensions.Options;
using Shouldly;
using Volo.Abp.DependencyInjection;
using Volo.Abp.EventBus.Distributed;
using Volo.Abp.EventBus.Local;
using Xunit;
namespace Volo.Abp.EventBus;
public class LocalAndDistributeEventHandlerRegister_Tests : EventBusTestBase
{
[Fact]
public void Should_Register_Both_Local_And_Distribute()
{
var localOptions = GetRequiredService<IOptions<AbpLocalEventBusOptions>>();
var distributedOptions = GetRequiredService<IOptions<AbpDistributedEventBusOptions>>();
localOptions.Value.Handlers.ShouldContain(x => x == typeof(MyEventHandle));
distributedOptions.Value.Handlers.ShouldContain(x => x == typeof(MyEventHandle));
}
class MyEventDate
{
}
class MyEventHandle : ILocalEventHandler<MyEventDate>, IDistributedEventHandler<MyEventDate>, ITransientDependency
{
Task ILocalEventHandler<MyEventDate>.HandleEventAsync(MyEventDate eventData)
{
return Task.CompletedTask;
}
Task IDistributedEventHandler<MyEventDate>.HandleEventAsync(MyEventDate eventData)
{
return Task.CompletedTask;
}
}
}
Loading…
Cancel
Save