Class NanoRouteHandlerExtensions

Adds typed handler overloads that project a RequestContext into a request object.

Inheritance
object
NanoRouteHandlerExtensions
Inherited Members
object.GetType()
object.MemberwiseClone()
object.ToString()
object.Equals(object)
object.Equals(object, object)
object.ReferenceEquals(object, object)
object.GetHashCode()
Namespace: NanoRoute.HandlerExtensions
Assembly: NanoRoute.dll
Syntax
public static class NanoRouteHandlerExtensions
Remarks

By default, writable public properties are bound from Parameters using the property name as the lookup key.

Properties of type RequestContext and CancellationToken are populated automatically from the current request.

Use ValueSourceAttribute to bind a property from a specific context key or service. Missing required context values and services throw InvalidOperationException.

Methods

AddHandler<TBuilder, TRequestContext>(TBuilder, IEnumerable<string>, string, Func<TRequestContext, CallNextHandlerDelegate, Task<HttpResponseMessage>>)

Registers a typed middleware handler that receives a request object and the next handler in the pipeline.

Declaration
public static TBuilder AddHandler<TBuilder, TRequestContext>(this TBuilder routeBuilder, IEnumerable<string> verbs, string pattern, Func<TRequestContext, CallNextHandlerDelegate, Task<HttpResponseMessage>> handler) where TBuilder : notnull, RouteBuilder where TRequestContext : notnull, new()
Parameters
Type Name Description
TBuilder routeBuilder
IEnumerable<string> verbs

The HTTP verbs handled by the route.

string pattern

The route pattern to register.

Func<TRequestContext, CallNextHandlerDelegate, Task<HttpResponseMessage>> handler

The typed middleware delegate.

Returns
Type Description
TBuilder

The current routeBuilder.

Type Parameters
Name Description
TBuilder
TRequestContext

The request-object type populated from the current route parameters, query bindings, services, and special framework values.

Remarks

Writable public properties are bound from Parameters by default.

A property of type RequestContext receives the current context, and a property of type CancellationToken receives the active request token.

Apply ValueSourceAttribute to bind a property from a different parameter name or from the request service provider.

AddHandler<TBuilder, TRequestContext>(TBuilder, IEnumerable<string>, string, Func<TRequestContext, Task<HttpResponseMessage>>)

Registers a typed handler that receives a request object built from the current RequestContext.

Declaration
public static TBuilder AddHandler<TBuilder, TRequestContext>(this TBuilder routeBuilder, IEnumerable<string> verbs, string pattern, Func<TRequestContext, Task<HttpResponseMessage>> handler) where TBuilder : notnull, RouteBuilder where TRequestContext : notnull, new()
Parameters
Type Name Description
TBuilder routeBuilder
IEnumerable<string> verbs

The HTTP verbs handled by the route.

string pattern

The route pattern to register.

Func<TRequestContext, Task<HttpResponseMessage>> handler

The typed handler delegate.

Returns
Type Description
TBuilder

The current routeBuilder.

Type Parameters
Name Description
TBuilder
TRequestContext

The request-object type populated from the current route parameters, query bindings, services, and special framework values.

Remarks

Writable public properties are bound from Parameters by default.

A property of type RequestContext receives the current context, and a property of type CancellationToken receives the active request token.

Apply ValueSourceAttribute to bind a property from a different parameter name or from the request service provider.

AddHandler<TBuilder, TRequestContext>(TBuilder, IEnumerable<string>, string, string, Func<TRequestContext, CallNextHandlerDelegate, Task<HttpResponseMessage>>)

Registers a typed middleware handler and the query-string bindings it depends on.

Declaration
public static TBuilder AddHandler<TBuilder, TRequestContext>(this TBuilder routeBuilder, IEnumerable<string> verbs, string pattern, string queryBindings, Func<TRequestContext, CallNextHandlerDelegate, Task<HttpResponseMessage>> handler) where TBuilder : notnull, RouteBuilder where TRequestContext : notnull, new()
Parameters
Type Name Description
TBuilder routeBuilder
IEnumerable<string> verbs

The HTTP verbs handled by the route.

string pattern

The route pattern to register.

string queryBindings

A query-parameter descriptor that is applied before handler is invoked.

Func<TRequestContext, CallNextHandlerDelegate, Task<HttpResponseMessage>> handler

The typed middleware delegate.

Returns
Type Description
TBuilder

The current routeBuilder.

Type Parameters
Name Description
TBuilder
TRequestContext

The request-object type populated from the current route parameters, query bindings, services, and special framework values.

Remarks

Writable public properties are bound from Parameters by default.

A property of type RequestContext receives the current context, and a property of type CancellationToken receives the active request token.

queryBindings are registered before the request object is created, so their parsed values are available through the default context binding rules.

Apply ValueSourceAttribute to bind a property from a different parameter name or from the request service provider.

AddHandler<TBuilder, TRequestContext>(TBuilder, IEnumerable<string>, string, string, Func<TRequestContext, Task<HttpResponseMessage>>)

Registers a typed handler and the query-string bindings it depends on.

Declaration
public static TBuilder AddHandler<TBuilder, TRequestContext>(this TBuilder routeBuilder, IEnumerable<string> verbs, string pattern, string queryBindings, Func<TRequestContext, Task<HttpResponseMessage>> handler) where TBuilder : notnull, RouteBuilder where TRequestContext : notnull, new()
Parameters
Type Name Description
TBuilder routeBuilder
IEnumerable<string> verbs

The HTTP verbs handled by the route.

string pattern

The route pattern to register.

string queryBindings

A query-parameter descriptor that is applied before handler is invoked.

Func<TRequestContext, Task<HttpResponseMessage>> handler

The typed handler delegate.

Returns
Type Description
TBuilder

The current routeBuilder.

Type Parameters
Name Description
TBuilder
TRequestContext

The request-object type populated from the current route parameters, query bindings, services, and special framework values.

Remarks

Writable public properties are bound from Parameters by default.

A property of type RequestContext receives the current context, and a property of type CancellationToken receives the active request token.

queryBindings are registered before the request object is created, so their parsed values are available through the default context binding rules.

Apply ValueSourceAttribute to bind a property from a different parameter name or from the request service provider.

In this article
Back to top Generated by DocFX