mirror of
https://github.com/m-lamonaca/dev-notes.git
synced 2025-04-08 11:56:41 +00:00
Add minimal api filter notes
This commit is contained in:
parent
77ec748785
commit
82642f25bc
1 changed files with 19 additions and 0 deletions
|
@ -139,6 +139,25 @@ app.MapGet("/todos/{id}", async Results<Ok<Todo>, NotFound> (int id, TodoDb db)
|
||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Filters
|
||||||
|
|
||||||
|
```cs
|
||||||
|
public class ExampleFilter : IRouteHandlerFilter
|
||||||
|
{
|
||||||
|
public async ValueTask<object?> InvokeAsync(RouteHandlerInvocationContext context, RouteHandlerFilterDelegate next)
|
||||||
|
{
|
||||||
|
// before endpoint call
|
||||||
|
var result = next(context);
|
||||||
|
/// after endpoint call
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
```cs
|
||||||
|
app.MapPost("/route", Handler).AddFilter<ExampleFilter>();
|
||||||
|
```
|
||||||
|
|
||||||
## Context
|
## Context
|
||||||
|
|
||||||
With Minimal APIs it's possible to access the contextual information by passing one of the following types as a parameter to your handler delegate:
|
With Minimal APIs it's possible to access the contextual information by passing one of the following types as a parameter to your handler delegate:
|
||||||
|
|
Loading…
Add table
Reference in a new issue