CSLA.NET 6.0.0
CSLA .NET is a software development framework that helps you build a reusable, maintainable object-oriented business layer for your app.
Csla/Core/ApplicationContextManager.cs
Go to the documentation of this file.
1//-----------------------------------------------------------------------
2// <copyright file="ApplicationContextManager.cs" company="Marimer LLC">
3// Copyright (c) Marimer LLC. All rights reserved.
4// Website: https://cslanet.com
5// </copyright>
6// <summary>Default context manager for the user property</summary>
7//-----------------------------------------------------------------------
8using System;
9using System.Security.Principal;
10using System.Threading;
11
12namespace Csla.Core
13{
19 {
20 private readonly AsyncLocal<ContextDictionary> _localContext = new();
21 private readonly AsyncLocal<ContextDictionary> _clientContext = new();
22
27 public bool IsStatefulContext => true;
28
32 public bool IsValid
33 {
34 get { return true; }
35 }
36
41 public virtual IPrincipal GetUser()
42 {
43 IPrincipal result = Thread.CurrentPrincipal;
44 if (result == null)
45 {
46 result = new System.Security.Claims.ClaimsPrincipal();
47 SetUser(result);
48 }
49 return result;
50 }
51
56 public virtual void SetUser(IPrincipal principal)
57 {
58 Thread.CurrentPrincipal = principal;
59 }
60
65 {
66 return _localContext.Value;
67 }
68
73 public void SetLocalContext(ContextDictionary localContext)
74 {
75 _localContext.Value = localContext;
76 }
77
83 {
84 return _clientContext.Value;
85 }
86
92 public void SetClientContext(ContextDictionary clientContext, ApplicationContext.ExecutionLocations executionLocation)
93 {
94 _clientContext.Value = clientContext;
95 }
96
97 private readonly AsyncLocal<ApplicationContext> _applicationContext = new();
98
103 {
104 get
105 {
106 return _applicationContext.Value;
107 }
108 set
109 {
110 _applicationContext.Value = value;
112 }
113 }
114
119 protected virtual void OnApplicationContextSet()
120 { }
121 }
122}
Provides consistent context information between the client and server DataPortal objects.
ExecutionLocations
Enum representing the locations code can execute.
Default context manager for the user property and local/client/global context dictionaries.
void SetLocalContext(ContextDictionary localContext)
Sets the local context dictionary.
bool IsStatefulContext
Gets a value indicating whether the context manager is stateful.
ContextDictionary GetClientContext(ApplicationContext.ExecutionLocations executionLocation)
Gets the client context dictionary.
virtual IPrincipal GetUser()
Gets the current user principal.
virtual void SetUser(IPrincipal principal)
Sets the current user principal.
virtual void OnApplicationContextSet()
Method called when the ApplicationContext property has been set to a new value.
bool IsValid
Returns a value indicating whether the context is valid.
void SetClientContext(ContextDictionary clientContext, ApplicationContext.ExecutionLocations executionLocation)
Sets the client context dictionary.
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.