Goodbye HttpContextAccessor

This commit is contained in:
Hao Kung 2015-08-12 13:13:27 -07:00
parent 44b762cf08
commit ad6e4b838a
3 changed files with 2 additions and 60 deletions

View File

@ -1,12 +0,0 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using Microsoft.AspNet.Http;
namespace Microsoft.AspNet.Hosting
{
public interface IHttpContextAccessor
{
HttpContext HttpContext { get; set; }
}
}

View File

@ -1,48 +0,0 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
#if DNX451
using System.Runtime.Remoting.Messaging;
using System.Runtime.Remoting;
#elif DNXCORE50
using System.Threading;
#endif
using Microsoft.AspNet.Http;
namespace Microsoft.AspNet.Hosting
{
public class HttpContextAccessor : IHttpContextAccessor
{
#if DNX451
private const string LogicalDataKey = "__HttpContext_Current__";
public HttpContext HttpContext
{
get
{
var handle = CallContext.LogicalGetData(LogicalDataKey) as ObjectHandle;
return handle != null ? handle.Unwrap() as HttpContext : null;
}
set
{
CallContext.LogicalSetData(LogicalDataKey, new ObjectHandle(value));
}
}
#elif DNXCORE50
private AsyncLocal<HttpContext> _httpContextCurrent = new AsyncLocal<HttpContext>();
public HttpContext HttpContext
{
get
{
return _httpContextCurrent.Value;
}
set
{
_httpContextCurrent.Value = value;
}
}
#endif
}
}

View File

@ -7,6 +7,8 @@ using Microsoft.AspNet.Hosting.Builder;
using Microsoft.AspNet.Hosting.Internal;
using Microsoft.AspNet.Hosting.Server;
using Microsoft.AspNet.Hosting.Startup;
using Microsoft.AspNet.Http;
using Microsoft.AspNet.Http.Internal;
using Microsoft.Dnx.Runtime;
using Microsoft.Framework.Configuration;
using Microsoft.Framework.DependencyInjection;