Class Router<TDescendant, TConfig>

Provides the self-typed base for concrete router implementations with strongly typed configuration.

Inheritance
object
Router
Router<TDescendant, TConfig>
HttpListenerRouter
Inherited Members
Router.TraceIdName
Router.OriginalRequestName
Router.Handle(HttpRequestMessage, IServiceProvider, CancellationToken)
object.GetType()
object.MemberwiseClone()
object.ToString()
object.Equals(object)
object.Equals(object, object)
object.ReferenceEquals(object, object)
object.GetHashCode()
Namespace: NanoRoute
Assembly: NanoRoute.dll
Syntax
public abstract class Router<TDescendant, TConfig> : Router where TDescendant : Router<TDescendant, TConfig> where TConfig : RouterConfig, new()
Type Parameters
Name Description
TDescendant

The concrete router type produced by CreateBuilder().

TConfig

The configuration type exposed by Config.

Remarks

Concrete routers derive from this type to inherit CreateBuilder() and a typed Config property. The concrete router must expose a public or non-public constructor that accepts RouterBuilder<TRouter, TConfig> so the generated factory can create immutable router snapshots.

Examples
public sealed class MyRouter : Router<MyRouter, RouterConfig>
{
    private MyRouter(RouterBuilder<MyRouter, RouterConfig> builder) : base(builder)
    {
    }
}

Constructors

Router(RouterBuilder<TDescendant, TConfig>)

Provides the self-typed base for concrete router implementations with strongly typed configuration.

Declaration
protected Router(RouterBuilder<TDescendant, TConfig> builder)
Parameters
Type Name Description
RouterBuilder<TDescendant, TConfig> builder

The builder whose route snapshot and configuration initialize the router.

Remarks

Concrete routers derive from this type to inherit CreateBuilder() and a typed Config property. The concrete router must expose a public or non-public constructor that accepts RouterBuilder<TRouter, TConfig> so the generated factory can create immutable router snapshots.

Examples
public sealed class MyRouter : Router<MyRouter, RouterConfig>
{
    private MyRouter(RouterBuilder<MyRouter, RouterConfig> builder) : base(builder)
    {
    }
}

Properties

Config

Configuration assigned to this instance.

Declaration
public TConfig Config { get; }
Property Value
Type Description
TConfig

Methods

CreateBuilder()

Creates a strongly typed builder.

Declaration
public static RouterBuilder<TDescendant, TConfig> CreateBuilder()
Returns
Type Description
RouterBuilder<TDescendant, TConfig>

A builder that can register handlers, value parsers, and router configuration.

Examples
RouterBuilder<MyRouter, RouterConfig> builder = MyRouter.CreateBuilder();
Exceptions
Type Condition
MissingMethodException

Thrown when TDescendant does not declare a public or non-public constructor that accepts RouterBuilder<TRouter, TConfig>.

In this article
Back to top Generated by DocFX