Method UseActiveSessions
- Namespace
- MVVrus.AspNetCore.ActiveSession
- Assembly
- MVVrus.AspNetCore.ActiveSession.dll
UseActiveSessions(IApplicationBuilder, IMiddlewareFilterSource?)
Adds the ActiveSession midleware to an application middleware pipeline along with a filter defining a scope of HTTP requests, for which an active session will be available.
public static IApplicationBuilder UseActiveSessions(this IApplicationBuilder Builder, IMiddlewareFilterSource? Filter = null)
Parameters
Builder
IApplicationBuilderThe application middleware pipeline builder
Filter
IMiddlewareFilterSourceA reference to an object instance implementing the IMiddlewareFilterSource interface that is used to filter requests for which an active session feature will be available and specify the suffix to be added to an Id property of active sessions assigned to requests that falls into the scope of the filter set by this method. Defaults to null that means the feature will be available for all requests.
Returns
- IApplicationBuilder
The
Builder
parameter value to allow call chaining.
Remarks
The ActiveSession midleware adds an implementation of the active session feature (available through IActiveSessionFeature) interface to the Features collection in the request context. This interface makes an active session object available for a request handler that uses the context.
If a filter is specified, it defines a scope of requests for which a feature will be added to their contexts. Not specifying a filter means that an active session will be available for handlers of all requests. UseActiveSessions methods may be called multiple times to add different filters for different scopes. All of these calls result in addition of a single ActiveSession middleware instance to the pipeline. This instance passes incoming requests to all added filters in order in which they have been added. If no filter accepts a request, a feature will not be added to the request context.
The middleware can be added to the pipeline only if at least one runner factory service (IRunnerFactory<TRequest, TResult>) is registered in the application's service container via one of AddActiveSession extension methods defined in the ActiveSessionServiceCollectionExtensions class.
This overload of the UseActiveSession method uses an IMiddlewareFilterSource interface as a filter to define
will a request fall into its scope and, if so, which suffix will be used to construct an identifier of an active session
available to the request handler.
If the Filter
is omitted or is null, the feature will be added
to request contexts for all request handlers.
UseActiveSessions(IApplicationBuilder, Func<HttpContext, (bool, string?)>)
public static IApplicationBuilder UseActiveSessions(this IApplicationBuilder Builder, Func<HttpContext, (bool, string?)> Filter)
Parameters
Builder
IApplicationBuilder- The application middleware pipeline builder
Filter
Func<HttpContext, (bool, string)>A delegate that is used to filter requests for which an active session feature will be available and to assign them suffix a to be added to an Id property of their active session object.
Returns
- IApplicationBuilder
The Builder
parameter value to allow call chaining.
Remarks
The ActiveSession midleware adds an implementation of the active session feature
(available through IActiveSessionFeature) interface
to the Features collection in the request context.
This interface makes an active session object available for a request handler that uses the context.
If a filter is specified, it defines a scope of requests for which a feature will be added to their contexts. Not specifying a filter means that an active session will be available for handlers of all requests. UseActiveSessions methods may be called multiple times to add different filters for different scopes. All of these calls result in addition of a single ActiveSession middleware instance to the pipeline. This instance passes incoming requests to all added filters in order in which they have been added. If no filter accepts a request, a feature will not be added to the request context.
The middleware can be added to the pipeline only if at least one runner factory service (IRunnerFactory<TRequest, TResult>) is registered in the application's service container via one of AddActiveSession extension methods defined in the ActiveSessionServiceCollectionExtensions class.
This UseActiveSessions method overload uses a delegate returning a bool result consisting of bool value used decide whever a request falls into the scope of the delegate as a filter and a value of the suffix to be assigned to an Id property.
Introduced in v.1.1UseActiveSessions(IApplicationBuilder, Func<HttpContext, bool>)
public static IApplicationBuilder UseActiveSessions(this IApplicationBuilder Builder, Func<HttpContext, bool> Filter)
Parameters
Builder
IApplicationBuilder- The application middleware pipeline builder
Filter
Func<HttpContext, bool>A predicate that is used to filter requests for which an active session feature will be available.
Returns
- IApplicationBuilder
The Builder
parameter value to allow call chaining.
Remarks
The ActiveSession midleware adds an implementation of the active session feature
(available through IActiveSessionFeature) interface
to the Features collection in the request context.
This interface makes an active session object available for a request handler that uses the context.
If a filter is specified, it defines a scope of requests for which a feature will be added to their contexts. Not specifying a filter means that an active session will be available for handlers of all requests. UseActiveSessions methods may be called multiple times to add different filters for different scopes. All of these calls result in addition of a single ActiveSession middleware instance to the pipeline. This instance passes incoming requests to all added filters in order in which they have been added. If no filter accepts a request, a feature will not be added to the request context.
The middleware can be added to the pipeline only if at least one runner factory service (IRunnerFactory<TRequest, TResult>) is registered in the application's service container via one of AddActiveSession extension methods defined in the ActiveSessionServiceCollectionExtensions class.
UseActiveSessions(IApplicationBuilder, string, TimeSpan)
public static IApplicationBuilder UseActiveSessions(this IApplicationBuilder Builder, string Filter, TimeSpan TimeOut = default)
Parameters
Builder
IApplicationBuilder- The application middleware pipeline builder
Filter
stringString with a regular expression to wich an HTTP request path must match to pass a filter
TimeOut
TimeSpanTimeout for the regular expression match operation. Use a value from the configuration if omitted.
Returns
- IApplicationBuilder
The Builder
parameter value to allow call chaining.
Remarks
The ActiveSession midleware adds an implementation of the active session feature
(available through IActiveSessionFeature) interface
to the Features collection in the request context.
This interface makes an active session object available for a request handler that uses the context.
If a filter is specified, it defines a scope of requests for which a feature will be added to their contexts. Not specifying a filter means that an active session will be available for handlers of all requests. UseActiveSessions methods may be called multiple times to add different filters for different scopes. All of these calls result in addition of a single ActiveSession middleware instance to the pipeline. This instance passes incoming requests to all added filters in order in which they have been added. If no filter accepts a request, a feature will not be added to the request context.
The middleware can be added to the pipeline only if at least one runner factory service (IRunnerFactory<TRequest, TResult>) is registered in the application's service container via one of AddActiveSession extension methods defined in the ActiveSessionServiceCollectionExtensions class.
Filter
parameter to decide which requests fall into its scope
UseActiveSessions(IApplicationBuilder, Func<HttpContext, bool>, string)
public static IApplicationBuilder UseActiveSessions(this IApplicationBuilder Builder, Func<HttpContext, bool> Filter, string Suffix)
Parameters
Builder
IApplicationBuilder- The application middleware pipeline builder
Filter
Func<HttpContext, bool>- A predicate that is used to filter requests for which an active session feature will be available.
Suffix
stringThe suffix to be added to an Id property of active sessions assigned to requests that falls into the scope of the filter set by this method.
Returns
- IApplicationBuilder
The Builder
parameter value to allow call chaining.
Remarks
The ActiveSession midleware adds an implementation of the active session feature
(available through IActiveSessionFeature) interface
to the Features collection in the request context.
This interface makes an active session object available for a request handler that uses the context.
If a filter is specified, it defines a scope of requests for which a feature will be added to their contexts. Not specifying a filter means that an active session will be available for handlers of all requests. UseActiveSessions methods may be called multiple times to add different filters for different scopes. All of these calls result in addition of a single ActiveSession middleware instance to the pipeline. This instance passes incoming requests to all added filters in order in which they have been added. If no filter accepts a request, a feature will not be added to the request context.
The middleware can be added to the pipeline only if at least one runner factory service (IRunnerFactory<TRequest, TResult>) is registered in the application's service container via one of AddActiveSession extension methods defined in the ActiveSessionServiceCollectionExtensions class.
Suffix
parameter as a suffix to be added to an active session identifier.
UseActiveSessions(IApplicationBuilder, string, string, TimeSpan)
public static IApplicationBuilder UseActiveSessions(this IApplicationBuilder Builder, string Filter, string Suffix, TimeSpan TimeOut = default)
Parameters
Builder
IApplicationBuilder- The application middleware pipeline builder
Filter
string- String with a regular expression to wich an HTTP request path must match to pass a filter
Suffix
string- The suffix to be added to an Id property of active sessions assigned to requests that falls into the scope of the filter set by this method.
TimeOut
TimeSpan- Timeout for the regular expression match operation. Use a value from the configuration if omitted.
Returns
- IApplicationBuilder
The Builder
parameter value to allow call chaining.
Remarks
The ActiveSession midleware adds an implementation of the active session feature
(available through IActiveSessionFeature) interface
to the Features collection in the request context.
This interface makes an active session object available for a request handler that uses the context.
If a filter is specified, it defines a scope of requests for which a feature will be added to their contexts. Not specifying a filter means that an active session will be available for handlers of all requests. UseActiveSessions methods may be called multiple times to add different filters for different scopes. All of these calls result in addition of a single ActiveSession middleware instance to the pipeline. This instance passes incoming requests to all added filters in order in which they have been added. If no filter accepts a request, a feature will not be added to the request context.
The middleware can be added to the pipeline only if at least one runner factory service (IRunnerFactory<TRequest, TResult>) is registered in the application's service container via one of AddActiveSession extension methods defined in the ActiveSessionServiceCollectionExtensions class.
Suffix
parameter as a suffix to be added to an active session identifier.