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.
ApplicationContextManagerStatic.cs
Go to the documentation of this file.
1//-----------------------------------------------------------------------
2// <copyright file="ApplicationContextManagerStatic.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.Security.Claims;
11
12namespace Csla.Core
13{
21 {
26 public bool IsStatefulContext => true;
27
31 public bool IsValid => true;
32
33 private static ContextDictionary currentLocalContext = new();
34 private static ContextDictionary currentClientContext = new();
35 private static IPrincipal currentPrincipal = new ClaimsPrincipal();
36 private static IServiceProvider currentDefaultServiceProvider;
37 private static IServiceProvider currentServiceProvider;
38
44 {
45 return currentClientContext;
46 }
47
51 public IServiceProvider GetDefaultServiceProvider()
52 {
53 return currentDefaultServiceProvider;
54 }
55
60 {
61 return currentLocalContext;
62 }
63
68 public IPrincipal GetUser()
69 {
70 return currentPrincipal;
71 }
72
78 public void SetClientContext(ContextDictionary clientContext, ApplicationContext.ExecutionLocations executionLocation)
79 {
80 currentClientContext = clientContext;
81 }
82
87 public void SetDefaultServiceProvider(IServiceProvider serviceProvider)
88 {
89 currentDefaultServiceProvider = serviceProvider;
90 }
91
96 public void SetLocalContext(ContextDictionary localContext)
97 {
98 currentLocalContext = localContext;
99 }
100
104 public IServiceProvider GetServiceProvider()
105 {
106 return currentServiceProvider ?? GetDefaultServiceProvider();
107 }
108
113 public void SetServiceProvider(IServiceProvider scope)
114 {
115 currentServiceProvider = scope;
116 }
117
122 public void SetUser(IPrincipal principal)
123 {
124 currentPrincipal = principal;
125 }
126
127 private static ApplicationContext _applicationContext;
128
132 public ApplicationContext ApplicationContext { get => _applicationContext; set => _applicationContext = value; }
133 }
134}
Provides consistent context information between the client and server DataPortal objects.
ExecutionLocations
Enum representing the locations code can execute.
Context manager for the user property and local/client/global context dictionaries that uses static f...
void SetClientContext(ContextDictionary clientContext, ApplicationContext.ExecutionLocations executionLocation)
Sets the client context dictionary.
void SetUser(IPrincipal principal)
Sets the current user principal.
IServiceProvider GetDefaultServiceProvider()
Gets the default IServiceProvider
ContextDictionary GetLocalContext()
Gets the local context dictionary.
bool IsStatefulContext
Gets a value indicating whether the context manager is stateful.
void SetLocalContext(ContextDictionary localContext)
Sets the local context dictionary.
IPrincipal GetUser()
Gets the current user principal.
void SetServiceProvider(IServiceProvider scope)
Sets the service provider for current scope
IServiceProvider GetServiceProvider()
Gets the service provider for current scope
bool IsValid
Returns a value indicating whether the context is valid.
ContextDictionary GetClientContext(ApplicationContext.ExecutionLocations executionLocation)
Gets the client context dictionary.
void SetDefaultServiceProvider(IServiceProvider serviceProvider)
Sets the default IServiceProvider
Dictionary type that is serializable with the SerializationFormatterFactory.GetFormatter().
Defines the interface for an application context manager type.