10using Microsoft.AspNetCore.Http;
11using Microsoft.Extensions.DependencyInjection;
13using System.Security.Claims;
24 private const string _localContextName =
"Csla.LocalContext";
25 private const string _clientContextName =
"Csla.ClientContext";
26 private const string _globalContextName =
"Csla.GlobalContext";
28 private IServiceProvider _serviceProvider;
37 _serviceProvider = serviceProvider;
48 if (_serviceProvider !=
null)
50 var httpContextAccessor = (IHttpContextAccessor)_serviceProvider.GetService(typeof(IHttpContextAccessor));
51 if (httpContextAccessor !=
null)
53 result = httpContextAccessor.HttpContext;
73 public System.Security.Principal.IPrincipal
GetUser()
88 public void SetUser(System.Security.Principal.IPrincipal principal)
107 HttpContext.Items[_localContextName] = localContext;
124 HttpContext.Items[_clientContextName] = clientContext;
141 HttpContext.Items[_globalContextName] = globalContext;
151 return HttpContext?.RequestServices ?? _serviceProvider;
161 _serviceProvider = serviceProvider;
Application context manager that uses HttpContextAccessor when resolving HttpContext to store context...
ContextDictionary GetGlobalContext()
Gets the global context.
void SetServiceProvider(IServiceProvider scope)
Sets the service provider for current scope
void SetDefaultServiceProvider(IServiceProvider serviceProvider)
Sets the default IServiceProvider
ApplicationContextManager(IServiceProvider serviceProvider)
Creates an instance of the object, initializing it with the required IServiceProvider.
void SetGlobalContext(ContextDictionary globalContext)
Sets the global context.
void SetLocalContext(ContextDictionary localContext)
Sets the local context.
ContextDictionary GetClientContext()
Gets the client context.
void SetUser(System.Security.Principal.IPrincipal principal)
Sets the current principal.
System.Security.Principal.IPrincipal GetUser()
Gets the current principal.
virtual HttpContext HttpContext
Gets the current HttpContext instance.
void SetClientContext(ContextDictionary clientContext)
Sets the client context.
bool IsValid
Gets a value indicating whether this context manager is valid for use in the current environment.
IServiceProvider GetDefaultServiceProvider()
Gets the default IServiceProvider
ContextDictionary GetLocalContext()
Gets the local context.
IServiceProvider GetServiceProvider()
Gets the service provider for current scope
Dictionary type that is serializable with the SerializationFormatterFactory.GetFormatter().
ClaimsPrincipal subclass that supports serialization by SerializationFormatterFactory....
Defines the interface for an application context manager type.