Skip to content

Commit 9a5c5e6

Browse files
authored
#4015 change context to interfaces (#4023)
* #4015 Change to use interfaces for ClientContext and LocalContext * #4015 Changes to use single IContextDictionary interface and concrete ContextDictionary under the covers. * #4015 Remove unwanted changes * #4015 Remove last unwanted change. * #4015 Changes to implement ConcurrentDictionary instead of HybridDictionary. * #4015 update to documentation
1 parent 7787b3d commit 9a5c5e6

21 files changed

+354
-105
lines changed

Source/Csla.AspNetCore/ApplicationContextManagerHttpContext.cs

+6-6
Original file line numberDiff line numberDiff line change
@@ -121,16 +121,16 @@ public void SetUser(System.Security.Principal.IPrincipal principal)
121121
/// <summary>
122122
/// Gets the local context.
123123
/// </summary>
124-
public ContextDictionary GetLocalContext()
124+
public IContextDictionary GetLocalContext()
125125
{
126-
return (ContextDictionary)HttpContext?.Items[_localContextName];
126+
return (IContextDictionary)HttpContext?.Items[_localContextName];
127127
}
128128

129129
/// <summary>
130130
/// Sets the local context.
131131
/// </summary>
132132
/// <param name="localContext">Local context.</param>
133-
public void SetLocalContext(ContextDictionary localContext)
133+
public void SetLocalContext(IContextDictionary localContext)
134134
{
135135
HttpContext.Items[_localContextName] = localContext;
136136
}
@@ -139,17 +139,17 @@ public void SetLocalContext(ContextDictionary localContext)
139139
/// Gets the client context.
140140
/// </summary>
141141
/// <param name="executionLocation"></param>
142-
public ContextDictionary GetClientContext(ApplicationContext.ExecutionLocations executionLocation)
142+
public IContextDictionary GetClientContext(ApplicationContext.ExecutionLocations executionLocation)
143143
{
144-
return (ContextDictionary)HttpContext?.Items[_clientContextName];
144+
return (IContextDictionary)HttpContext?.Items[_clientContextName];
145145
}
146146

147147
/// <summary>
148148
/// Sets the client context.
149149
/// </summary>
150150
/// <param name="clientContext">Client context.</param>
151151
/// <param name="executionLocation"></param>
152-
public void SetClientContext(ContextDictionary clientContext, ApplicationContext.ExecutionLocations executionLocation)
152+
public void SetClientContext(IContextDictionary clientContext, ApplicationContext.ExecutionLocations executionLocation)
153153
{
154154
HttpContext.Items[_clientContextName] = clientContext;
155155
}

Source/Csla.AspNetCore/Blazor/ApplicationContextManagerBlazor.cs

+10-10
Original file line numberDiff line numberDiff line change
@@ -138,19 +138,19 @@ public IPrincipal GetUser()
138138
/// <summary>
139139
/// Gets the local context.
140140
/// </summary>
141-
public ContextDictionary GetLocalContext()
141+
public IContextDictionary GetLocalContext()
142142
{
143-
ContextDictionary localContext;
143+
IContextDictionary localContext;
144144
var sessionManager = ApplicationContext.GetRequiredService<ISessionManager>();
145145
var session = sessionManager.GetSession();
146146
session.TryGetValue("localContext", out var result);
147-
if (result is ContextDictionary context)
147+
if (result is IContextDictionary context)
148148
{
149149
localContext = context;
150150
}
151151
else
152152
{
153-
localContext = [];
153+
localContext = new ContextDictionary();
154154
SetLocalContext(localContext);
155155
}
156156
return localContext;
@@ -160,7 +160,7 @@ public ContextDictionary GetLocalContext()
160160
/// Sets the local context.
161161
/// </summary>
162162
/// <param name="localContext">Local context.</param>
163-
public void SetLocalContext(ContextDictionary localContext)
163+
public void SetLocalContext(IContextDictionary localContext)
164164
{
165165
var sessionManager = ApplicationContext.GetRequiredService<ISessionManager>();
166166
var session = sessionManager.GetSession();
@@ -171,19 +171,19 @@ public void SetLocalContext(ContextDictionary localContext)
171171
/// Gets the client context.
172172
/// </summary>
173173
/// <param name="executionLocation"></param>
174-
public ContextDictionary GetClientContext(ApplicationContext.ExecutionLocations executionLocation)
174+
public IContextDictionary GetClientContext(ApplicationContext.ExecutionLocations executionLocation)
175175
{
176-
ContextDictionary clientContext;
176+
IContextDictionary clientContext;
177177
var sessionManager = ApplicationContext.GetRequiredService<ISessionManager>();
178178
var session = sessionManager.GetSession();
179179
session.TryGetValue("clientContext", out var result);
180-
if (result is ContextDictionary context)
180+
if (result is IContextDictionary context)
181181
{
182182
clientContext = context;
183183
}
184184
else
185185
{
186-
clientContext = [];
186+
clientContext = new ContextDictionary();
187187
SetClientContext(clientContext, ApplicationContext.ExecutionLocation);
188188
}
189189
return clientContext;
@@ -194,7 +194,7 @@ public ContextDictionary GetClientContext(ApplicationContext.ExecutionLocations
194194
/// </summary>
195195
/// <param name="clientContext">Client context.</param>
196196
/// <param name="executionLocation"></param>
197-
public void SetClientContext(ContextDictionary clientContext, ApplicationContext.ExecutionLocations executionLocation)
197+
public void SetClientContext(IContextDictionary clientContext, ApplicationContext.ExecutionLocations executionLocation)
198198
{
199199
var sessionManager = ApplicationContext.GetRequiredService<ISessionManager>();
200200
var session = sessionManager.GetSession();

Source/Csla.AspNetCore/Blazor/ApplicationContextManagerInMemory.cs

+6-6
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ namespace Csla.AspNetCore.Blazor
2020
/// </summary>
2121
public class ApplicationContextManagerInMemory : IContextManager, IDisposable
2222
{
23-
private ContextDictionary LocalContext { get; set; }
24-
private ContextDictionary ClientContext { get; set; }
23+
private IContextDictionary LocalContext { get; set; }
24+
private IContextDictionary ClientContext { get; set; }
2525
private IPrincipal CurrentPrincipal { get; set; }
2626
private readonly ClaimsPrincipal UnauthenticatedPrincipal = new();
2727
private bool disposedValue;
@@ -168,7 +168,7 @@ private void SetHostPrincipal(Task<AuthenticationState> task)
168168
/// <summary>
169169
/// Gets the local context.
170170
/// </summary>
171-
public ContextDictionary GetLocalContext()
171+
public IContextDictionary GetLocalContext()
172172
{
173173
if (LocalContext == null)
174174
LocalContext = new ContextDictionary();
@@ -179,7 +179,7 @@ public ContextDictionary GetLocalContext()
179179
/// Sets the local context.
180180
/// </summary>
181181
/// <param name="localContext">Local context.</param>
182-
public void SetLocalContext(ContextDictionary localContext)
182+
public void SetLocalContext(IContextDictionary localContext)
183183
{
184184
LocalContext = localContext;
185185
}
@@ -188,7 +188,7 @@ public void SetLocalContext(ContextDictionary localContext)
188188
/// Gets the client context.
189189
/// </summary>
190190
/// <param name="executionLocation"></param>
191-
public ContextDictionary GetClientContext(ApplicationContext.ExecutionLocations executionLocation)
191+
public IContextDictionary GetClientContext(ApplicationContext.ExecutionLocations executionLocation)
192192
{
193193
if (ClientContext == null)
194194
ClientContext = new ContextDictionary();
@@ -200,7 +200,7 @@ public ContextDictionary GetClientContext(ApplicationContext.ExecutionLocations
200200
/// </summary>
201201
/// <param name="clientContext">Client context.</param>
202202
/// <param name="executionLocation"></param>
203-
public void SetClientContext(ContextDictionary clientContext, ApplicationContext.ExecutionLocations executionLocation)
203+
public void SetClientContext(IContextDictionary clientContext, ApplicationContext.ExecutionLocations executionLocation)
204204
{
205205
ClientContext = clientContext;
206206
}

Source/Csla.Blazor.WebAssembly/ApplicationContextManager.cs

+10-10
Original file line numberDiff line numberDiff line change
@@ -101,19 +101,19 @@ public virtual void SetUser(IPrincipal principal)
101101
/// <summary>
102102
/// Gets the local context.
103103
/// </summary>
104-
public ContextDictionary GetLocalContext()
104+
public IContextDictionary GetLocalContext()
105105
{
106-
ContextDictionary localContext;
106+
IContextDictionary localContext;
107107
var sessionManager = ApplicationContext.GetRequiredService<ISessionManager>();
108108
var session = sessionManager.GetCachedSession();
109109
session.TryGetValue("localContext", out var result);
110-
if (result is ContextDictionary context)
110+
if (result is IContextDictionary context)
111111
{
112112
localContext = context;
113113
}
114114
else
115115
{
116-
localContext = [];
116+
localContext = new ContextDictionary();
117117
SetLocalContext(localContext);
118118
}
119119
return localContext;
@@ -123,7 +123,7 @@ public ContextDictionary GetLocalContext()
123123
/// Sets the local context.
124124
/// </summary>
125125
/// <param name="localContext">Local context.</param>
126-
public void SetLocalContext(ContextDictionary localContext)
126+
public void SetLocalContext(IContextDictionary localContext)
127127
{
128128
var sessionManager = ApplicationContext.GetRequiredService<ISessionManager>();
129129
var session = sessionManager.GetCachedSession();
@@ -134,19 +134,19 @@ public void SetLocalContext(ContextDictionary localContext)
134134
/// Gets the client context.
135135
/// </summary>
136136
/// <param name="executionLocation"></param>
137-
public ContextDictionary GetClientContext(ApplicationContext.ExecutionLocations executionLocation)
137+
public IContextDictionary GetClientContext(ApplicationContext.ExecutionLocations executionLocation)
138138
{
139-
ContextDictionary clientContext;
139+
IContextDictionary clientContext;
140140
var sessionManager = ApplicationContext.GetRequiredService<ISessionManager>();
141141
var session = sessionManager.GetCachedSession();
142142
session.TryGetValue("clientContext", out var result);
143-
if (result is ContextDictionary context)
143+
if (result is IContextDictionary context)
144144
{
145145
clientContext = context;
146146
}
147147
else
148148
{
149-
clientContext = [];
149+
clientContext = new ContextDictionary();
150150
SetClientContext(clientContext, ApplicationContext.ExecutionLocation);
151151
}
152152
return clientContext;
@@ -157,7 +157,7 @@ public ContextDictionary GetClientContext(ApplicationContext.ExecutionLocations
157157
/// </summary>
158158
/// <param name="clientContext">Client context.</param>
159159
/// <param name="executionLocation"></param>
160-
public void SetClientContext(ContextDictionary clientContext, ApplicationContext.ExecutionLocations executionLocation)
160+
public void SetClientContext(IContextDictionary clientContext, ApplicationContext.ExecutionLocations executionLocation)
161161
{
162162
var sessionManager = ApplicationContext.GetRequiredService<ISessionManager>();
163163
var session = sessionManager.GetCachedSession();

Source/Csla.Channels.Grpc/GrpcPortal.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ public async Task<DataPortalResponse> Create(CriteriaRequest request)
182182
true,
183183
request.ClientCulture,
184184
request.ClientUICulture,
185-
(ContextDictionary)SerializationFormatterFactory.GetFormatter(_applicationContext).Deserialize(request.ClientContext));
185+
(IContextDictionary)SerializationFormatterFactory.GetFormatter(_applicationContext).Deserialize(request.ClientContext));
186186

187187
var dpr = await dataPortalServer.Create(objectType, criteria, context, true);
188188

@@ -230,7 +230,7 @@ public async Task<DataPortalResponse> Fetch(CriteriaRequest request)
230230
true,
231231
request.ClientCulture,
232232
request.ClientUICulture,
233-
(ContextDictionary)SerializationFormatterFactory.GetFormatter(_applicationContext).Deserialize(request.ClientContext));
233+
(IContextDictionary)SerializationFormatterFactory.GetFormatter(_applicationContext).Deserialize(request.ClientContext));
234234

235235
var dpr = await dataPortalServer.Fetch(objectType, criteria, context, true);
236236

@@ -272,7 +272,7 @@ public async Task<DataPortalResponse> Update(UpdateRequest request)
272272
true,
273273
request.ClientCulture,
274274
request.ClientUICulture,
275-
(ContextDictionary)SerializationFormatterFactory.GetFormatter(_applicationContext).Deserialize(request.ClientContext));
275+
(IContextDictionary)SerializationFormatterFactory.GetFormatter(_applicationContext).Deserialize(request.ClientContext));
276276

277277
var dpr = await dataPortalServer.Update(obj, context, true);
278278

@@ -321,7 +321,7 @@ public async Task<DataPortalResponse> Delete(CriteriaRequest request)
321321
true,
322322
request.ClientCulture,
323323
request.ClientUICulture,
324-
(ContextDictionary)SerializationFormatterFactory.GetFormatter(_applicationContext).Deserialize(request.ClientContext));
324+
(IContextDictionary)SerializationFormatterFactory.GetFormatter(_applicationContext).Deserialize(request.ClientContext));
325325

326326
var dpr = await dataPortalServer.Delete(objectType, criteria, context, true);
327327

Source/Csla.Channels.RabbitMq/RabbitMqPortal.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ public async Task<DataPortalResponse> Create(CriteriaRequest request)
219219
true,
220220
request.ClientCulture,
221221
request.ClientUICulture,
222-
(ContextDictionary)SerializationFormatterFactory.GetFormatter(_applicationContext).Deserialize(request.ClientContext));
222+
(IContextDictionary)SerializationFormatterFactory.GetFormatter(_applicationContext).Deserialize(request.ClientContext));
223223

224224
var dpr = await dataPortalServer.Create(objectType, criteria, context, true);
225225

@@ -263,7 +263,7 @@ public async Task<DataPortalResponse> Fetch(CriteriaRequest request)
263263
true,
264264
request.ClientCulture,
265265
request.ClientUICulture,
266-
(ContextDictionary)SerializationFormatterFactory.GetFormatter(_applicationContext).Deserialize(request.ClientContext));
266+
(IContextDictionary)SerializationFormatterFactory.GetFormatter(_applicationContext).Deserialize(request.ClientContext));
267267

268268
var dpr = await dataPortalServer.Fetch(objectType, criteria, context, true);
269269

@@ -301,7 +301,7 @@ public async Task<DataPortalResponse> Update(UpdateRequest request)
301301
true,
302302
request.ClientCulture,
303303
request.ClientUICulture,
304-
(ContextDictionary)SerializationFormatterFactory.GetFormatter(_applicationContext).Deserialize(request.ClientContext));
304+
(IContextDictionary)SerializationFormatterFactory.GetFormatter(_applicationContext).Deserialize(request.ClientContext));
305305

306306
var dpr = await dataPortalServer.Update(obj, context, true);
307307

@@ -346,7 +346,7 @@ public async Task<DataPortalResponse> Delete(CriteriaRequest request)
346346
true,
347347
request.ClientCulture,
348348
request.ClientUICulture,
349-
(ContextDictionary)SerializationFormatterFactory.GetFormatter(_applicationContext).Deserialize(request.ClientContext));
349+
(IContextDictionary)SerializationFormatterFactory.GetFormatter(_applicationContext).Deserialize(request.ClientContext));
350350

351351
var dpr = await dataPortalServer.Delete(objectType, criteria, context, true);
352352

Source/Csla.Web.Mvc.Shared/ApplicationContextManager.cs

+6-6
Original file line numberDiff line numberDiff line change
@@ -62,16 +62,16 @@ public void SetUser(System.Security.Principal.IPrincipal principal)
6262
/// <summary>
6363
/// Gets the local context.
6464
/// </summary>
65-
public ContextDictionary GetLocalContext()
65+
public IContextDictionary GetLocalContext()
6666
{
67-
return (ContextDictionary)HttpContext.Current.Items[_localContextName];
67+
return (IContextDictionary)HttpContext.Current.Items[_localContextName];
6868
}
6969

7070
/// <summary>
7171
/// Sets the local context.
7272
/// </summary>
7373
/// <param name="localContext">Local context.</param>
74-
public void SetLocalContext(ContextDictionary localContext)
74+
public void SetLocalContext(IContextDictionary localContext)
7575
{
7676
HttpContext.Current.Items[_localContextName] = localContext;
7777
}
@@ -80,17 +80,17 @@ public void SetLocalContext(ContextDictionary localContext)
8080
/// Gets the client context.
8181
/// </summary>
8282
/// <param name="executionLocation"></param>
83-
public ContextDictionary GetClientContext(ApplicationContext.ExecutionLocations executionLocation)
83+
public IContextDictionary GetClientContext(ApplicationContext.ExecutionLocations executionLocation)
8484
{
85-
return (ContextDictionary)HttpContext.Current.Items[_clientContextName];
85+
return (IContextDictionary)HttpContext.Current.Items[_clientContextName];
8686
}
8787

8888
/// <summary>
8989
/// Sets the client context.
9090
/// </summary>
9191
/// <param name="clientContext">Client context.</param>
9292
/// <param name="executionLocation"></param>
93-
public void SetClientContext(ContextDictionary clientContext, ApplicationContext.ExecutionLocations executionLocation)
93+
public void SetClientContext(IContextDictionary clientContext, ApplicationContext.ExecutionLocations executionLocation)
9494
{
9595
HttpContext.Current.Items[_clientContextName] = clientContext;
9696
}

Source/Csla.Web.Mvc.Shared/Server/Hosts/HttpPortal.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public async Task<DataPortalResponse> Create(CriteriaRequest request)
5959
true,
6060
request.ClientCulture,
6161
request.ClientUICulture,
62-
(ContextDictionary)SerializationFormatterFactory.GetFormatter(_applicationContext).Deserialize(request.ClientContext));
62+
(IContextDictionary)SerializationFormatterFactory.GetFormatter(_applicationContext).Deserialize(request.ClientContext));
6363

6464
var dpr = await dataPortalServer.Create(objectType, criteria, context, true);
6565

@@ -105,7 +105,7 @@ public async Task<DataPortalResponse> Fetch(CriteriaRequest request)
105105
true,
106106
request.ClientCulture,
107107
request.ClientUICulture,
108-
(ContextDictionary)SerializationFormatterFactory.GetFormatter(_applicationContext).Deserialize(request.ClientContext));
108+
(IContextDictionary)SerializationFormatterFactory.GetFormatter(_applicationContext).Deserialize(request.ClientContext));
109109

110110
var dpr = await dataPortalServer.Fetch(objectType, criteria, context, true);
111111

@@ -145,7 +145,7 @@ public async Task<DataPortalResponse> Update(UpdateRequest request)
145145
true,
146146
request.ClientCulture,
147147
request.ClientUICulture,
148-
(ContextDictionary)SerializationFormatterFactory.GetFormatter(_applicationContext).Deserialize(request.ClientContext));
148+
(IContextDictionary)SerializationFormatterFactory.GetFormatter(_applicationContext).Deserialize(request.ClientContext));
149149

150150
var dpr = await dataPortalServer.Update(obj, context, true);
151151

@@ -192,7 +192,7 @@ public async Task<DataPortalResponse> Delete(CriteriaRequest request)
192192
true,
193193
request.ClientCulture,
194194
request.ClientUICulture,
195-
(ContextDictionary)SerializationFormatterFactory.GetFormatter(_applicationContext).Deserialize(request.ClientContext));
195+
(IContextDictionary)SerializationFormatterFactory.GetFormatter(_applicationContext).Deserialize(request.ClientContext));
196196

197197
var dpr = await dataPortalServer.Delete(objectType, criteria, context, true);
198198

0 commit comments

Comments
 (0)