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.
ApplicationContextAccessor.cs
Go to the documentation of this file.
1//-----------------------------------------------------------------------
2// <copyright file="ApplicationContextAccessor.cs" company="Marimer LLC">
3// Copyright (c) Marimer LLC. All rights reserved.
4// Website: https://cslanet.com
5// </copyright>
6// <summary>Provides access to the correct current application</summary>
7//-----------------------------------------------------------------------
8using System;
9using System.Collections.Generic;
10using Csla.Runtime;
12
13namespace Csla.Core
14{
20 {
28 IEnumerable<IContextManager> contextManagerList,
29 IContextManagerLocal localContextManager,
30 IServiceProvider serviceProvider)
31 {
32 ServiceProvider = serviceProvider;
33 LocalContextManager = localContextManager;
34
35 foreach (var context in contextManagerList)
36 {
37 if (context.IsValid)
38 {
39 ContextManager = context;
40 break;
41 }
42 }
43 if (ContextManager is null)
44 {
45 ContextManager = new Core.ApplicationContextManagerAsyncLocal();
46 }
47 }
48
49 internal IServiceProvider ServiceProvider { get; private set; }
50 private IContextManager ContextManager { get; set; }
51 private IContextManager LocalContextManager { get; set; }
52
58 {
59 var runtimeInfo = ServiceProvider.GetRequiredService<IRuntimeInfo>();
60 if (!runtimeInfo.LocalProxyNewScopeExists)
61 return ContextManager;
62 else
63 return LocalContextManager;
64 }
65 }
66}
Provides access to the correct current application context manager instance depending on runtime envi...
ApplicationContextAccessor(IEnumerable< IContextManager > contextManagerList, IContextManagerLocal localContextManager, IServiceProvider serviceProvider)
Creates a new instance of the type.
IContextManager GetContextManager()
Gets a reference to the correct current application context manager instance depending on runtime env...
Defines the interface for an application context manager type.
Subtype of IContextManager for use by LocalProxy.
Information about the current runtime environment.
Definition: IRuntimeInfo.cs:14