ActionEventHandler.cs 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. using System;
  2. using Abp.Dependency;
  3. namespace Abp.Events.Bus.Handlers.Internals
  4. {
  5. /// <summary>
  6. /// This event handler is an adapter to be able to use an action as <see cref="IEventHandler{TEventData}"/> implementation.
  7. /// </summary>
  8. /// <typeparam name="TEventData">Event type</typeparam>
  9. internal class ActionEventHandler<TEventData> :
  10. IEventHandler<TEventData>,
  11. ITransientDependency
  12. {
  13. /// <summary>
  14. /// Action to handle the event.
  15. /// </summary>
  16. public Action<TEventData> Action { get; private set; }
  17. /// <summary>
  18. /// Creates a new instance of <see cref="ActionEventHandler{TEventData}"/>.
  19. /// </summary>
  20. /// <param name="handler">Action to handle the event</param>
  21. public ActionEventHandler(Action<TEventData> handler)
  22. {
  23. Action = handler;
  24. }
  25. /// <summary>
  26. /// Handles the event.
  27. /// </summary>
  28. /// <param name="eventData"></param>
  29. public void HandleEvent(TEventData eventData)
  30. {
  31. Action(eventData);
  32. }
  33. }
  34. }