forked from aspnet/AspNetWebStack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathScopeStorage.cs
More file actions
41 lines (34 loc) · 1.46 KB
/
Copy pathScopeStorage.cs
File metadata and controls
41 lines (34 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Collections.Generic;
namespace System.Web.WebPages.Scope
{
public static class ScopeStorage
{
private static readonly IScopeStorageProvider _defaultStorageProvider = new StaticScopeStorageProvider();
private static IScopeStorageProvider _stateStorageProvider;
public static IScopeStorageProvider CurrentProvider
{
get { return _stateStorageProvider ?? _defaultStorageProvider; }
set { _stateStorageProvider = value; }
}
public static IDictionary<object, object> CurrentScope
{
get { return CurrentProvider.CurrentScope; }
}
public static IDictionary<object, object> GlobalScope
{
get { return CurrentProvider.GlobalScope; }
}
public static IDisposable CreateTransientScope(IDictionary<object, object> context)
{
var currentContext = CurrentScope;
CurrentProvider.CurrentScope = context;
return new DisposableAction(() => CurrentProvider.CurrentScope = currentContext); // Return an IDisposable that pops the item back off
}
public static IDisposable CreateTransientScope()
{
return CreateTransientScope(new ScopeStorageDictionary(baseScope: CurrentScope));
}
}
}