Use new HttpContext.Features API.
This commit is contained in:
parent
66a7c2e389
commit
dd737ce946
|
|
@ -69,7 +69,7 @@ namespace Microsoft.AspNet.Mvc
|
|||
throw new FileNotFoundException(Resources.FormatFileResult_InvalidPath(FileName), FileName);
|
||||
}
|
||||
|
||||
var sendFile = response.HttpContext.GetFeature<IHttpSendFileFeature>();
|
||||
var sendFile = response.HttpContext.Features.Get<IHttpSendFileFeature>();
|
||||
if (sendFile != null)
|
||||
{
|
||||
await sendFile.SendFileAsync(
|
||||
|
|
|
|||
|
|
@ -86,7 +86,7 @@ namespace Microsoft.AspNet.Mvc
|
|||
if (fileInfo.Exists)
|
||||
{
|
||||
var physicalPath = fileInfo.PhysicalPath;
|
||||
var sendFile = response.HttpContext.GetFeature<IHttpSendFileFeature>();
|
||||
var sendFile = response.HttpContext.Features.Get<IHttpSendFileFeature>();
|
||||
if (sendFile != null && !string.IsNullOrEmpty(physicalPath))
|
||||
{
|
||||
await sendFile.SendFileAsync(
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ using System;
|
|||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNet.Http.Features;
|
||||
using Microsoft.AspNet.Mvc.Rendering;
|
||||
using Microsoft.AspNet.PageExecutionInstrumentation;
|
||||
using Microsoft.Framework.Internal;
|
||||
|
|
@ -68,7 +69,7 @@ namespace Microsoft.AspNet.Mvc.Razor
|
|||
/// <inheritdoc />
|
||||
public virtual async Task RenderAsync([NotNull] ViewContext context)
|
||||
{
|
||||
_pageExecutionFeature = context.HttpContext.GetFeature<IPageExecutionListenerFeature>();
|
||||
_pageExecutionFeature = context.HttpContext.Features.Get<IPageExecutionListenerFeature>();
|
||||
|
||||
// Partials don't execute _ViewStart pages, but may execute Layout pages if the Layout property
|
||||
// is explicitly specified in the page.
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
|
||||
using System;
|
||||
using Microsoft.AspNet.Diagnostics;
|
||||
using Microsoft.AspNet.Http.Features;
|
||||
using Microsoft.Framework.Internal;
|
||||
|
||||
namespace Microsoft.AspNet.Mvc
|
||||
|
|
@ -21,7 +22,7 @@ namespace Microsoft.AspNet.Mvc
|
|||
/// <inheritdoc />
|
||||
public void OnResourceExecuting([NotNull]ResourceExecutingContext context)
|
||||
{
|
||||
var statusCodeFeature = context.HttpContext.GetFeature<IStatusCodePagesFeature>();
|
||||
var statusCodeFeature = context.HttpContext.Features.Get<IStatusCodePagesFeature>();
|
||||
if (statusCodeFeature != null)
|
||||
{
|
||||
// Turn off the StatusCodePages feature.
|
||||
|
|
|
|||
|
|
@ -183,7 +183,7 @@ namespace Microsoft.AspNet.Mvc
|
|||
|
||||
private static bool IsSessionEnabled(HttpContext context)
|
||||
{
|
||||
return context.GetFeature<ISessionFeature>() != null;
|
||||
return context.Features.Get<ISessionFeature>() != null;
|
||||
}
|
||||
|
||||
internal void EnsureObjectCanBeSerialized(object item)
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@ namespace Microsoft.AspNet.Mvc.WebApiCompatShim
|
|||
{
|
||||
response.StatusCode = (int)responseMessage.StatusCode;
|
||||
|
||||
var responseFeature = context.HttpContext.GetFeature<IHttpResponseFeature>();
|
||||
var responseFeature = context.HttpContext.Features.Get<IHttpResponseFeature>();
|
||||
if (responseFeature != null)
|
||||
{
|
||||
responseFeature.ReasonPhrase = responseMessage.ReasonPhrase;
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
|
||||
using System.Net.Http;
|
||||
using Microsoft.AspNet.Http;
|
||||
using Microsoft.AspNet.Http.Features;
|
||||
|
||||
namespace Microsoft.AspNet.Mvc.WebApiCompatShim
|
||||
{
|
||||
|
|
@ -10,11 +11,11 @@ namespace Microsoft.AspNet.Mvc.WebApiCompatShim
|
|||
{
|
||||
public static HttpRequestMessage GetHttpRequestMessage(this HttpContext httpContext)
|
||||
{
|
||||
var feature = httpContext.GetFeature<IHttpRequestMessageFeature>();
|
||||
var feature = httpContext.Features.Get<IHttpRequestMessageFeature>();
|
||||
if (feature == null)
|
||||
{
|
||||
feature = new HttpRequestMessageFeature(httpContext);
|
||||
httpContext.SetFeature(feature);
|
||||
httpContext.Features.Set(feature);
|
||||
}
|
||||
|
||||
return feature.HttpRequestMessage;
|
||||
|
|
|
|||
|
|
@ -61,7 +61,7 @@ namespace Microsoft.AspNet.Mvc
|
|||
.Returns(Task.FromResult<int>(0));
|
||||
|
||||
var httpContext = new DefaultHttpContext();
|
||||
httpContext.SetFeature(sendFileMock.Object);
|
||||
httpContext.Features.Set(sendFileMock.Object);
|
||||
var context = new ActionContext(httpContext, new RouteData(), new ActionDescriptor());
|
||||
|
||||
// Act
|
||||
|
|
|
|||
|
|
@ -100,7 +100,7 @@ namespace Microsoft.AspNet.Mvc
|
|||
.Returns(Task.FromResult<int>(0));
|
||||
|
||||
var httpContext = new DefaultHttpContext();
|
||||
httpContext.SetFeature(sendFileMock.Object);
|
||||
httpContext.Features.Set(sendFileMock.Object);
|
||||
var context = new ActionContext(httpContext, new RouteData(), new ActionDescriptor());
|
||||
|
||||
// Act
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ using System.Collections.Generic;
|
|||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNet.Http.Features;
|
||||
using Microsoft.AspNet.Http.Internal;
|
||||
using Microsoft.AspNet.Mvc.ModelBinding;
|
||||
using Microsoft.AspNet.PageExecutionInstrumentation;
|
||||
|
|
@ -1096,7 +1097,7 @@ namespace Microsoft.AspNet.Mvc.Razor
|
|||
page,
|
||||
isPartial: false);
|
||||
var viewContext = CreateViewContext(view);
|
||||
viewContext.HttpContext.SetFeature<IPageExecutionListenerFeature>(feature.Object);
|
||||
viewContext.HttpContext.Features.Set<IPageExecutionListenerFeature>(feature.Object);
|
||||
|
||||
// Act
|
||||
await view.RenderAsync(viewContext);
|
||||
|
|
@ -1142,7 +1143,7 @@ namespace Microsoft.AspNet.Mvc.Razor
|
|||
isPartial: true);
|
||||
var viewContext = CreateViewContext(view);
|
||||
viewContext.Writer = writer;
|
||||
viewContext.HttpContext.SetFeature<IPageExecutionListenerFeature>(feature.Object);
|
||||
viewContext.HttpContext.Features.Set<IPageExecutionListenerFeature>(feature.Object);
|
||||
|
||||
// Act
|
||||
await view.RenderAsync(viewContext);
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using Microsoft.AspNet.Diagnostics;
|
||||
using Microsoft.AspNet.Http.Features;
|
||||
using Microsoft.AspNet.Http.Internal;
|
||||
using Microsoft.AspNet.Routing;
|
||||
using Xunit;
|
||||
|
|
@ -17,7 +18,7 @@ namespace Microsoft.AspNet.Mvc.Core.Test
|
|||
var skipStatusCodeAttribute = new SkipStatusCodePagesAttribute();
|
||||
var resourceExecutingContext = CreateResourceExecutingContext(new IFilterMetadata[] { skipStatusCodeAttribute });
|
||||
var statusCodePagesFeature = new TestStatusCodeFeature();
|
||||
resourceExecutingContext.HttpContext.SetFeature<IStatusCodePagesFeature>(statusCodePagesFeature);
|
||||
resourceExecutingContext.HttpContext.Features.Set<IStatusCodePagesFeature>(statusCodePagesFeature);
|
||||
|
||||
// Act
|
||||
skipStatusCodeAttribute.OnResourceExecuting(resourceExecutingContext);
|
||||
|
|
|
|||
|
|
@ -352,7 +352,7 @@ namespace Microsoft.AspNet.Mvc
|
|||
var httpContext = new DefaultHttpContext();
|
||||
if(sessionEnabled)
|
||||
{
|
||||
httpContext.SetFeature<ISessionFeature>(new SessionFeature() { Session = session });
|
||||
httpContext.Features.Set<ISessionFeature>(new SessionFeature() { Session = session });
|
||||
}
|
||||
return httpContext;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,10 +26,10 @@ namespace FilesWebSite
|
|||
{
|
||||
var environment = (IApplicationEnvironment)context.RequestServices.GetService(typeof(IApplicationEnvironment));
|
||||
|
||||
if (context.GetFeature<IHttpSendFileFeature>() == null)
|
||||
if (context.Features.Get<IHttpSendFileFeature>() == null)
|
||||
{
|
||||
var sendFile = new SendFileFallBack(context.Response.Body, environment.ApplicationBasePath);
|
||||
context.SetFeature<IHttpSendFileFeature>(sendFile);
|
||||
context.Features.Set<IHttpSendFileFeature>(sendFile);
|
||||
}
|
||||
|
||||
await _next(context);
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ using System;
|
|||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNet.Builder;
|
||||
using Microsoft.AspNet.Http;
|
||||
using Microsoft.AspNet.Http.Features;
|
||||
using Microsoft.AspNet.Mvc.Razor.Compilation;
|
||||
using Microsoft.AspNet.PageExecutionInstrumentation;
|
||||
using Microsoft.Framework.DependencyInjection;
|
||||
|
|
@ -34,7 +35,7 @@ namespace RazorPageExecutionInstrumentationWebSite
|
|||
{
|
||||
var pageExecutionContext = context.ApplicationServices.GetRequiredService<TestPageExecutionContext>();
|
||||
var listenerFeature = new TestPageExecutionListenerFeature(pageExecutionContext);
|
||||
context.SetFeature<IPageExecutionListenerFeature>(listenerFeature);
|
||||
context.Features.Set<IPageExecutionListenerFeature>(listenerFeature);
|
||||
}
|
||||
|
||||
await next();
|
||||
|
|
|
|||
Loading…
Reference in New Issue