|
|
|
@ -5,6 +5,7 @@ |
|
|
|
// All rights reserved. Licensed under the MIT license.
|
|
|
|
// ==========================================================================
|
|
|
|
|
|
|
|
using System.Threading; |
|
|
|
using Microsoft.AspNetCore.Http; |
|
|
|
using Squidex.Domain.Apps.Entities; |
|
|
|
using Squidex.Infrastructure; |
|
|
|
@ -14,10 +15,24 @@ namespace Squidex.Web |
|
|
|
public sealed class ContextProvider : IContextProvider |
|
|
|
{ |
|
|
|
private readonly IHttpContextAccessor httpContextAccessor; |
|
|
|
private readonly AsyncLocal<Context> asyncLocal = new AsyncLocal<Context>(); |
|
|
|
|
|
|
|
public Context Context |
|
|
|
{ |
|
|
|
get { return httpContextAccessor.HttpContext.Context(); } |
|
|
|
get |
|
|
|
{ |
|
|
|
if (httpContextAccessor.HttpContext == null) |
|
|
|
{ |
|
|
|
if (asyncLocal.Value == null) |
|
|
|
{ |
|
|
|
asyncLocal.Value = new Context(); |
|
|
|
} |
|
|
|
|
|
|
|
return asyncLocal.Value; |
|
|
|
} |
|
|
|
|
|
|
|
return httpContextAccessor.HttpContext.Context(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public ContextProvider(IHttpContextAccessor httpContextAccessor) |
|
|
|
|