mirror of https://github.com/abpframework/abp.git
committed by
GitHub
33 changed files with 239 additions and 613 deletions
@ -1,38 +0,0 @@ |
|||
using System; |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp.DependencyInjection; |
|||
|
|||
namespace Volo.Abp.EventBus |
|||
{ |
|||
/// <summary>
|
|||
/// This event handler is an adapter to be able to use an action as <see cref="IAsyncEventHandler{TEventData}"/> implementation.
|
|||
/// </summary>
|
|||
/// <typeparam name="TEvent">Event type</typeparam>
|
|||
internal class AsyncActionEventHandler<TEvent> : |
|||
IAsyncEventHandler<TEvent>, |
|||
ITransientDependency |
|||
{ |
|||
/// <summary>
|
|||
/// Function to handle the event.
|
|||
/// </summary>
|
|||
public Func<TEvent, Task> Action { get; } |
|||
|
|||
/// <summary>
|
|||
/// Creates a new instance of <see cref="AsyncActionEventHandler{TEventData}"/>.
|
|||
/// </summary>
|
|||
/// <param name="handler">Action to handle the event</param>
|
|||
public AsyncActionEventHandler(Func<TEvent, Task> handler) |
|||
{ |
|||
Action = handler; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Handles the event.
|
|||
/// </summary>
|
|||
/// <param name="eventData"></param>
|
|||
public async Task HandleEventAsync(TEvent eventData) |
|||
{ |
|||
await Action(eventData); |
|||
} |
|||
} |
|||
} |
|||
@ -1,17 +0,0 @@ |
|||
using System.Threading.Tasks; |
|||
|
|||
namespace Volo.Abp.EventBus |
|||
{ |
|||
/// <summary>
|
|||
/// Defines an interface of a class that handles events asynchrounously of type <see cref="IAsyncEventHandler{TEventData}"/>.
|
|||
/// </summary>
|
|||
/// <typeparam name="TEvent">Event type to handle</typeparam>
|
|||
public interface IAsyncEventHandler<in TEvent> : IEventHandler |
|||
{ |
|||
/// <summary>
|
|||
/// Handler handles the event by implementing this method.
|
|||
/// </summary>
|
|||
/// <param name="eventData">Event data</param>
|
|||
Task HandleEventAsync(TEvent eventData); |
|||
} |
|||
} |
|||
@ -1,16 +0,0 @@ |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp.DependencyInjection; |
|||
|
|||
namespace Volo.Abp.EventBus |
|||
{ |
|||
public class MySimpleAsyncEventDataHandler : IAsyncEventHandler<MySimpleEventData>, ISingletonDependency |
|||
{ |
|||
public int TotalData { get; private set; } |
|||
|
|||
public Task HandleEventAsync(MySimpleEventData eventData) |
|||
{ |
|||
TotalData += eventData.Value; |
|||
return Task.CompletedTask; |
|||
} |
|||
} |
|||
} |
|||
@ -1,23 +0,0 @@ |
|||
using System; |
|||
using System.Threading.Tasks; |
|||
|
|||
namespace Volo.Abp.EventBus |
|||
{ |
|||
public class MySimpleTransientAsyncEventHandler : IAsyncEventHandler<MySimpleEventData>, IDisposable |
|||
{ |
|||
public static int HandleCount { get; set; } |
|||
|
|||
public static int DisposeCount { get; set; } |
|||
|
|||
public Task HandleEventAsync(MySimpleEventData eventData) |
|||
{ |
|||
++HandleCount; |
|||
return Task.FromResult(0); |
|||
} |
|||
|
|||
public void Dispose() |
|||
{ |
|||
++DisposeCount; |
|||
} |
|||
} |
|||
} |
|||
Loading…
Reference in new issue