Class RouteResolverBase<TData>
Implements the logic for resolving the requested path of a HTTP context against a route, possibly handling different contexts via different handlers.
Namespace: EmbedIO.Routing
Syntax
public abstract class RouteResolverBase<TData> : ConfiguredObject
Type Parameters
Name | Description |
---|---|
TData | The type of the data used to select a suitable handler for the context. |
Constructors
RouteResolverBase(RouteMatcher)
Initializes a new instance of the RouteResolverBase<TData> class.
Declaration
protected RouteResolverBase(RouteMatcher matcher)
Parameters
Type | Name | Description |
---|---|---|
RouteMatcher | matcher | The RouteMatcher to match URL paths against. |
Properties
IsBaseRoute
Gets a value indicating whether Route is a base route.
Declaration
public bool IsBaseRoute { get; }
Property Value
Type | Description |
---|---|
Boolean |
Matcher
Gets the RouteMatcher used to match routes.
Declaration
public RouteMatcher Matcher { get; }
Property Value
Type | Description |
---|---|
RouteMatcher |
Route
Gets the route this resolver matches URL paths against.
Declaration
public string Route { get; }
Property Value
Type | Description |
---|---|
String |
Methods
Add(TData, RouteHandlerCallback)
Associates some data to a handler.
The ResolveAsync(IHttpContext) method calls GetContextData(IHttpContext)
to extract data from the context; then, for each registered data / handler pair,
MatchContextData(TData, TData) is called to determine whether handler
should be called.
Declaration
public void Add(TData data, RouteHandlerCallback handler)
Parameters
Type | Name | Description |
---|---|---|
TData | data | Data used to determine which contexts are
suitable to be handled by |
RouteHandlerCallback | handler | A callback used to handle matching contexts. |
See Also
Add(TData, SyncRouteHandlerCallback)
Associates some data to a synchronous handler.
The ResolveAsync(IHttpContext) method calls GetContextData(IHttpContext)
to extract data from the context; then, for each registered data / handler pair,
MatchContextData(TData, TData) is called to determine whether handler
should be called.
Declaration
public void Add(TData data, SyncRouteHandlerCallback handler)
Parameters
Type | Name | Description |
---|---|---|
TData | data | Data used to determine which contexts are
suitable to be handled by |
SyncRouteHandlerCallback | handler | A callback used to handle matching contexts. |
See Also
GetContextData(IHttpContext)
Called by ResolveAsync(IHttpContext) to extract data from a context.
The extracted data are then used to select which handlers are suitable to handle the context.
Declaration
protected abstract TData GetContextData(IHttpContext context)
Parameters
Type | Name | Description |
---|---|---|
IHttpContext | context | The HTTP context to extract data from. |
Returns
Type | Description |
---|---|
TData | The extracted data. |
See Also
Lock()
Locks this instance, preventing further handler additions.
Declaration
public void Lock()
MatchContextData(TData, TData)
Called by ResolveAsync(IHttpContext) to match data extracted from a context against data associated with a handler.
Declaration
protected abstract bool MatchContextData(TData contextData, TData handlerData)
Parameters
Type | Name | Description |
---|---|---|
TData | contextData | The data extracted from the context. |
TData | handlerData | The data associated with the handler. |
Returns
Type | Description |
---|---|
Boolean | true if the handler should be called to handle the context; otherwise, false. |
ResolveAsync(IHttpContext)
Asynchronously matches a URL path against Route;
if the match is successful, tries to handle the specified context
using handlers selected according to data extracted from the context.
Registered data / handler pairs are tried in the same order they were added.
Declaration
public Task<RouteResolutionResult> ResolveAsync(IHttpContext context)
Parameters
Type | Name | Description |
---|---|---|
IHttpContext | context | The context to handle. |
Returns
Type | Description |
---|---|
Task<RouteResolutionResult> | A |