From a2eec4f863bc6d5c3bad43a483ac0041b2b98cb5 Mon Sep 17 00:00:00 2001 From: Praburaj Date: Wed, 25 Feb 2015 17:48:46 -0800 Subject: [PATCH] Changing the IHttpContextFactory.CreateHttpContext take in a IFeatureCollection Addresses: https://github.com/aspnet/Hosting/issues/162 --- .../IServerFactory.cs | 3 ++- src/Microsoft.AspNet.Hosting.Interfaces/project.json | 8 ++++---- .../Builder/HttpContextFactory.cs | 7 +++---- .../Builder/IHttpContextFactory.cs | 3 ++- src/Microsoft.AspNet.Hosting/PipelineInstance.cs | 5 +++-- src/Microsoft.AspNet.TestHost/ClientHandler.cs | 4 ++-- src/Microsoft.AspNet.TestHost/TestServer.cs | 9 +++++---- .../Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs | 7 ++++--- 8 files changed, 25 insertions(+), 21 deletions(-) diff --git a/src/Microsoft.AspNet.Hosting.Interfaces/IServerFactory.cs b/src/Microsoft.AspNet.Hosting.Interfaces/IServerFactory.cs index 979730e5de..f389a1ec4c 100644 --- a/src/Microsoft.AspNet.Hosting.Interfaces/IServerFactory.cs +++ b/src/Microsoft.AspNet.Hosting.Interfaces/IServerFactory.cs @@ -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 application); + IDisposable Start(IServerInformation serverInformation, Func application); } } diff --git a/src/Microsoft.AspNet.Hosting.Interfaces/project.json b/src/Microsoft.AspNet.Hosting.Interfaces/project.json index 9e5b132ac8..6f33dd5cea 100644 --- a/src/Microsoft.AspNet.Hosting.Interfaces/project.json +++ b/src/Microsoft.AspNet.Hosting.Interfaces/project.json @@ -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": {} } -} +} \ No newline at end of file diff --git a/src/Microsoft.AspNet.Hosting/Builder/HttpContextFactory.cs b/src/Microsoft.AspNet.Hosting/Builder/HttpContextFactory.cs index 227d7bd2f4..9c03e2fcb1 100644 --- a/src/Microsoft.AspNet.Hosting/Builder/HttpContextFactory.cs +++ b/src/Microsoft.AspNet.Hosting/Builder/HttpContextFactory.cs @@ -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; } } diff --git a/src/Microsoft.AspNet.Hosting/Builder/IHttpContextFactory.cs b/src/Microsoft.AspNet.Hosting/Builder/IHttpContextFactory.cs index cdd6be9fac..ba3e7a36dc 100644 --- a/src/Microsoft.AspNet.Hosting/Builder/IHttpContextFactory.cs +++ b/src/Microsoft.AspNet.Hosting/Builder/IHttpContextFactory.cs @@ -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); } } \ No newline at end of file diff --git a/src/Microsoft.AspNet.Hosting/PipelineInstance.cs b/src/Microsoft.AspNet.Hosting/PipelineInstance.cs index d69a700c94..3d14ee404c 100644 --- a/src/Microsoft.AspNet.Hosting/PipelineInstance.cs +++ b/src/Microsoft.AspNet.Hosting/PipelineInstance.cs @@ -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); } diff --git a/src/Microsoft.AspNet.TestHost/ClientHandler.cs b/src/Microsoft.AspNet.TestHost/ClientHandler.cs index 1549565532..f190c0b539 100644 --- a/src/Microsoft.AspNet.TestHost/ClientHandler.cs +++ b/src/Microsoft.AspNet.TestHost/ClientHandler.cs @@ -23,14 +23,14 @@ namespace Microsoft.AspNet.TestHost /// public class ClientHandler : HttpMessageHandler { - private readonly Func _next; + private readonly Func _next; private readonly PathString _pathBase; /// /// Create a new handler. /// /// The pipeline entry point. - public ClientHandler(Func next, PathString pathBase) + public ClientHandler(Func next, PathString pathBase) { if (next == null) { diff --git a/src/Microsoft.AspNet.TestHost/TestServer.cs b/src/Microsoft.AspNet.TestHost/TestServer.cs index 6505344c2e..ef7c53c2d1 100644 --- a/src/Microsoft.AspNet.TestHost/TestServer.cs +++ b/src/Microsoft.AspNet.TestHost/TestServer.cs @@ -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 _appDelegate; + private Func _appDelegate; private IDisposable _appInstance; private bool _disposed = false; @@ -83,7 +84,7 @@ namespace Microsoft.AspNet.TestHost return ServerInfo; } - public IDisposable Start(IServerInformation serverInformation, Func application) + public IDisposable Start(IServerInformation serverInformation, Func 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() diff --git a/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs b/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs index 3784c49be0..e8395c649f 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs @@ -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 application) + public IDisposable Start(IServerInformation serverInformation, Func application) { var startInstance = new StartInstance(application); _startInstances.Add(startInstance); @@ -82,9 +83,9 @@ namespace Microsoft.AspNet.Hosting public class StartInstance : IDisposable { - private readonly Func _application; + private readonly Func _application; - public StartInstance(Func application) + public StartInstance(Func application) { _application = application; }