CSLA.NET 5.4.2
CSLA .NET is a software development framework that helps you build a reusable, maintainable object-oriented business layer for your app.
Csla.Web.Shared/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>Application context manager that uses HttpContext</summary>
7//-----------------------------------------------------------------------
8using System;
9using System.Collections.Generic;
10using System.Linq;
11using System.Text;
12using Csla.Core;
13using System.Web;
14
15namespace Csla.Web
16{
22 {
23 private const string _localContextName = "Csla.LocalContext";
24 private const string _clientContextName = "Csla.ClientContext";
25 private const string _globalContextName = "Csla.GlobalContext";
26
27 private IServiceProvider _defaultServiceProvider = null;
28
34 public bool IsValid
35 {
36 get { return HttpContext.Current != null; }
37 }
38
42 public System.Security.Principal.IPrincipal GetUser()
43 {
44 var result = HttpContext.Current.User;
45 if (result == null)
46 {
47 result = new System.Security.Claims.ClaimsPrincipal();
48 SetUser(result);
49 }
50 return result;
51 }
52
57 public void SetUser(System.Security.Principal.IPrincipal principal)
58 {
59 HttpContext.Current.User = principal;
60 }
61
66 {
67 return (ContextDictionary)HttpContext.Current.Items[_localContextName];
68 }
69
74 public void SetLocalContext(ContextDictionary localContext)
75 {
76 HttpContext.Current.Items[_localContextName] = localContext;
77 }
78
83 {
84 return (ContextDictionary)HttpContext.Current.Items[_clientContextName];
85 }
86
91 public void SetClientContext(ContextDictionary clientContext)
92 {
93 HttpContext.Current.Items[_clientContextName] = clientContext;
94 }
95
100 {
101 return (ContextDictionary)HttpContext.Current.Items[_globalContextName];
102 }
103
108 public void SetGlobalContext(ContextDictionary globalContext)
109 {
110 HttpContext.Current.Items[_globalContextName] = globalContext;
111 }
112
116 public IServiceProvider GetDefaultServiceProvider()
117 {
118 return _defaultServiceProvider;
119 }
120
125 public void SetDefaultServiceProvider(IServiceProvider serviceProvider)
126 {
127 _defaultServiceProvider = serviceProvider;
128 }
129
134 public IServiceProvider GetServiceProvider()
135 {
136 return (IServiceProvider)ApplicationContext.LocalContext["__sps"] ?? GetDefaultServiceProvider();
137 }
138
143 public void SetServiceProvider(IServiceProvider scope)
144 {
145 Csla.ApplicationContext.LocalContext["__sps"] = scope;
146 }
147 }
148}
Dictionary type that is serializable with the SerializationFormatterFactory.GetFormatter().
Application context manager that uses HttpContext to store context values.
void SetUser(System.Security.Principal.IPrincipal principal)
Sets the current principal.
System.Security.Principal.IPrincipal GetUser()
Gets the current principal.
void SetGlobalContext(ContextDictionary globalContext)
Sets the global context.
void SetDefaultServiceProvider(IServiceProvider serviceProvider)
Sets the default IServiceProvider
ContextDictionary GetGlobalContext()
Gets the global context.
bool IsValid
Gets a value indicating whether this context manager is valid for use in the current environment.
void SetLocalContext(ContextDictionary localContext)
Sets the local context.
IServiceProvider GetServiceProvider()
Gets the service provider for current scope
ContextDictionary GetClientContext()
Gets the client context.
ContextDictionary GetLocalContext()
Gets the local context.
void SetServiceProvider(IServiceProvider scope)
Sets the service provider for current scope
IServiceProvider GetDefaultServiceProvider()
Gets the default IServiceProvider
void SetClientContext(ContextDictionary clientContext)
Sets the client context.
Defines the interface for an application context manager type.