9using System.Security.Principal;
10using System.Threading;
22 private AsyncLocal<ContextDictionary> _localContext =
new AsyncLocal<ContextDictionary>();
23 private AsyncLocal<ContextDictionary> _clientContext =
new AsyncLocal<ContextDictionary>();
24 private const string _globalContextName =
"Csla.GlobalContext";
40 IPrincipal result = Thread.CurrentPrincipal;
43 result =
new System.Security.Claims.ClaimsPrincipal();
53 public virtual void SetUser(IPrincipal principal)
55 Thread.CurrentPrincipal = principal;
63 return _localContext.Value;
72 _localContext.Value = localContext;
80 return _clientContext.Value;
89 _clientContext.Value = clientContext;
97 LocalDataStoreSlot slot = Thread.GetNamedDataSlot(_globalContextName);
107 LocalDataStoreSlot slot = Thread.GetNamedDataSlot(_globalContextName);
108 Thread.SetData(slot, globalContext);
111 private static IServiceProvider _provider;
127 _provider = serviceProvider;
134#pragma warning disable CS3002
136#pragma warning restore CS3002
145#pragma warning disable CS3001
147#pragma warning restore CS3001
Default context manager for the user property and local/client/global context dictionaries.
void SetLocalContext(ContextDictionary localContext)
Sets the local context dictionary.
IServiceProvider GetDefaultServiceProvider()
Gets the default IServiceProvider
virtual IPrincipal GetUser()
Gets the current user principal.
virtual void SetUser(IPrincipal principal)
Sets the current user principal.
void SetDefaultServiceProvider(IServiceProvider serviceProvider)
Sets the default IServiceProvider
ContextDictionary GetGlobalContext()
Gets the global context dictionary.
ContextDictionary GetClientContext()
Gets the client context dictionary.
IServiceProvider GetServiceProvider()
Gets the service provider for current scope
bool IsValid
Returns a value indicating whether the context is valid.
void SetClientContext(ContextDictionary clientContext)
Sets the client context dictionary.
void SetGlobalContext(ContextDictionary globalContext)
Sets the global context dictionary.
void SetServiceProvider(IServiceProvider scope)
Sets the service provider for current scope
ContextDictionary GetLocalContext()
Gets the local context dictionary.
Dictionary type that is serializable with the SerializationFormatterFactory.GetFormatter().
Defines the interface for an application context manager type.