Struct ValueParserContext
Carries the current route segment and request-scoped services into an asynchronous value parser.
Inherited Members
Namespace: NanoRoute
Assembly: NanoRoute.dll
Syntax
public readonly struct ValueParserContext
Examples
builder.AddValueParser("user", static async context =>
{
Guid id = Guid.Parse(context.Segment.ToString());
object? user = await context.Services.GetRequiredService<IUserStore>().FindAsync(id, context.Cancellation);
return new ValueParseResult(user is not null, user);
});
Properties
Arguments
Gets the parser arguments that were bound during route registration.
Declaration
public object? Arguments { get; init; }
Property Value
| Type | Description |
|---|---|
| object |
Examples
ParserLimits? limits = (ParserLimits?) context.Arguments;
Cancellation
Gets the linked pipeline cancellation token.
Declaration
public CancellationToken Cancellation { get; init; }
Property Value
| Type | Description |
|---|---|
| CancellationToken |
Examples
context.Cancellation.ThrowIfCancellationRequested();
Segment
Gets the decoded route segment.
Declaration
public required ReadOnlyMemory<char> Segment { get; init; }
Property Value
| Type | Description |
|---|---|
| ReadOnlyMemory<char> |
Examples
string value = context.Segment.ToString();
Services
Gets the request-scoped service provider.
Declaration
public required IServiceProvider Services { get; init; }
Property Value
| Type | Description |
|---|---|
| IServiceProvider |
Examples
IUserStore store = context.Services.GetRequiredService<IUserStore>();