start context scoping

This commit is contained in:
2021-10-27 16:03:15 +02:00
parent 4529d637ae
commit 0b7ed671b3
+38 -2
View File
@@ -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;
}
/// <inheritdoc />
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);
}
/// <inheritdoc />
public void Dispose()
{
Context.Override(_originalApp);
}
}
public interface IZeroContext
{
/// <summary>
@@ -201,6 +232,11 @@ namespace zero.Core
/// </summary>
void Override(Application app);
/// <summary>
/// SCOPE
/// </summary>
ZeroContextScope CreateScope(Application app);
/// <summary>
/// Get a custom property from this scoped context
/// </summary>