| 1234567891011121314151617181920212223242526272829303132333435363738 |
- using System;
- using System.Threading.Tasks;
- using Abp.Dependency;
- namespace Abp.Events.Bus.Handlers.Internals
- {
- /// <summary>
- /// This event handler is an adapter to be able to use an action as <see cref="IAsyncEventHandler{TEventData}"/> implementation.
- /// </summary>
- /// <typeparam name="TEventData">Event type</typeparam>
- internal class AsyncActionEventHandler<TEventData> :
- IAsyncEventHandler<TEventData>,
- ITransientDependency
- {
- /// <summary>
- /// Function to handle the event.
- /// </summary>
- public Func<TEventData, Task> Action { get; private set; }
- /// <summary>
- /// Creates a new instance of <see cref="AsyncActionEventHandler{TEventData}"/>.
- /// </summary>
- /// <param name="handler">Action to handle the event</param>
- public AsyncActionEventHandler(Func<TEventData, Task> handler)
- {
- Action = handler;
- }
- /// <summary>
- /// Handles the event.
- /// </summary>
- /// <param name="eventData"></param>
- public async Task HandleEventAsync(TEventData eventData)
- {
- await Action(eventData);
- }
- }
- }
|