Changing the IHttpContextFactory.CreateHttpContext take in a IFeatureCollection

Addresses: https://github.com/aspnet/Hosting/issues/162
This commit is contained in:
Praburaj 2015-02-25 17:48:46 -08:00
parent 00864c1af4
commit a2eec4f863
8 changed files with 25 additions and 21 deletions

View File

@ -4,6 +4,7 @@
using System; using System;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNet.Builder; using Microsoft.AspNet.Builder;
using Microsoft.AspNet.FeatureModel;
using Microsoft.Framework.ConfigurationModel; using Microsoft.Framework.ConfigurationModel;
namespace Microsoft.AspNet.Hosting.Server namespace Microsoft.AspNet.Hosting.Server
@ -11,6 +12,6 @@ namespace Microsoft.AspNet.Hosting.Server
public interface IServerFactory public interface IServerFactory
{ {
IServerInformation Initialize(IConfiguration configuration); IServerInformation Initialize(IConfiguration configuration);
IDisposable Start(IServerInformation serverInformation, Func<object, Task> application); IDisposable Start(IServerInformation serverInformation, Func<IFeatureCollection, Task> application);
} }
} }

View File

@ -2,12 +2,12 @@
"version": "1.0.0-*", "version": "1.0.0-*",
"dependencies": { "dependencies": {
"Microsoft.AspNet.Http": "1.0.0-*", "Microsoft.AspNet.Http": "1.0.0-*",
"Microsoft.AspNet.FeatureModel": "1.0.0-*",
"Microsoft.AspNet.FileProviders.Interfaces": "1.0.0-*", "Microsoft.AspNet.FileProviders.Interfaces": "1.0.0-*",
"Microsoft.Framework.ConfigurationModel": "1.0.0-*" "Microsoft.Framework.ConfigurationModel": "1.0.0-*"
}, },
"frameworks": { "frameworks": {
"aspnet50": { }, "aspnet50": {},
"aspnetcore50": { } "aspnetcore50": {}
} }
} }

View File

@ -9,11 +9,10 @@ namespace Microsoft.AspNet.Hosting.Builder
{ {
public class HttpContextFactory : IHttpContextFactory public class HttpContextFactory : IHttpContextFactory
{ {
public HttpContext CreateHttpContext(object serverContext) public HttpContext CreateHttpContext(IFeatureCollection featureCollection)
{ {
var featureObject = serverContext as IFeatureCollection ?? new FeatureObject(serverContext); var featureObject = featureCollection ?? new FeatureObject(null);
var featureCollection = new FeatureCollection(featureObject); var httpContext = new DefaultHttpContext(new FeatureCollection(featureObject));
var httpContext = new DefaultHttpContext(featureCollection);
return httpContext; return httpContext;
} }
} }

View File

@ -1,12 +1,13 @@
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. // 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. // 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; using Microsoft.AspNet.Http;
namespace Microsoft.AspNet.Hosting.Builder namespace Microsoft.AspNet.Hosting.Builder
{ {
public interface IHttpContextFactory public interface IHttpContextFactory
{ {
HttpContext CreateHttpContext(object serverContext); HttpContext CreateHttpContext(IFeatureCollection featureCollection);
} }
} }

View File

@ -4,6 +4,7 @@
using System; using System;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNet.Builder; using Microsoft.AspNet.Builder;
using Microsoft.AspNet.FeatureModel;
using Microsoft.AspNet.Hosting.Builder; using Microsoft.AspNet.Hosting.Builder;
namespace Microsoft.AspNet.Hosting namespace Microsoft.AspNet.Hosting
@ -21,9 +22,9 @@ namespace Microsoft.AspNet.Hosting
_contextAccessor = contextAccessor; _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; _contextAccessor.Value = httpContext;
return _requestDelegate(httpContext); return _requestDelegate(httpContext);
} }

View File

@ -23,14 +23,14 @@ namespace Microsoft.AspNet.TestHost
/// </summary> /// </summary>
public class ClientHandler : HttpMessageHandler public class ClientHandler : HttpMessageHandler
{ {
private readonly Func<object, Task> _next; private readonly Func<IFeatureCollection, Task> _next;
private readonly PathString _pathBase; private readonly PathString _pathBase;
/// <summary> /// <summary>
/// Create a new handler. /// Create a new handler.
/// </summary> /// </summary>
/// <param name="next">The pipeline entry point.</param> /// <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) if (next == null)
{ {

View File

@ -5,6 +5,7 @@ using System;
using System.Net.Http; using System.Net.Http;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNet.Builder; using Microsoft.AspNet.Builder;
using Microsoft.AspNet.FeatureModel;
using Microsoft.AspNet.Hosting; using Microsoft.AspNet.Hosting;
using Microsoft.AspNet.Hosting.Server; using Microsoft.AspNet.Hosting.Server;
using Microsoft.AspNet.Http; using Microsoft.AspNet.Http;
@ -21,7 +22,7 @@ namespace Microsoft.AspNet.TestHost
private const string DefaultEnvironmentName = "Development"; private const string DefaultEnvironmentName = "Development";
private const string ServerName = nameof(TestServer); private const string ServerName = nameof(TestServer);
private static readonly ServerInformation ServerInfo = new ServerInformation(); private static readonly ServerInformation ServerInfo = new ServerInformation();
private Func<object, Task> _appDelegate; private Func<IFeatureCollection, Task> _appDelegate;
private IDisposable _appInstance; private IDisposable _appInstance;
private bool _disposed = false; private bool _disposed = false;
@ -83,7 +84,7 @@ namespace Microsoft.AspNet.TestHost
return ServerInfo; 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))) if (!(serverInformation.GetType() == typeof(ServerInformation)))
{ {
@ -95,13 +96,13 @@ namespace Microsoft.AspNet.TestHost
return this; return this;
} }
public Task Invoke(object env) public Task Invoke(IFeatureCollection featureCollection)
{ {
if (_disposed) if (_disposed)
{ {
throw new ObjectDisposedException(GetType().FullName); throw new ObjectDisposedException(GetType().FullName);
} }
return _appDelegate(env); return _appDelegate(featureCollection);
} }
public void Dispose() public void Dispose()

View File

@ -6,6 +6,7 @@ using System.Collections.Generic;
using System.IO; using System.IO;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNet.Builder; using Microsoft.AspNet.Builder;
using Microsoft.AspNet.FeatureModel;
using Microsoft.AspNet.Hosting.Server; using Microsoft.AspNet.Hosting.Server;
using Microsoft.Framework.ConfigurationModel; using Microsoft.Framework.ConfigurationModel;
using Microsoft.Framework.DependencyInjection; using Microsoft.Framework.DependencyInjection;
@ -73,7 +74,7 @@ namespace Microsoft.AspNet.Hosting
return null; 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); var startInstance = new StartInstance(application);
_startInstances.Add(startInstance); _startInstances.Add(startInstance);
@ -82,9 +83,9 @@ namespace Microsoft.AspNet.Hosting
public class StartInstance : IDisposable 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; _application = application;
} }