mirror of https://github.com/abpframework/abp.git
16 changed files with 162 additions and 179 deletions
@ -1,7 +1,128 @@ |
|||
using System; |
|||
using System.Threading.Tasks; |
|||
|
|||
namespace Volo.Abp.EventBus |
|||
{ |
|||
public interface IEventBus : IEventSubscriber, IEventPublisher |
|||
public interface IEventBus |
|||
{ |
|||
/// <summary>
|
|||
/// Triggers an event asynchronously.
|
|||
/// </summary>
|
|||
/// <typeparam name="TEvent">Event type</typeparam>
|
|||
/// <param name="eventData">Related data for the event</param>
|
|||
/// <returns>The task to handle async operation</returns>
|
|||
Task PublishAsync<TEvent>(TEvent eventData) |
|||
where TEvent : class; |
|||
|
|||
/// <summary>
|
|||
/// Triggers an event asynchronously.
|
|||
/// </summary>
|
|||
/// <param name="eventType">Event type</param>
|
|||
/// <param name="eventData">Related data for the event</param>
|
|||
/// <returns>The task to handle async operation</returns>
|
|||
Task PublishAsync(Type eventType, object eventData); |
|||
|
|||
/// <summary>
|
|||
/// Registers to an event.
|
|||
/// Given action is called for all event occurrences.
|
|||
/// </summary>
|
|||
/// <param name="action">Action to handle events</param>
|
|||
/// <typeparam name="TEvent">Event type</typeparam>
|
|||
IDisposable Subscribe<TEvent>(Func<TEvent, Task> action) |
|||
where TEvent : class; |
|||
|
|||
/// <summary>
|
|||
/// Registers to an event.
|
|||
/// Same (given) instance of the handler is used for all event occurrences.
|
|||
/// </summary>
|
|||
/// <typeparam name="TEvent">Event type</typeparam>
|
|||
/// <param name="handler">Object to handle the event</param>
|
|||
IDisposable Subscribe<TEvent>(ILocalEventHandler<TEvent> handler) |
|||
where TEvent : class; |
|||
|
|||
/// <summary>
|
|||
/// Registers to an event.
|
|||
/// A new instance of <see cref="THandler"/> object is created for every event occurrence.
|
|||
/// </summary>
|
|||
/// <typeparam name="TEvent">Event type</typeparam>
|
|||
/// <typeparam name="THandler">Type of the event handler</typeparam>
|
|||
IDisposable Subscribe<TEvent, THandler>() |
|||
where TEvent : class |
|||
where THandler : IEventHandler, new(); |
|||
|
|||
/// <summary>
|
|||
/// Registers to an event.
|
|||
/// Same (given) instance of the handler is used for all event occurrences.
|
|||
/// </summary>
|
|||
/// <param name="eventType">Event type</param>
|
|||
/// <param name="handler">Object to handle the event</param>
|
|||
IDisposable Subscribe(Type eventType, IEventHandler handler); |
|||
|
|||
/// <summary>
|
|||
/// Registers to an event.
|
|||
/// Given factory is used to create/release handlers
|
|||
/// </summary>
|
|||
/// <typeparam name="TEvent">Event type</typeparam>
|
|||
/// <param name="factory">A factory to create/release handlers</param>
|
|||
IDisposable Subscribe<TEvent>(IEventHandlerFactory factory) |
|||
where TEvent : class; |
|||
|
|||
/// <summary>
|
|||
/// Registers to an event.
|
|||
/// </summary>
|
|||
/// <param name="eventType">Event type</param>
|
|||
/// <param name="factory">A factory to create/release handlers</param>
|
|||
IDisposable Subscribe(Type eventType, IEventHandlerFactory factory); |
|||
|
|||
/// <summary>
|
|||
/// Unregisters from an event.
|
|||
/// </summary>
|
|||
/// <typeparam name="TEvent">Event type</typeparam>
|
|||
/// <param name="action"></param>
|
|||
void Unsubscribe<TEvent>(Func<TEvent, Task> action) |
|||
where TEvent : class; |
|||
|
|||
/// <summary>
|
|||
/// Unregisters from an event.
|
|||
/// </summary>
|
|||
/// <typeparam name="TEvent">Event type</typeparam>
|
|||
/// <param name="handler">Handler object that is registered before</param>
|
|||
void Unsubscribe<TEvent>(ILocalEventHandler<TEvent> handler) |
|||
where TEvent : class; |
|||
|
|||
/// <summary>
|
|||
/// Unregisters from an event.
|
|||
/// </summary>
|
|||
/// <param name="eventType">Event type</param>
|
|||
/// <param name="handler">Handler object that is registered before</param>
|
|||
void Unsubscribe(Type eventType, IEventHandler handler); |
|||
|
|||
/// <summary>
|
|||
/// Unregisters from an event.
|
|||
/// </summary>
|
|||
/// <typeparam name="TEvent">Event type</typeparam>
|
|||
/// <param name="factory">Factory object that is registered before</param>
|
|||
void Unsubscribe<TEvent>(IEventHandlerFactory factory) |
|||
where TEvent : class; |
|||
|
|||
/// <summary>
|
|||
/// Unregisters from an event.
|
|||
/// </summary>
|
|||
/// <param name="eventType">Event type</param>
|
|||
/// <param name="factory">Factory object that is registered before</param>
|
|||
void Unsubscribe(Type eventType, IEventHandlerFactory factory); |
|||
|
|||
/// <summary>
|
|||
/// Unregisters all event handlers of given event type.
|
|||
/// </summary>
|
|||
/// <typeparam name="TEvent">Event type</typeparam>
|
|||
void UnsubscribeAll<TEvent>() |
|||
where TEvent : class; |
|||
|
|||
/// <summary>
|
|||
/// Unregisters all event handlers of given event type.
|
|||
/// </summary>
|
|||
/// <param name="eventType">Event type</param>
|
|||
void UnsubscribeAll(Type eventType); |
|||
} |
|||
} |
|||
@ -1,26 +1,13 @@ |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp.EventBus.Distributed; |
|||
|
|||
namespace Volo.Abp.EventBus |
|||
{ |
|||
/// <summary>
|
|||
/// Undirect base interface for all event handlers.
|
|||
/// Implement <see cref="IEventHandler{TEvent}"/> instead of this one.
|
|||
/// Implement <see cref="ILocalEventHandler{TEvent}"/> or <see cref="IDistributedEventHandler{TEvent}"/> instead of this one.
|
|||
/// </summary>
|
|||
public interface IEventHandler |
|||
{ |
|||
|
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Defines an interface of a class that handles events asynchrounously of type <see cref="IEventHandler{TEvent}"/>.
|
|||
/// </summary>
|
|||
/// <typeparam name="TEvent">Event type to handle</typeparam>
|
|||
public interface IEventHandler<in TEvent> : IEventHandler |
|||
{ |
|||
/// <summary>
|
|||
/// Handler handles the event by implementing this method.
|
|||
/// </summary>
|
|||
/// <param name="eventData">Event data</param>
|
|||
Task HandleEventAsync(TEvent eventData); |
|||
} |
|||
} |
|||
@ -1,25 +0,0 @@ |
|||
using System; |
|||
using System.Threading.Tasks; |
|||
|
|||
namespace Volo.Abp.EventBus |
|||
{ |
|||
public interface IEventPublisher |
|||
{ |
|||
/// <summary>
|
|||
/// Triggers an event asynchronously.
|
|||
/// </summary>
|
|||
/// <typeparam name="TEvent">Event type</typeparam>
|
|||
/// <param name="eventData">Related data for the event</param>
|
|||
/// <returns>The task to handle async operation</returns>
|
|||
Task PublishAsync<TEvent>(TEvent eventData) |
|||
where TEvent : class; |
|||
|
|||
/// <summary>
|
|||
/// Triggers an event asynchronously.
|
|||
/// </summary>
|
|||
/// <param name="eventType">Event type</param>
|
|||
/// <param name="eventData">Related data for the event</param>
|
|||
/// <returns>The task to handle async operation</returns>
|
|||
Task PublishAsync(Type eventType, object eventData); |
|||
} |
|||
} |
|||
@ -1,111 +0,0 @@ |
|||
using System; |
|||
using System.Threading.Tasks; |
|||
|
|||
namespace Volo.Abp.EventBus |
|||
{ |
|||
public interface IEventSubscriber |
|||
{ |
|||
/// <summary>
|
|||
/// Registers to an event.
|
|||
/// Given action is called for all event occurrences.
|
|||
/// </summary>
|
|||
/// <param name="action">Action to handle events</param>
|
|||
/// <typeparam name="TEvent">Event type</typeparam>
|
|||
IDisposable Subscribe<TEvent>(Func<TEvent, Task> action) |
|||
where TEvent : class; |
|||
|
|||
/// <summary>
|
|||
/// Registers to an event.
|
|||
/// Same (given) instance of the handler is used for all event occurrences.
|
|||
/// </summary>
|
|||
/// <typeparam name="TEvent">Event type</typeparam>
|
|||
/// <param name="handler">Object to handle the event</param>
|
|||
IDisposable Subscribe<TEvent>(IEventHandler<TEvent> handler) |
|||
where TEvent : class; |
|||
|
|||
/// <summary>
|
|||
/// Registers to an event.
|
|||
/// A new instance of <see cref="THandler"/> object is created for every event occurrence.
|
|||
/// </summary>
|
|||
/// <typeparam name="TEvent">Event type</typeparam>
|
|||
/// <typeparam name="THandler">Type of the event handler</typeparam>
|
|||
IDisposable Subscribe<TEvent, THandler>() |
|||
where TEvent : class |
|||
where THandler : IEventHandler, new(); |
|||
|
|||
/// <summary>
|
|||
/// Registers to an event.
|
|||
/// Same (given) instance of the handler is used for all event occurrences.
|
|||
/// </summary>
|
|||
/// <param name="eventType">Event type</param>
|
|||
/// <param name="handler">Object to handle the event</param>
|
|||
IDisposable Subscribe(Type eventType, IEventHandler handler); |
|||
|
|||
/// <summary>
|
|||
/// Registers to an event.
|
|||
/// Given factory is used to create/release handlers
|
|||
/// </summary>
|
|||
/// <typeparam name="TEvent">Event type</typeparam>
|
|||
/// <param name="factory">A factory to create/release handlers</param>
|
|||
IDisposable Subscribe<TEvent>(IEventHandlerFactory factory) |
|||
where TEvent : class; |
|||
|
|||
/// <summary>
|
|||
/// Registers to an event.
|
|||
/// </summary>
|
|||
/// <param name="eventType">Event type</param>
|
|||
/// <param name="factory">A factory to create/release handlers</param>
|
|||
IDisposable Subscribe(Type eventType, IEventHandlerFactory factory); |
|||
|
|||
/// <summary>
|
|||
/// Unregisters from an event.
|
|||
/// </summary>
|
|||
/// <typeparam name="TEvent">Event type</typeparam>
|
|||
/// <param name="action"></param>
|
|||
void Unsubscribe<TEvent>(Func<TEvent, Task> action) |
|||
where TEvent : class; |
|||
|
|||
/// <summary>
|
|||
/// Unregisters from an event.
|
|||
/// </summary>
|
|||
/// <typeparam name="TEvent">Event type</typeparam>
|
|||
/// <param name="handler">Handler object that is registered before</param>
|
|||
void Unsubscribe<TEvent>(IEventHandler<TEvent> handler) |
|||
where TEvent : class; |
|||
|
|||
/// <summary>
|
|||
/// Unregisters from an event.
|
|||
/// </summary>
|
|||
/// <param name="eventType">Event type</param>
|
|||
/// <param name="handler">Handler object that is registered before</param>
|
|||
void Unsubscribe(Type eventType, IEventHandler handler); |
|||
|
|||
/// <summary>
|
|||
/// Unregisters from an event.
|
|||
/// </summary>
|
|||
/// <typeparam name="TEvent">Event type</typeparam>
|
|||
/// <param name="factory">Factory object that is registered before</param>
|
|||
void Unsubscribe<TEvent>(IEventHandlerFactory factory) |
|||
where TEvent : class; |
|||
|
|||
/// <summary>
|
|||
/// Unregisters from an event.
|
|||
/// </summary>
|
|||
/// <param name="eventType">Event type</param>
|
|||
/// <param name="factory">Factory object that is registered before</param>
|
|||
void Unsubscribe(Type eventType, IEventHandlerFactory factory); |
|||
|
|||
/// <summary>
|
|||
/// Unregisters all event handlers of given event type.
|
|||
/// </summary>
|
|||
/// <typeparam name="TEvent">Event type</typeparam>
|
|||
void UnsubscribeAll<TEvent>() |
|||
where TEvent : class; |
|||
|
|||
/// <summary>
|
|||
/// Unregisters all event handlers of given event type.
|
|||
/// </summary>
|
|||
/// <param name="eventType">Event type</param>
|
|||
void UnsubscribeAll(Type eventType); |
|||
} |
|||
} |
|||
@ -0,0 +1,13 @@ |
|||
using System.Threading.Tasks; |
|||
|
|||
namespace Volo.Abp.EventBus |
|||
{ |
|||
public interface ILocalEventHandler<in TEvent> : IEventHandler |
|||
{ |
|||
/// <summary>
|
|||
/// Handler handles the event by implementing this method.
|
|||
/// </summary>
|
|||
/// <param name="eventData">Event data</param>
|
|||
Task HandleEventAsync(TEvent eventData); |
|||
} |
|||
} |
|||
Loading…
Reference in new issue