Handler Registration
Current Model (Sample-Aligned)
NOF no longer depends on calling AddAllHandlers() or Add*AutoInjectServices() from user code.
The runtime model is:
- Source generators emit assembly-level initializers (
[assembly: AssemblyInitializeAttribute<...>]). - Initializers write metadata into the builder-owned
Registry:
Registry.AutoInjectRegistryRegistry.RequestHandlerRegistryRegistry.CommandHandlerRegistryRegistry.NotificationHandlerRegistryRegistry.EventHandlerRegistryRegistry.MapperRegistry
- At startup,
builder.AddApplicationPart(assembly)executes those initializers. - Registry collections freeze on first read; indexed registries build their indexes when frozen.
- Registration steps wire the runtime:
AutoInjectServiceRegistrationStepRequestHandlerServiceRegistrationStepHandlerServiceRegistrationStep
This is the same pattern used by the sample app:
builder.AddApplicationPart(typeof(NOFSampleService).Assembly)
.AddApplicationPart(typeof(TokenAuthorityService).Assembly);
Practical Guidance
- If handlers or mappers are not discovered, first check that the assembly containing them is added via
AddApplicationPart(...). - Keep RPC contracts (
IRpcService) and their implementations in assemblies that are loaded as application parts. - Transport integrations such as RabbitMQ consume the frozen handler registries, so stale or missing application parts will prevent consumer registration.
AutoInjectRegistrystores nativeServiceDescriptorinstances; there is no separateAutoInjectServiceRegistrationmodel anymore.