Documentation Index
Fetch the complete documentation index at: https://mintlify.com/ServiceComposer/ServiceComposer.AspNetCore/llms.txt
Use this file to discover all available pages before exploring further.
ICompositionEventsHandler<TEvent> lets any component in the composition pipeline react to events raised by other handlers. Whenever a handler calls ICompositionContext.RaiseEvent<TEvent>, every registered ICompositionEventsHandler<TEvent> is invoked — regardless of which route triggered the composition. This makes the generic handler appropriate for cross-cutting, route-agnostic reactions such as logging, telemetry enrichment, or shared ViewModel transformations.
When you need a handler that reacts only to events raised on a specific route, use ICompositionEventsSubscriber instead.
Implementations are discovered automatically by the assembly scanner and registered as transient services.
Namespace
ServiceComposer.AspNetCore
Interface definition
Related delegate type
CompositionEventHandler<TEvent> is the delegate type used when subscribing to events through ICompositionEventsPublisher (see ICompositionEventsSubscriber):
Methods
Handle
Called by the ServiceComposer pipeline every time an event of typeTEvent is raised via ICompositionContext.RaiseEvent, on any composition route.
The raised event instance. The type parameter
TEvent must exactly match the type passed to RaiseEvent<TEvent>.The current
HttpRequest. Use this to access route values, query string, the shared ViewModel (GetComposedResponseModel()), or the composition context (GetCompositionContext()).Task — a task that completes when the handler has finished processing the event.
Route scope
ICompositionEventsHandler<TEvent> has no route affinity. It is invoked for every composition request on which the matching event is raised. If you need a handler that is scoped to a particular route, subscribe inline using ICompositionEventsSubscriber.
Because
ICompositionEventsHandler<TEvent> is route-agnostic, avoid writing route-specific logic inside it. Use request.HttpContext.GetEndpoint() or route-value inspection if you need to branch on the matched route.Usage example
The following event and handler illustrate a simple case where pricing information is broadcast as an event and an inventory handler reacts to it:AnEvent on every route:
DI registration
The assembly scanner registers everyICompositionEventsHandler<TEvent> implementation as a transient service. Enable scanning with AddViewModelComposition:
Each
ICompositionEventsHandler<TEvent> implementation is transient. A new instance is created for every composition request, which means state cannot be shared across requests via instance fields.