Class EventBus
- Namespace
- ReflectionEventing
- Assembly
- ReflectionEventing.dll
Represents a class that provides event publishing capabilities.
public class EventBus : IEventBus
- Inheritance
-
EventBus
- Implements
- Derived
- Inherited Members
- Extension Methods
Remarks
This class uses a service provider to get required services and a consumer provider to get consumers for a specific event type.
Constructors
EventBus(IConsumerProvider, IConsumerTypesProvider, IEventsQueue)
Represents a class that provides event publishing capabilities.
public EventBus(IConsumerProvider consumerProviders, IConsumerTypesProvider consumerTypesProvider, IEventsQueue queue)
Parameters
consumerProvidersIConsumerProviderconsumerTypesProviderIConsumerTypesProviderqueueIEventsQueue
Remarks
This class uses a service provider to get required services and a consumer provider to get consumers for a specific event type.
Methods
PublishAsync<TEvent>(TEvent, CancellationToken)
Adds the specified event to the queue.Another scope will take over execution as configured.
public virtual Task PublishAsync<TEvent>(TEvent eventItem, CancellationToken cancellationToken = default) where TEvent : class
Parameters
eventItemTEventThe event to publish.
cancellationTokenCancellationTokenA cancellation token that can be used to cancel the operation.
Returns
- Task
A task that represents the asynchronous operation.
Type Parameters
TEventThe type of the event to publish.
Remarks
The method only adds the event to the execution queue, it does not wait for its successful execution.
SendAsync<TEvent>(TEvent, CancellationToken)
Sends the specified event asynchronously within the current scope, waiting for its execution.
public virtual Task SendAsync<TEvent>(TEvent eventItem, CancellationToken cancellationToken = default) where TEvent : class
Parameters
eventItemTEventThe event to send.
cancellationTokenCancellationTokenA cancellation token that can be used to cancel the operation.
Returns
- Task
A task that represents the asynchronous operation.
Type Parameters
TEventThe type of the event to send.
Remarks
This method gets the consumers for the specified event type from the consumer provider and then uses the service provider to get the required service for each consumer. Each consumer is then used to consume the event asynchronously.