mirror of https://github.com/abpframework/abp.git
committed by
GitHub
3 changed files with 83 additions and 4 deletions
@ -0,0 +1,17 @@ |
|||
using System; |
|||
|
|||
namespace Volo.Abp.EventBus.Local; |
|||
|
|||
[AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = true)] |
|||
public class LocalEventHandlerOrderAttribute : Attribute |
|||
{ |
|||
/// <summary>
|
|||
/// Handlers execute in ascending numeric value of the Order property.
|
|||
/// </summary>
|
|||
public int Order { get; set; } |
|||
|
|||
public LocalEventHandlerOrderAttribute(int order) |
|||
{ |
|||
Order = order; |
|||
} |
|||
} |
|||
@ -0,0 +1,56 @@ |
|||
using System.Threading.Tasks; |
|||
using Shouldly; |
|||
using Volo.Abp.DependencyInjection; |
|||
using Volo.Abp.Domain.Entities; |
|||
using Volo.Abp.Domain.Entities.Events; |
|||
using Xunit; |
|||
|
|||
namespace Volo.Abp.EventBus.Local; |
|||
|
|||
public class EventBus_Order_Test : EventBusTestBase |
|||
{ |
|||
public static string HandlerExecuteOrder { get; set; } |
|||
|
|||
[Fact] |
|||
public async Task Handler_Should_Execute_By_Order() |
|||
{ |
|||
HandlerExecuteOrder = ""; |
|||
await LocalEventBus.PublishAsync(new MyOrderEventHandlerEventData()); |
|||
HandlerExecuteOrder.ShouldBe("321"); |
|||
} |
|||
|
|||
public class MyOrderEventHandlerEventData |
|||
{ |
|||
|
|||
} |
|||
|
|||
public class MyOrderEventHandler : ILocalEventHandler<MyOrderEventHandlerEventData>, ITransientDependency |
|||
{ |
|||
public Task HandleEventAsync(MyOrderEventHandlerEventData eventData) |
|||
{ |
|||
HandlerExecuteOrder += "1"; |
|||
return Task.CompletedTask; |
|||
} |
|||
} |
|||
|
|||
[LocalEventHandlerOrder(-2)] |
|||
public class MyOrderEventHandler2 : ILocalEventHandler<MyOrderEventHandlerEventData>, ITransientDependency |
|||
{ |
|||
public Task HandleEventAsync(MyOrderEventHandlerEventData eventData) |
|||
{ |
|||
HandlerExecuteOrder += "2"; |
|||
return Task.CompletedTask; |
|||
} |
|||
} |
|||
|
|||
[LocalEventHandlerOrder(-3)] |
|||
public class MyOrderEventHandler3 : ILocalEventHandler<MyOrderEventHandlerEventData>, ITransientDependency |
|||
{ |
|||
public Task HandleEventAsync(MyOrderEventHandlerEventData eventData) |
|||
{ |
|||
HandlerExecuteOrder += "3"; |
|||
return Task.CompletedTask; |
|||
} |
|||
} |
|||
|
|||
} |
|||
Loading…
Reference in new issue