Update HttpContextAccessor.cs

This commit is contained in:
jtkech
2015-12-17 07:08:12 +01:00
parent 5f65c5101d
commit 981c1cb056

View File

@@ -6,6 +6,7 @@ namespace Orchard.Mvc {
public class HttpContextAccessor : IHttpContextAccessor { public class HttpContextAccessor : IHttpContextAccessor {
readonly ILifetimeScope _lifetimeScope; readonly ILifetimeScope _lifetimeScope;
private HttpContextBase _httpContext; private HttpContextBase _httpContext;
private IWorkContextAccessor _wca;
public HttpContextAccessor(ILifetimeScope lifetimeScope) { public HttpContextAccessor(ILifetimeScope lifetimeScope) {
_lifetimeScope = lifetimeScope; _lifetimeScope = lifetimeScope;
@@ -20,9 +21,10 @@ namespace Orchard.Mvc {
if (_httpContext != null) if (_httpContext != null)
return _httpContext; return _httpContext;
var workContext = _lifetimeScope.IsRegistered<IWorkContextAccessor>() ? if (_wca == null && _lifetimeScope.IsRegistered<IWorkContextAccessor>())
_lifetimeScope.Resolve<IWorkContextAccessor>().GetContext(null) : null; _wca = _lifetimeScope.Resolve<IWorkContextAccessor>();
var workContext = _wca != null ? _wca.GetContext(null) : null;
return workContext != null ? workContext.HttpContext : null; return workContext != null ? workContext.HttpContext : null;
} }