Registration methods
Vitreous provides two ways to register handlers. They are mutually exclusive — choose one.
Source-generated (recommended)
Section titled “Source-generated (recommended)”AddVitreousHandlers() has zero runtime reflection. The generator emits a concrete dispatcher at build time. Requires Vitreous.SourceGeneration on the entry-point project.
builder.Services.AddVitreousHandlers();Reflection-based
Section titled “Reflection-based”AddVitreousHandlers(params Assembly[]) scans the supplied assemblies at application startup. No source generator needed. Useful for plugin architectures or when compile-time generation is not available.
builder.Services.AddVitreousHandlers( typeof(CreateOrderHandler).Assembly, typeof(SendConfirmationEmailHandler).Assembly);The reflection-based APIs are marked [RequiresUnreferencedCode] and [RequiresDynamicCode], so trimmed and AOT apps get IL2026 and IL3050 for them. See Native AOT and trimming.
Comparison
Section titled “Comparison”AddVitreousHandlers() |
AddVitreousHandlers(assemblies) |
|
|---|---|---|
| Discovery | Build time | Startup (reflection) |
| Runtime reflection | None | Yes |
| AOT compatible | Yes | No |
| Multi-project | Automatic | Manual — specify each assembly |
| Dispatcher | VitreousDispatcher (generated) |
ReflectionSender |
| Best for | Most applications | Plugin architectures, dynamic loading |
Both overloads accept an Action<VitreousOptions>. See Options.