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:
parent
148a878951
commit
f77c1ff29b
20 changed files with 918 additions and 133 deletions
24
README.md
24
README.md
|
|
@ -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.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue