Changing the IHttpContextFactory.CreateHttpContext take in a IFeatureCollection
Addresses: https://github.com/aspnet/Hosting/issues/162
This commit is contained in:
parent
00864c1af4
commit
a2eec4f863
|
|
@ -4,6 +4,7 @@
|
|||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNet.Builder;
|
||||
using Microsoft.AspNet.FeatureModel;
|
||||
using Microsoft.Framework.ConfigurationModel;
|
||||
|
||||
namespace Microsoft.AspNet.Hosting.Server
|
||||
|
|
@ -11,6 +12,6 @@ namespace Microsoft.AspNet.Hosting.Server
|
|||
public interface IServerFactory
|
||||
{
|
||||
IServerInformation Initialize(IConfiguration configuration);
|
||||
IDisposable Start(IServerInformation serverInformation, Func<object, Task> application);
|
||||
IDisposable Start(IServerInformation serverInformation, Func<IFeatureCollection, Task> application);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,12 +2,12 @@
|
|||
"version": "1.0.0-*",
|
||||
"dependencies": {
|
||||
"Microsoft.AspNet.Http": "1.0.0-*",
|
||||
"Microsoft.AspNet.FeatureModel": "1.0.0-*",
|
||||
"Microsoft.AspNet.FileProviders.Interfaces": "1.0.0-*",
|
||||
"Microsoft.Framework.ConfigurationModel": "1.0.0-*"
|
||||
},
|
||||
|
||||
"frameworks": {
|
||||
"aspnet50": { },
|
||||
"aspnetcore50": { }
|
||||
"aspnet50": {},
|
||||
"aspnetcore50": {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -9,11 +9,10 @@ namespace Microsoft.AspNet.Hosting.Builder
|
|||
{
|
||||
public class HttpContextFactory : IHttpContextFactory
|
||||
{
|
||||
public HttpContext CreateHttpContext(object serverContext)
|
||||
public HttpContext CreateHttpContext(IFeatureCollection featureCollection)
|
||||
{
|
||||
var featureObject = serverContext as IFeatureCollection ?? new FeatureObject(serverContext);
|
||||
var featureCollection = new FeatureCollection(featureObject);
|
||||
var httpContext = new DefaultHttpContext(featureCollection);
|
||||
var featureObject = featureCollection ?? new FeatureObject(null);
|
||||
var httpContext = new DefaultHttpContext(new FeatureCollection(featureObject));
|
||||
return httpContext;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,12 +1,13 @@
|
|||
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using Microsoft.AspNet.FeatureModel;
|
||||
using Microsoft.AspNet.Http;
|
||||
|
||||
namespace Microsoft.AspNet.Hosting.Builder
|
||||
{
|
||||
public interface IHttpContextFactory
|
||||
{
|
||||
HttpContext CreateHttpContext(object serverContext);
|
||||
HttpContext CreateHttpContext(IFeatureCollection featureCollection);
|
||||
}
|
||||
}
|
||||
|
|
@ -4,6 +4,7 @@
|
|||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNet.Builder;
|
||||
using Microsoft.AspNet.FeatureModel;
|
||||
using Microsoft.AspNet.Hosting.Builder;
|
||||
|
||||
namespace Microsoft.AspNet.Hosting
|
||||
|
|
@ -21,9 +22,9 @@ namespace Microsoft.AspNet.Hosting
|
|||
_contextAccessor = contextAccessor;
|
||||
}
|
||||
|
||||
public Task Invoke(object serverEnvironment)
|
||||
public Task Invoke(IFeatureCollection featureCollection)
|
||||
{
|
||||
var httpContext = _httpContextFactory.CreateHttpContext(serverEnvironment);
|
||||
var httpContext = _httpContextFactory.CreateHttpContext(featureCollection);
|
||||
_contextAccessor.Value = httpContext;
|
||||
return _requestDelegate(httpContext);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,14 +23,14 @@ namespace Microsoft.AspNet.TestHost
|
|||
/// </summary>
|
||||
public class ClientHandler : HttpMessageHandler
|
||||
{
|
||||
private readonly Func<object, Task> _next;
|
||||
private readonly Func<IFeatureCollection, Task> _next;
|
||||
private readonly PathString _pathBase;
|
||||
|
||||
/// <summary>
|
||||
/// Create a new handler.
|
||||
/// </summary>
|
||||
/// <param name="next">The pipeline entry point.</param>
|
||||
public ClientHandler(Func<object, Task> next, PathString pathBase)
|
||||
public ClientHandler(Func<IFeatureCollection, Task> next, PathString pathBase)
|
||||
{
|
||||
if (next == null)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ using System;
|
|||
using System.Net.Http;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNet.Builder;
|
||||
using Microsoft.AspNet.FeatureModel;
|
||||
using Microsoft.AspNet.Hosting;
|
||||
using Microsoft.AspNet.Hosting.Server;
|
||||
using Microsoft.AspNet.Http;
|
||||
|
|
@ -21,7 +22,7 @@ namespace Microsoft.AspNet.TestHost
|
|||
private const string DefaultEnvironmentName = "Development";
|
||||
private const string ServerName = nameof(TestServer);
|
||||
private static readonly ServerInformation ServerInfo = new ServerInformation();
|
||||
private Func<object, Task> _appDelegate;
|
||||
private Func<IFeatureCollection, Task> _appDelegate;
|
||||
private IDisposable _appInstance;
|
||||
private bool _disposed = false;
|
||||
|
||||
|
|
@ -83,7 +84,7 @@ namespace Microsoft.AspNet.TestHost
|
|||
return ServerInfo;
|
||||
}
|
||||
|
||||
public IDisposable Start(IServerInformation serverInformation, Func<object, Task> application)
|
||||
public IDisposable Start(IServerInformation serverInformation, Func<IFeatureCollection, Task> application)
|
||||
{
|
||||
if (!(serverInformation.GetType() == typeof(ServerInformation)))
|
||||
{
|
||||
|
|
@ -95,13 +96,13 @@ namespace Microsoft.AspNet.TestHost
|
|||
return this;
|
||||
}
|
||||
|
||||
public Task Invoke(object env)
|
||||
public Task Invoke(IFeatureCollection featureCollection)
|
||||
{
|
||||
if (_disposed)
|
||||
{
|
||||
throw new ObjectDisposedException(GetType().FullName);
|
||||
}
|
||||
return _appDelegate(env);
|
||||
return _appDelegate(featureCollection);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ using System.Collections.Generic;
|
|||
using System.IO;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNet.Builder;
|
||||
using Microsoft.AspNet.FeatureModel;
|
||||
using Microsoft.AspNet.Hosting.Server;
|
||||
using Microsoft.Framework.ConfigurationModel;
|
||||
using Microsoft.Framework.DependencyInjection;
|
||||
|
|
@ -73,7 +74,7 @@ namespace Microsoft.AspNet.Hosting
|
|||
return null;
|
||||
}
|
||||
|
||||
public IDisposable Start(IServerInformation serverInformation, Func<object, Task> application)
|
||||
public IDisposable Start(IServerInformation serverInformation, Func<IFeatureCollection, Task> application)
|
||||
{
|
||||
var startInstance = new StartInstance(application);
|
||||
_startInstances.Add(startInstance);
|
||||
|
|
@ -82,9 +83,9 @@ namespace Microsoft.AspNet.Hosting
|
|||
|
||||
public class StartInstance : IDisposable
|
||||
{
|
||||
private readonly Func<object, Task> _application;
|
||||
private readonly Func<IFeatureCollection, Task> _application;
|
||||
|
||||
public StartInstance(Func<object, Task> application)
|
||||
public StartInstance(Func<IFeatureCollection, Task> application)
|
||||
{
|
||||
_application = application;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue