HandlerRegistrations
Namespace: RA.Utilities.Dispatcher.Generated
HandlerRegistrations is the runtime-side queue that carries the compile-time registrations of your handlers and closed pipeline behaviors. You never call it directly — the source generator's module initializers enqueue into it, and AddMediator() drains it.
📦 Type Definition
public static class HandlerRegistrations
{
public static void Add(Action<IServiceCollection> registration);
internal static void ApplyAll(IServiceCollection services);
}
🎯 How It Works
- At compile time, the package's source generator emits a module initializer per assembly containing
IRequestHandler<,>/IRequestHandler<>/INotificationHandler<>implementations or closed behaviors. The initializer callsHandlerRegistrations.Add(...)with a callback that registers:- handlers under their interfaces and as themselves (concrete type, for the generated mediator's direct injection),
- closed behaviors under their behavior interfaces.
- At assembly load, the module initializer runs and queues the callback.
- At startup,
AddMediator()callsApplyAll, applying every queued registration to theIServiceCollectionin one pass.
The queue is thread-safe (a lock guards a snapshot on apply).
⏳ Lifetimes
| Registration | Lifetime |
|---|---|
IRequestHandler<TRequest, TResponse> → handler | Scoped |
IRequestHandler<TRequest> → handler | Scoped |
INotificationHandler<TNotification> → handler | Transient |
| Handler as its concrete type | Same as the interface registration |
| Closed behavior under its interface | Transient |
🔗 Related
- Auto Registration — the discovery rules, diagnostics (
DSAG001–DSAG005,DSAG010), and the assembly-loading guarantee. MediatorRegistrations— the sibling queue for the generatedMediator.