Browse Source

Fallback for context with http context exists.

pull/387/head
Sebastian Stehle 7 years ago
parent
commit
35f394f2c3
  1. 17
      src/Squidex.Web/ContextProvider.cs

17
src/Squidex.Web/ContextProvider.cs

@ -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)

Loading…
Cancel
Save