The TaskHub.Shared.Events.Abstractions module defines the core interfaces and base classes for the event-driven architecture within the system.
Every event in the system must implement IEvent.
public interface IEvent
{
DateTime CreatedAt { get; }
}
EventBase provides a default implementation that sets CreatedAt to DateTime.UtcNow.
Cross-events (or Integration Events) are used for communication between different microservices or modules. They often carry more metadata and are designed for serialization.
public interface ICrossEvent : IEvent
{
Guid EventId { get; }
string EventName { get; }
}
The IEventsBus is responsible for dispatching cross-events.
public interface IEventsBus
{
Task SendAsync<TEvent>(TEvent request, CancellationToken ct)
where TEvent : ICrossEvent;
}
Unlike the ICommandsBus, the IEventsBus is typically asynchronous and fire-and-forget from the perspective of the publisher’s business logic (often implemented via an Outbox pattern).
Handlers for events must implement this interface.
public interface IEventHandler<in TRequest> where TRequest : IEvent
{
Task HandleAsync(TRequest request, CancellationToken ct);
}