Skip to content

Commit ec0d825

Browse files
committed
Add middleware convention section
1 parent 8dfc91b commit ec0d825

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

README.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,32 @@ Valid handler method names:
237237
- Known parameters: `CancellationToken` is automatically provided by the mediator
238238
- Service resolution: All other parameters are resolved from the DI container
239239

240+
### Ignoring Handlers
241+
242+
- Annotate handler classes or methods with `[FoundatioIgnore]` to exclude them from discovery
243+
244+
## 🎪 Middleware Conventions
245+
246+
- Classes should end with `Middleware`
247+
- Valid method names:
248+
- `Before(...)` / `BeforeAsync(...)`
249+
- `After(...)` / `AfterAsync(...)`
250+
- `Finally(...)` / `FinallyAsync(...)`
251+
- First parameter must be the message (can be `object`, an interface, or a concrete type)
252+
- Lifecycle methods are optional—you can implement any subset (`Before`, `After`, `Finally`)
253+
- `Before` can return:
254+
- a `HandlerResult` to short-circuit execution
255+
- a single state value
256+
- a tuple of state values
257+
- Values (single or tuple elements) returned from `Before` are matched by type and injected into `After`/`Finally` parameters
258+
- `After` runs only on successful handler completion
259+
- `Finally` always runs, regardless of success or failure
260+
- Methods may declare additional parameters: `CancellationToken`, DI-resolved services
261+
262+
### Ignoring Middleware
263+
264+
- Annotate middleware classes or methods with `[FoundatioIgnore]` to exclude them from discovery
265+
240266
## 🔧 API Reference
241267

242268
### IMediator Interface

0 commit comments

Comments
 (0)