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.
ICompositionEventsSubscriber provides fine-grained, route-scoped event handling within the ServiceComposer pipeline. Unlike ICompositionEventsHandler<TEvent> — which is invoked globally regardless of route — an ICompositionEventsSubscriber is only activated on routes that match its HTTP method and route template attributes. This makes it the right choice whenever you need event reactions that are tightly scoped to a particular endpoint.
Implementations are discovered by the assembly scanner, registered as transient services, and called during the composition lifecycle to register their lambda-based subscriptions before the composition handlers run.
Namespace
ServiceComposer.AspNetCore
Interface definition
Related interface: ICompositionEventsPublisher
ICompositionEventsPublisher is injected into Subscribe by the pipeline. It exposes one method:
publisher.Subscribe<TEvent>(handler) to register a CompositionEventHandler<TEvent> delegate that will be invoked when any composition handler raises TEvent on the matched route.
Related delegate type
Methods
Subscribe
Called once per matched request, before composition handlers execute. Register one or more event handlers by callingpublisher.Subscribe<TEvent>.
The event publisher scoped to the current composition request and route. Call
publisher.Subscribe<TEvent>(handler) for each event type this subscriber wants to handle on the matched route.void.
Route binding
Decorate the implementing class (or theSubscribe method) with standard ASP.NET Core routing attributes — [HttpGet], [HttpPost], [HttpPut], [HttpDelete] — to declare the route(s) this subscriber should be active on. The assembly scanner reads these attributes and maps the subscriber to the appropriate composition endpoints.
Usage example
The following example shows a subscriber that is active only onGET /route-based-handler/{some-id}. When AnEvent is raised by any handler on that route, the lambda receives it and writes to the ViewModel.
RaiseEvent on the same route:
Choosing between ICompositionEventsSubscriber and ICompositionEventsHandler
| Concern | ICompositionEventsSubscriber | ICompositionEventsHandler<TEvent> |
|---|---|---|
| Route scope | Specific routes only | All routes |
| Registration style | Lambda delegate | Class-based |
| Multiple event types | Multiple Subscribe<T> calls in one method | One class per event type |
| Typical use case | Tightly coupled route logic | Cross-cutting concerns |
DI registration
The assembly scanner discovers and registersICompositionEventsSubscriber implementations automatically as transient services when AddViewModelComposition is called: