diff --git a/zero.Core/ZeroContext.cs b/zero.Core/ZeroContext.cs
index 93d5ef3b..05f3053e 100644
--- a/zero.Core/ZeroContext.cs
+++ b/zero.Core/ZeroContext.cs
@@ -2,6 +2,7 @@
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Logging;
using Raven.Client.Documents.Session;
+using System;
using System.Collections.Concurrent;
using System.Security.Claims;
using System.Threading.Tasks;
@@ -125,8 +126,15 @@ namespace zero.Core
public void Override(Application app)
{
Application = app;
- AppId = app.Id;
- Store.ResolvedDatabase = Application.Database;
+ AppId = app?.Id;
+ Store.ResolvedDatabase = app?.Database;
+ }
+
+
+ ///
+ public ZeroContextScope CreateScope(Application app)
+ {
+ return new(this, app);
}
@@ -143,6 +151,29 @@ namespace zero.Core
}
+
+ public class ZeroContextScope : IDisposable
+ {
+ public IZeroContext Context { get; }
+
+ Application _originalApp = null;
+
+ public ZeroContextScope(IZeroContext context, Application app)
+ {
+ Context = context;
+ _originalApp = app;
+ Context.Override(app);
+ }
+
+ ///
+ public void Dispose()
+ {
+ Context.Override(_originalApp);
+ }
+ }
+
+
+
public interface IZeroContext
{
///
@@ -201,6 +232,11 @@ namespace zero.Core
///
void Override(Application app);
+ ///
+ /// SCOPE
+ ///
+ ZeroContextScope CreateScope(Application app);
+
///
/// Get a custom property from this scoped context
///