Class SessionServiceCollectionExtensions
- Namespace
- Microsoft.Extensions.DependencyInjection
- Assembly
- Stratara.Sessions.dll
DI extensions for Stratara's session-context provider.
public static class SessionServiceCollectionExtensions
- Inheritance
-
SessionServiceCollectionExtensions
- Inherited Members
Methods
AddSessionContext(IServiceCollection)
Register the concrete ISessionContextProvider implementation as
a scoped service plus the SessionContextOptions binding. Pair with
app.UseMiddleware<SessionContextMiddleware>() in the ASP.NET Core
pipeline to populate the context per request.
public static IServiceCollection AddSessionContext(this IServiceCollection services)
Parameters
servicesIServiceCollectionThe service collection to mutate.
Returns
- IServiceCollection
The same service collection, to enable chaining.
Examples
Registers the scoped context and its accessor. In an ASP.NET host, add the middleware too — without it the context stays empty for every request:
services.AddSessionContext();
app.UseMiddleware<SessionContextMiddleware>();