feat: add Roslyn-based compile-time request handler registration

Introduce compile-time registration capabilities with source generation, enabling automatic handler registration.
This commit is contained in:
Louis Seubert 2026-05-23 21:22:30 +02:00
commit f77c1ff29b
Signed by: louis9902
GPG key ID: 4B9DB28F826553BD
20 changed files with 918 additions and 133 deletions

View file

@ -66,7 +66,29 @@ public class ScalarBehavior : IScalarRequestBehavior<ScalarRequest, string>
}
```
### Compile-time registration
Projects that directly reference `Geekeey.Request` also get generated registration methods in the
`Geekeey.Request` namespace:
```csharp
collection.AddRequestDispatcher(builder => builder
.AddExampleProject()
.Add(typeof(ScalarBehavior)));
collection.AddRequestDispatcher(builder => builder
.AddExampleProject(ServiceLifetime.Scoped)
.Add(typeof(ScalarBehavior)));
```
- generation is enabled by default
- disable it with `<CompiletimeRequestDispatchHandlerRegistration>false</CompiletimeRequestDispatchHandlerRegistration>`
- rename the generated `Add<Name>(...)` methods with `CompiletimeRequestDispatchHandlerName`
- only request handlers are generated; behaviors still need normal registration
- nested request handlers are rejected during `Add(...)` registration, including `SearchHandlerInAssembly(...)` and by the source generator
- use one registration style per assembly: generated methods or `SearchHandlerInAssembly(...)`
## Behaviour of the Handlers
Handlers are resolved from either the DI conatiner or are created on the fly but can receive arguments from the DI
Handlers are resolved from either the DI container or are created on the fly but can receive arguments from the DI
container when being constructed. The same also applied for the request pipeline behaviours.