From c37c555333f9fa33c19af22fa1dcfdbb6b4de1a1 Mon Sep 17 00:00:00 2001 From: Louis DeJardin Date: Sun, 9 Feb 2014 18:28:14 -0800 Subject: [PATCH 001/987] Initializing repository --- .gitattributes | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ .gitignore | 22 ++++++++++++++++++++++ NuGet.Config | 13 +++++++++++++ build.cmd | 15 +++++++++++++++ makefile.shade | 7 +++++++ 5 files changed, 107 insertions(+) create mode 100644 .gitattributes create mode 100644 .gitignore create mode 100644 NuGet.Config create mode 100644 build.cmd create mode 100644 makefile.shade diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000000..bdaa5ba982 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,50 @@ +*.doc diff=astextplain +*.DOC diff=astextplain +*.docx diff=astextplain +*.DOCX diff=astextplain +*.dot diff=astextplain +*.DOT diff=astextplain +*.pdf diff=astextplain +*.PDF diff=astextplain +*.rtf diff=astextplain +*.RTF diff=astextplain + +*.jpg binary +*.png binary +*.gif binary + +*.cs text=auto diff=csharp +*.vb text=auto +*.resx text=auto +*.c text=auto +*.cpp text=auto +*.cxx text=auto +*.h text=auto +*.hxx text=auto +*.py text=auto +*.rb text=auto +*.java text=auto +*.html text=auto +*.htm text=auto +*.css text=auto +*.scss text=auto +*.sass text=auto +*.less text=auto +*.js text=auto +*.lisp text=auto +*.clj text=auto +*.sql text=auto +*.php text=auto +*.lua text=auto +*.m text=auto +*.asm text=auto +*.erl text=auto +*.fs text=auto +*.fsx text=auto +*.hs text=auto + +*.csproj text=auto +*.vbproj text=auto +*.fsproj text=auto +*.dbproj text=auto +*.sln text=auto eol=crlf diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000000..2554a1fc23 --- /dev/null +++ b/.gitignore @@ -0,0 +1,22 @@ +[Oo]bj/ +[Bb]in/ +TestResults/ +.nuget/ +_ReSharper.*/ +packages/ +artifacts/ +PublishProfiles/ +*.user +*.suo +*.cache +*.docstates +_ReSharper.* +nuget.exe +*net45.csproj +*k10.csproj +*.psess +*.vsp +*.pidb +*.userprefs +*DS_Store +*.ncrunchsolution diff --git a/NuGet.Config b/NuGet.Config new file mode 100644 index 0000000000..ab583b0ff7 --- /dev/null +++ b/NuGet.Config @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/build.cmd b/build.cmd new file mode 100644 index 0000000000..d54931bc8f --- /dev/null +++ b/build.cmd @@ -0,0 +1,15 @@ +@echo off +cd %~dp0 + +IF EXIST .nuget\NuGet.exe goto restore +echo Downloading latest version of NuGet.exe... +md .nuget +@powershell -NoProfile -ExecutionPolicy unrestricted -Command "$ProgressPreference = 'SilentlyContinue'; Invoke-WebRequest 'https://www.nuget.org/nuget.exe' -OutFile '.nuget\NuGet.exe'" + +:restore +IF EXIST packages\KoreBuild goto run +.nuget\NuGet.exe install KoreBuild -ExcludeVersion -o packages -nocache -pre +.nuget\NuGet.exe install Sake -version 0.2 -o packages -ExcludeVersion + +:run +packages\Sake\tools\Sake.exe -I packages\KoreBuild\build -f makefile.shade %* diff --git a/makefile.shade b/makefile.shade new file mode 100644 index 0000000000..6357ea2841 --- /dev/null +++ b/makefile.shade @@ -0,0 +1,7 @@ + +var VERSION='0.1' +var FULL_VERSION='0.1' +var AUTHORS='Microsoft' + +use-standard-lifecycle +k-standard-goals From 0e813fbb790230a9226641d218573b9e4a0fb5b3 Mon Sep 17 00:00:00 2001 From: Louis DeJardin Date: Sun, 9 Feb 2014 23:25:56 -0800 Subject: [PATCH 002/987] Rough outline of hosting components --- Hosting.sln | 43 ++++++++ .../Builder/BuilderFactory.cs | 20 ++++ .../Builder/HttpContextFactory.cs | 18 +++ .../Builder/IBuilderFactory.cs | 9 ++ .../Builder/IHttpContextFactory.cs | 9 ++ .../HostingContext.cs | 20 ++++ src/Microsoft.AspNet.Hosting/HostingEngine.cs | 104 ++++++++++++++++++ .../HostingServices.cs | 81 ++++++++++++++ .../IHostingEngine.cs | 9 ++ .../PipelineInstance.cs | 31 ++++++ .../Server/IServerFactory.cs | 11 ++ .../Server/IServerFactoryProvider.cs | 7 ++ .../Server/IServerManager.cs | 7 ++ .../Server/ServerManager.cs | 10 ++ .../ServerFactoryProvider.cs | 13 +++ .../Startup/IStartupLoader.cs | 11 ++ .../Startup/IStartupLoaderProvider.cs | 9 ++ .../Startup/IStartupManager.cs | 10 ++ .../Startup/NullStartupLoader.cs | 21 ++++ .../Startup/StartupLoader.cs | 62 +++++++++++ .../Startup/StartupLoaderProvider.cs | 21 ++++ .../Startup/StartupManager.cs | 36 ++++++ .../WebApplication.cs | 23 ++++ src/Microsoft.AspNet.Hosting/project.json | 14 +++ .../Fakes/FakeStartup.cs | 11 ++ .../Fakes/FakeStartupWithServices.cs | 19 ++++ .../Fakes/IFakeStartupCallback.cs | 7 ++ .../HostingEngineTests.cs | 88 +++++++++++++++ .../StartupManagerTests.cs | 51 +++++++++ .../project.json | 12 ++ 30 files changed, 787 insertions(+) create mode 100644 Hosting.sln create mode 100644 src/Microsoft.AspNet.Hosting/Builder/BuilderFactory.cs create mode 100644 src/Microsoft.AspNet.Hosting/Builder/HttpContextFactory.cs create mode 100644 src/Microsoft.AspNet.Hosting/Builder/IBuilderFactory.cs create mode 100644 src/Microsoft.AspNet.Hosting/Builder/IHttpContextFactory.cs create mode 100644 src/Microsoft.AspNet.Hosting/HostingContext.cs create mode 100644 src/Microsoft.AspNet.Hosting/HostingEngine.cs create mode 100644 src/Microsoft.AspNet.Hosting/HostingServices.cs create mode 100644 src/Microsoft.AspNet.Hosting/IHostingEngine.cs create mode 100644 src/Microsoft.AspNet.Hosting/PipelineInstance.cs create mode 100644 src/Microsoft.AspNet.Hosting/Server/IServerFactory.cs create mode 100644 src/Microsoft.AspNet.Hosting/Server/IServerFactoryProvider.cs create mode 100644 src/Microsoft.AspNet.Hosting/Server/IServerManager.cs create mode 100644 src/Microsoft.AspNet.Hosting/Server/ServerManager.cs create mode 100644 src/Microsoft.AspNet.Hosting/ServerFactoryProvider.cs create mode 100644 src/Microsoft.AspNet.Hosting/Startup/IStartupLoader.cs create mode 100644 src/Microsoft.AspNet.Hosting/Startup/IStartupLoaderProvider.cs create mode 100644 src/Microsoft.AspNet.Hosting/Startup/IStartupManager.cs create mode 100644 src/Microsoft.AspNet.Hosting/Startup/NullStartupLoader.cs create mode 100644 src/Microsoft.AspNet.Hosting/Startup/StartupLoader.cs create mode 100644 src/Microsoft.AspNet.Hosting/Startup/StartupLoaderProvider.cs create mode 100644 src/Microsoft.AspNet.Hosting/Startup/StartupManager.cs create mode 100644 src/Microsoft.AspNet.Hosting/WebApplication.cs create mode 100644 src/Microsoft.AspNet.Hosting/project.json create mode 100644 test/Microsoft.AspNet.Hosting.Tests/Fakes/FakeStartup.cs create mode 100644 test/Microsoft.AspNet.Hosting.Tests/Fakes/FakeStartupWithServices.cs create mode 100644 test/Microsoft.AspNet.Hosting.Tests/Fakes/IFakeStartupCallback.cs create mode 100644 test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs create mode 100644 test/Microsoft.AspNet.Hosting.Tests/StartupManagerTests.cs create mode 100644 test/Microsoft.AspNet.Hosting.Tests/project.json diff --git a/Hosting.sln b/Hosting.sln new file mode 100644 index 0000000000..3394417c72 --- /dev/null +++ b/Hosting.sln @@ -0,0 +1,43 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 2013 +VisualStudioVersion = 12.0.21005.1 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{E0497F39-AFFB-4819-A116-E39E361915AB}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{FEB39027-9158-4DE2-997F-7ADAEF8188D0}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.AspNet.Hosting.net45", "src\Microsoft.AspNet.Hosting\Microsoft.AspNet.Hosting.net45.csproj", "{D546290B-E280-4D99-BA9C-0D364A0AFB54}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.AspNet.Hosting.k10", "src\Microsoft.AspNet.Hosting\Microsoft.AspNet.Hosting.k10.csproj", "{DBB72F0F-755D-41CF-8FE2-F4B6AE214E91}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.AspNet.Hosting.Tests.net45", "test\Microsoft.AspNet.Hosting.Tests\Microsoft.AspNet.Hosting.Tests.net45.csproj", "{80588AF3-6B14-4D11-9DC4-1EF6453B54C9}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {D546290B-E280-4D99-BA9C-0D364A0AFB54}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {D546290B-E280-4D99-BA9C-0D364A0AFB54}.Debug|Any CPU.Build.0 = Debug|Any CPU + {D546290B-E280-4D99-BA9C-0D364A0AFB54}.Release|Any CPU.ActiveCfg = Release|Any CPU + {D546290B-E280-4D99-BA9C-0D364A0AFB54}.Release|Any CPU.Build.0 = Release|Any CPU + {DBB72F0F-755D-41CF-8FE2-F4B6AE214E91}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {DBB72F0F-755D-41CF-8FE2-F4B6AE214E91}.Debug|Any CPU.Build.0 = Debug|Any CPU + {DBB72F0F-755D-41CF-8FE2-F4B6AE214E91}.Release|Any CPU.ActiveCfg = Release|Any CPU + {DBB72F0F-755D-41CF-8FE2-F4B6AE214E91}.Release|Any CPU.Build.0 = Release|Any CPU + {80588AF3-6B14-4D11-9DC4-1EF6453B54C9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {80588AF3-6B14-4D11-9DC4-1EF6453B54C9}.Debug|Any CPU.Build.0 = Debug|Any CPU + {80588AF3-6B14-4D11-9DC4-1EF6453B54C9}.Release|Any CPU.ActiveCfg = Release|Any CPU + {80588AF3-6B14-4D11-9DC4-1EF6453B54C9}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(NestedProjects) = preSolution + {D546290B-E280-4D99-BA9C-0D364A0AFB54} = {E0497F39-AFFB-4819-A116-E39E361915AB} + {DBB72F0F-755D-41CF-8FE2-F4B6AE214E91} = {E0497F39-AFFB-4819-A116-E39E361915AB} + {80588AF3-6B14-4D11-9DC4-1EF6453B54C9} = {FEB39027-9158-4DE2-997F-7ADAEF8188D0} + EndGlobalSection +EndGlobal diff --git a/src/Microsoft.AspNet.Hosting/Builder/BuilderFactory.cs b/src/Microsoft.AspNet.Hosting/Builder/BuilderFactory.cs new file mode 100644 index 0000000000..bee42edcd3 --- /dev/null +++ b/src/Microsoft.AspNet.Hosting/Builder/BuilderFactory.cs @@ -0,0 +1,20 @@ +using System; +using Microsoft.AspNet.Abstractions; + +namespace Microsoft.AspNet.Hosting.Builder +{ + public class BuilderFactory : IBuilderFactory + { + private readonly IServiceProvider _serviceProvider; + + public BuilderFactory(IServiceProvider serviceProvider) + { + _serviceProvider = serviceProvider; + } + + public IBuilder CreateBuilder() + { + return new PipelineCore.Builder(_serviceProvider); + } + } +} diff --git a/src/Microsoft.AspNet.Hosting/Builder/HttpContextFactory.cs b/src/Microsoft.AspNet.Hosting/Builder/HttpContextFactory.cs new file mode 100644 index 0000000000..18dc5a4341 --- /dev/null +++ b/src/Microsoft.AspNet.Hosting/Builder/HttpContextFactory.cs @@ -0,0 +1,18 @@ +using Microsoft.AspNet.Abstractions; +using Microsoft.AspNet.FeatureModel; +using Microsoft.AspNet.Hosting.Server; +using Microsoft.AspNet.PipelineCore; + +namespace Microsoft.AspNet.Hosting.Builder +{ + public class HttpContextFactory : IHttpContextFactory + { + public HttpContext CreateHttpContext(object serverContext) + { + var featureObject = serverContext as IFeatureCollection ?? new FeatureObject(serverContext); + var featureCollection = new FeatureCollection(featureObject); + var httpContext = new DefaultHttpContext(featureCollection); + return httpContext; + } + } +} \ No newline at end of file diff --git a/src/Microsoft.AspNet.Hosting/Builder/IBuilderFactory.cs b/src/Microsoft.AspNet.Hosting/Builder/IBuilderFactory.cs new file mode 100644 index 0000000000..f69589727a --- /dev/null +++ b/src/Microsoft.AspNet.Hosting/Builder/IBuilderFactory.cs @@ -0,0 +1,9 @@ +using Microsoft.AspNet.Abstractions; + +namespace Microsoft.AspNet.Hosting.Builder +{ + public interface IBuilderFactory + { + IBuilder CreateBuilder(); + } +} \ No newline at end of file diff --git a/src/Microsoft.AspNet.Hosting/Builder/IHttpContextFactory.cs b/src/Microsoft.AspNet.Hosting/Builder/IHttpContextFactory.cs new file mode 100644 index 0000000000..3db4473167 --- /dev/null +++ b/src/Microsoft.AspNet.Hosting/Builder/IHttpContextFactory.cs @@ -0,0 +1,9 @@ +using Microsoft.AspNet.Abstractions; + +namespace Microsoft.AspNet.Hosting.Builder +{ + public interface IHttpContextFactory + { + HttpContext CreateHttpContext(object serverContext); + } +} \ No newline at end of file diff --git a/src/Microsoft.AspNet.Hosting/HostingContext.cs b/src/Microsoft.AspNet.Hosting/HostingContext.cs new file mode 100644 index 0000000000..303e9e7770 --- /dev/null +++ b/src/Microsoft.AspNet.Hosting/HostingContext.cs @@ -0,0 +1,20 @@ +using System; +using Microsoft.AspNet.Abstractions; +using Microsoft.AspNet.Hosting.Server; + +namespace Microsoft.AspNet.Hosting +{ + public class HostingContext + { + public IServiceProvider Services { get; set; } + + public IBuilder Builder { get; set; } + + public string ApplicationName { get; set; } + public Action ApplicationStartup { get; set; } + public RequestDelegate ApplicationDelegate { get; set; } + + public string ServerName { get; set; } + public IServerFactory ServerFactory { get; set; } + } +} \ No newline at end of file diff --git a/src/Microsoft.AspNet.Hosting/HostingEngine.cs b/src/Microsoft.AspNet.Hosting/HostingEngine.cs new file mode 100644 index 0000000000..6a33dbde7d --- /dev/null +++ b/src/Microsoft.AspNet.Hosting/HostingEngine.cs @@ -0,0 +1,104 @@ +using System; +using System.Threading; +using Microsoft.AspNet.Abstractions; +using Microsoft.AspNet.Hosting.Builder; +using Microsoft.AspNet.Hosting.Startup; +using Microsoft.AspNet.Hosting.Server; + +namespace Microsoft.AspNet.Hosting +{ + public class HostingEngine : IHostingEngine + { + private readonly IServerManager _serverManager; + private readonly IStartupManager _startupManager; + private readonly IBuilderFactory _builderFactory; + private readonly IHttpContextFactory _httpContextFactory; + + public HostingEngine( + IServerManager serverManager, + IStartupManager startupManager, + IBuilderFactory builderFactory, + IHttpContextFactory httpContextFactory) + { + _serverManager = serverManager; + _startupManager = startupManager; + _builderFactory = builderFactory; + _httpContextFactory = httpContextFactory; + } + + public IDisposable Start(HostingContext context) + { + EnsureBuilder(context); + EnsureServerFactory(context); + EnsureApplicationDelegate(context); + + var pipeline = new PipelineInstance(_httpContextFactory, context.ApplicationDelegate); + var server = context.ServerFactory.Start(pipeline.Invoke); + + return new Disposable(() => + { + server.Dispose(); + pipeline.Dispose(); + }); + } + + private void EnsureBuilder(HostingContext context) + { + if (context.Builder != null) + { + return; + } + + context.Builder = _builderFactory.CreateBuilder(); + } + + private void EnsureServerFactory(HostingContext context) + { + if (context.ServerFactory != null) + { + return; + } + + context.ServerFactory = _serverManager.GetServer(context.ServerName); + } + + private void EnsureApplicationDelegate(HostingContext context) + { + if (context.ApplicationDelegate != null) + { + return; + } + + EnsureApplicationStartup(context); + EnsureBuilder(context); + + context.ApplicationStartup.Invoke(context.Builder); + context.ApplicationDelegate = context.Builder.Build(); + } + + private void EnsureApplicationStartup(HostingContext context) + { + if (context.ApplicationStartup != null) + { + return; + } + + context.ApplicationStartup = _startupManager.LoadStartup(context.ApplicationName); + } + + private class Disposable : IDisposable + { + private Action _dispose; + + public Disposable(Action dispose) + { + _dispose = dispose; + } + + public void Dispose() + { + Interlocked.Exchange(ref _dispose, () => { }).Invoke(); + } + } + } +} \ No newline at end of file diff --git a/src/Microsoft.AspNet.Hosting/HostingServices.cs b/src/Microsoft.AspNet.Hosting/HostingServices.cs new file mode 100644 index 0000000000..5af7a8c077 --- /dev/null +++ b/src/Microsoft.AspNet.Hosting/HostingServices.cs @@ -0,0 +1,81 @@ +using System; +using System.Collections.Generic; +using Microsoft.AspNet.Configuration; +using Microsoft.AspNet.DependencyInjection; +using Microsoft.AspNet.Hosting.Builder; +using Microsoft.AspNet.Hosting.Startup; +using Microsoft.AspNet.Hosting.Server; + +namespace Microsoft.AspNet.Hosting +{ + public static class HostingServices + { + public static IEnumerable DefaultServices() + { + return DefaultServices(new EmptyConfiguration()); + } + + public static IEnumerable DefaultServices(IConfiguration configuration) + { + yield return DescribeService(configuration); + yield return DescribeService(configuration); + + yield return DescribeService(configuration); + yield return DescribeService(configuration); + + yield return DescribeService(configuration); + yield return DescribeService(configuration); + } + + public static IServiceDescriptor DescribeService(IConfiguration configuration, + LifecycleKind lifecycle = LifecycleKind.Transient) + { + return DescribeService(typeof(TService), typeof(TImplementation), configuration, lifecycle); + } + + public static IServiceDescriptor DescribeService( + Type serviceType, + Type implementationType, + IConfiguration configuration, + LifecycleKind lifecycle) + { + var serviceTypeName = serviceType.FullName; + var implemenationTypeName = configuration.Get(serviceTypeName); + if (!String.IsNullOrEmpty(implemenationTypeName)) + { + try + { + implementationType = Type.GetType(implemenationTypeName); + } + catch (Exception ex) + { + throw new Exception(string.Format("TODO: unable to locate implementation {0} for service {1}", implemenationTypeName, serviceTypeName), ex); + } + } + return new ServiceTypeDescriptor(serviceType, implementationType, lifecycle); + } + + public class EmptyConfiguration : IConfiguration + { + public string Get(string key) + { + return null; + } + } + + public class ServiceTypeDescriptor : IServiceDescriptor + { + public ServiceTypeDescriptor(Type serviceType, Type implementationType, LifecycleKind lifecycle) + { + ServiceType = serviceType; + ImplementationType = implementationType; + Lifecycle = lifecycle; + } + + public LifecycleKind Lifecycle { get; private set; } + public Type ServiceType { get; private set; } + public Type ImplementationType { get; private set; } + public object ImplementationInstance { get; private set; } + } + } +} \ No newline at end of file diff --git a/src/Microsoft.AspNet.Hosting/IHostingEngine.cs b/src/Microsoft.AspNet.Hosting/IHostingEngine.cs new file mode 100644 index 0000000000..89195e69f4 --- /dev/null +++ b/src/Microsoft.AspNet.Hosting/IHostingEngine.cs @@ -0,0 +1,9 @@ +using System; + +namespace Microsoft.AspNet.Hosting +{ + public interface IHostingEngine + { + IDisposable Start(HostingContext context); + } +} \ No newline at end of file diff --git a/src/Microsoft.AspNet.Hosting/PipelineInstance.cs b/src/Microsoft.AspNet.Hosting/PipelineInstance.cs new file mode 100644 index 0000000000..cc7580b713 --- /dev/null +++ b/src/Microsoft.AspNet.Hosting/PipelineInstance.cs @@ -0,0 +1,31 @@ +using System; +using System.Threading.Tasks; +using Microsoft.AspNet.Abstractions; +using Microsoft.AspNet.Hosting.Builder; +using Microsoft.AspNet.Hosting.Server; + +namespace Microsoft.AspNet.Hosting +{ + public class PipelineInstance : IDisposable + { + private readonly IHttpContextFactory _httpContextFactory; + private readonly RequestDelegate _requestDelegate; + + public PipelineInstance(IHttpContextFactory httpContextFactory, RequestDelegate requestDelegate) + { + _httpContextFactory = httpContextFactory; + _requestDelegate = requestDelegate; + } + + public Task Invoke(object serverEnvironment) + { + var httpContext = _httpContextFactory.CreateHttpContext(serverEnvironment); + return _requestDelegate(httpContext); + } + + public void Dispose() + { + // TODO: application notification of disposal + } + } +} diff --git a/src/Microsoft.AspNet.Hosting/Server/IServerFactory.cs b/src/Microsoft.AspNet.Hosting/Server/IServerFactory.cs new file mode 100644 index 0000000000..2d8350d53e --- /dev/null +++ b/src/Microsoft.AspNet.Hosting/Server/IServerFactory.cs @@ -0,0 +1,11 @@ +using System; +using System.Threading.Tasks; +using Microsoft.AspNet.Abstractions; + +namespace Microsoft.AspNet.Hosting.Server +{ + public interface IServerFactory + { + IDisposable Start(Func application); + } +} diff --git a/src/Microsoft.AspNet.Hosting/Server/IServerFactoryProvider.cs b/src/Microsoft.AspNet.Hosting/Server/IServerFactoryProvider.cs new file mode 100644 index 0000000000..714a51ba8b --- /dev/null +++ b/src/Microsoft.AspNet.Hosting/Server/IServerFactoryProvider.cs @@ -0,0 +1,7 @@ +namespace Microsoft.AspNet.Hosting.Server +{ + public interface IServerFactoryProvider + { + IServerFactory GetServerFactory(string serverName); + } +} diff --git a/src/Microsoft.AspNet.Hosting/Server/IServerManager.cs b/src/Microsoft.AspNet.Hosting/Server/IServerManager.cs new file mode 100644 index 0000000000..471f9445bd --- /dev/null +++ b/src/Microsoft.AspNet.Hosting/Server/IServerManager.cs @@ -0,0 +1,7 @@ +namespace Microsoft.AspNet.Hosting.Server +{ + public interface IServerManager + { + IServerFactory GetServer(string serverName); + } +} \ No newline at end of file diff --git a/src/Microsoft.AspNet.Hosting/Server/ServerManager.cs b/src/Microsoft.AspNet.Hosting/Server/ServerManager.cs new file mode 100644 index 0000000000..b8bf9cf6b5 --- /dev/null +++ b/src/Microsoft.AspNet.Hosting/Server/ServerManager.cs @@ -0,0 +1,10 @@ +namespace Microsoft.AspNet.Hosting.Server +{ + public class ServerManager : IServerManager + { + public IServerFactory GetServer(string serverName) + { + throw new System.NotImplementedException(); + } + } +} diff --git a/src/Microsoft.AspNet.Hosting/ServerFactoryProvider.cs b/src/Microsoft.AspNet.Hosting/ServerFactoryProvider.cs new file mode 100644 index 0000000000..eb5743a86a --- /dev/null +++ b/src/Microsoft.AspNet.Hosting/ServerFactoryProvider.cs @@ -0,0 +1,13 @@ +using System; +using Microsoft.AspNet.Hosting.Server; + +namespace Microsoft.AspNet.Hosting +{ + public class ServerFactoryProvider : IServerFactoryProvider + { + public IServerFactory GetServerFactory(string serverFactoryIdentifier) + { + throw new NotImplementedException(); + } + } +} \ No newline at end of file diff --git a/src/Microsoft.AspNet.Hosting/Startup/IStartupLoader.cs b/src/Microsoft.AspNet.Hosting/Startup/IStartupLoader.cs new file mode 100644 index 0000000000..067e5a4ebe --- /dev/null +++ b/src/Microsoft.AspNet.Hosting/Startup/IStartupLoader.cs @@ -0,0 +1,11 @@ +using System; +using System.Collections.Generic; +using Microsoft.AspNet.Abstractions; + +namespace Microsoft.AspNet.Hosting.Startup +{ + public interface IStartupLoader + { + Action LoadStartup(string applicationName, IList diagnosticMessages); + } +} diff --git a/src/Microsoft.AspNet.Hosting/Startup/IStartupLoaderProvider.cs b/src/Microsoft.AspNet.Hosting/Startup/IStartupLoaderProvider.cs new file mode 100644 index 0000000000..ad96af9793 --- /dev/null +++ b/src/Microsoft.AspNet.Hosting/Startup/IStartupLoaderProvider.cs @@ -0,0 +1,9 @@ +namespace Microsoft.AspNet.Hosting.Startup +{ + public interface IStartupLoaderProvider + { + int Order { get; } + + IStartupLoader CreateStartupLoader(IStartupLoader next); + } +} \ No newline at end of file diff --git a/src/Microsoft.AspNet.Hosting/Startup/IStartupManager.cs b/src/Microsoft.AspNet.Hosting/Startup/IStartupManager.cs new file mode 100644 index 0000000000..0d92e09a89 --- /dev/null +++ b/src/Microsoft.AspNet.Hosting/Startup/IStartupManager.cs @@ -0,0 +1,10 @@ +using System; +using Microsoft.AspNet.Abstractions; + +namespace Microsoft.AspNet.Hosting.Startup +{ + public interface IStartupManager + { + Action LoadStartup(string applicationName); + } +} \ No newline at end of file diff --git a/src/Microsoft.AspNet.Hosting/Startup/NullStartupLoader.cs b/src/Microsoft.AspNet.Hosting/Startup/NullStartupLoader.cs new file mode 100644 index 0000000000..e5e63c01f7 --- /dev/null +++ b/src/Microsoft.AspNet.Hosting/Startup/NullStartupLoader.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using Microsoft.AspNet.Abstractions; + +namespace Microsoft.AspNet.Hosting.Startup +{ + public class NullStartupLoader : IStartupLoader + { + static NullStartupLoader() + { + Instance = new NullStartupLoader(); + } + + public static IStartupLoader Instance { get; private set; } + + public Action LoadStartup(string applicationName, IList diagnosticMessages) + { + return null; + } + } +} \ No newline at end of file diff --git a/src/Microsoft.AspNet.Hosting/Startup/StartupLoader.cs b/src/Microsoft.AspNet.Hosting/Startup/StartupLoader.cs new file mode 100644 index 0000000000..c0949b178f --- /dev/null +++ b/src/Microsoft.AspNet.Hosting/Startup/StartupLoader.cs @@ -0,0 +1,62 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; +using Microsoft.AspNet.Abstractions; +using Microsoft.AspNet.DependencyInjection; + +namespace Microsoft.AspNet.Hosting.Startup +{ + public class StartupLoader : IStartupLoader + { + private readonly IServiceProvider _services; + private readonly IStartupLoader _next; + + public StartupLoader(IServiceProvider services, IStartupLoader next) + { + _services = services; + _next = next; + } + + public Action LoadStartup(string applicationName, IList diagnosticMessages) + { + if (String.IsNullOrWhiteSpace(applicationName)) + { + return _next.LoadStartup(applicationName, diagnosticMessages); + } + + var parts = applicationName.Split(new[] { ',' }, 2); + if (parts.Length == 2) + { + var typeName = parts[0]; + var assemblyName = parts[1]; + + var assembly = Assembly.Load(new AssemblyName(assemblyName)); + if (assembly == null) + { + throw new Exception(String.Format("TODO: assembly {0} failed to load message", assemblyName)); + } + + var type = assembly.GetType(typeName); + if (type == null) + { + throw new Exception(String.Format("TODO: type {0} failed to load message", typeName)); + } + + var methodInfo = type.GetTypeInfo().GetDeclaredMethod("Configuration"); + if (methodInfo == null) + { + throw new Exception("TODO: Configuration method not found"); + } + + object instance = null; + if (!methodInfo.IsStatic) + { + instance = ActivatorUtilities.GetServiceOrCreateInstance(_services, type); + } + return builder => methodInfo.Invoke(instance, new object[] { builder }); + } + throw new Exception("TODO: Unrecognized format"); + } + } +} diff --git a/src/Microsoft.AspNet.Hosting/Startup/StartupLoaderProvider.cs b/src/Microsoft.AspNet.Hosting/Startup/StartupLoaderProvider.cs new file mode 100644 index 0000000000..a30cc50488 --- /dev/null +++ b/src/Microsoft.AspNet.Hosting/Startup/StartupLoaderProvider.cs @@ -0,0 +1,21 @@ +using System; + +namespace Microsoft.AspNet.Hosting.Startup +{ + public class StartupLoaderProvider : IStartupLoaderProvider + { + private readonly IServiceProvider _services; + + public StartupLoaderProvider(IServiceProvider services) + { + _services = services; + } + + public int Order { get { return -100; } } + + public IStartupLoader CreateStartupLoader(IStartupLoader next) + { + return new StartupLoader(_services, next); + } + } +} diff --git a/src/Microsoft.AspNet.Hosting/Startup/StartupManager.cs b/src/Microsoft.AspNet.Hosting/Startup/StartupManager.cs new file mode 100644 index 0000000000..41d68b03da --- /dev/null +++ b/src/Microsoft.AspNet.Hosting/Startup/StartupManager.cs @@ -0,0 +1,36 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using Microsoft.AspNet.Abstractions; + +namespace Microsoft.AspNet.Hosting.Startup +{ + public class StartupManager : IStartupManager + { + private readonly IEnumerable _providers; + + public StartupManager(IEnumerable providers) + { + _providers = providers; + } + + public Action LoadStartup(string applicationName) + { + // build ordered chain of application loaders + var chain = _providers + .OrderBy(provider => provider.Order) + .Aggregate(NullStartupLoader.Instance, (next, provider) => provider.CreateStartupLoader(next)); + + // invoke chain to acquire application entrypoint and diagnostic messages + var diagnosticMessages = new List(); + var application = chain.LoadStartup(applicationName, diagnosticMessages); + + if (application == null) + { + throw new Exception(diagnosticMessages.Aggregate("TODO: web application entrypoint not found message", (a, b) => a + "\r\n" + b)); + } + + return application; + } + } +} \ No newline at end of file diff --git a/src/Microsoft.AspNet.Hosting/WebApplication.cs b/src/Microsoft.AspNet.Hosting/WebApplication.cs new file mode 100644 index 0000000000..773ae80d26 --- /dev/null +++ b/src/Microsoft.AspNet.Hosting/WebApplication.cs @@ -0,0 +1,23 @@ +using System; +using Microsoft.AspNet.DependencyInjection; + +namespace Microsoft.AspNet.Hosting +{ + public static class WebApplication + { + public static IDisposable Start() + { + var context = new HostingContext + { + Services = new ServiceProvider().Add(HostingServices.DefaultServices()) + }; + + var engine = context.Services.GetService(); + if (engine == null) + { + throw new Exception("TODO: IHostingEngine service not available exception"); + } + return engine.Start(context); + } + } +} \ No newline at end of file diff --git a/src/Microsoft.AspNet.Hosting/project.json b/src/Microsoft.AspNet.Hosting/project.json new file mode 100644 index 0000000000..57e379cfb1 --- /dev/null +++ b/src/Microsoft.AspNet.Hosting/project.json @@ -0,0 +1,14 @@ +{ + "version": "0.1-alpha-*", + "dependencies":{ + "Microsoft.AspNet.DependencyInjection":"0.1-alpha-*", + "Microsoft.AspNet.Configuration":"0.1-alpha-*", + "Microsoft.AspNet.PipelineCore":"0.1-alpha-*", + "Microsoft.AspNet.Abstractions":"0.1-alpha-*", + "Microsoft.AspNet.FeatureModel":"0.1-alpha-*" + }, + "configurations": { + "net45" : {}, + "k10" : {} + } +} diff --git a/test/Microsoft.AspNet.Hosting.Tests/Fakes/FakeStartup.cs b/test/Microsoft.AspNet.Hosting.Tests/Fakes/FakeStartup.cs new file mode 100644 index 0000000000..f8aae20612 --- /dev/null +++ b/test/Microsoft.AspNet.Hosting.Tests/Fakes/FakeStartup.cs @@ -0,0 +1,11 @@ +using Microsoft.AspNet.Abstractions; + +namespace Microsoft.AspNet.Hosting.Tests.Fakes +{ + public class FakeStartup + { + public void Configuration(IBuilder builder) + { + } + } +} \ No newline at end of file diff --git a/test/Microsoft.AspNet.Hosting.Tests/Fakes/FakeStartupWithServices.cs b/test/Microsoft.AspNet.Hosting.Tests/Fakes/FakeStartupWithServices.cs new file mode 100644 index 0000000000..1557c568ab --- /dev/null +++ b/test/Microsoft.AspNet.Hosting.Tests/Fakes/FakeStartupWithServices.cs @@ -0,0 +1,19 @@ +using Microsoft.AspNet.Abstractions; + +namespace Microsoft.AspNet.Hosting.Tests.Fakes +{ + public class FakeStartupWithServices + { + private readonly IFakeStartupCallback _fakeStartupCallback; + + public FakeStartupWithServices(IFakeStartupCallback fakeStartupCallback) + { + _fakeStartupCallback = fakeStartupCallback; + } + + public void Configuration(IBuilder builder) + { + _fakeStartupCallback.ConfigurationMethodCalled(this); + } + } +} \ No newline at end of file diff --git a/test/Microsoft.AspNet.Hosting.Tests/Fakes/IFakeStartupCallback.cs b/test/Microsoft.AspNet.Hosting.Tests/Fakes/IFakeStartupCallback.cs new file mode 100644 index 0000000000..cfe02c2b46 --- /dev/null +++ b/test/Microsoft.AspNet.Hosting.Tests/Fakes/IFakeStartupCallback.cs @@ -0,0 +1,7 @@ +namespace Microsoft.AspNet.Hosting.Tests.Fakes +{ + public interface IFakeStartupCallback + { + void ConfigurationMethodCalled(object instance); + } +} \ No newline at end of file diff --git a/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs b/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs new file mode 100644 index 0000000000..ab29f28bb5 --- /dev/null +++ b/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs @@ -0,0 +1,88 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.AspNet.Abstractions; +using Microsoft.AspNet.DependencyInjection; +using Microsoft.AspNet.Hosting.Server; +using Xunit; + +namespace Microsoft.AspNet.Hosting.Tests +{ + public class HostingEngineTests : IServerManager, IServerFactory + { + private readonly IList _startInstances = new List(); + + [Fact] + public void HostingEngineCanBeResolvedWithDefaultServices() + { + var services = new ServiceProvider() + .Add(HostingServices.DefaultServices()); + + var engine = services.GetService(); + + Assert.NotNull(engine); + } + + [Fact] + public void HostingEngineCanBeStarted() + { + var services = new ServiceProvider() + .Add(HostingServices.DefaultServices() + .Where(descriptor => descriptor.ServiceType != typeof(IServerManager))) + .AddInstance(this); + + var engine = services.GetService(); + + var context = new HostingContext + { + ApplicationName = "Microsoft.AspNet.Hosting.Tests.Fakes.FakeStartup, Microsoft.AspNet.Hosting.Tests" + }; + + var engineStart = engine.Start(context); + + Assert.NotNull(engineStart); + Assert.Equal(1, _startInstances.Count); + Assert.Equal(0, _startInstances[0].DisposeCalls); + + engineStart.Dispose(); + + Assert.Equal(1, _startInstances[0].DisposeCalls); + } + + public IServerFactory GetServer(string serverName) + { + return this; + } + + public void Initialize(IBuilder builder) + { + + } + + public IDisposable Start(Func application) + { + var startInstance = new StartInstance(application); + _startInstances.Add(startInstance); + return startInstance; + } + + public class StartInstance : IDisposable + { + private readonly Func _application; + + public StartInstance(Func application) + { + _application = application; + } + + public int DisposeCalls { get; set; } + + public void Dispose() + { + DisposeCalls += 1; + } + } + } +} diff --git a/test/Microsoft.AspNet.Hosting.Tests/StartupManagerTests.cs b/test/Microsoft.AspNet.Hosting.Tests/StartupManagerTests.cs new file mode 100644 index 0000000000..4a848b13fb --- /dev/null +++ b/test/Microsoft.AspNet.Hosting.Tests/StartupManagerTests.cs @@ -0,0 +1,51 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using Microsoft.AspNet.Abstractions; +using Microsoft.AspNet.DependencyInjection; +using Microsoft.AspNet.Hosting.Startup; +using Microsoft.AspNet.Hosting.Tests.Fakes; +using Xunit; + +namespace Microsoft.AspNet.Hosting.Tests +{ + + public class StartupManagerTests : IFakeStartupCallback + { + private readonly IList _configurationMethodCalledList = new List(); + + [Fact] + public void DefaultServicesLocateStartupByNameAndNamespace() + { + IServiceProvider services = new ServiceProvider().Add(HostingServices.DefaultServices()); + + var manager = services.GetService(); + + var startup = manager.LoadStartup("Microsoft.AspNet.Hosting.Tests.Fakes.FakeStartup, Microsoft.AspNet.Hosting.Tests"); + + Assert.IsType(manager); + Assert.NotNull(startup); + } + + [Fact] + public void StartupClassMayHaveHostingServicesInjected() + { + IServiceProvider services = new ServiceProvider() + .Add(HostingServices.DefaultServices()) + .AddInstance(this); + + var manager = services.GetService(); + + var startup = manager.LoadStartup("Microsoft.AspNet.Hosting.Tests.Fakes.FakeStartupWithServices, Microsoft.AspNet.Hosting.Tests"); + + startup.Invoke(null); + + Assert.Equal(1, _configurationMethodCalledList.Count); + } + + public void ConfigurationMethodCalled(object instance) + { + _configurationMethodCalledList.Add(instance); + } + } +} diff --git a/test/Microsoft.AspNet.Hosting.Tests/project.json b/test/Microsoft.AspNet.Hosting.Tests/project.json new file mode 100644 index 0000000000..486e0ac6b1 --- /dev/null +++ b/test/Microsoft.AspNet.Hosting.Tests/project.json @@ -0,0 +1,12 @@ +{ + "version": "0.1-alpha-*", + "dependencies": { + "xunit": "1.9.2", + "Microsoft.AspNet.Hosting":"", + "Microsoft.AspNet.Abstractions":"0.1-alpha-*", + "Microsoft.AspNet.DependencyInjection":"0.1-alpha-*" + }, + "configurations": { + "net45": {} + } +} \ No newline at end of file From f59d29b5ebac253ebd57ebf8ae276dc19cb2f262 Mon Sep 17 00:00:00 2001 From: Louis DeJardin Date: Mon, 10 Feb 2014 17:57:44 -0800 Subject: [PATCH 003/987] Renaming DefaultServices to GetDefaultServices --- src/Microsoft.AspNet.Hosting/HostingServices.cs | 6 +++--- src/Microsoft.AspNet.Hosting/WebApplication.cs | 2 +- test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs | 4 ++-- test/Microsoft.AspNet.Hosting.Tests/StartupManagerTests.cs | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/Microsoft.AspNet.Hosting/HostingServices.cs b/src/Microsoft.AspNet.Hosting/HostingServices.cs index 5af7a8c077..2c8a9437c9 100644 --- a/src/Microsoft.AspNet.Hosting/HostingServices.cs +++ b/src/Microsoft.AspNet.Hosting/HostingServices.cs @@ -10,12 +10,12 @@ namespace Microsoft.AspNet.Hosting { public static class HostingServices { - public static IEnumerable DefaultServices() + public static IEnumerable GetDefaultServices() { - return DefaultServices(new EmptyConfiguration()); + return GetDefaultServices(new EmptyConfiguration()); } - public static IEnumerable DefaultServices(IConfiguration configuration) + public static IEnumerable GetDefaultServices(IConfiguration configuration) { yield return DescribeService(configuration); yield return DescribeService(configuration); diff --git a/src/Microsoft.AspNet.Hosting/WebApplication.cs b/src/Microsoft.AspNet.Hosting/WebApplication.cs index 773ae80d26..fca80cb48c 100644 --- a/src/Microsoft.AspNet.Hosting/WebApplication.cs +++ b/src/Microsoft.AspNet.Hosting/WebApplication.cs @@ -9,7 +9,7 @@ namespace Microsoft.AspNet.Hosting { var context = new HostingContext { - Services = new ServiceProvider().Add(HostingServices.DefaultServices()) + Services = new ServiceProvider().Add(HostingServices.GetDefaultServices()) }; var engine = context.Services.GetService(); diff --git a/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs b/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs index ab29f28bb5..74580b3a5e 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs @@ -18,7 +18,7 @@ namespace Microsoft.AspNet.Hosting.Tests public void HostingEngineCanBeResolvedWithDefaultServices() { var services = new ServiceProvider() - .Add(HostingServices.DefaultServices()); + .Add(HostingServices.GetDefaultServices()); var engine = services.GetService(); @@ -29,7 +29,7 @@ namespace Microsoft.AspNet.Hosting.Tests public void HostingEngineCanBeStarted() { var services = new ServiceProvider() - .Add(HostingServices.DefaultServices() + .Add(HostingServices.GetDefaultServices() .Where(descriptor => descriptor.ServiceType != typeof(IServerManager))) .AddInstance(this); diff --git a/test/Microsoft.AspNet.Hosting.Tests/StartupManagerTests.cs b/test/Microsoft.AspNet.Hosting.Tests/StartupManagerTests.cs index 4a848b13fb..c2770d98b0 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/StartupManagerTests.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/StartupManagerTests.cs @@ -17,7 +17,7 @@ namespace Microsoft.AspNet.Hosting.Tests [Fact] public void DefaultServicesLocateStartupByNameAndNamespace() { - IServiceProvider services = new ServiceProvider().Add(HostingServices.DefaultServices()); + IServiceProvider services = new ServiceProvider().Add(HostingServices.GetDefaultServices()); var manager = services.GetService(); @@ -31,7 +31,7 @@ namespace Microsoft.AspNet.Hosting.Tests public void StartupClassMayHaveHostingServicesInjected() { IServiceProvider services = new ServiceProvider() - .Add(HostingServices.DefaultServices()) + .Add(HostingServices.GetDefaultServices()) .AddInstance(this); var manager = services.GetService(); From 14679a78ee91838637dc0d517ff9eb517fbefd47 Mon Sep 17 00:00:00 2001 From: Louis DeJardin Date: Mon, 10 Feb 2014 18:18:10 -0800 Subject: [PATCH 004/987] Implementing code review feedback --- src/Microsoft.AspNet.Hosting/HostingServices.cs | 8 ++++---- src/Microsoft.AspNet.Hosting/Server/ServerManager.cs | 6 ++++-- src/Microsoft.AspNet.Hosting/Startup/StartupLoader.cs | 2 +- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/Microsoft.AspNet.Hosting/HostingServices.cs b/src/Microsoft.AspNet.Hosting/HostingServices.cs index 2c8a9437c9..298b187a71 100644 --- a/src/Microsoft.AspNet.Hosting/HostingServices.cs +++ b/src/Microsoft.AspNet.Hosting/HostingServices.cs @@ -40,16 +40,16 @@ namespace Microsoft.AspNet.Hosting LifecycleKind lifecycle) { var serviceTypeName = serviceType.FullName; - var implemenationTypeName = configuration.Get(serviceTypeName); - if (!String.IsNullOrEmpty(implemenationTypeName)) + var implementationTypeName = configuration.Get(serviceTypeName); + if (!String.IsNullOrEmpty(implementationTypeName)) { try { - implementationType = Type.GetType(implemenationTypeName); + implementationType = Type.GetType(implementationTypeName); } catch (Exception ex) { - throw new Exception(string.Format("TODO: unable to locate implementation {0} for service {1}", implemenationTypeName, serviceTypeName), ex); + throw new Exception(string.Format("TODO: unable to locate implementation {0} for service {1}", implementationTypeName, serviceTypeName), ex); } } return new ServiceTypeDescriptor(serviceType, implementationType, lifecycle); diff --git a/src/Microsoft.AspNet.Hosting/Server/ServerManager.cs b/src/Microsoft.AspNet.Hosting/Server/ServerManager.cs index b8bf9cf6b5..a6b91be91d 100644 --- a/src/Microsoft.AspNet.Hosting/Server/ServerManager.cs +++ b/src/Microsoft.AspNet.Hosting/Server/ServerManager.cs @@ -1,10 +1,12 @@ +using System; + namespace Microsoft.AspNet.Hosting.Server { public class ServerManager : IServerManager { public IServerFactory GetServer(string serverName) { - throw new System.NotImplementedException(); + throw new NotImplementedException(); } } -} +} \ No newline at end of file diff --git a/src/Microsoft.AspNet.Hosting/Startup/StartupLoader.cs b/src/Microsoft.AspNet.Hosting/Startup/StartupLoader.cs index c0949b178f..da13ebfff9 100644 --- a/src/Microsoft.AspNet.Hosting/Startup/StartupLoader.cs +++ b/src/Microsoft.AspNet.Hosting/Startup/StartupLoader.cs @@ -20,7 +20,7 @@ namespace Microsoft.AspNet.Hosting.Startup public Action LoadStartup(string applicationName, IList diagnosticMessages) { - if (String.IsNullOrWhiteSpace(applicationName)) + if (String.IsNullOrEmpty(applicationName)) { return _next.LoadStartup(applicationName, diagnosticMessages); } From 7aeecf6bce21fe2c9c9189a9affab9d1a8c9109f Mon Sep 17 00:00:00 2001 From: David Fowler Date: Fri, 14 Feb 2014 00:20:08 -0800 Subject: [PATCH 005/987] Look for Startup and AssemblyName.Startup --- src/Microsoft.AspNet.Hosting/Startup/StartupLoader.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Microsoft.AspNet.Hosting/Startup/StartupLoader.cs b/src/Microsoft.AspNet.Hosting/Startup/StartupLoader.cs index da13ebfff9..2ed642f959 100644 --- a/src/Microsoft.AspNet.Hosting/Startup/StartupLoader.cs +++ b/src/Microsoft.AspNet.Hosting/Startup/StartupLoader.cs @@ -37,7 +37,7 @@ namespace Microsoft.AspNet.Hosting.Startup throw new Exception(String.Format("TODO: assembly {0} failed to load message", assemblyName)); } - var type = assembly.GetType(typeName); + var type = assembly.GetType(typeName) ?? assembly.GetType(assemblyName + "." + typeName); if (type == null) { throw new Exception(String.Format("TODO: type {0} failed to load message", typeName)); From 590ae2720857d6346548f0175d5f9e6b693938fa Mon Sep 17 00:00:00 2001 From: Louis DeJardin Date: Mon, 24 Feb 2014 13:31:31 -0800 Subject: [PATCH 006/987] Adding ITypeActivator and TypeActivator to hosting services --- src/Microsoft.AspNet.Hosting/HostingServices.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Microsoft.AspNet.Hosting/HostingServices.cs b/src/Microsoft.AspNet.Hosting/HostingServices.cs index 298b187a71..19982a159a 100644 --- a/src/Microsoft.AspNet.Hosting/HostingServices.cs +++ b/src/Microsoft.AspNet.Hosting/HostingServices.cs @@ -25,6 +25,8 @@ namespace Microsoft.AspNet.Hosting yield return DescribeService(configuration); yield return DescribeService(configuration); + + yield return DescribeService(configuration); } public static IServiceDescriptor DescribeService(IConfiguration configuration, From c4e98614e5cd11331e706b83493df8497404d701 Mon Sep 17 00:00:00 2001 From: Louis DeJardin Date: Tue, 4 Mar 2014 20:23:51 -0800 Subject: [PATCH 007/987] Pointing at updated configuration package name --- src/Microsoft.AspNet.Hosting/HostingServices.cs | 12 ++---------- src/Microsoft.AspNet.Hosting/project.json | 2 +- 2 files changed, 3 insertions(+), 11 deletions(-) diff --git a/src/Microsoft.AspNet.Hosting/HostingServices.cs b/src/Microsoft.AspNet.Hosting/HostingServices.cs index 19982a159a..a8b90e96b4 100644 --- a/src/Microsoft.AspNet.Hosting/HostingServices.cs +++ b/src/Microsoft.AspNet.Hosting/HostingServices.cs @@ -1,6 +1,6 @@ using System; using System.Collections.Generic; -using Microsoft.AspNet.Configuration; +using Microsoft.AspNet.ConfigurationModel; using Microsoft.AspNet.DependencyInjection; using Microsoft.AspNet.Hosting.Builder; using Microsoft.AspNet.Hosting.Startup; @@ -12,7 +12,7 @@ namespace Microsoft.AspNet.Hosting { public static IEnumerable GetDefaultServices() { - return GetDefaultServices(new EmptyConfiguration()); + return GetDefaultServices(new Configuration()); } public static IEnumerable GetDefaultServices(IConfiguration configuration) @@ -57,14 +57,6 @@ namespace Microsoft.AspNet.Hosting return new ServiceTypeDescriptor(serviceType, implementationType, lifecycle); } - public class EmptyConfiguration : IConfiguration - { - public string Get(string key) - { - return null; - } - } - public class ServiceTypeDescriptor : IServiceDescriptor { public ServiceTypeDescriptor(Type serviceType, Type implementationType, LifecycleKind lifecycle) diff --git a/src/Microsoft.AspNet.Hosting/project.json b/src/Microsoft.AspNet.Hosting/project.json index 57e379cfb1..ae3bdc0eef 100644 --- a/src/Microsoft.AspNet.Hosting/project.json +++ b/src/Microsoft.AspNet.Hosting/project.json @@ -2,7 +2,7 @@ "version": "0.1-alpha-*", "dependencies":{ "Microsoft.AspNet.DependencyInjection":"0.1-alpha-*", - "Microsoft.AspNet.Configuration":"0.1-alpha-*", + "Microsoft.AspNet.ConfigurationModel":"0.1-alpha-*", "Microsoft.AspNet.PipelineCore":"0.1-alpha-*", "Microsoft.AspNet.Abstractions":"0.1-alpha-*", "Microsoft.AspNet.FeatureModel":"0.1-alpha-*" From f420ba460019b4c216dbccf53d153e7d5ee8bcb8 Mon Sep 17 00:00:00 2001 From: David Fowler Date: Fri, 7 Mar 2014 02:39:48 -0800 Subject: [PATCH 008/987] Added required packages for K --- src/Microsoft.AspNet.Hosting/project.json | 30 ++++++++++++++++------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/src/Microsoft.AspNet.Hosting/project.json b/src/Microsoft.AspNet.Hosting/project.json index ae3bdc0eef..0577dc0777 100644 --- a/src/Microsoft.AspNet.Hosting/project.json +++ b/src/Microsoft.AspNet.Hosting/project.json @@ -1,14 +1,26 @@ { "version": "0.1-alpha-*", - "dependencies":{ - "Microsoft.AspNet.DependencyInjection":"0.1-alpha-*", - "Microsoft.AspNet.ConfigurationModel":"0.1-alpha-*", - "Microsoft.AspNet.PipelineCore":"0.1-alpha-*", - "Microsoft.AspNet.Abstractions":"0.1-alpha-*", - "Microsoft.AspNet.FeatureModel":"0.1-alpha-*" + "dependencies": { + "Microsoft.AspNet.DependencyInjection": "0.1-alpha-*", + "Microsoft.AspNet.ConfigurationModel": "0.1-alpha-*", + "Microsoft.AspNet.PipelineCore": "0.1-alpha-*", + "Microsoft.AspNet.Abstractions": "0.1-alpha-*", + "Microsoft.AspNet.FeatureModel": "0.1-alpha-*" }, "configurations": { - "net45" : {}, - "k10" : {} + "net45": {}, + "k10": { + "dependencies": { + "System.Collections": "4.0.0.0", + "System.ComponentModel": "4.0.0.0", + "System.Diagnostics.Debug": "4.0.10.0", + "System.Linq": "4.0.0.0", + "System.Reflection": "4.0.10.0", + "System.Runtime": "4.0.20.0", + "System.Runtime.Extensions": "4.0.10.0", + "System.Threading": "4.0.0.0", + "System.Threading.Tasks": "4.0.0.0" + } + } } -} +} \ No newline at end of file From 7423a21b11523c8d6be74d6b9905aeaec329482f Mon Sep 17 00:00:00 2001 From: David Fowler Date: Sat, 8 Mar 2014 12:34:29 -0800 Subject: [PATCH 009/987] Added ability to run unit tests on build --- global.json | 3 +++ .../project.json | 20 ++++++++++++++----- 2 files changed, 18 insertions(+), 5 deletions(-) create mode 100644 global.json diff --git a/global.json b/global.json new file mode 100644 index 0000000000..840c36f6ad --- /dev/null +++ b/global.json @@ -0,0 +1,3 @@ +{ + "sources": ["src"] +} \ No newline at end of file diff --git a/test/Microsoft.AspNet.Hosting.Tests/project.json b/test/Microsoft.AspNet.Hosting.Tests/project.json index 486e0ac6b1..05d852b2aa 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/project.json +++ b/test/Microsoft.AspNet.Hosting.Tests/project.json @@ -1,12 +1,22 @@ { "version": "0.1-alpha-*", "dependencies": { - "xunit": "1.9.2", - "Microsoft.AspNet.Hosting":"", - "Microsoft.AspNet.Abstractions":"0.1-alpha-*", - "Microsoft.AspNet.DependencyInjection":"0.1-alpha-*" + "Microsoft.AspNet.Hosting": "", + "Microsoft.AspNet.Abstractions":"0.1-alpha-*", + "Microsoft.AspNet.DependencyInjection":"0.1-alpha-*", + "Xunit.KRunner": "0.1-alpha-*", + "xunit.abstractions": "3.0.0-alpha-*", + "xunit2": "0.1-alpha-*", + "xunit2.assert": "0.1-alpha-*" }, "configurations": { - "net45": {} + "net45": { + "dependencies": { + "System.Runtime" : "" + } + } + }, + "commands": { + "test": "Xunit.KRunner" } } \ No newline at end of file From 059a7665d030d158d4f1fa9746ef7884a131be23 Mon Sep 17 00:00:00 2001 From: Brice Lambson Date: Mon, 10 Mar 2014 12:28:41 -0700 Subject: [PATCH 010/987] React to xunit changes --- test/Microsoft.AspNet.Hosting.Tests/project.json | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/test/Microsoft.AspNet.Hosting.Tests/project.json b/test/Microsoft.AspNet.Hosting.Tests/project.json index 05d852b2aa..8c46f5dd94 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/project.json +++ b/test/Microsoft.AspNet.Hosting.Tests/project.json @@ -5,9 +5,10 @@ "Microsoft.AspNet.Abstractions":"0.1-alpha-*", "Microsoft.AspNet.DependencyInjection":"0.1-alpha-*", "Xunit.KRunner": "0.1-alpha-*", - "xunit.abstractions": "3.0.0-alpha-*", - "xunit2": "0.1-alpha-*", - "xunit2.assert": "0.1-alpha-*" + "xunit.abstractions": "2.0.0-aspnet-*", + "xunit.assert": "2.0.0-aspnet-*", + "xunit.core": "2.0.0-aspnet-*", + "xunit.execution": "2.0.0-aspnet-*" }, "configurations": { "net45": { From 45adfac95b3a8b4fcdd9e6fd36635f3b220cfa95 Mon Sep 17 00:00:00 2001 From: Pranav K Date: Tue, 11 Mar 2014 11:38:25 -0700 Subject: [PATCH 011/987] Updating MyGet feed to unblock build --- NuGet.Config | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NuGet.Config b/NuGet.Config index ab583b0ff7..9dc2833940 100644 --- a/NuGet.Config +++ b/NuGet.Config @@ -1,7 +1,7 @@  - + From a3eb280275a5f16425be004610fd1110eee9dbcf Mon Sep 17 00:00:00 2001 From: Chris Ross Date: Wed, 12 Mar 2014 15:07:37 -0700 Subject: [PATCH 012/987] Implement Program.Main and ServerManager. Add Startup search. --- samples/KWebStartup/Startup.cs | 21 +++++ samples/KWebStartup/project.json | 32 ++++++++ .../AssemblyNeutralAttribute.cs | 10 +++ src/Microsoft.AspNet.Hosting/HostingEngine.cs | 4 +- .../HostingServices.cs | 2 +- .../IApplicationEnvironment.cs | 14 ++++ src/Microsoft.AspNet.Hosting/Program.cs | 60 ++++++++++++++ .../Server/IServerFactory.cs | 2 + .../Server/IServerFactoryProvider.cs | 7 -- .../Server/IServerManager.cs | 2 +- .../Server/ServerManager.cs | 81 ++++++++++++++++++- .../ServerFactoryProvider.cs | 13 --- .../Startup/StartupLoader.cs | 81 ++++++++++++------- src/Microsoft.AspNet.Hosting/project.json | 3 + .../HostingEngineTests.cs | 12 +-- 15 files changed, 281 insertions(+), 63 deletions(-) create mode 100644 samples/KWebStartup/Startup.cs create mode 100644 samples/KWebStartup/project.json create mode 100644 src/Microsoft.AspNet.Hosting/AssemblyNeutralAttribute.cs create mode 100644 src/Microsoft.AspNet.Hosting/IApplicationEnvironment.cs create mode 100644 src/Microsoft.AspNet.Hosting/Program.cs delete mode 100644 src/Microsoft.AspNet.Hosting/Server/IServerFactoryProvider.cs delete mode 100644 src/Microsoft.AspNet.Hosting/ServerFactoryProvider.cs diff --git a/samples/KWebStartup/Startup.cs b/samples/KWebStartup/Startup.cs new file mode 100644 index 0000000000..cd080de5f2 --- /dev/null +++ b/samples/KWebStartup/Startup.cs @@ -0,0 +1,21 @@ +using Microsoft.AspNet.Abstractions; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace KWebStartup +{ + public class Startup + { + public void Configuration(IBuilder app) + { + app.Run(async context => + { + context.Response.ContentType = "text/plain"; + await context.Response.WriteAsync("Hello world"); + }); + } + } +} \ No newline at end of file diff --git a/samples/KWebStartup/project.json b/samples/KWebStartup/project.json new file mode 100644 index 0000000000..471e0621f6 --- /dev/null +++ b/samples/KWebStartup/project.json @@ -0,0 +1,32 @@ +{ + "version": "0.1-alpha-*", + "dependencies": { + "Microsoft.AspNet.Hosting": "0.1-alpha-*", + "Microsoft.AspNet.Server.WebListener": "0.1-alpha-*" + }, + "commands": { "web": "Microsoft.AspNet.Hosting server.name=Microsoft.AspNet.Server.WebListener" }, + "configurations": { + "net45": { + }, + "k10": { + "dependencies": { + "System.Console": "4.0.0.0", + "System.Collections": "4.0.0.0", + "System.Diagnostics.Debug": "4.0.10.0", + "System.Diagnostics.Tools": "4.0.0.0", + "System.Globalization": "4.0.10.0", + "System.IO": "4.0.0.0", + "System.IO.FileSystem": "4.0.0.0", + "System.IO.FileSystem.Primitives": "4.0.0.0", + "System.Linq": "4.0.0.0", + "System.Reflection": "4.0.10.0", + "System.Resources.ResourceManager": "4.0.0.0", + "System.Runtime": "4.0.20.0", + "System.Runtime.Extensions": "4.0.10.0", + "System.Runtime.InteropServices": "4.0.10.0", + "System.Text.Encoding": "4.0.10.0", + "System.Threading.Tasks": "4.0.0.0" + } + } + } +} \ No newline at end of file diff --git a/src/Microsoft.AspNet.Hosting/AssemblyNeutralAttribute.cs b/src/Microsoft.AspNet.Hosting/AssemblyNeutralAttribute.cs new file mode 100644 index 0000000000..2191d5198d --- /dev/null +++ b/src/Microsoft.AspNet.Hosting/AssemblyNeutralAttribute.cs @@ -0,0 +1,10 @@ +using System; + +namespace Microsoft.Net.Runtime +{ + [AssemblyNeutral] + [AttributeUsage(AttributeTargets.All, Inherited = false, AllowMultiple = true)] + public sealed class AssemblyNeutralAttribute : Attribute + { + } +} diff --git a/src/Microsoft.AspNet.Hosting/HostingEngine.cs b/src/Microsoft.AspNet.Hosting/HostingEngine.cs index 6a33dbde7d..da496d32e0 100644 --- a/src/Microsoft.AspNet.Hosting/HostingEngine.cs +++ b/src/Microsoft.AspNet.Hosting/HostingEngine.cs @@ -1,6 +1,7 @@ using System; using System.Threading; using Microsoft.AspNet.Abstractions; +using Microsoft.AspNet.DependencyInjection; using Microsoft.AspNet.Hosting.Builder; using Microsoft.AspNet.Hosting.Startup; using Microsoft.AspNet.Hosting.Server; @@ -54,12 +55,13 @@ namespace Microsoft.AspNet.Hosting private void EnsureServerFactory(HostingContext context) { + context.ServerFactory = context.ServerFactory ?? context.Services.GetService(); if (context.ServerFactory != null) { return; } - context.ServerFactory = _serverManager.GetServer(context.ServerName); + context.ServerFactory = _serverManager.GetServerFactory(context.ServerName); } private void EnsureApplicationDelegate(HostingContext context) diff --git a/src/Microsoft.AspNet.Hosting/HostingServices.cs b/src/Microsoft.AspNet.Hosting/HostingServices.cs index a8b90e96b4..d5f4d58a59 100644 --- a/src/Microsoft.AspNet.Hosting/HostingServices.cs +++ b/src/Microsoft.AspNet.Hosting/HostingServices.cs @@ -18,7 +18,7 @@ namespace Microsoft.AspNet.Hosting public static IEnumerable GetDefaultServices(IConfiguration configuration) { yield return DescribeService(configuration); - yield return DescribeService(configuration); + yield return DescribeService(configuration); yield return DescribeService(configuration); yield return DescribeService(configuration); diff --git a/src/Microsoft.AspNet.Hosting/IApplicationEnvironment.cs b/src/Microsoft.AspNet.Hosting/IApplicationEnvironment.cs new file mode 100644 index 0000000000..1c772bc835 --- /dev/null +++ b/src/Microsoft.AspNet.Hosting/IApplicationEnvironment.cs @@ -0,0 +1,14 @@ +using System; +using System.Runtime.Versioning; + +namespace Microsoft.Net.Runtime +{ + [AssemblyNeutral] + public interface IApplicationEnvironment + { + string ApplicationName { get; } + string Version { get; } + string ApplicationBasePath { get; } + FrameworkName TargetFramework { get; } + } +} \ No newline at end of file diff --git a/src/Microsoft.AspNet.Hosting/Program.cs b/src/Microsoft.AspNet.Hosting/Program.cs new file mode 100644 index 0000000000..3b1f10ae33 --- /dev/null +++ b/src/Microsoft.AspNet.Hosting/Program.cs @@ -0,0 +1,60 @@ +using Microsoft.AspNet.ConfigurationModel; +using Microsoft.AspNet.ConfigurationModel.Sources; +using Microsoft.AspNet.DependencyInjection; +using Microsoft.AspNet.Hosting.Server; +using Microsoft.Net.Runtime; +using System; +using System.IO; + +namespace Microsoft.AspNet.Hosting +{ + public class Program + { + private const string HostingIniFile = "Microsoft.AspNet.Hosting.ini"; + + private readonly IServiceProvider _serviceProvider; + + public Program(IServiceProvider serviceProvider) + { + _serviceProvider = serviceProvider; + } + + public void Main(string[] args) + { + var config = new Configuration(); + config.AddCommandLine(args); + config.AddEnvironmentVariables(); + if (File.Exists(HostingIniFile)) + { + config.AddIniFile(HostingIniFile); + } + + var services = new ServiceProvider(_serviceProvider) + .Add(HostingServices.GetDefaultServices(config)); + + var appEnvironment = _serviceProvider.GetService(); + + var context = new HostingContext() + { + Services = services, + ServerName = config.Get("server.name"), // TODO: Key names + ApplicationName = config.Get("app.name") // TODO: Key names + ?? appEnvironment.ApplicationName, + }; + + var engine = services.GetService(); + if (engine == null) + { + throw new Exception("TODO: IHostingEngine service not available exception"); + } + + using (engine.Start(context)) + { +#if NET45 + Console.WriteLine("Started"); + Console.ReadLine(); +#endif + } + } + } +} diff --git a/src/Microsoft.AspNet.Hosting/Server/IServerFactory.cs b/src/Microsoft.AspNet.Hosting/Server/IServerFactory.cs index 2d8350d53e..368004e197 100644 --- a/src/Microsoft.AspNet.Hosting/Server/IServerFactory.cs +++ b/src/Microsoft.AspNet.Hosting/Server/IServerFactory.cs @@ -1,9 +1,11 @@ using System; using System.Threading.Tasks; using Microsoft.AspNet.Abstractions; +using Microsoft.Net.Runtime; namespace Microsoft.AspNet.Hosting.Server { + [AssemblyNeutral] public interface IServerFactory { IDisposable Start(Func application); diff --git a/src/Microsoft.AspNet.Hosting/Server/IServerFactoryProvider.cs b/src/Microsoft.AspNet.Hosting/Server/IServerFactoryProvider.cs deleted file mode 100644 index 714a51ba8b..0000000000 --- a/src/Microsoft.AspNet.Hosting/Server/IServerFactoryProvider.cs +++ /dev/null @@ -1,7 +0,0 @@ -namespace Microsoft.AspNet.Hosting.Server -{ - public interface IServerFactoryProvider - { - IServerFactory GetServerFactory(string serverName); - } -} diff --git a/src/Microsoft.AspNet.Hosting/Server/IServerManager.cs b/src/Microsoft.AspNet.Hosting/Server/IServerManager.cs index 471f9445bd..5a6b6b9166 100644 --- a/src/Microsoft.AspNet.Hosting/Server/IServerManager.cs +++ b/src/Microsoft.AspNet.Hosting/Server/IServerManager.cs @@ -2,6 +2,6 @@ namespace Microsoft.AspNet.Hosting.Server { public interface IServerManager { - IServerFactory GetServer(string serverName); + IServerFactory GetServerFactory(string serverName); } } \ No newline at end of file diff --git a/src/Microsoft.AspNet.Hosting/Server/ServerManager.cs b/src/Microsoft.AspNet.Hosting/Server/ServerManager.cs index a6b91be91d..a35e3a9fb6 100644 --- a/src/Microsoft.AspNet.Hosting/Server/ServerManager.cs +++ b/src/Microsoft.AspNet.Hosting/Server/ServerManager.cs @@ -1,12 +1,89 @@ +using Microsoft.AspNet.DependencyInjection; using System; +using System.Linq; +using System.Reflection; namespace Microsoft.AspNet.Hosting.Server { public class ServerManager : IServerManager { - public IServerFactory GetServer(string serverName) + private readonly IServiceProvider _services; + + public ServerManager(IServiceProvider services) { - throw new NotImplementedException(); + _services = services; + } + + public IServerFactory GetServerFactory(string serverFactoryIdentifier) + { + if (string.IsNullOrWhiteSpace(serverFactoryIdentifier)) + { + throw new ArgumentNullException("serverFactoryIdentifier"); + } + + string typeName; + string assemblyName; + var parts = serverFactoryIdentifier.Split(new[] { ',' }, 2); + if (parts.Length == 1) + { + typeName = null; + assemblyName = serverFactoryIdentifier; + } + else if (parts.Length == 2) + { + typeName = parts[0]; + assemblyName = parts[1]; + } + else + { + throw new ArgumentException("TODO: Unrecognized format", "serverFactoryIdentifier"); + } + + var assembly = Assembly.Load(new AssemblyName(assemblyName)); + if (assembly == null) + { + throw new Exception(String.Format("TODO: assembly {0} failed to load message", assemblyName)); + } + + Type type = null; + Type interfaceInfo; + if (string.IsNullOrWhiteSpace(typeName)) + { + foreach (var typeInfo in assembly.DefinedTypes) + { + interfaceInfo = typeInfo.ImplementedInterfaces.FirstOrDefault(interf => + interf.FullName == typeof(IServerFactory).FullName); + if (interfaceInfo != null) + { + type = typeInfo.AsType(); + } + } + + if (type == null) + { + throw new Exception(String.Format("TODO: type {0} failed to load message", typeName ?? "")); + } + } + else + { + type = assembly.GetType(typeName) ?? assembly.GetType(assemblyName + "." + typeName); + + if (type == null) + { + throw new Exception(String.Format("TODO: type {0} failed to load message", typeName ?? "")); + } + + interfaceInfo = type.GetTypeInfo().ImplementedInterfaces.FirstOrDefault(interf => + interf.FullName == typeof(IServerFactory).FullName); + + if (interfaceInfo == null) + { + throw new Exception("TODO: IServerFactory interface not found"); + } + } + + object instance = ActivatorUtilities.GetServiceOrCreateInstance(_services, type); + return (IServerFactory)instance; } } } \ No newline at end of file diff --git a/src/Microsoft.AspNet.Hosting/ServerFactoryProvider.cs b/src/Microsoft.AspNet.Hosting/ServerFactoryProvider.cs deleted file mode 100644 index eb5743a86a..0000000000 --- a/src/Microsoft.AspNet.Hosting/ServerFactoryProvider.cs +++ /dev/null @@ -1,13 +0,0 @@ -using System; -using Microsoft.AspNet.Hosting.Server; - -namespace Microsoft.AspNet.Hosting -{ - public class ServerFactoryProvider : IServerFactoryProvider - { - public IServerFactory GetServerFactory(string serverFactoryIdentifier) - { - throw new NotImplementedException(); - } - } -} \ No newline at end of file diff --git a/src/Microsoft.AspNet.Hosting/Startup/StartupLoader.cs b/src/Microsoft.AspNet.Hosting/Startup/StartupLoader.cs index 2ed642f959..abdd853bbf 100644 --- a/src/Microsoft.AspNet.Hosting/Startup/StartupLoader.cs +++ b/src/Microsoft.AspNet.Hosting/Startup/StartupLoader.cs @@ -25,38 +25,61 @@ namespace Microsoft.AspNet.Hosting.Startup return _next.LoadStartup(applicationName, diagnosticMessages); } + string typeName; + string assemblyName; var parts = applicationName.Split(new[] { ',' }, 2); - if (parts.Length == 2) + if (parts.Length == 1) { - var typeName = parts[0]; - var assemblyName = parts[1]; - - var assembly = Assembly.Load(new AssemblyName(assemblyName)); - if (assembly == null) - { - throw new Exception(String.Format("TODO: assembly {0} failed to load message", assemblyName)); - } - - var type = assembly.GetType(typeName) ?? assembly.GetType(assemblyName + "." + typeName); - if (type == null) - { - throw new Exception(String.Format("TODO: type {0} failed to load message", typeName)); - } - - var methodInfo = type.GetTypeInfo().GetDeclaredMethod("Configuration"); - if (methodInfo == null) - { - throw new Exception("TODO: Configuration method not found"); - } - - object instance = null; - if (!methodInfo.IsStatic) - { - instance = ActivatorUtilities.GetServiceOrCreateInstance(_services, type); - } - return builder => methodInfo.Invoke(instance, new object[] { builder }); + typeName = null; + assemblyName = applicationName; } - throw new Exception("TODO: Unrecognized format"); + else if (parts.Length == 2) + { + typeName = parts[0]; + assemblyName = parts[1]; + } + else + { + throw new Exception("TODO: Unrecognized format"); + } + + var assembly = Assembly.Load(new AssemblyName(assemblyName)); + if (assembly == null) + { + throw new Exception(String.Format("TODO: assembly {0} failed to load message", assemblyName)); + } + + Type type = null; + if (string.IsNullOrWhiteSpace(typeName)) + { + var typeInfo = assembly.DefinedTypes.FirstOrDefault(aType => aType.Name.Equals("Startup")); + if (typeInfo != null) + { + type = typeInfo.AsType(); + } + } + else + { + type = assembly.GetType(typeName); + } + + if (type == null) + { + throw new Exception(String.Format("TODO: type {0} failed to load message", typeName)); + } + + var methodInfo = type.GetTypeInfo().GetDeclaredMethod("Configuration"); + if (methodInfo == null) + { + throw new Exception("TODO: Configuration method not found"); + } + + object instance = null; + if (!methodInfo.IsStatic) + { + instance = ActivatorUtilities.GetServiceOrCreateInstance(_services, type); + } + return builder => methodInfo.Invoke(instance, new object[] { builder }); } } } diff --git a/src/Microsoft.AspNet.Hosting/project.json b/src/Microsoft.AspNet.Hosting/project.json index 0577dc0777..07acc75da3 100644 --- a/src/Microsoft.AspNet.Hosting/project.json +++ b/src/Microsoft.AspNet.Hosting/project.json @@ -14,6 +14,9 @@ "System.Collections": "4.0.0.0", "System.ComponentModel": "4.0.0.0", "System.Diagnostics.Debug": "4.0.10.0", + "System.IO": "4.0.0.0", + "System.IO.FileSystem": "4.0.0.0", + "System.IO.FileSystem.Primitives": "4.0.0.0", "System.Linq": "4.0.0.0", "System.Reflection": "4.0.10.0", "System.Runtime": "4.0.20.0", diff --git a/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs b/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs index 74580b3a5e..476e1a4454 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs @@ -10,7 +10,7 @@ using Xunit; namespace Microsoft.AspNet.Hosting.Tests { - public class HostingEngineTests : IServerManager, IServerFactory + public class HostingEngineTests : IServerFactory { private readonly IList _startInstances = new List(); @@ -29,14 +29,13 @@ namespace Microsoft.AspNet.Hosting.Tests public void HostingEngineCanBeStarted() { var services = new ServiceProvider() - .Add(HostingServices.GetDefaultServices() - .Where(descriptor => descriptor.ServiceType != typeof(IServerManager))) - .AddInstance(this); + .Add(HostingServices.GetDefaultServices()); var engine = services.GetService(); var context = new HostingContext { + ServerFactory = this, ApplicationName = "Microsoft.AspNet.Hosting.Tests.Fakes.FakeStartup, Microsoft.AspNet.Hosting.Tests" }; @@ -51,11 +50,6 @@ namespace Microsoft.AspNet.Hosting.Tests Assert.Equal(1, _startInstances[0].DisposeCalls); } - public IServerFactory GetServer(string serverName) - { - return this; - } - public void Initialize(IBuilder builder) { From ee4bb6de87b8dca4bb6a1888ec3761a1e564fc83 Mon Sep 17 00:00:00 2001 From: Chris Ross Date: Thu, 13 Mar 2014 09:33:29 -0700 Subject: [PATCH 013/987] Review feedback. Style cleanup. Updated build template files. --- .gitignore | 2 + Hosting.sln | 18 ++++++++- NuGet.Config | 2 +- build.cmd | 12 +++++- samples/KWebStartup/Startup.cs | 5 --- samples/KWebStartup/project.json | 1 + src/Microsoft.AspNet.Hosting/HostingEngine.cs | 8 ++-- .../HostingServices.cs | 2 +- src/Microsoft.AspNet.Hosting/Program.cs | 10 ++--- .../Server/ServerManager.cs | 39 ++++++------------- .../Startup/StartupLoader.cs | 22 ++--------- src/Microsoft.AspNet.Hosting/Utilities.cs | 29 ++++++++++++++ .../Fakes/FakeStartup.cs | 2 +- .../Fakes/FakeStartupWithServices.cs | 2 +- .../Fakes/IFakeStartupCallback.cs | 2 +- .../HostingEngineTests.cs | 4 +- .../StartupManagerTests.cs | 6 +-- 17 files changed, 91 insertions(+), 75 deletions(-) create mode 100644 src/Microsoft.AspNet.Hosting/Utilities.cs diff --git a/.gitignore b/.gitignore index 2554a1fc23..8bc217058d 100644 --- a/.gitignore +++ b/.gitignore @@ -20,3 +20,5 @@ nuget.exe *.userprefs *DS_Store *.ncrunchsolution +*.*sdf +*.ipch \ No newline at end of file diff --git a/Hosting.sln b/Hosting.sln index 3394417c72..def8ba2b14 100644 --- a/Hosting.sln +++ b/Hosting.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 2013 -VisualStudioVersion = 12.0.21005.1 +VisualStudioVersion = 12.0.30203.2 MinimumVisualStudioVersion = 10.0.40219.1 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{E0497F39-AFFB-4819-A116-E39E361915AB}" EndProject @@ -13,6 +13,12 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.AspNet.Hosting.k1 EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.AspNet.Hosting.Tests.net45", "test\Microsoft.AspNet.Hosting.Tests\Microsoft.AspNet.Hosting.Tests.net45.csproj", "{80588AF3-6B14-4D11-9DC4-1EF6453B54C9}" EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "samples", "samples", "{C30C98CD-3D69-4AE9-B680-0E0E6D8834C6}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "KWebStartup.net45", "samples\KWebStartup\KWebStartup.net45.csproj", "{E9B21845-E51A-4B8C-AF0B-0C4CE16550BF}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "KWebStartup.k10", "samples\KWebStartup\KWebStartup.k10.csproj", "{348007AA-AB91-48B2-98DB-57D068E2C1AE}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -31,6 +37,14 @@ Global {80588AF3-6B14-4D11-9DC4-1EF6453B54C9}.Debug|Any CPU.Build.0 = Debug|Any CPU {80588AF3-6B14-4D11-9DC4-1EF6453B54C9}.Release|Any CPU.ActiveCfg = Release|Any CPU {80588AF3-6B14-4D11-9DC4-1EF6453B54C9}.Release|Any CPU.Build.0 = Release|Any CPU + {E9B21845-E51A-4B8C-AF0B-0C4CE16550BF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {E9B21845-E51A-4B8C-AF0B-0C4CE16550BF}.Debug|Any CPU.Build.0 = Debug|Any CPU + {E9B21845-E51A-4B8C-AF0B-0C4CE16550BF}.Release|Any CPU.ActiveCfg = Release|Any CPU + {E9B21845-E51A-4B8C-AF0B-0C4CE16550BF}.Release|Any CPU.Build.0 = Release|Any CPU + {348007AA-AB91-48B2-98DB-57D068E2C1AE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {348007AA-AB91-48B2-98DB-57D068E2C1AE}.Debug|Any CPU.Build.0 = Debug|Any CPU + {348007AA-AB91-48B2-98DB-57D068E2C1AE}.Release|Any CPU.ActiveCfg = Release|Any CPU + {348007AA-AB91-48B2-98DB-57D068E2C1AE}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -39,5 +53,7 @@ Global {D546290B-E280-4D99-BA9C-0D364A0AFB54} = {E0497F39-AFFB-4819-A116-E39E361915AB} {DBB72F0F-755D-41CF-8FE2-F4B6AE214E91} = {E0497F39-AFFB-4819-A116-E39E361915AB} {80588AF3-6B14-4D11-9DC4-1EF6453B54C9} = {FEB39027-9158-4DE2-997F-7ADAEF8188D0} + {E9B21845-E51A-4B8C-AF0B-0C4CE16550BF} = {C30C98CD-3D69-4AE9-B680-0E0E6D8834C6} + {348007AA-AB91-48B2-98DB-57D068E2C1AE} = {C30C98CD-3D69-4AE9-B680-0E0E6D8834C6} EndGlobalSection EndGlobal diff --git a/NuGet.Config b/NuGet.Config index 9dc2833940..a059188b09 100644 --- a/NuGet.Config +++ b/NuGet.Config @@ -1,7 +1,7 @@  - + diff --git a/build.cmd b/build.cmd index d54931bc8f..7045ee1f84 100644 --- a/build.cmd +++ b/build.cmd @@ -1,10 +1,18 @@ @echo off cd %~dp0 -IF EXIST .nuget\NuGet.exe goto restore +SETLOCAL +SET CACHED_NUGET=%LocalAppData%\NuGet\NuGet.exe + +IF EXIST %CACHED_NUGET% goto copynuget echo Downloading latest version of NuGet.exe... +IF NOT EXIST %LocalAppData%\NuGet md %LocalAppData%\NuGet +@powershell -NoProfile -ExecutionPolicy unrestricted -Command "$ProgressPreference = 'SilentlyContinue'; Invoke-WebRequest 'https://www.nuget.org/nuget.exe' -OutFile '%CACHED_NUGET%'" + +:copynuget +IF EXIST .nuget\nuget.exe goto restore md .nuget -@powershell -NoProfile -ExecutionPolicy unrestricted -Command "$ProgressPreference = 'SilentlyContinue'; Invoke-WebRequest 'https://www.nuget.org/nuget.exe' -OutFile '.nuget\NuGet.exe'" +copy %CACHED_NUGET% .nuget\nuget.exe > nul :restore IF EXIST packages\KoreBuild goto run diff --git a/samples/KWebStartup/Startup.cs b/samples/KWebStartup/Startup.cs index cd080de5f2..fc82494f77 100644 --- a/samples/KWebStartup/Startup.cs +++ b/samples/KWebStartup/Startup.cs @@ -1,9 +1,4 @@ using Microsoft.AspNet.Abstractions; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace KWebStartup { diff --git a/samples/KWebStartup/project.json b/samples/KWebStartup/project.json index 471e0621f6..1d16b7bd9e 100644 --- a/samples/KWebStartup/project.json +++ b/samples/KWebStartup/project.json @@ -1,6 +1,7 @@ { "version": "0.1-alpha-*", "dependencies": { + "Microsoft.AspNet.Abstractions": "0.1-alpha-*", "Microsoft.AspNet.Hosting": "0.1-alpha-*", "Microsoft.AspNet.Server.WebListener": "0.1-alpha-*" }, diff --git a/src/Microsoft.AspNet.Hosting/HostingEngine.cs b/src/Microsoft.AspNet.Hosting/HostingEngine.cs index da496d32e0..1bf28ef25b 100644 --- a/src/Microsoft.AspNet.Hosting/HostingEngine.cs +++ b/src/Microsoft.AspNet.Hosting/HostingEngine.cs @@ -1,10 +1,9 @@ using System; using System.Threading; -using Microsoft.AspNet.Abstractions; using Microsoft.AspNet.DependencyInjection; using Microsoft.AspNet.Hosting.Builder; -using Microsoft.AspNet.Hosting.Startup; using Microsoft.AspNet.Hosting.Server; +using Microsoft.AspNet.Hosting.Startup; namespace Microsoft.AspNet.Hosting { @@ -55,7 +54,10 @@ namespace Microsoft.AspNet.Hosting private void EnsureServerFactory(HostingContext context) { - context.ServerFactory = context.ServerFactory ?? context.Services.GetService(); + if (context.ServerFactory == null) + { + context.ServerFactory = context.Services.GetService(); + } if (context.ServerFactory != null) { return; diff --git a/src/Microsoft.AspNet.Hosting/HostingServices.cs b/src/Microsoft.AspNet.Hosting/HostingServices.cs index d5f4d58a59..9fe29dbc36 100644 --- a/src/Microsoft.AspNet.Hosting/HostingServices.cs +++ b/src/Microsoft.AspNet.Hosting/HostingServices.cs @@ -3,8 +3,8 @@ using System.Collections.Generic; using Microsoft.AspNet.ConfigurationModel; using Microsoft.AspNet.DependencyInjection; using Microsoft.AspNet.Hosting.Builder; -using Microsoft.AspNet.Hosting.Startup; using Microsoft.AspNet.Hosting.Server; +using Microsoft.AspNet.Hosting.Startup; namespace Microsoft.AspNet.Hosting { diff --git a/src/Microsoft.AspNet.Hosting/Program.cs b/src/Microsoft.AspNet.Hosting/Program.cs index 3b1f10ae33..52d0da3911 100644 --- a/src/Microsoft.AspNet.Hosting/Program.cs +++ b/src/Microsoft.AspNet.Hosting/Program.cs @@ -1,10 +1,8 @@ -using Microsoft.AspNet.ConfigurationModel; -using Microsoft.AspNet.ConfigurationModel.Sources; -using Microsoft.AspNet.DependencyInjection; -using Microsoft.AspNet.Hosting.Server; -using Microsoft.Net.Runtime; -using System; +using System; using System.IO; +using Microsoft.AspNet.ConfigurationModel; +using Microsoft.AspNet.DependencyInjection; +using Microsoft.Net.Runtime; namespace Microsoft.AspNet.Hosting { diff --git a/src/Microsoft.AspNet.Hosting/Server/ServerManager.cs b/src/Microsoft.AspNet.Hosting/Server/ServerManager.cs index a35e3a9fb6..daa2eedcb7 100644 --- a/src/Microsoft.AspNet.Hosting/Server/ServerManager.cs +++ b/src/Microsoft.AspNet.Hosting/Server/ServerManager.cs @@ -1,7 +1,7 @@ -using Microsoft.AspNet.DependencyInjection; using System; using System.Linq; using System.Reflection; +using Microsoft.AspNet.DependencyInjection; namespace Microsoft.AspNet.Hosting.Server { @@ -16,28 +16,14 @@ namespace Microsoft.AspNet.Hosting.Server public IServerFactory GetServerFactory(string serverFactoryIdentifier) { - if (string.IsNullOrWhiteSpace(serverFactoryIdentifier)) + if (string.IsNullOrEmpty(serverFactoryIdentifier)) { - throw new ArgumentNullException("serverFactoryIdentifier"); + throw new ArgumentException(string.Empty, "serverFactoryIdentifier"); } - string typeName; - string assemblyName; - var parts = serverFactoryIdentifier.Split(new[] { ',' }, 2); - if (parts.Length == 1) - { - typeName = null; - assemblyName = serverFactoryIdentifier; - } - else if (parts.Length == 2) - { - typeName = parts[0]; - assemblyName = parts[1]; - } - else - { - throw new ArgumentException("TODO: Unrecognized format", "serverFactoryIdentifier"); - } + var nameParts = Utilities.SplitTypeName(serverFactoryIdentifier); + string typeName = nameParts.Item1; + string assemblyName = nameParts.Item2; var assembly = Assembly.Load(new AssemblyName(assemblyName)); if (assembly == null) @@ -47,12 +33,11 @@ namespace Microsoft.AspNet.Hosting.Server Type type = null; Type interfaceInfo; - if (string.IsNullOrWhiteSpace(typeName)) + if (string.IsNullOrEmpty(typeName)) { foreach (var typeInfo in assembly.DefinedTypes) { - interfaceInfo = typeInfo.ImplementedInterfaces.FirstOrDefault(interf => - interf.FullName == typeof(IServerFactory).FullName); + interfaceInfo = typeInfo.ImplementedInterfaces.FirstOrDefault(interf => interf.Equals(typeof(IServerFactory))); if (interfaceInfo != null) { type = typeInfo.AsType(); @@ -66,15 +51,14 @@ namespace Microsoft.AspNet.Hosting.Server } else { - type = assembly.GetType(typeName) ?? assembly.GetType(assemblyName + "." + typeName); + type = assembly.GetType(typeName); if (type == null) { throw new Exception(String.Format("TODO: type {0} failed to load message", typeName ?? "")); } - interfaceInfo = type.GetTypeInfo().ImplementedInterfaces.FirstOrDefault(interf => - interf.FullName == typeof(IServerFactory).FullName); + interfaceInfo = type.GetTypeInfo().ImplementedInterfaces.FirstOrDefault(interf => interf.Equals(typeof(IServerFactory))); if (interfaceInfo == null) { @@ -82,8 +66,7 @@ namespace Microsoft.AspNet.Hosting.Server } } - object instance = ActivatorUtilities.GetServiceOrCreateInstance(_services, type); - return (IServerFactory)instance; + return (IServerFactory)ActivatorUtilities.GetServiceOrCreateInstance(_services, type); } } } \ No newline at end of file diff --git a/src/Microsoft.AspNet.Hosting/Startup/StartupLoader.cs b/src/Microsoft.AspNet.Hosting/Startup/StartupLoader.cs index abdd853bbf..b6a40be8e2 100644 --- a/src/Microsoft.AspNet.Hosting/Startup/StartupLoader.cs +++ b/src/Microsoft.AspNet.Hosting/Startup/StartupLoader.cs @@ -25,23 +25,9 @@ namespace Microsoft.AspNet.Hosting.Startup return _next.LoadStartup(applicationName, diagnosticMessages); } - string typeName; - string assemblyName; - var parts = applicationName.Split(new[] { ',' }, 2); - if (parts.Length == 1) - { - typeName = null; - assemblyName = applicationName; - } - else if (parts.Length == 2) - { - typeName = parts[0]; - assemblyName = parts[1]; - } - else - { - throw new Exception("TODO: Unrecognized format"); - } + var nameParts = Utilities.SplitTypeName(applicationName); + string typeName = nameParts.Item1; + string assemblyName = nameParts.Item2; var assembly = Assembly.Load(new AssemblyName(assemblyName)); if (assembly == null) @@ -50,7 +36,7 @@ namespace Microsoft.AspNet.Hosting.Startup } Type type = null; - if (string.IsNullOrWhiteSpace(typeName)) + if (string.IsNullOrEmpty(typeName)) { var typeInfo = assembly.DefinedTypes.FirstOrDefault(aType => aType.Name.Equals("Startup")); if (typeInfo != null) diff --git a/src/Microsoft.AspNet.Hosting/Utilities.cs b/src/Microsoft.AspNet.Hosting/Utilities.cs new file mode 100644 index 0000000000..21ec780149 --- /dev/null +++ b/src/Microsoft.AspNet.Hosting/Utilities.cs @@ -0,0 +1,29 @@ +using System; + +namespace Microsoft.AspNet.Hosting +{ + internal static class Utilities + { + internal static Tuple SplitTypeName(string identifier) + { + string typeName; + string assemblyName; + var parts = identifier.Split(new[] { ',' }, 2); + if (parts.Length == 1) + { + typeName = null; + assemblyName = identifier.Trim(); + } + else if (parts.Length == 2) + { + typeName = parts[0].Trim(); + assemblyName = parts[1].Trim(); + } + else + { + throw new ArgumentException("TODO: Unrecognized format", "identifier"); + } + return new Tuple(typeName, assemblyName); + } + } +} diff --git a/test/Microsoft.AspNet.Hosting.Tests/Fakes/FakeStartup.cs b/test/Microsoft.AspNet.Hosting.Tests/Fakes/FakeStartup.cs index f8aae20612..255fcf1aef 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/Fakes/FakeStartup.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/Fakes/FakeStartup.cs @@ -1,6 +1,6 @@ using Microsoft.AspNet.Abstractions; -namespace Microsoft.AspNet.Hosting.Tests.Fakes +namespace Microsoft.AspNet.Hosting.Fakes { public class FakeStartup { diff --git a/test/Microsoft.AspNet.Hosting.Tests/Fakes/FakeStartupWithServices.cs b/test/Microsoft.AspNet.Hosting.Tests/Fakes/FakeStartupWithServices.cs index 1557c568ab..ee8b28e3a5 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/Fakes/FakeStartupWithServices.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/Fakes/FakeStartupWithServices.cs @@ -1,6 +1,6 @@ using Microsoft.AspNet.Abstractions; -namespace Microsoft.AspNet.Hosting.Tests.Fakes +namespace Microsoft.AspNet.Hosting.Fakes { public class FakeStartupWithServices { diff --git a/test/Microsoft.AspNet.Hosting.Tests/Fakes/IFakeStartupCallback.cs b/test/Microsoft.AspNet.Hosting.Tests/Fakes/IFakeStartupCallback.cs index cfe02c2b46..7fd7c9ba2b 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/Fakes/IFakeStartupCallback.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/Fakes/IFakeStartupCallback.cs @@ -1,4 +1,4 @@ -namespace Microsoft.AspNet.Hosting.Tests.Fakes +namespace Microsoft.AspNet.Hosting.Fakes { public interface IFakeStartupCallback { diff --git a/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs b/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs index 476e1a4454..e7e9c3a266 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs @@ -1,14 +1,12 @@ using System; -using System.Collections; using System.Collections.Generic; -using System.Linq; using System.Threading.Tasks; using Microsoft.AspNet.Abstractions; using Microsoft.AspNet.DependencyInjection; using Microsoft.AspNet.Hosting.Server; using Xunit; -namespace Microsoft.AspNet.Hosting.Tests +namespace Microsoft.AspNet.Hosting { public class HostingEngineTests : IServerFactory { diff --git a/test/Microsoft.AspNet.Hosting.Tests/StartupManagerTests.cs b/test/Microsoft.AspNet.Hosting.Tests/StartupManagerTests.cs index c2770d98b0..1f464894d4 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/StartupManagerTests.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/StartupManagerTests.cs @@ -1,13 +1,11 @@ using System; -using System.Collections; using System.Collections.Generic; -using Microsoft.AspNet.Abstractions; using Microsoft.AspNet.DependencyInjection; using Microsoft.AspNet.Hosting.Startup; -using Microsoft.AspNet.Hosting.Tests.Fakes; +using Microsoft.AspNet.Hosting.Fakes; using Xunit; -namespace Microsoft.AspNet.Hosting.Tests +namespace Microsoft.AspNet.Hosting { public class StartupManagerTests : IFakeStartupCallback From 6a5cb913c8508e76899ef42cfa30208c378b0dd7 Mon Sep 17 00:00:00 2001 From: Chris Ross Date: Thu, 13 Mar 2014 14:25:30 -0700 Subject: [PATCH 014/987] Review cleanup. Cleaner Startup auto-detect. Fix tests. --- src/Microsoft.AspNet.Hosting/Program.cs | 2 -- .../Startup/StartupLoader.cs | 15 ++++++++++----- src/Microsoft.AspNet.Hosting/project.json | 1 + .../HostingEngineTests.cs | 2 +- .../StartupManagerTests.cs | 4 ++-- 5 files changed, 14 insertions(+), 10 deletions(-) diff --git a/src/Microsoft.AspNet.Hosting/Program.cs b/src/Microsoft.AspNet.Hosting/Program.cs index 52d0da3911..ffc4a713d9 100644 --- a/src/Microsoft.AspNet.Hosting/Program.cs +++ b/src/Microsoft.AspNet.Hosting/Program.cs @@ -48,10 +48,8 @@ namespace Microsoft.AspNet.Hosting using (engine.Start(context)) { -#if NET45 Console.WriteLine("Started"); Console.ReadLine(); -#endif } } } diff --git a/src/Microsoft.AspNet.Hosting/Startup/StartupLoader.cs b/src/Microsoft.AspNet.Hosting/Startup/StartupLoader.cs index b6a40be8e2..f49dd7a3c8 100644 --- a/src/Microsoft.AspNet.Hosting/Startup/StartupLoader.cs +++ b/src/Microsoft.AspNet.Hosting/Startup/StartupLoader.cs @@ -38,16 +38,21 @@ namespace Microsoft.AspNet.Hosting.Startup Type type = null; if (string.IsNullOrEmpty(typeName)) { - var typeInfo = assembly.DefinedTypes.FirstOrDefault(aType => aType.Name.Equals("Startup")); + typeName = "Startup"; + } + + // Check the most likely places first + type = assembly.GetType(typeName) ?? assembly.GetType(assembly + "." + typeName); + + if (type == null) + { + // Full scan + var typeInfo = assembly.DefinedTypes.FirstOrDefault(aType => aType.Name.Equals(typeName)); if (typeInfo != null) { type = typeInfo.AsType(); } } - else - { - type = assembly.GetType(typeName); - } if (type == null) { diff --git a/src/Microsoft.AspNet.Hosting/project.json b/src/Microsoft.AspNet.Hosting/project.json index 07acc75da3..26ca426580 100644 --- a/src/Microsoft.AspNet.Hosting/project.json +++ b/src/Microsoft.AspNet.Hosting/project.json @@ -12,6 +12,7 @@ "k10": { "dependencies": { "System.Collections": "4.0.0.0", + "System.Console": "4.0.0.0", "System.ComponentModel": "4.0.0.0", "System.Diagnostics.Debug": "4.0.10.0", "System.IO": "4.0.0.0", diff --git a/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs b/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs index e7e9c3a266..87220ea473 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs @@ -34,7 +34,7 @@ namespace Microsoft.AspNet.Hosting var context = new HostingContext { ServerFactory = this, - ApplicationName = "Microsoft.AspNet.Hosting.Tests.Fakes.FakeStartup, Microsoft.AspNet.Hosting.Tests" + ApplicationName = "Microsoft.AspNet.Hosting.Fakes.FakeStartup, Microsoft.AspNet.Hosting.Tests" }; var engineStart = engine.Start(context); diff --git a/test/Microsoft.AspNet.Hosting.Tests/StartupManagerTests.cs b/test/Microsoft.AspNet.Hosting.Tests/StartupManagerTests.cs index 1f464894d4..5f58859ab2 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/StartupManagerTests.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/StartupManagerTests.cs @@ -19,7 +19,7 @@ namespace Microsoft.AspNet.Hosting var manager = services.GetService(); - var startup = manager.LoadStartup("Microsoft.AspNet.Hosting.Tests.Fakes.FakeStartup, Microsoft.AspNet.Hosting.Tests"); + var startup = manager.LoadStartup("Microsoft.AspNet.Hosting.Fakes.FakeStartup, Microsoft.AspNet.Hosting.Tests"); Assert.IsType(manager); Assert.NotNull(startup); @@ -34,7 +34,7 @@ namespace Microsoft.AspNet.Hosting var manager = services.GetService(); - var startup = manager.LoadStartup("Microsoft.AspNet.Hosting.Tests.Fakes.FakeStartupWithServices, Microsoft.AspNet.Hosting.Tests"); + var startup = manager.LoadStartup("Microsoft.AspNet.Hosting.Fakes.FakeStartupWithServices, Microsoft.AspNet.Hosting.Tests"); startup.Invoke(null); From 2b7272fe07ea9cfd6d28ca74348bde12a3949d0e Mon Sep 17 00:00:00 2001 From: Chris Ross Date: Fri, 14 Mar 2014 10:17:46 -0700 Subject: [PATCH 015/987] Review feedback. --- .../Startup/StartupLoader.cs | 2 +- src/Microsoft.AspNet.Hosting/Utilities.cs | 15 +++------------ 2 files changed, 4 insertions(+), 13 deletions(-) diff --git a/src/Microsoft.AspNet.Hosting/Startup/StartupLoader.cs b/src/Microsoft.AspNet.Hosting/Startup/StartupLoader.cs index f49dd7a3c8..7b1362e90f 100644 --- a/src/Microsoft.AspNet.Hosting/Startup/StartupLoader.cs +++ b/src/Microsoft.AspNet.Hosting/Startup/StartupLoader.cs @@ -47,7 +47,7 @@ namespace Microsoft.AspNet.Hosting.Startup if (type == null) { // Full scan - var typeInfo = assembly.DefinedTypes.FirstOrDefault(aType => aType.Name.Equals(typeName)); + var typeInfo = assembly.DefinedTypes.FirstOrDefault(aType => aType.Name.Equals(typeName, StringComparison.OrdinalIgnoreCase)); if (typeInfo != null) { type = typeInfo.AsType(); diff --git a/src/Microsoft.AspNet.Hosting/Utilities.cs b/src/Microsoft.AspNet.Hosting/Utilities.cs index 21ec780149..ae98ea538f 100644 --- a/src/Microsoft.AspNet.Hosting/Utilities.cs +++ b/src/Microsoft.AspNet.Hosting/Utilities.cs @@ -6,23 +6,14 @@ namespace Microsoft.AspNet.Hosting { internal static Tuple SplitTypeName(string identifier) { - string typeName; - string assemblyName; + string typeName = null; + string assemblyName = identifier.Trim(); var parts = identifier.Split(new[] { ',' }, 2); - if (parts.Length == 1) - { - typeName = null; - assemblyName = identifier.Trim(); - } - else if (parts.Length == 2) + if (parts.Length == 2) { typeName = parts[0].Trim(); assemblyName = parts[1].Trim(); } - else - { - throw new ArgumentException("TODO: Unrecognized format", "identifier"); - } return new Tuple(typeName, assemblyName); } } From c3e0279aac7df3aa6e2b778a81f6dd1778cfe4e1 Mon Sep 17 00:00:00 2001 From: David Fowler Date: Fri, 14 Mar 2014 14:22:20 -0700 Subject: [PATCH 016/987] Updated to use service collection --- src/Microsoft.AspNet.Hosting/Program.cs | 5 +++-- src/Microsoft.AspNet.Hosting/WebApplication.cs | 7 ++++++- .../HostingEngineTests.cs | 11 +++++++---- .../StartupManagerTests.cs | 14 +++++++++----- 4 files changed, 25 insertions(+), 12 deletions(-) diff --git a/src/Microsoft.AspNet.Hosting/Program.cs b/src/Microsoft.AspNet.Hosting/Program.cs index ffc4a713d9..0db86e734d 100644 --- a/src/Microsoft.AspNet.Hosting/Program.cs +++ b/src/Microsoft.AspNet.Hosting/Program.cs @@ -27,8 +27,9 @@ namespace Microsoft.AspNet.Hosting config.AddIniFile(HostingIniFile); } - var services = new ServiceProvider(_serviceProvider) - .Add(HostingServices.GetDefaultServices(config)); + var serviceCollection = new ServiceCollection(); + serviceCollection.Add(HostingServices.GetDefaultServices(config)); + var services = serviceCollection.FallbackServices; var appEnvironment = _serviceProvider.GetService(); diff --git a/src/Microsoft.AspNet.Hosting/WebApplication.cs b/src/Microsoft.AspNet.Hosting/WebApplication.cs index fca80cb48c..f01c7dea23 100644 --- a/src/Microsoft.AspNet.Hosting/WebApplication.cs +++ b/src/Microsoft.AspNet.Hosting/WebApplication.cs @@ -1,5 +1,6 @@ using System; using Microsoft.AspNet.DependencyInjection; +using Microsoft.AspNet.DependencyInjection.Fallback; namespace Microsoft.AspNet.Hosting { @@ -7,9 +8,12 @@ namespace Microsoft.AspNet.Hosting { public static IDisposable Start() { + var serviceCollection = new ServiceCollection(); + serviceCollection.Add(HostingServices.GetDefaultServices()); + var context = new HostingContext { - Services = new ServiceProvider().Add(HostingServices.GetDefaultServices()) + Services = serviceCollection.BuildServiceProvider() }; var engine = context.Services.GetService(); @@ -17,6 +21,7 @@ namespace Microsoft.AspNet.Hosting { throw new Exception("TODO: IHostingEngine service not available exception"); } + return engine.Start(context); } } diff --git a/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs b/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs index 87220ea473..eb09beba24 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs @@ -4,6 +4,7 @@ using System.Threading.Tasks; using Microsoft.AspNet.Abstractions; using Microsoft.AspNet.DependencyInjection; using Microsoft.AspNet.Hosting.Server; +using Microsoft.AspNet.DependencyInjection.Fallback; using Xunit; namespace Microsoft.AspNet.Hosting @@ -15,8 +16,9 @@ namespace Microsoft.AspNet.Hosting [Fact] public void HostingEngineCanBeResolvedWithDefaultServices() { - var services = new ServiceProvider() - .Add(HostingServices.GetDefaultServices()); + var serviceCollection = new ServiceCollection(); + serviceCollection.Add(HostingServices.GetDefaultServices()); + var services = serviceCollection.BuildServiceProvider(); var engine = services.GetService(); @@ -26,8 +28,9 @@ namespace Microsoft.AspNet.Hosting [Fact] public void HostingEngineCanBeStarted() { - var services = new ServiceProvider() - .Add(HostingServices.GetDefaultServices()); + var serviceCollection = new ServiceCollection(); + serviceCollection.Add(HostingServices.GetDefaultServices()); + var services = serviceCollection.BuildServiceProvider(); var engine = services.GetService(); diff --git a/test/Microsoft.AspNet.Hosting.Tests/StartupManagerTests.cs b/test/Microsoft.AspNet.Hosting.Tests/StartupManagerTests.cs index 5f58859ab2..d2693d12a1 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/StartupManagerTests.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/StartupManagerTests.cs @@ -1,13 +1,14 @@ using System; using System.Collections.Generic; using Microsoft.AspNet.DependencyInjection; +using Microsoft.AspNet.DependencyInjection.Fallback; using Microsoft.AspNet.Hosting.Startup; using Microsoft.AspNet.Hosting.Fakes; using Xunit; namespace Microsoft.AspNet.Hosting { - + public class StartupManagerTests : IFakeStartupCallback { private readonly IList _configurationMethodCalledList = new List(); @@ -15,7 +16,9 @@ namespace Microsoft.AspNet.Hosting [Fact] public void DefaultServicesLocateStartupByNameAndNamespace() { - IServiceProvider services = new ServiceProvider().Add(HostingServices.GetDefaultServices()); + var serviceCollection = new ServiceCollection(); + serviceCollection.Add(HostingServices.GetDefaultServices()); + var services = serviceCollection.BuildServiceProvider(); var manager = services.GetService(); @@ -28,9 +31,10 @@ namespace Microsoft.AspNet.Hosting [Fact] public void StartupClassMayHaveHostingServicesInjected() { - IServiceProvider services = new ServiceProvider() - .Add(HostingServices.GetDefaultServices()) - .AddInstance(this); + var serviceCollection = new ServiceCollection(); + serviceCollection.Add(HostingServices.GetDefaultServices()); + serviceCollection.AddInstance(this); + var services = serviceCollection.BuildServiceProvider(); var manager = services.GetService(); From 4d511b3aef12874d100d7cdf5289c330b4c362df Mon Sep 17 00:00:00 2001 From: Chris Ross Date: Fri, 14 Mar 2014 15:13:00 -0700 Subject: [PATCH 017/987] Make IServerFactory not assembly neutral temporarily. --- src/Microsoft.AspNet.Hosting/Server/IServerFactory.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Microsoft.AspNet.Hosting/Server/IServerFactory.cs b/src/Microsoft.AspNet.Hosting/Server/IServerFactory.cs index 368004e197..4ae76a13b4 100644 --- a/src/Microsoft.AspNet.Hosting/Server/IServerFactory.cs +++ b/src/Microsoft.AspNet.Hosting/Server/IServerFactory.cs @@ -5,7 +5,7 @@ using Microsoft.Net.Runtime; namespace Microsoft.AspNet.Hosting.Server { - [AssemblyNeutral] + // TODO: [AssemblyNeutral] public interface IServerFactory { IDisposable Start(Func application); From d7bbcb96449a59699b1b265ea2cbde6e0630a537 Mon Sep 17 00:00:00 2001 From: David Fowler Date: Sat, 15 Mar 2014 14:41:41 -0700 Subject: [PATCH 018/987] Fixed service provider building --- src/Microsoft.AspNet.Hosting/Program.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Microsoft.AspNet.Hosting/Program.cs b/src/Microsoft.AspNet.Hosting/Program.cs index 0db86e734d..8153333fb1 100644 --- a/src/Microsoft.AspNet.Hosting/Program.cs +++ b/src/Microsoft.AspNet.Hosting/Program.cs @@ -2,6 +2,7 @@ using System.IO; using Microsoft.AspNet.ConfigurationModel; using Microsoft.AspNet.DependencyInjection; +using Microsoft.AspNet.DependencyInjection.Fallback; using Microsoft.Net.Runtime; namespace Microsoft.AspNet.Hosting @@ -29,7 +30,8 @@ namespace Microsoft.AspNet.Hosting var serviceCollection = new ServiceCollection(); serviceCollection.Add(HostingServices.GetDefaultServices(config)); - var services = serviceCollection.FallbackServices; + var services = serviceCollection.BuildServiceProvider(); + serviceCollection.FallbackServices = _serviceProvider; var appEnvironment = _serviceProvider.GetService(); From 063420067e8529da45cab4bdb2e14dab785a5d0f Mon Sep 17 00:00:00 2001 From: GrabYourPitchforks Date: Mon, 17 Mar 2014 14:09:31 -0700 Subject: [PATCH 019/987] HostingServices should provide a default implementation of IDataProtectionProvider --- src/Microsoft.AspNet.Hosting/HostingServices.cs | 11 +++++++++++ src/Microsoft.AspNet.Hosting/project.json | 3 ++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/Microsoft.AspNet.Hosting/HostingServices.cs b/src/Microsoft.AspNet.Hosting/HostingServices.cs index 9fe29dbc36..9032db6706 100644 --- a/src/Microsoft.AspNet.Hosting/HostingServices.cs +++ b/src/Microsoft.AspNet.Hosting/HostingServices.cs @@ -5,6 +5,7 @@ using Microsoft.AspNet.DependencyInjection; using Microsoft.AspNet.Hosting.Builder; using Microsoft.AspNet.Hosting.Server; using Microsoft.AspNet.Hosting.Startup; +using Microsoft.AspNet.Security.DataProtection; namespace Microsoft.AspNet.Hosting { @@ -27,6 +28,16 @@ namespace Microsoft.AspNet.Hosting yield return DescribeService(configuration); yield return DescribeService(configuration); + + // The default IDataProtectionProvider is a singleton. + // Note: DPAPI isn't usable in IIS where the user profile hasn't been loaded, but loading DPAPI + // is deferred until the first call to Protect / Unprotect. It's up to an IIS-based host to + // replace this service as part of application initialization. + yield return new ServiceDescriptor { + ServiceType = typeof(IDataProtectionProvider), + Lifecycle = LifecycleKind.Singleton, + ImplementationInstance = DataProtectionProvider.CreateFromDpapi() + }; } public static IServiceDescriptor DescribeService(IConfiguration configuration, diff --git a/src/Microsoft.AspNet.Hosting/project.json b/src/Microsoft.AspNet.Hosting/project.json index 26ca426580..3f0cca6268 100644 --- a/src/Microsoft.AspNet.Hosting/project.json +++ b/src/Microsoft.AspNet.Hosting/project.json @@ -5,7 +5,8 @@ "Microsoft.AspNet.ConfigurationModel": "0.1-alpha-*", "Microsoft.AspNet.PipelineCore": "0.1-alpha-*", "Microsoft.AspNet.Abstractions": "0.1-alpha-*", - "Microsoft.AspNet.FeatureModel": "0.1-alpha-*" + "Microsoft.AspNet.FeatureModel": "0.1-alpha-*", + "Microsoft.AspNet.Security.DataProtection": "0.1-alpha-*" }, "configurations": { "net45": {}, From cd9d3a333572cf7d32f80e9d038b00860ca73918 Mon Sep 17 00:00:00 2001 From: David Fowler Date: Mon, 17 Mar 2014 19:24:31 -0700 Subject: [PATCH 020/987] Updated hosting to use service describer --- .../HostingServices.cs | 68 +++---------------- 1 file changed, 11 insertions(+), 57 deletions(-) diff --git a/src/Microsoft.AspNet.Hosting/HostingServices.cs b/src/Microsoft.AspNet.Hosting/HostingServices.cs index 9032db6706..3f9555448e 100644 --- a/src/Microsoft.AspNet.Hosting/HostingServices.cs +++ b/src/Microsoft.AspNet.Hosting/HostingServices.cs @@ -1,5 +1,4 @@ -using System; -using System.Collections.Generic; +using System.Collections.Generic; using Microsoft.AspNet.ConfigurationModel; using Microsoft.AspNet.DependencyInjection; using Microsoft.AspNet.Hosting.Builder; @@ -18,69 +17,24 @@ namespace Microsoft.AspNet.Hosting public static IEnumerable GetDefaultServices(IConfiguration configuration) { - yield return DescribeService(configuration); - yield return DescribeService(configuration); + var describer = new ServiceDescriber(configuration); - yield return DescribeService(configuration); - yield return DescribeService(configuration); + yield return describer.Transient(); + yield return describer.Transient(); - yield return DescribeService(configuration); - yield return DescribeService(configuration); + yield return describer.Transient(); + yield return describer.Transient(); - yield return DescribeService(configuration); + yield return describer.Transient(); + yield return describer.Transient(); + + yield return describer.Transient(); // The default IDataProtectionProvider is a singleton. // Note: DPAPI isn't usable in IIS where the user profile hasn't been loaded, but loading DPAPI // is deferred until the first call to Protect / Unprotect. It's up to an IIS-based host to // replace this service as part of application initialization. - yield return new ServiceDescriptor { - ServiceType = typeof(IDataProtectionProvider), - Lifecycle = LifecycleKind.Singleton, - ImplementationInstance = DataProtectionProvider.CreateFromDpapi() - }; - } - - public static IServiceDescriptor DescribeService(IConfiguration configuration, - LifecycleKind lifecycle = LifecycleKind.Transient) - { - return DescribeService(typeof(TService), typeof(TImplementation), configuration, lifecycle); - } - - public static IServiceDescriptor DescribeService( - Type serviceType, - Type implementationType, - IConfiguration configuration, - LifecycleKind lifecycle) - { - var serviceTypeName = serviceType.FullName; - var implementationTypeName = configuration.Get(serviceTypeName); - if (!String.IsNullOrEmpty(implementationTypeName)) - { - try - { - implementationType = Type.GetType(implementationTypeName); - } - catch (Exception ex) - { - throw new Exception(string.Format("TODO: unable to locate implementation {0} for service {1}", implementationTypeName, serviceTypeName), ex); - } - } - return new ServiceTypeDescriptor(serviceType, implementationType, lifecycle); - } - - public class ServiceTypeDescriptor : IServiceDescriptor - { - public ServiceTypeDescriptor(Type serviceType, Type implementationType, LifecycleKind lifecycle) - { - ServiceType = serviceType; - ImplementationType = implementationType; - Lifecycle = lifecycle; - } - - public LifecycleKind Lifecycle { get; private set; } - public Type ServiceType { get; private set; } - public Type ImplementationType { get; private set; } - public object ImplementationInstance { get; private set; } + yield return describer.Instance(DataProtectionProvider.CreateFromDpapi()); } } } \ No newline at end of file From ea1f93aa919e9059cb17a5600fe43465e8982195 Mon Sep 17 00:00:00 2001 From: GrabYourPitchforks Date: Tue, 18 Mar 2014 11:44:25 -0700 Subject: [PATCH 021/987] Fix bad call to Assembly.GetType in Hosting. CR: chrross --- src/Microsoft.AspNet.Hosting/Startup/StartupLoader.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Microsoft.AspNet.Hosting/Startup/StartupLoader.cs b/src/Microsoft.AspNet.Hosting/Startup/StartupLoader.cs index 7b1362e90f..eed8e7a6e4 100644 --- a/src/Microsoft.AspNet.Hosting/Startup/StartupLoader.cs +++ b/src/Microsoft.AspNet.Hosting/Startup/StartupLoader.cs @@ -42,7 +42,7 @@ namespace Microsoft.AspNet.Hosting.Startup } // Check the most likely places first - type = assembly.GetType(typeName) ?? assembly.GetType(assembly + "." + typeName); + type = assembly.GetType(typeName) ?? assembly.GetType(assembly.GetName().Name + "." + typeName); if (type == null) { From aa0b52df4eb6968a243358bd0a5046cb123e77b8 Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Tue, 18 Mar 2014 15:04:49 -0700 Subject: [PATCH 022/987] ServiceCollection.FallbackServices no longer exists - Pass the fallback service provider to BuildServiceProvider instead --- src/Microsoft.AspNet.Hosting/Program.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Microsoft.AspNet.Hosting/Program.cs b/src/Microsoft.AspNet.Hosting/Program.cs index 8153333fb1..76dffada12 100644 --- a/src/Microsoft.AspNet.Hosting/Program.cs +++ b/src/Microsoft.AspNet.Hosting/Program.cs @@ -30,8 +30,7 @@ namespace Microsoft.AspNet.Hosting var serviceCollection = new ServiceCollection(); serviceCollection.Add(HostingServices.GetDefaultServices(config)); - var services = serviceCollection.BuildServiceProvider(); - serviceCollection.FallbackServices = _serviceProvider; + var services = serviceCollection.BuildServiceProvider(_serviceProvider); var appEnvironment = _serviceProvider.GetService(); From c39a41bd9f055ee6c780f043f01ff63bbf972667 Mon Sep 17 00:00:00 2001 From: Louis DeJardin Date: Tue, 18 Mar 2014 23:01:42 -0700 Subject: [PATCH 023/987] Adding UseContainer middleware Assigns values to HttpContext.ApplicationServices and HttpContext.RequestServices as call passes through --- Hosting.sln | 50 +++++--- .../ContainerExtensions.cs | 45 +++++++ .../ContainerMiddleware.cs | 114 ++++++++++++++++++ .../project.json | 23 ++++ 4 files changed, 217 insertions(+), 15 deletions(-) create mode 100644 src/Microsoft.AspNet.RequestContainer/ContainerExtensions.cs create mode 100644 src/Microsoft.AspNet.RequestContainer/ContainerMiddleware.cs create mode 100644 src/Microsoft.AspNet.RequestContainer/project.json diff --git a/Hosting.sln b/Hosting.sln index def8ba2b14..76c17f7d3e 100644 --- a/Hosting.sln +++ b/Hosting.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 2013 -VisualStudioVersion = 12.0.30203.2 +VisualStudioVersion = 12.0.21005.1 MinimumVisualStudioVersion = 10.0.40219.1 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{E0497F39-AFFB-4819-A116-E39E361915AB}" EndProject @@ -15,9 +15,17 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.AspNet.Hosting.Te EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "samples", "samples", "{C30C98CD-3D69-4AE9-B680-0E0E6D8834C6}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "KWebStartup.net45", "samples\KWebStartup\KWebStartup.net45.csproj", "{E9B21845-E51A-4B8C-AF0B-0C4CE16550BF}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.AspNet.RequestContainer.net45", "src\Microsoft.AspNet.RequestContainer\Microsoft.AspNet.RequestContainer.net45.csproj", "{F4C7B46C-B39F-4172-9C3A-05352183D469}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "KWebStartup.k10", "samples\KWebStartup\KWebStartup.k10.csproj", "{348007AA-AB91-48B2-98DB-57D068E2C1AE}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.AspNet.RequestContainer.k10", "src\Microsoft.AspNet.RequestContainer\Microsoft.AspNet.RequestContainer.k10.csproj", "{FD9833B9-3FB1-4612-BBB4-64F539DB0F8B}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "net45", "net45", "{93FB86DB-7D2A-46CE-AFD2-0B53E6A8CF69}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "k10", "k10", "{EB784E77-FD42-46EC-9C8C-502B78962407}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "KWebStartup.k10", "samples\KWebStartup\KWebStartup.k10.csproj", "{C0235BA1-9198-42C0-92D8-7578E9B9D96B}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "KWebStartup.net45", "samples\KWebStartup\KWebStartup.net45.csproj", "{B5939234-73ED-4DAD-A2C6-D61AA6DFB406}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -37,23 +45,35 @@ Global {80588AF3-6B14-4D11-9DC4-1EF6453B54C9}.Debug|Any CPU.Build.0 = Debug|Any CPU {80588AF3-6B14-4D11-9DC4-1EF6453B54C9}.Release|Any CPU.ActiveCfg = Release|Any CPU {80588AF3-6B14-4D11-9DC4-1EF6453B54C9}.Release|Any CPU.Build.0 = Release|Any CPU - {E9B21845-E51A-4B8C-AF0B-0C4CE16550BF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {E9B21845-E51A-4B8C-AF0B-0C4CE16550BF}.Debug|Any CPU.Build.0 = Debug|Any CPU - {E9B21845-E51A-4B8C-AF0B-0C4CE16550BF}.Release|Any CPU.ActiveCfg = Release|Any CPU - {E9B21845-E51A-4B8C-AF0B-0C4CE16550BF}.Release|Any CPU.Build.0 = Release|Any CPU - {348007AA-AB91-48B2-98DB-57D068E2C1AE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {348007AA-AB91-48B2-98DB-57D068E2C1AE}.Debug|Any CPU.Build.0 = Debug|Any CPU - {348007AA-AB91-48B2-98DB-57D068E2C1AE}.Release|Any CPU.ActiveCfg = Release|Any CPU - {348007AA-AB91-48B2-98DB-57D068E2C1AE}.Release|Any CPU.Build.0 = Release|Any CPU + {F4C7B46C-B39F-4172-9C3A-05352183D469}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {F4C7B46C-B39F-4172-9C3A-05352183D469}.Debug|Any CPU.Build.0 = Debug|Any CPU + {F4C7B46C-B39F-4172-9C3A-05352183D469}.Release|Any CPU.ActiveCfg = Release|Any CPU + {F4C7B46C-B39F-4172-9C3A-05352183D469}.Release|Any CPU.Build.0 = Release|Any CPU + {FD9833B9-3FB1-4612-BBB4-64F539DB0F8B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {FD9833B9-3FB1-4612-BBB4-64F539DB0F8B}.Debug|Any CPU.Build.0 = Debug|Any CPU + {FD9833B9-3FB1-4612-BBB4-64F539DB0F8B}.Release|Any CPU.ActiveCfg = Release|Any CPU + {FD9833B9-3FB1-4612-BBB4-64F539DB0F8B}.Release|Any CPU.Build.0 = Release|Any CPU + {C0235BA1-9198-42C0-92D8-7578E9B9D96B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {C0235BA1-9198-42C0-92D8-7578E9B9D96B}.Debug|Any CPU.Build.0 = Debug|Any CPU + {C0235BA1-9198-42C0-92D8-7578E9B9D96B}.Release|Any CPU.ActiveCfg = Release|Any CPU + {C0235BA1-9198-42C0-92D8-7578E9B9D96B}.Release|Any CPU.Build.0 = Release|Any CPU + {B5939234-73ED-4DAD-A2C6-D61AA6DFB406}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {B5939234-73ED-4DAD-A2C6-D61AA6DFB406}.Debug|Any CPU.Build.0 = Debug|Any CPU + {B5939234-73ED-4DAD-A2C6-D61AA6DFB406}.Release|Any CPU.ActiveCfg = Release|Any CPU + {B5939234-73ED-4DAD-A2C6-D61AA6DFB406}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection GlobalSection(NestedProjects) = preSolution - {D546290B-E280-4D99-BA9C-0D364A0AFB54} = {E0497F39-AFFB-4819-A116-E39E361915AB} - {DBB72F0F-755D-41CF-8FE2-F4B6AE214E91} = {E0497F39-AFFB-4819-A116-E39E361915AB} + {93FB86DB-7D2A-46CE-AFD2-0B53E6A8CF69} = {E0497F39-AFFB-4819-A116-E39E361915AB} + {EB784E77-FD42-46EC-9C8C-502B78962407} = {E0497F39-AFFB-4819-A116-E39E361915AB} {80588AF3-6B14-4D11-9DC4-1EF6453B54C9} = {FEB39027-9158-4DE2-997F-7ADAEF8188D0} - {E9B21845-E51A-4B8C-AF0B-0C4CE16550BF} = {C30C98CD-3D69-4AE9-B680-0E0E6D8834C6} - {348007AA-AB91-48B2-98DB-57D068E2C1AE} = {C30C98CD-3D69-4AE9-B680-0E0E6D8834C6} + {F4C7B46C-B39F-4172-9C3A-05352183D469} = {93FB86DB-7D2A-46CE-AFD2-0B53E6A8CF69} + {D546290B-E280-4D99-BA9C-0D364A0AFB54} = {93FB86DB-7D2A-46CE-AFD2-0B53E6A8CF69} + {FD9833B9-3FB1-4612-BBB4-64F539DB0F8B} = {EB784E77-FD42-46EC-9C8C-502B78962407} + {DBB72F0F-755D-41CF-8FE2-F4B6AE214E91} = {EB784E77-FD42-46EC-9C8C-502B78962407} + {C0235BA1-9198-42C0-92D8-7578E9B9D96B} = {C30C98CD-3D69-4AE9-B680-0E0E6D8834C6} + {B5939234-73ED-4DAD-A2C6-D61AA6DFB406} = {C30C98CD-3D69-4AE9-B680-0E0E6D8834C6} EndGlobalSection EndGlobal diff --git a/src/Microsoft.AspNet.RequestContainer/ContainerExtensions.cs b/src/Microsoft.AspNet.RequestContainer/ContainerExtensions.cs new file mode 100644 index 0000000000..4cfdb4210f --- /dev/null +++ b/src/Microsoft.AspNet.RequestContainer/ContainerExtensions.cs @@ -0,0 +1,45 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using Microsoft.AspNet.Abstractions; +using Microsoft.AspNet.DependencyInjection; +using Microsoft.AspNet.DependencyInjection.Fallback; + +namespace Microsoft.AspNet.RequestContainer +{ + public static class ContainerExtensions + { + public static IBuilder UseMiddleware(this IBuilder builder, Type middleware, params object[] args) + { + // TODO: move this ext method someplace nice + return builder.Use(next => + { + //TODO: this should be MethodInfo.CreateDelegate for coreclr + var typeActivator = builder.ServiceProvider.GetService(); + var instance = typeActivator.CreateInstance(middleware, new[] { next }.Concat(args).ToArray()); + return (RequestDelegate)Delegate.CreateDelegate(typeof(RequestDelegate), instance, "Invoke"); + }); + } + + public static IBuilder UseContainer(this IBuilder app) + { + return app.UseMiddleware(typeof(ContainerMiddleware)); + } + + public static IBuilder UseContainer(this IBuilder app, IServiceProvider applicationServices) + { + app.ServiceProvider = applicationServices; + + return app.UseMiddleware(typeof(ContainerMiddleware)); + } + + public static IBuilder UseContainer(this IBuilder app, IEnumerable applicationServices) + { + var serviceCollection = new ServiceCollection(); + serviceCollection.Add(applicationServices); + app.ServiceProvider = serviceCollection.BuildServiceProvider(app.ServiceProvider); + + return app.UseMiddleware(typeof(ContainerMiddleware)); + } + } +} \ No newline at end of file diff --git a/src/Microsoft.AspNet.RequestContainer/ContainerMiddleware.cs b/src/Microsoft.AspNet.RequestContainer/ContainerMiddleware.cs new file mode 100644 index 0000000000..d2295e90c1 --- /dev/null +++ b/src/Microsoft.AspNet.RequestContainer/ContainerMiddleware.cs @@ -0,0 +1,114 @@ +using System; +#if NET45 +using System.Runtime.Remoting.Messaging; +#endif +using System.Threading.Tasks; +using Microsoft.AspNet.Abstractions; +using Microsoft.AspNet.DependencyInjection; + +namespace Microsoft.AspNet.RequestContainer +{ + public class ContainerMiddleware + { + private const string LogicalDataKey = "__HttpContext_Current__"; + private readonly RequestDelegate _next; + private readonly IServiceProvider _rootServiceProvider; + private readonly IContextAccessor _rootHttpContextAccessor; + private readonly IServiceScopeFactory _rootServiceScopeFactory; + + public ContainerMiddleware( + RequestDelegate next, + IServiceProvider rootServiceProvider, + IContextAccessor rootHttpContextAccessor, + IServiceScopeFactory rootServiceScopeFactory) + { + if (rootServiceProvider == null) + { + throw new ArgumentNullException("rootServiceProvider"); + } + if (rootHttpContextAccessor == null) + { + throw new ArgumentNullException("rootHttpContextAccessor"); + } + if (rootServiceScopeFactory == null) + { + throw new ArgumentNullException("rootServiceScopeFactory"); + } + + _next = next; + _rootServiceProvider = rootServiceProvider; + _rootServiceScopeFactory = rootServiceScopeFactory; + _rootHttpContextAccessor = rootHttpContextAccessor; + + _rootHttpContextAccessor.SetContextSource(AccessRootHttpContext, ExchangeRootHttpContext); + } + + private HttpContext AccessRootHttpContext() + { +#if NET45 + return CallContext.LogicalGetData(LogicalDataKey) as HttpContext; +#else + throw new NotImplementedException() +#endif + } + + private HttpContext ExchangeRootHttpContext(HttpContext httpContext) + { +#if NET45 + var prior = CallContext.LogicalGetData(LogicalDataKey) as HttpContext; + CallContext.LogicalSetData(LogicalDataKey, httpContext); + return prior; +#else + throw new NotImplementedException() +#endif + } + + public async Task Invoke(HttpContext httpContext) + { + if (httpContext.RequestServices != null) + { + throw new Exception("TODO: nested request container scope? this is probably a mistake on your part?"); + } + + var priorApplicationServices = httpContext.ApplicationServices; + var priorRequestServices = httpContext.RequestServices; + + var appServiceProvider = _rootServiceProvider; + var appServiceScopeFactory = _rootServiceScopeFactory; + var appHttpContextAccessor = _rootHttpContextAccessor; + + if (priorApplicationServices != null && + priorApplicationServices != appServiceProvider) + { + appServiceProvider = priorApplicationServices; + appServiceScopeFactory = priorApplicationServices.GetService(); + appHttpContextAccessor = priorApplicationServices.GetService>(); + } + + using (var scope = appServiceScopeFactory.CreateScope()) + { + var scopeServiceProvider = scope.ServiceProvider; + var scopeHttpContextAccessor = scopeServiceProvider.GetService>(); + + httpContext.ApplicationServices = appServiceProvider; + httpContext.RequestServices = scopeServiceProvider; + + var priorAppHttpContext = appHttpContextAccessor.ExchangeValue(httpContext); + var priorScopeHttpContext = scopeHttpContextAccessor.ExchangeValue(httpContext); + + try + { + await _next.Invoke(httpContext); + } + finally + { + scopeHttpContextAccessor.ExchangeValue(priorScopeHttpContext); + appHttpContextAccessor.ExchangeValue(priorAppHttpContext); + + httpContext.RequestServices = priorRequestServices; + httpContext.ApplicationServices = priorApplicationServices; + } + } + } + } +} diff --git a/src/Microsoft.AspNet.RequestContainer/project.json b/src/Microsoft.AspNet.RequestContainer/project.json new file mode 100644 index 0000000000..b89873123e --- /dev/null +++ b/src/Microsoft.AspNet.RequestContainer/project.json @@ -0,0 +1,23 @@ +{ + "version": "0.1-alpha-*", + "dependencies": { + "Microsoft.AspNet.DependencyInjection": "0.1-alpha-*", + "Microsoft.AspNet.Abstractions": "0.1-alpha-*" + }, + "configurations": { + "net45": {}, + "k10": { + "dependencies": { + "System.Collections": "4.0.0.0", + "System.ComponentModel": "4.0.0.0", + "System.Diagnostics.Debug": "4.0.10.0", + "System.Linq": "4.0.0.0", + "System.Reflection": "4.0.10.0", + "System.Runtime": "4.0.20.0", + "System.Runtime.Extensions": "4.0.10.0", + "System.Threading": "4.0.0.0", + "System.Threading.Tasks": "4.0.0.0" + } + } + } +} \ No newline at end of file From 7b038d4e3108cadfda9a1c04eff98b65dc0aabb1 Mon Sep 17 00:00:00 2001 From: Louis DeJardin Date: Wed, 19 Mar 2014 14:26:04 -0700 Subject: [PATCH 024/987] Adding standard implementation of IContextAccessor<> --- src/Microsoft.AspNet.Hosting/HostingServices.cs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/Microsoft.AspNet.Hosting/HostingServices.cs b/src/Microsoft.AspNet.Hosting/HostingServices.cs index 3f9555448e..4ef1e162c6 100644 --- a/src/Microsoft.AspNet.Hosting/HostingServices.cs +++ b/src/Microsoft.AspNet.Hosting/HostingServices.cs @@ -30,6 +30,13 @@ namespace Microsoft.AspNet.Hosting yield return describer.Transient(); + yield return new ServiceDescriptor + { + ServiceType = typeof(IContextAccessor<>), + ImplementationType = typeof(ContextAccessor<>), + Lifecycle = LifecycleKind.Scoped + }; + // The default IDataProtectionProvider is a singleton. // Note: DPAPI isn't usable in IIS where the user profile hasn't been loaded, but loading DPAPI // is deferred until the first call to Protect / Unprotect. It's up to an IIS-based host to From 951e8df8935dcae1984346d97c50f3dc366c8617 Mon Sep 17 00:00:00 2001 From: Louis DeJardin Date: Tue, 18 Mar 2014 23:29:26 -0700 Subject: [PATCH 025/987] Making core clr friendly --- .../ContainerExtensions.cs | 21 ++++++++++--------- .../ContainerMiddleware.cs | 13 ++++++++++-- 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/src/Microsoft.AspNet.RequestContainer/ContainerExtensions.cs b/src/Microsoft.AspNet.RequestContainer/ContainerExtensions.cs index 4cfdb4210f..86d72c1e20 100644 --- a/src/Microsoft.AspNet.RequestContainer/ContainerExtensions.cs +++ b/src/Microsoft.AspNet.RequestContainer/ContainerExtensions.cs @@ -1,4 +1,5 @@ using System; +using System.Reflection; using System.Collections.Generic; using System.Linq; using Microsoft.AspNet.Abstractions; @@ -14,32 +15,32 @@ namespace Microsoft.AspNet.RequestContainer // TODO: move this ext method someplace nice return builder.Use(next => { - //TODO: this should be MethodInfo.CreateDelegate for coreclr var typeActivator = builder.ServiceProvider.GetService(); var instance = typeActivator.CreateInstance(middleware, new[] { next }.Concat(args).ToArray()); - return (RequestDelegate)Delegate.CreateDelegate(typeof(RequestDelegate), instance, "Invoke"); + var methodinfo = middleware.GetTypeInfo().GetDeclaredMethod("Invoke"); + return (RequestDelegate)methodinfo.CreateDelegate(typeof(RequestDelegate), instance); }); } - public static IBuilder UseContainer(this IBuilder app) + public static IBuilder UseContainer(this IBuilder builder) { - return app.UseMiddleware(typeof(ContainerMiddleware)); + return builder.UseMiddleware(typeof(ContainerMiddleware)); } - public static IBuilder UseContainer(this IBuilder app, IServiceProvider applicationServices) + public static IBuilder UseContainer(this IBuilder builder, IServiceProvider applicationServices) { - app.ServiceProvider = applicationServices; + builder.ServiceProvider = applicationServices; - return app.UseMiddleware(typeof(ContainerMiddleware)); + return builder.UseMiddleware(typeof(ContainerMiddleware)); } - public static IBuilder UseContainer(this IBuilder app, IEnumerable applicationServices) + public static IBuilder UseContainer(this IBuilder builder, IEnumerable applicationServices) { var serviceCollection = new ServiceCollection(); serviceCollection.Add(applicationServices); - app.ServiceProvider = serviceCollection.BuildServiceProvider(app.ServiceProvider); + builder.ServiceProvider = serviceCollection.BuildServiceProvider(builder.ServiceProvider); - return app.UseMiddleware(typeof(ContainerMiddleware)); + return builder.UseMiddleware(typeof(ContainerMiddleware)); } } } \ No newline at end of file diff --git a/src/Microsoft.AspNet.RequestContainer/ContainerMiddleware.cs b/src/Microsoft.AspNet.RequestContainer/ContainerMiddleware.cs index d2295e90c1..a33a6ac7db 100644 --- a/src/Microsoft.AspNet.RequestContainer/ContainerMiddleware.cs +++ b/src/Microsoft.AspNet.RequestContainer/ContainerMiddleware.cs @@ -43,12 +43,19 @@ namespace Microsoft.AspNet.RequestContainer _rootHttpContextAccessor.SetContextSource(AccessRootHttpContext, ExchangeRootHttpContext); } +#if NET45 +#else +#warning This MUST NOT be ThreadStatic in reality + [ThreadStatic] + HttpContext THIS_IS_BROKEN_AND_MUST_BE_CHANGED; +#endif + private HttpContext AccessRootHttpContext() { #if NET45 return CallContext.LogicalGetData(LogicalDataKey) as HttpContext; #else - throw new NotImplementedException() + return THIS_IS_BROKEN_AND_MUST_BE_CHANGED; #endif } @@ -59,7 +66,9 @@ namespace Microsoft.AspNet.RequestContainer CallContext.LogicalSetData(LogicalDataKey, httpContext); return prior; #else - throw new NotImplementedException() + var prior = THIS_IS_BROKEN_AND_MUST_BE_CHANGED; + THIS_IS_BROKEN_AND_MUST_BE_CHANGED = httpContext; + return prior; #endif } From ff1962883240d942ced116e8c42950317fbd93b3 Mon Sep 17 00:00:00 2001 From: Louis DeJardin Date: Wed, 19 Mar 2014 00:02:58 -0700 Subject: [PATCH 026/987] Removing the temporary use of thread static --- .../ContainerMiddleware.cs | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/src/Microsoft.AspNet.RequestContainer/ContainerMiddleware.cs b/src/Microsoft.AspNet.RequestContainer/ContainerMiddleware.cs index a33a6ac7db..61d985fc3d 100644 --- a/src/Microsoft.AspNet.RequestContainer/ContainerMiddleware.cs +++ b/src/Microsoft.AspNet.RequestContainer/ContainerMiddleware.cs @@ -43,20 +43,13 @@ namespace Microsoft.AspNet.RequestContainer _rootHttpContextAccessor.SetContextSource(AccessRootHttpContext, ExchangeRootHttpContext); } -#if NET45 -#else -#warning This MUST NOT be ThreadStatic in reality - [ThreadStatic] - HttpContext THIS_IS_BROKEN_AND_MUST_BE_CHANGED; -#endif - private HttpContext AccessRootHttpContext() { #if NET45 return CallContext.LogicalGetData(LogicalDataKey) as HttpContext; #else - return THIS_IS_BROKEN_AND_MUST_BE_CHANGED; -#endif + throw new Exception("TODO: CallContext not available"); +#endif } private HttpContext ExchangeRootHttpContext(HttpContext httpContext) @@ -66,9 +59,7 @@ namespace Microsoft.AspNet.RequestContainer CallContext.LogicalSetData(LogicalDataKey, httpContext); return prior; #else - var prior = THIS_IS_BROKEN_AND_MUST_BE_CHANGED; - THIS_IS_BROKEN_AND_MUST_BE_CHANGED = httpContext; - return prior; + return null; #endif } From 11762840cdb7e1dd064f89e0aec4ae2be9726e19 Mon Sep 17 00:00:00 2001 From: Chris Ross Date: Wed, 19 Mar 2014 11:43:13 -0700 Subject: [PATCH 027/987] Add an Initialize step to IServerFactory. --- samples/KWebStartup/project.json | 2 +- src/Microsoft.AspNet.Hosting/HostingContext.cs | 3 +++ src/Microsoft.AspNet.Hosting/HostingEngine.cs | 17 +++++++++++++++-- src/Microsoft.AspNet.Hosting/Program.cs | 1 + .../Server/IServerFactory.cs | 4 +++- .../HostingEngineTests.cs | 10 ++++++++-- .../Microsoft.AspNet.Hosting.Tests/project.json | 1 + 7 files changed, 32 insertions(+), 6 deletions(-) diff --git a/samples/KWebStartup/project.json b/samples/KWebStartup/project.json index 1d16b7bd9e..70b55fad15 100644 --- a/samples/KWebStartup/project.json +++ b/samples/KWebStartup/project.json @@ -5,7 +5,7 @@ "Microsoft.AspNet.Hosting": "0.1-alpha-*", "Microsoft.AspNet.Server.WebListener": "0.1-alpha-*" }, - "commands": { "web": "Microsoft.AspNet.Hosting server.name=Microsoft.AspNet.Server.WebListener" }, + "commands": { "web": "Microsoft.AspNet.Hosting server.name=Microsoft.AspNet.Server.WebListener server.urls=http://localhost:5001" }, "configurations": { "net45": { }, diff --git a/src/Microsoft.AspNet.Hosting/HostingContext.cs b/src/Microsoft.AspNet.Hosting/HostingContext.cs index 303e9e7770..b1d96a88e0 100644 --- a/src/Microsoft.AspNet.Hosting/HostingContext.cs +++ b/src/Microsoft.AspNet.Hosting/HostingContext.cs @@ -1,5 +1,6 @@ using System; using Microsoft.AspNet.Abstractions; +using Microsoft.AspNet.ConfigurationModel; using Microsoft.AspNet.Hosting.Server; namespace Microsoft.AspNet.Hosting @@ -7,6 +8,7 @@ namespace Microsoft.AspNet.Hosting public class HostingContext { public IServiceProvider Services { get; set; } + public IConfiguration Configuration { get; set; } public IBuilder Builder { get; set; } @@ -16,5 +18,6 @@ namespace Microsoft.AspNet.Hosting public string ServerName { get; set; } public IServerFactory ServerFactory { get; set; } + public IServerInformation Server { get; set; } } } \ No newline at end of file diff --git a/src/Microsoft.AspNet.Hosting/HostingEngine.cs b/src/Microsoft.AspNet.Hosting/HostingEngine.cs index 1bf28ef25b..b04d02f65a 100644 --- a/src/Microsoft.AspNet.Hosting/HostingEngine.cs +++ b/src/Microsoft.AspNet.Hosting/HostingEngine.cs @@ -30,10 +30,11 @@ namespace Microsoft.AspNet.Hosting { EnsureBuilder(context); EnsureServerFactory(context); + InitalizeServerFactory(context); EnsureApplicationDelegate(context); var pipeline = new PipelineInstance(_httpContextFactory, context.ApplicationDelegate); - var server = context.ServerFactory.Start(pipeline.Invoke); + var server = context.ServerFactory.Start(context.Server, pipeline.Invoke); return new Disposable(() => { @@ -66,6 +67,19 @@ namespace Microsoft.AspNet.Hosting context.ServerFactory = _serverManager.GetServerFactory(context.ServerName); } + private void InitalizeServerFactory(HostingContext context) + { + if (context.Server == null) + { + context.Server = context.ServerFactory.Initialize(context.Configuration); + } + + if (context.Builder.Server == null) + { + context.Builder.Server = context.Server; + } + } + private void EnsureApplicationDelegate(HostingContext context) { if (context.ApplicationDelegate != null) @@ -74,7 +88,6 @@ namespace Microsoft.AspNet.Hosting } EnsureApplicationStartup(context); - EnsureBuilder(context); context.ApplicationStartup.Invoke(context.Builder); context.ApplicationDelegate = context.Builder.Build(); diff --git a/src/Microsoft.AspNet.Hosting/Program.cs b/src/Microsoft.AspNet.Hosting/Program.cs index 76dffada12..18dc9f4899 100644 --- a/src/Microsoft.AspNet.Hosting/Program.cs +++ b/src/Microsoft.AspNet.Hosting/Program.cs @@ -37,6 +37,7 @@ namespace Microsoft.AspNet.Hosting var context = new HostingContext() { Services = services, + Configuration = config, ServerName = config.Get("server.name"), // TODO: Key names ApplicationName = config.Get("app.name") // TODO: Key names ?? appEnvironment.ApplicationName, diff --git a/src/Microsoft.AspNet.Hosting/Server/IServerFactory.cs b/src/Microsoft.AspNet.Hosting/Server/IServerFactory.cs index 4ae76a13b4..79b4b6c554 100644 --- a/src/Microsoft.AspNet.Hosting/Server/IServerFactory.cs +++ b/src/Microsoft.AspNet.Hosting/Server/IServerFactory.cs @@ -1,6 +1,7 @@ using System; using System.Threading.Tasks; using Microsoft.AspNet.Abstractions; +using Microsoft.AspNet.ConfigurationModel; using Microsoft.Net.Runtime; namespace Microsoft.AspNet.Hosting.Server @@ -8,6 +9,7 @@ namespace Microsoft.AspNet.Hosting.Server // TODO: [AssemblyNeutral] public interface IServerFactory { - IDisposable Start(Func application); + IServerInformation Initialize(IConfiguration configuraiton); + IDisposable Start(IServerInformation serverInformation, Func application); } } diff --git a/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs b/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs index eb09beba24..b94ec289b2 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs @@ -2,9 +2,10 @@ using System.Collections.Generic; using System.Threading.Tasks; using Microsoft.AspNet.Abstractions; +using Microsoft.AspNet.ConfigurationModel; using Microsoft.AspNet.DependencyInjection; -using Microsoft.AspNet.Hosting.Server; using Microsoft.AspNet.DependencyInjection.Fallback; +using Microsoft.AspNet.Hosting.Server; using Xunit; namespace Microsoft.AspNet.Hosting @@ -56,7 +57,12 @@ namespace Microsoft.AspNet.Hosting } - public IDisposable Start(Func application) + public IServerInformation Initialize(IConfiguration configuraiton) + { + return null; + } + + public IDisposable Start(IServerInformation serverInformation, Func application) { var startInstance = new StartInstance(application); _startInstances.Add(startInstance); diff --git a/test/Microsoft.AspNet.Hosting.Tests/project.json b/test/Microsoft.AspNet.Hosting.Tests/project.json index 8c46f5dd94..b99c5d336f 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/project.json +++ b/test/Microsoft.AspNet.Hosting.Tests/project.json @@ -2,6 +2,7 @@ "version": "0.1-alpha-*", "dependencies": { "Microsoft.AspNet.Hosting": "", + "Microsoft.AspNet.ConfigurationModel": "0.1-alpha-*", "Microsoft.AspNet.Abstractions":"0.1-alpha-*", "Microsoft.AspNet.DependencyInjection":"0.1-alpha-*", "Xunit.KRunner": "0.1-alpha-*", From 982cf2a1d63cd153419d807dafbe61ce854f3009 Mon Sep 17 00:00:00 2001 From: Chris Ross Date: Thu, 20 Mar 2014 11:20:16 -0700 Subject: [PATCH 028/987] Code review cleanup. --- src/Microsoft.AspNet.Hosting/Server/IServerFactory.cs | 3 +-- test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/Microsoft.AspNet.Hosting/Server/IServerFactory.cs b/src/Microsoft.AspNet.Hosting/Server/IServerFactory.cs index 79b4b6c554..054e5e0308 100644 --- a/src/Microsoft.AspNet.Hosting/Server/IServerFactory.cs +++ b/src/Microsoft.AspNet.Hosting/Server/IServerFactory.cs @@ -2,14 +2,13 @@ using System.Threading.Tasks; using Microsoft.AspNet.Abstractions; using Microsoft.AspNet.ConfigurationModel; -using Microsoft.Net.Runtime; namespace Microsoft.AspNet.Hosting.Server { // TODO: [AssemblyNeutral] public interface IServerFactory { - IServerInformation Initialize(IConfiguration configuraiton); + IServerInformation Initialize(IConfiguration configuration); IDisposable Start(IServerInformation serverInformation, Func application); } } diff --git a/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs b/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs index b94ec289b2..a7fbfc88f1 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs @@ -57,7 +57,7 @@ namespace Microsoft.AspNet.Hosting } - public IServerInformation Initialize(IConfiguration configuraiton) + public IServerInformation Initialize(IConfiguration configuration) { return null; } From 9a4678d40fd9b91687058c512e6a62932474d71a Mon Sep 17 00:00:00 2001 From: Chris Ross Date: Thu, 20 Mar 2014 21:13:31 -0700 Subject: [PATCH 029/987] Change config order. --- src/Microsoft.AspNet.Hosting/Program.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Microsoft.AspNet.Hosting/Program.cs b/src/Microsoft.AspNet.Hosting/Program.cs index 18dc9f4899..e8ce97b453 100644 --- a/src/Microsoft.AspNet.Hosting/Program.cs +++ b/src/Microsoft.AspNet.Hosting/Program.cs @@ -22,11 +22,11 @@ namespace Microsoft.AspNet.Hosting { var config = new Configuration(); config.AddCommandLine(args); - config.AddEnvironmentVariables(); if (File.Exists(HostingIniFile)) { config.AddIniFile(HostingIniFile); } + config.AddEnvironmentVariables(); var serviceCollection = new ServiceCollection(); serviceCollection.Add(HostingServices.GetDefaultServices(config)); From 2207acb917ecf327b1738878551c014c1c9172ed Mon Sep 17 00:00:00 2001 From: Ryan Nowak Date: Fri, 21 Mar 2014 17:53:18 -0700 Subject: [PATCH 030/987] Incorporate breaking change from DI --- src/Microsoft.AspNet.RequestContainer/ContainerExtensions.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Microsoft.AspNet.RequestContainer/ContainerExtensions.cs b/src/Microsoft.AspNet.RequestContainer/ContainerExtensions.cs index 86d72c1e20..05b56f92cd 100644 --- a/src/Microsoft.AspNet.RequestContainer/ContainerExtensions.cs +++ b/src/Microsoft.AspNet.RequestContainer/ContainerExtensions.cs @@ -16,7 +16,7 @@ namespace Microsoft.AspNet.RequestContainer return builder.Use(next => { var typeActivator = builder.ServiceProvider.GetService(); - var instance = typeActivator.CreateInstance(middleware, new[] { next }.Concat(args).ToArray()); + var instance = typeActivator.CreateInstance(builder.ServiceProvider, middleware, new[] { next }.Concat(args).ToArray()); var methodinfo = middleware.GetTypeInfo().GetDeclaredMethod("Invoke"); return (RequestDelegate)methodinfo.CreateDelegate(typeof(RequestDelegate), instance); }); From b366cb1cd09b43364e2ea5f6b61e3a2bc820dbbf Mon Sep 17 00:00:00 2001 From: Pranav K Date: Thu, 27 Mar 2014 18:30:24 -0700 Subject: [PATCH 031/987] Updating CoreCLR package versions --- samples/KWebStartup/project.json | 6 +++--- src/Microsoft.AspNet.Hosting/project.json | 2 +- src/Microsoft.AspNet.RequestContainer/project.json | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/samples/KWebStartup/project.json b/samples/KWebStartup/project.json index 70b55fad15..9b3ca4f7cf 100644 --- a/samples/KWebStartup/project.json +++ b/samples/KWebStartup/project.json @@ -24,9 +24,9 @@ "System.Resources.ResourceManager": "4.0.0.0", "System.Runtime": "4.0.20.0", "System.Runtime.Extensions": "4.0.10.0", - "System.Runtime.InteropServices": "4.0.10.0", - "System.Text.Encoding": "4.0.10.0", - "System.Threading.Tasks": "4.0.0.0" + "System.Runtime.InteropServices": "4.0.20.0", + "System.Text.Encoding": "4.0.20.0", + "System.Threading.Tasks": "4.0.10.0" } } } diff --git a/src/Microsoft.AspNet.Hosting/project.json b/src/Microsoft.AspNet.Hosting/project.json index 3f0cca6268..be245644fd 100644 --- a/src/Microsoft.AspNet.Hosting/project.json +++ b/src/Microsoft.AspNet.Hosting/project.json @@ -24,7 +24,7 @@ "System.Runtime": "4.0.20.0", "System.Runtime.Extensions": "4.0.10.0", "System.Threading": "4.0.0.0", - "System.Threading.Tasks": "4.0.0.0" + "System.Threading.Tasks": "4.0.10.0" } } } diff --git a/src/Microsoft.AspNet.RequestContainer/project.json b/src/Microsoft.AspNet.RequestContainer/project.json index b89873123e..a438c15933 100644 --- a/src/Microsoft.AspNet.RequestContainer/project.json +++ b/src/Microsoft.AspNet.RequestContainer/project.json @@ -16,7 +16,7 @@ "System.Runtime": "4.0.20.0", "System.Runtime.Extensions": "4.0.10.0", "System.Threading": "4.0.0.0", - "System.Threading.Tasks": "4.0.0.0" + "System.Threading.Tasks": "4.0.10.0" } } } From 8ca4a331e2766efe243993cabbbbca79f6498d17 Mon Sep 17 00:00:00 2001 From: Javier Calvarro Nelson Date: Thu, 3 Apr 2014 17:45:05 -0700 Subject: [PATCH 032/987] Created an in memory host for testing purposes and added the appropriate APIs to allow sending requests through the pipeline easily. --- Hosting.sln | 24 +- .../RequestInformation.cs | 34 +++ .../ResponseInformation.cs | 29 +++ src/Microsoft.AspNet.TestHost/TestClient.cs | 206 ++++++++++++++++++ src/Microsoft.AspNet.TestHost/TestServer.cs | 109 +++++++++ src/Microsoft.AspNet.TestHost/project.json | 32 +++ .../TestApplicationEnvironment.cs | 29 +++ .../TestClientTests.cs | 153 +++++++++++++ .../TestServerTests.cs | 74 +++++++ .../project.json | 41 ++++ 10 files changed, 726 insertions(+), 5 deletions(-) create mode 100644 src/Microsoft.AspNet.TestHost/RequestInformation.cs create mode 100644 src/Microsoft.AspNet.TestHost/ResponseInformation.cs create mode 100644 src/Microsoft.AspNet.TestHost/TestClient.cs create mode 100644 src/Microsoft.AspNet.TestHost/TestServer.cs create mode 100644 src/Microsoft.AspNet.TestHost/project.json create mode 100644 test/Microsoft.AspNet.TestHost.Tests/TestApplicationEnvironment.cs create mode 100644 test/Microsoft.AspNet.TestHost.Tests/TestClientTests.cs create mode 100644 test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs create mode 100644 test/Microsoft.AspNet.TestHost.Tests/project.json diff --git a/Hosting.sln b/Hosting.sln index 76c17f7d3e..164d969b42 100644 --- a/Hosting.sln +++ b/Hosting.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 2013 -VisualStudioVersion = 12.0.21005.1 +VisualStudioVersion = 12.0.30319.0 MinimumVisualStudioVersion = 10.0.40219.1 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{E0497F39-AFFB-4819-A116-E39E361915AB}" EndProject @@ -27,6 +27,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "KWebStartup.k10", "samples\ EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "KWebStartup.net45", "samples\KWebStartup\KWebStartup.net45.csproj", "{B5939234-73ED-4DAD-A2C6-D61AA6DFB406}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.AspNet.TestHost.Tests.net45", "test\Microsoft.AspNet.TestHost.Tests\Microsoft.AspNet.TestHost.Tests.net45.csproj", "{A19DBFCE-7B43-4BC6-9C3B-A47EBB65E145}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.AspNet.TestHost.net45", "src\Microsoft.AspNet.TestHost\Microsoft.AspNet.TestHost.net45.csproj", "{25E1550A-A73F-4E06-9F13-9F72695ADFC8}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -61,19 +65,29 @@ Global {B5939234-73ED-4DAD-A2C6-D61AA6DFB406}.Debug|Any CPU.Build.0 = Debug|Any CPU {B5939234-73ED-4DAD-A2C6-D61AA6DFB406}.Release|Any CPU.ActiveCfg = Release|Any CPU {B5939234-73ED-4DAD-A2C6-D61AA6DFB406}.Release|Any CPU.Build.0 = Release|Any CPU + {A19DBFCE-7B43-4BC6-9C3B-A47EBB65E145}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {A19DBFCE-7B43-4BC6-9C3B-A47EBB65E145}.Debug|Any CPU.Build.0 = Debug|Any CPU + {A19DBFCE-7B43-4BC6-9C3B-A47EBB65E145}.Release|Any CPU.ActiveCfg = Release|Any CPU + {A19DBFCE-7B43-4BC6-9C3B-A47EBB65E145}.Release|Any CPU.Build.0 = Release|Any CPU + {25E1550A-A73F-4E06-9F13-9F72695ADFC8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {25E1550A-A73F-4E06-9F13-9F72695ADFC8}.Debug|Any CPU.Build.0 = Debug|Any CPU + {25E1550A-A73F-4E06-9F13-9F72695ADFC8}.Release|Any CPU.ActiveCfg = Release|Any CPU + {25E1550A-A73F-4E06-9F13-9F72695ADFC8}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection GlobalSection(NestedProjects) = preSolution - {93FB86DB-7D2A-46CE-AFD2-0B53E6A8CF69} = {E0497F39-AFFB-4819-A116-E39E361915AB} - {EB784E77-FD42-46EC-9C8C-502B78962407} = {E0497F39-AFFB-4819-A116-E39E361915AB} + {D546290B-E280-4D99-BA9C-0D364A0AFB54} = {93FB86DB-7D2A-46CE-AFD2-0B53E6A8CF69} + {DBB72F0F-755D-41CF-8FE2-F4B6AE214E91} = {EB784E77-FD42-46EC-9C8C-502B78962407} {80588AF3-6B14-4D11-9DC4-1EF6453B54C9} = {FEB39027-9158-4DE2-997F-7ADAEF8188D0} {F4C7B46C-B39F-4172-9C3A-05352183D469} = {93FB86DB-7D2A-46CE-AFD2-0B53E6A8CF69} - {D546290B-E280-4D99-BA9C-0D364A0AFB54} = {93FB86DB-7D2A-46CE-AFD2-0B53E6A8CF69} {FD9833B9-3FB1-4612-BBB4-64F539DB0F8B} = {EB784E77-FD42-46EC-9C8C-502B78962407} - {DBB72F0F-755D-41CF-8FE2-F4B6AE214E91} = {EB784E77-FD42-46EC-9C8C-502B78962407} + {93FB86DB-7D2A-46CE-AFD2-0B53E6A8CF69} = {E0497F39-AFFB-4819-A116-E39E361915AB} + {EB784E77-FD42-46EC-9C8C-502B78962407} = {E0497F39-AFFB-4819-A116-E39E361915AB} {C0235BA1-9198-42C0-92D8-7578E9B9D96B} = {C30C98CD-3D69-4AE9-B680-0E0E6D8834C6} {B5939234-73ED-4DAD-A2C6-D61AA6DFB406} = {C30C98CD-3D69-4AE9-B680-0E0E6D8834C6} + {A19DBFCE-7B43-4BC6-9C3B-A47EBB65E145} = {FEB39027-9158-4DE2-997F-7ADAEF8188D0} + {25E1550A-A73F-4E06-9F13-9F72695ADFC8} = {93FB86DB-7D2A-46CE-AFD2-0B53E6A8CF69} EndGlobalSection EndGlobal diff --git a/src/Microsoft.AspNet.TestHost/RequestInformation.cs b/src/Microsoft.AspNet.TestHost/RequestInformation.cs new file mode 100644 index 0000000000..eabfc0213a --- /dev/null +++ b/src/Microsoft.AspNet.TestHost/RequestInformation.cs @@ -0,0 +1,34 @@ +using System; +using System.Collections.Generic; +using System.IO; +using Microsoft.AspNet.HttpFeature; + +namespace Microsoft.AspNet.TestHost +{ + internal class RequestInformation : IHttpRequestInformation + { + public RequestInformation() + { + Headers = new Dictionary(StringComparer.OrdinalIgnoreCase); + PathBase = ""; + Body = Stream.Null; + Protocol = "HTTP/1.1"; + } + + public Stream Body { get; set; } + + public IDictionary Headers { get; set; } + + public string Method { get; set; } + + public string Path { get; set; } + + public string PathBase { get; set; } + + public string Protocol { get; set; } + + public string QueryString { get; set; } + + public string Scheme { get; set; } + } +} diff --git a/src/Microsoft.AspNet.TestHost/ResponseInformation.cs b/src/Microsoft.AspNet.TestHost/ResponseInformation.cs new file mode 100644 index 0000000000..7000b081c5 --- /dev/null +++ b/src/Microsoft.AspNet.TestHost/ResponseInformation.cs @@ -0,0 +1,29 @@ +using System; +using System.Collections.Generic; +using System.IO; +using Microsoft.AspNet.HttpFeature; + +namespace Microsoft.AspNet.TestHost +{ + internal class ResponseInformation : IHttpResponseInformation + { + public ResponseInformation() + { + Headers = new Dictionary(StringComparer.OrdinalIgnoreCase); + Body = new MemoryStream(); + } + + public int StatusCode { get; set; } + + public string ReasonPhrase { get; set; } + + public IDictionary Headers { get; set; } + + public Stream Body { get; set; } + + public void OnSendingHeaders(Action callback, object state) + { + // TODO: Figure out how to implement this thing. + } + } +} diff --git a/src/Microsoft.AspNet.TestHost/TestClient.cs b/src/Microsoft.AspNet.TestHost/TestClient.cs new file mode 100644 index 0000000000..e5f5fb6778 --- /dev/null +++ b/src/Microsoft.AspNet.TestHost/TestClient.cs @@ -0,0 +1,206 @@ +using System; +using System.Collections.Generic; +using System.Globalization; +using System.IO; +using System.Text; +using System.Threading.Tasks; +using Microsoft.AspNet.Abstractions; +using Microsoft.AspNet.FeatureModel; +using Microsoft.AspNet.HttpFeature; +using Microsoft.AspNet.PipelineCore; + +namespace Microsoft.AspNet.TestHost +{ + public class TestClient + { + private readonly Func _pipeline; + + public TestClient(Func pipeline) + { + _pipeline = pipeline; + } + + public async Task SendAsync(string method, + string url, + IDictionary headers = null, + Stream body = null, + Action onSendingRequest = null) + { + return await SendAsync(method, new Uri(url), headers, body, onSendingRequest); + } + + public async Task SendAsync(string method, + Uri uri, + IDictionary headers = null, + Stream body = null, + Action onSendingRequest = null) + { + var request = CreateRequest(method, uri, headers, body); + var response = new ResponseInformation(); + + var features = new FeatureCollection(); + features.Add(typeof(IHttpRequestInformation), request); + features.Add(typeof(IHttpResponseInformation), response); + var httpContext = new DefaultHttpContext(features); + + if (onSendingRequest != null) + { + onSendingRequest(httpContext.Request); + } + await _pipeline(features); + + response.Body.Seek(0, SeekOrigin.Begin); + return httpContext.Response; + } + + private static IHttpRequestInformation CreateRequest( + string method, + Uri uri, + IDictionary headers, + Stream body) + { + var request = new RequestInformation(); + request.Method = method; + request.Scheme = uri.Scheme; + request.Path = PathString.FromUriComponent(uri).Value; + request.QueryString = QueryString.FromUriComponent(uri).Value; + request.Headers = headers ?? request.Headers; + if (!request.Headers.ContainsKey("Host")) + { + var host = new string[1]; + if (uri.IsDefaultPort) + { + host[0] = uri.Host; + } + else + { + host[0] = uri.GetComponents(UriComponents.HostAndPort, UriFormat.UriEscaped); + } + request.Headers["Host"] = host; + } + + if (body != null) + { + EnsureContentLength(request.Headers, body); + request.Body = body; + } + else + { + request.Body = Stream.Null; + } + return request; + } + + public async Task GetAsync(string url) + { + var uri = new Uri(url); + return await GetAsync(uri); + } + + public async Task GetAsync(Uri uri) + { + return await SendAsync("GET", uri); + } + + public async Task GetStringAsync(string url) + { + var uri = new Uri(url); + return await GetStringAsync(uri); + } + + public async Task GetStringAsync(Uri uri) + { + var response = await GetAsync(uri); + return await new StreamReader(response.Body).ReadToEndAsync(); + } + + public async Task GetStreamAsync(string url) + { + var uri = new Uri(url); + return await GetStreamAsync(uri); + } + + public async Task GetStreamAsync(Uri uri) + { + var response = await GetAsync(uri); + return response.Body; + } + + public async Task PostAsync( + string url, + string content, + string contentType, + Action onSendingRequest = null) + { + return await PostAsync(new Uri(url), content, contentType, onSendingRequest); + } + + public async Task PostAsync( + Uri url, + string content, + string contentType, + Action onSendingRequest = null) + { + var bytes = GetBytes(content); + var headers = CreateContentHeaders(contentType, bytes.Length); + var body = new MemoryStream(bytes); + + return await SendAsync("POST", url, headers, body, onSendingRequest); + } + + public async Task PutAsync( + string url, + string content, + string contentType, + Action onSendingRequest = null) + { + return await PutAsync(new Uri(url), content, contentType, onSendingRequest); + } + + public async Task PutAsync( + Uri url, + string content, + string contentType, + Action onSendingRequest = null) + { + var bytes = GetBytes(content); + var headers = CreateContentHeaders(contentType, bytes.Length); + var body = new MemoryStream(bytes); + + return await SendAsync("PUT", url, headers, body, onSendingRequest); + } + + public async Task DeleteAsync(string url) + { + return await DeleteAsync(new Uri(url)); + } + + public async Task DeleteAsync(Uri uri) + { + return await SendAsync("DELETE", uri); + } + + private static void EnsureContentLength(IDictionary dictionary, Stream body) + { + if (!dictionary.ContainsKey("Content-Length")) + { + dictionary["Content-Length"] = new[] { body.Length.ToString(CultureInfo.InvariantCulture) }; + } + } + + private static byte[] GetBytes(string content) + { + var bytes = Encoding.UTF8.GetBytes(content); + return bytes; + } + + private static Dictionary CreateContentHeaders(string contentType, int contentLength) + { + return new Dictionary(StringComparer.OrdinalIgnoreCase) + { + { "Content-Type", new [] { contentType } }, + { "Content-Length", new [] { contentLength.ToString(CultureInfo.InvariantCulture) } } + }; + } + } +} diff --git a/src/Microsoft.AspNet.TestHost/TestServer.cs b/src/Microsoft.AspNet.TestHost/TestServer.cs new file mode 100644 index 0000000000..9256501426 --- /dev/null +++ b/src/Microsoft.AspNet.TestHost/TestServer.cs @@ -0,0 +1,109 @@ +using System; +using System.Collections.Generic; +using System.Runtime.Versioning; +using System.Threading.Tasks; +using Microsoft.AspNet.Abstractions; +using Microsoft.AspNet.ConfigurationModel; +using Microsoft.AspNet.DependencyInjection; +using Microsoft.AspNet.DependencyInjection.Fallback; +using Microsoft.AspNet.Hosting; +using Microsoft.AspNet.Hosting.Server; +using Microsoft.AspNet.Hosting.Startup; +using Microsoft.Net.Runtime; + +namespace Microsoft.AspNet.TestHost +{ + public class TestServer : IServerFactory, IDisposable + { + private static readonly string ServerName = typeof(TestServer).FullName; + private static readonly ServerInformation ServerInfo = new ServerInformation(); + private Func _appDelegate; + private TestClient _handler; + + public TestServer(IConfiguration config, IServiceProvider serviceProvider, Action appStartup) + { + var env = serviceProvider.GetService(); + if (env == null) + { + throw new ArgumentException("IApplicationEnvironment couldn't be resolved.", "serviceProvider"); + } + + HostingContext hostContext = new HostingContext() + { + ApplicationName = env.ApplicationName, + Configuration = config, + ServerFactory = this, + Services = serviceProvider, + ApplicationStartup = appStartup + }; + + var engine = serviceProvider.GetService(); + var disposable = engine.Start(hostContext); + } + + public static TestServer Create(IServiceProvider provider) + { + var startupLoader = new StartupLoader(provider, new NullStartupLoader()); + var name = typeof(TStartup).AssemblyQualifiedName; + var diagnosticMessages = new List(); + return Create(provider, startupLoader.LoadStartup(name, diagnosticMessages)); + } + + public static TestServer Create(IServiceProvider provider, Action app) + { + var collection = new ServiceCollection(); + var hostingServices = HostingServices.GetDefaultServices(); + + var config = new Configuration(); + collection.Add(hostingServices); + + var serviceProvider = collection.BuildServiceProvider(provider); + return new TestServer(config, serviceProvider, app); + } + + public TestClient Handler + { + get + { + if (_handler == null) + { + _handler = new TestClient(_appDelegate); + } + + return _handler; + } + } + + public IServerInformation Initialize(IConfiguration configuration) + { + return ServerInfo; + } + + public IDisposable Start(IServerInformation serverInformation, Func application) + { + if (!(serverInformation.GetType() == typeof(ServerInformation))) + { + throw new ArgumentException(string.Format("The server must be {0}", ServerName), "serverInformation"); + } + + _appDelegate = application; + + return this; + } + + public void Dispose() + { + // IServerFactory.Start needs to return an IDisposable. Typically this IDisposable instance is used to + // clear any server resources when tearing down the host. In our case we don't have anything to clear + // so we just implement IDisposable and do nothing. + } + + private class ServerInformation : IServerInformation + { + public string Name + { + get { return TestServer.ServerName; } + } + } + } +} diff --git a/src/Microsoft.AspNet.TestHost/project.json b/src/Microsoft.AspNet.TestHost/project.json new file mode 100644 index 0000000000..48c00f0871 --- /dev/null +++ b/src/Microsoft.AspNet.TestHost/project.json @@ -0,0 +1,32 @@ +{ + "version" : "0.1-alpha-*", + "dependencies": { + "System.Reflection": "4.0.10.0", + "System.Runtime" : "4.0.20.0", + "Microsoft.AspNet.Abstractions": "0.1-alpha-*", + "Microsoft.AspNet.ConfigurationModel": "0.1-alpha-*", + "Microsoft.AspNet.DependencyInjection": "0.1-alpha-*", + "Microsoft.AspNet.FeatureModel": "0.1-alpha-*", + "Microsoft.AspNet.Hosting": "0.1-alpha-*", + "Microsoft.AspNet.HttpFeature": "0.1-alpha-*", + "Microsoft.AspNet.PipelineCore": "0.1-alpha-*", + "Microsoft.AspNet.Security.DataProtection": "0.1-alpha-*" + }, + "configurations": { + "net45": { + "dependencies": { + "System.Collections": "4.0.0.0", + "System.ComponentModel": "4.0.0.0", + "System.Globalization": "4.0.10.0", + "System.Linq": "4.0.0.0", + "System.Reflection": "4.0.10.0", + "System.Runtime": "4.0.20.0", + "System.Runtime.Extensions": "4.0.10.0", + "System.Runtime.Serialization.Primitives": "4.0.0.0", + "System.Threading": "4.0.0.0", + "System.Threading.Tasks": "4.0.0.0", + "System.Threading.Thread": "4.0.0.0" + } + } + } +} \ No newline at end of file diff --git a/test/Microsoft.AspNet.TestHost.Tests/TestApplicationEnvironment.cs b/test/Microsoft.AspNet.TestHost.Tests/TestApplicationEnvironment.cs new file mode 100644 index 0000000000..93fb40c3f5 --- /dev/null +++ b/test/Microsoft.AspNet.TestHost.Tests/TestApplicationEnvironment.cs @@ -0,0 +1,29 @@ +using System; +using System.Runtime.Versioning; +using Microsoft.Net.Runtime; + +namespace Microsoft.AspNet.TestHost.Tests +{ + public class TestApplicationEnvironment : IApplicationEnvironment + { + public string ApplicationName + { + get { return "Test App environment"; } + } + + public string Version + { + get { return "1.0.0"; } + } + + public string ApplicationBasePath + { + get { return Environment.CurrentDirectory; } + } + + public FrameworkName TargetFramework + { + get { return new FrameworkName(".NETFramework", new Version(4, 5)); } + } + } +} diff --git a/test/Microsoft.AspNet.TestHost.Tests/TestClientTests.cs b/test/Microsoft.AspNet.TestHost.Tests/TestClientTests.cs new file mode 100644 index 0000000000..b18dd0ccfa --- /dev/null +++ b/test/Microsoft.AspNet.TestHost.Tests/TestClientTests.cs @@ -0,0 +1,153 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Runtime.Versioning; +using System.Threading.Tasks; +using Microsoft.AspNet.Abstractions; +using Microsoft.AspNet.DependencyInjection; +using Microsoft.AspNet.DependencyInjection.Fallback; +using Microsoft.Net.Runtime; +using Xunit; + +namespace Microsoft.AspNet.TestHost.Tests +{ + public class TestClientTests + { + private readonly IServiceProvider _services; + private readonly TestServer _server; + + public TestClientTests() + { + _services = new ServiceCollection() + .AddSingleton() + .BuildServiceProvider(); + + _server = TestServer.Create(_services, app => app.Run(async ctx => { })); + } + + [Fact] + public async Task SendAsync_ConfiguresRequestProperly() + { + // Arrange + var client = _server.Handler; + + // Act + var response = await client.SendAsync("GET", "http://localhost:12345/Home/Index?id=3&name=peter#fragment"); + var request = response.HttpContext.Request; + + // Assert + Assert.NotNull(request); + Assert.Equal("HTTP/1.1", request.Protocol); + Assert.Equal("GET", request.Method); + Assert.Equal("http", request.Scheme); + Assert.Equal("localhost:12345", request.Host.Value); + Assert.Equal("", request.PathBase.Value); + Assert.True(request.Path.HasValue); + Assert.Equal("/Home/Index", request.Path.Value); + Assert.Equal("?id=3&name=peter", request.QueryString.Value); + Assert.Null(request.ContentLength); + Assert.Equal(1, request.Headers.Count); + Assert.True(request.Headers.ContainsKey("Host")); + } + + [Fact] + public async Task SendAsync_InvokesCallbackWhenPassed() + { + // Arrange + var client = _server.Handler; + var invoked = false; + + // Act + var response = await client.SendAsync("GET", "http://localhost:12345/", null, null, _ => invoked = true); + + // Assert + Assert.True(invoked); + } + + [Fact] + public async Task SendAsync_RespectsExistingHost() + { + // Arrange + var client = _server.Handler; + var headers = new Dictionary { { "Host", new string[] { "server:12345" } } }; + + // Act + var response = await client.SendAsync("GET", "http://localhost:12345/Home/", headers); + var request = response.HttpContext.Request; + + // Assert + Assert.Equal("server:12345", request.Host.Value); + } + + [Fact] + public async Task SendAsync_RespectsArgumentBody() + { + // Arrange + var client = _server.Handler; + var headers = new Dictionary { { "Content-Type", new string[] { "text/plain" } } }; + var body = new MemoryStream(); + new StreamWriter(body).Write("Hello world"); + body.Position = 0; + + // Act + var response = await client.SendAsync("POST", "http://host/", headers, body); + var request = response.HttpContext.Request; + + // Assert + Assert.Same(body, request.Body); + Assert.Equal(0, request.Body.Position); + Assert.Equal(body.Length, request.ContentLength); + } + + [Fact] + public async Task SendAsync_RewindsTheResponseStream() + { + // Arrange + var server = TestServer.Create(_services, app => app.Run(ctx => ctx.Response.WriteAsync("Hello world"))); + var client = server.Handler; + + // Act + var response = await client.SendAsync("GET", "http://localhost"); + + // Assert + Assert.Equal(0, response.Body.Position); + Assert.Equal("Hello world", new StreamReader(response.Body).ReadToEnd()); + } + + [Fact] + public async Task PutAsyncWorks() + { + // Arrange + RequestDelegate appDelegate = async ctx => + await ctx.Response.WriteAsync(new StreamReader(ctx.Request.Body).ReadToEnd()); + var server = TestServer.Create(_services, app => app.Run(appDelegate)); + var client = server.Handler; + + // Act + var response = await client.PutAsync("http://localhost:12345", "Hello world", "text/plain"); + var request = response.HttpContext.Request; + + // Assert + Assert.Equal("PUT", request.Method); + Assert.Equal("Hello world", new StreamReader(response.Body).ReadToEnd()); + } + + [Fact] + public async Task PostAsyncWorks() + { + // Arrange + RequestDelegate appDelegate = async ctx => + await ctx.Response.WriteAsync(new StreamReader(ctx.Request.Body).ReadToEnd()); + var server = TestServer.Create(_services, app => app.Run(appDelegate)); + var client = server.Handler; + + // Act + var response = await client.PostAsync("http://localhost:12345", "Hello world", "text/plain"); + var request = response.HttpContext.Request; + + // Assert + Assert.Equal("POST", request.Method); + Assert.Equal("Hello world", new StreamReader(response.Body).ReadToEnd()); + } + } +} diff --git a/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs b/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs new file mode 100644 index 0000000000..62416f99f1 --- /dev/null +++ b/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs @@ -0,0 +1,74 @@ +using System; +using System.IO; +using System.Runtime.Versioning; +using System.Threading.Tasks; +using Microsoft.AspNet.Abstractions; +using Microsoft.AspNet.DependencyInjection; +using Microsoft.AspNet.DependencyInjection.Fallback; +using Microsoft.Net.Runtime; +using Xunit; + +namespace Microsoft.AspNet.TestHost.Tests +{ + public class TestServerTests + { + [Fact] + public void CreateWithDelegate() + { + // Arrange + var services = new ServiceCollection() + .AddSingleton() + .BuildServiceProvider(); + + // Act & Assert + Assert.DoesNotThrow(() => TestServer.Create(services, app => { })); + } + + [Fact] + public async Task CreateWithGeneric() + { + // Arrange + var services = new ServiceCollection() + .AddSingleton() + .BuildServiceProvider(); + + var server = TestServer.Create(services); + var client = server.Handler; + + // Act + var response = await client.GetAsync("http://any"); + + // Assert + Assert.Equal("Startup", new StreamReader(response.Body).ReadToEnd()); + } + + [Fact] + public void ThrowsIfNoApplicationEnvironmentIsRegisteredWithTheProvider() + { + // Arrange + var services = new ServiceCollection() + .BuildServiceProvider(); + + // Act & Assert + Assert.Throws( + "serviceProvider", + () => TestServer.Create(services)); + } + + public class Startup + { + public void Configuration(IBuilder builder) + { + builder.Run(ctx => ctx.Response.WriteAsync("Startup")); + } + } + + public class AnotherStartup + { + public void Configuration(IBuilder builder) + { + builder.Run(ctx => ctx.Response.WriteAsync("Another Startup")); + } + } + } +} diff --git a/test/Microsoft.AspNet.TestHost.Tests/project.json b/test/Microsoft.AspNet.TestHost.Tests/project.json new file mode 100644 index 0000000000..34ba146fef --- /dev/null +++ b/test/Microsoft.AspNet.TestHost.Tests/project.json @@ -0,0 +1,41 @@ +{ + "version" : "0.1-alpha-*", + "dependencies": { + "System.Reflection": "4.0.10.0", + "System.Runtime" : "4.0.20.0", + "Microsoft.AspNet.Abstractions": "0.1-alpha-*", + "Microsoft.AspNet.ConfigurationModel": "0.1-alpha-*", + "Microsoft.AspNet.DependencyInjection": "0.1-alpha-*", + "Microsoft.AspNet.FeatureModel": "0.1-alpha-*", + "Microsoft.AspNet.Hosting": "", + "Microsoft.AspNet.TestHost": "", + "Microsoft.AspNet.HttpFeature": "0.1-alpha-*", + "Microsoft.AspNet.PipelineCore": "0.1-alpha-*", + "Microsoft.AspNet.Security.DataProtection": "0.1-alpha-*", + "xunit.abstractions": "2.0.0-aspnet-*", + "xunit.assert": "2.0.0-aspnet-*", + "xunit.core": "2.0.0-aspnet-*", + "xunit.execution": "2.0.0-aspnet-*", + "Xunit.KRunner": "0.1-alpha-*" + }, + "commands": { + "test": "Xunit.KRunner" + }, + "configurations": { + "net45": { + "dependencies": { + "System.Collections": "4.0.0.0", + "System.ComponentModel": "4.0.0.0", + "System.Globalization": "4.0.10.0", + "System.Linq": "4.0.0.0", + "System.Reflection": "4.0.10.0", + "System.Runtime": "4.0.20.0", + "System.Runtime.Extensions": "4.0.10.0", + "System.Runtime.Serialization.Primitives": "4.0.0.0", + "System.Threading": "4.0.0.0", + "System.Threading.Tasks": "4.0.0.0", + "System.Threading.Thread": "4.0.0.0" + } + } + } +} \ No newline at end of file From 73a00a1b21106a5fcdded1982bf3d89aa7e1f742 Mon Sep 17 00:00:00 2001 From: Javier Calvarro Nelson Date: Wed, 9 Apr 2014 14:00:06 -0700 Subject: [PATCH 033/987] Bumped the version of System.Threading.Tasks to 4.0.10.0 to fix the build break --- test/Microsoft.AspNet.TestHost.Tests/project.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/Microsoft.AspNet.TestHost.Tests/project.json b/test/Microsoft.AspNet.TestHost.Tests/project.json index 34ba146fef..3b30a0aed7 100644 --- a/test/Microsoft.AspNet.TestHost.Tests/project.json +++ b/test/Microsoft.AspNet.TestHost.Tests/project.json @@ -33,7 +33,7 @@ "System.Runtime.Extensions": "4.0.10.0", "System.Runtime.Serialization.Primitives": "4.0.0.0", "System.Threading": "4.0.0.0", - "System.Threading.Tasks": "4.0.0.0", + "System.Threading.Tasks": "4.0.10.0", "System.Threading.Thread": "4.0.0.0" } } From 89e532873e463ce7531af659427cac14378bd19d Mon Sep 17 00:00:00 2001 From: Javier Calvarro Nelson Date: Wed, 9 Apr 2014 14:05:01 -0700 Subject: [PATCH 034/987] Bumped the version of System.Threading.Tasks to 4.0.10.0 to fix the build break in the remaining project.json --- src/Microsoft.AspNet.TestHost/project.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Microsoft.AspNet.TestHost/project.json b/src/Microsoft.AspNet.TestHost/project.json index 48c00f0871..0028a68196 100644 --- a/src/Microsoft.AspNet.TestHost/project.json +++ b/src/Microsoft.AspNet.TestHost/project.json @@ -24,7 +24,7 @@ "System.Runtime.Extensions": "4.0.10.0", "System.Runtime.Serialization.Primitives": "4.0.0.0", "System.Threading": "4.0.0.0", - "System.Threading.Tasks": "4.0.0.0", + "System.Threading.Tasks": "4.0.10.0", "System.Threading.Thread": "4.0.0.0" } } From e3c64aeb55893effd104c88b1ced3e80f8711c9f Mon Sep 17 00:00:00 2001 From: David Fowler Date: Wed, 9 Apr 2014 22:08:21 -0700 Subject: [PATCH 035/987] Updated to use the new tooling --- Hosting.sln | 141 ++++++++++-------- samples/KWebStartup/KWebStartup.kproj | 26 ++++ samples/KWebStartup/project.json | 2 +- .../Microsoft.AspNet.Hosting.kproj | 49 ++++++ .../Microsoft.AspNet.RequestContainer.kproj | 27 ++++ .../Microsoft.AspNet.TestHost.kproj | 29 ++++ src/Microsoft.AspNet.TestHost/project.json | 14 +- .../Microsoft.AspNet.Hosting.Tests.kproj | 31 ++++ .../project.json | 3 - .../Microsoft.AspNet.TestHost.Tests.kproj | 29 ++++ .../project.json | 19 +-- 11 files changed, 273 insertions(+), 97 deletions(-) create mode 100644 samples/KWebStartup/KWebStartup.kproj create mode 100644 src/Microsoft.AspNet.Hosting/Microsoft.AspNet.Hosting.kproj create mode 100644 src/Microsoft.AspNet.RequestContainer/Microsoft.AspNet.RequestContainer.kproj create mode 100644 src/Microsoft.AspNet.TestHost/Microsoft.AspNet.TestHost.kproj create mode 100644 test/Microsoft.AspNet.Hosting.Tests/Microsoft.AspNet.Hosting.Tests.kproj create mode 100644 test/Microsoft.AspNet.TestHost.Tests/Microsoft.AspNet.TestHost.Tests.kproj diff --git a/Hosting.sln b/Hosting.sln index 164d969b42..afb4be9861 100644 --- a/Hosting.sln +++ b/Hosting.sln @@ -1,93 +1,106 @@  Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 2013 -VisualStudioVersion = 12.0.30319.0 +VisualStudioVersion = 12.0.30327.0 MinimumVisualStudioVersion = 10.0.40219.1 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{E0497F39-AFFB-4819-A116-E39E361915AB}" EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{FEB39027-9158-4DE2-997F-7ADAEF8188D0}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.AspNet.Hosting.net45", "src\Microsoft.AspNet.Hosting\Microsoft.AspNet.Hosting.net45.csproj", "{D546290B-E280-4D99-BA9C-0D364A0AFB54}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.AspNet.Hosting.k10", "src\Microsoft.AspNet.Hosting\Microsoft.AspNet.Hosting.k10.csproj", "{DBB72F0F-755D-41CF-8FE2-F4B6AE214E91}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.AspNet.Hosting.Tests.net45", "test\Microsoft.AspNet.Hosting.Tests\Microsoft.AspNet.Hosting.Tests.net45.csproj", "{80588AF3-6B14-4D11-9DC4-1EF6453B54C9}" -EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "samples", "samples", "{C30C98CD-3D69-4AE9-B680-0E0E6D8834C6}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.AspNet.RequestContainer.net45", "src\Microsoft.AspNet.RequestContainer\Microsoft.AspNet.RequestContainer.net45.csproj", "{F4C7B46C-B39F-4172-9C3A-05352183D469}" +Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNet.TestHost.Tests", "test\Microsoft.AspNet.TestHost.Tests\Microsoft.AspNet.TestHost.Tests.kproj", "{0ACB2719-9484-49B5-B8E3-117091192511}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.AspNet.RequestContainer.k10", "src\Microsoft.AspNet.RequestContainer\Microsoft.AspNet.RequestContainer.k10.csproj", "{FD9833B9-3FB1-4612-BBB4-64F539DB0F8B}" +Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNet.TestHost", "src\Microsoft.AspNet.TestHost\Microsoft.AspNet.TestHost.kproj", "{1A415A3F-1081-45DB-809B-EE19CEA02DC0}" EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "net45", "net45", "{93FB86DB-7D2A-46CE-AFD2-0B53E6A8CF69}" +Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNet.Hosting", "src\Microsoft.AspNet.Hosting\Microsoft.AspNet.Hosting.kproj", "{3944F036-7E75-47E8-AA52-C4B89A64EC3A}" EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "k10", "k10", "{EB784E77-FD42-46EC-9C8C-502B78962407}" +Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNet.Hosting.Tests", "test\Microsoft.AspNet.Hosting.Tests\Microsoft.AspNet.Hosting.Tests.kproj", "{D4F18D58-52B1-435D-A012-10F2CDF158C4}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "KWebStartup.k10", "samples\KWebStartup\KWebStartup.k10.csproj", "{C0235BA1-9198-42C0-92D8-7578E9B9D96B}" +Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNet.RequestContainer", "src\Microsoft.AspNet.RequestContainer\Microsoft.AspNet.RequestContainer.kproj", "{374A5B0C-3E93-4A23-A4A0-EE2AB6DF7814}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "KWebStartup.net45", "samples\KWebStartup\KWebStartup.net45.csproj", "{B5939234-73ED-4DAD-A2C6-D61AA6DFB406}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.AspNet.TestHost.Tests.net45", "test\Microsoft.AspNet.TestHost.Tests\Microsoft.AspNet.TestHost.Tests.net45.csproj", "{A19DBFCE-7B43-4BC6-9C3B-A47EBB65E145}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.AspNet.TestHost.net45", "src\Microsoft.AspNet.TestHost\Microsoft.AspNet.TestHost.net45.csproj", "{25E1550A-A73F-4E06-9F13-9F72695ADFC8}" +Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "KWebStartup", "samples\KWebStartup\KWebStartup.kproj", "{A2F321A5-3F55-4413-B357-EEF85DC0ECA6}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU + Debug|Mixed Platforms = Debug|Mixed Platforms + Debug|x86 = Debug|x86 Release|Any CPU = Release|Any CPU + Release|Mixed Platforms = Release|Mixed Platforms + Release|x86 = Release|x86 EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution - {D546290B-E280-4D99-BA9C-0D364A0AFB54}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {D546290B-E280-4D99-BA9C-0D364A0AFB54}.Debug|Any CPU.Build.0 = Debug|Any CPU - {D546290B-E280-4D99-BA9C-0D364A0AFB54}.Release|Any CPU.ActiveCfg = Release|Any CPU - {D546290B-E280-4D99-BA9C-0D364A0AFB54}.Release|Any CPU.Build.0 = Release|Any CPU - {DBB72F0F-755D-41CF-8FE2-F4B6AE214E91}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {DBB72F0F-755D-41CF-8FE2-F4B6AE214E91}.Debug|Any CPU.Build.0 = Debug|Any CPU - {DBB72F0F-755D-41CF-8FE2-F4B6AE214E91}.Release|Any CPU.ActiveCfg = Release|Any CPU - {DBB72F0F-755D-41CF-8FE2-F4B6AE214E91}.Release|Any CPU.Build.0 = Release|Any CPU - {80588AF3-6B14-4D11-9DC4-1EF6453B54C9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {80588AF3-6B14-4D11-9DC4-1EF6453B54C9}.Debug|Any CPU.Build.0 = Debug|Any CPU - {80588AF3-6B14-4D11-9DC4-1EF6453B54C9}.Release|Any CPU.ActiveCfg = Release|Any CPU - {80588AF3-6B14-4D11-9DC4-1EF6453B54C9}.Release|Any CPU.Build.0 = Release|Any CPU - {F4C7B46C-B39F-4172-9C3A-05352183D469}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {F4C7B46C-B39F-4172-9C3A-05352183D469}.Debug|Any CPU.Build.0 = Debug|Any CPU - {F4C7B46C-B39F-4172-9C3A-05352183D469}.Release|Any CPU.ActiveCfg = Release|Any CPU - {F4C7B46C-B39F-4172-9C3A-05352183D469}.Release|Any CPU.Build.0 = Release|Any CPU - {FD9833B9-3FB1-4612-BBB4-64F539DB0F8B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {FD9833B9-3FB1-4612-BBB4-64F539DB0F8B}.Debug|Any CPU.Build.0 = Debug|Any CPU - {FD9833B9-3FB1-4612-BBB4-64F539DB0F8B}.Release|Any CPU.ActiveCfg = Release|Any CPU - {FD9833B9-3FB1-4612-BBB4-64F539DB0F8B}.Release|Any CPU.Build.0 = Release|Any CPU - {C0235BA1-9198-42C0-92D8-7578E9B9D96B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {C0235BA1-9198-42C0-92D8-7578E9B9D96B}.Debug|Any CPU.Build.0 = Debug|Any CPU - {C0235BA1-9198-42C0-92D8-7578E9B9D96B}.Release|Any CPU.ActiveCfg = Release|Any CPU - {C0235BA1-9198-42C0-92D8-7578E9B9D96B}.Release|Any CPU.Build.0 = Release|Any CPU - {B5939234-73ED-4DAD-A2C6-D61AA6DFB406}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {B5939234-73ED-4DAD-A2C6-D61AA6DFB406}.Debug|Any CPU.Build.0 = Debug|Any CPU - {B5939234-73ED-4DAD-A2C6-D61AA6DFB406}.Release|Any CPU.ActiveCfg = Release|Any CPU - {B5939234-73ED-4DAD-A2C6-D61AA6DFB406}.Release|Any CPU.Build.0 = Release|Any CPU - {A19DBFCE-7B43-4BC6-9C3B-A47EBB65E145}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {A19DBFCE-7B43-4BC6-9C3B-A47EBB65E145}.Debug|Any CPU.Build.0 = Debug|Any CPU - {A19DBFCE-7B43-4BC6-9C3B-A47EBB65E145}.Release|Any CPU.ActiveCfg = Release|Any CPU - {A19DBFCE-7B43-4BC6-9C3B-A47EBB65E145}.Release|Any CPU.Build.0 = Release|Any CPU - {25E1550A-A73F-4E06-9F13-9F72695ADFC8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {25E1550A-A73F-4E06-9F13-9F72695ADFC8}.Debug|Any CPU.Build.0 = Debug|Any CPU - {25E1550A-A73F-4E06-9F13-9F72695ADFC8}.Release|Any CPU.ActiveCfg = Release|Any CPU - {25E1550A-A73F-4E06-9F13-9F72695ADFC8}.Release|Any CPU.Build.0 = Release|Any CPU + {0ACB2719-9484-49B5-B8E3-117091192511}.Debug|Any CPU.ActiveCfg = Debug|x86 + {0ACB2719-9484-49B5-B8E3-117091192511}.Debug|Mixed Platforms.ActiveCfg = Debug|x86 + {0ACB2719-9484-49B5-B8E3-117091192511}.Debug|Mixed Platforms.Build.0 = Debug|x86 + {0ACB2719-9484-49B5-B8E3-117091192511}.Debug|x86.ActiveCfg = Debug|x86 + {0ACB2719-9484-49B5-B8E3-117091192511}.Debug|x86.Build.0 = Debug|x86 + {0ACB2719-9484-49B5-B8E3-117091192511}.Release|Any CPU.ActiveCfg = Release|x86 + {0ACB2719-9484-49B5-B8E3-117091192511}.Release|Mixed Platforms.ActiveCfg = Release|x86 + {0ACB2719-9484-49B5-B8E3-117091192511}.Release|Mixed Platforms.Build.0 = Release|x86 + {0ACB2719-9484-49B5-B8E3-117091192511}.Release|x86.ActiveCfg = Release|x86 + {0ACB2719-9484-49B5-B8E3-117091192511}.Release|x86.Build.0 = Release|x86 + {1A415A3F-1081-45DB-809B-EE19CEA02DC0}.Debug|Any CPU.ActiveCfg = Debug|x86 + {1A415A3F-1081-45DB-809B-EE19CEA02DC0}.Debug|Mixed Platforms.ActiveCfg = Debug|x86 + {1A415A3F-1081-45DB-809B-EE19CEA02DC0}.Debug|Mixed Platforms.Build.0 = Debug|x86 + {1A415A3F-1081-45DB-809B-EE19CEA02DC0}.Debug|x86.ActiveCfg = Debug|x86 + {1A415A3F-1081-45DB-809B-EE19CEA02DC0}.Debug|x86.Build.0 = Debug|x86 + {1A415A3F-1081-45DB-809B-EE19CEA02DC0}.Release|Any CPU.ActiveCfg = Release|x86 + {1A415A3F-1081-45DB-809B-EE19CEA02DC0}.Release|Mixed Platforms.ActiveCfg = Release|x86 + {1A415A3F-1081-45DB-809B-EE19CEA02DC0}.Release|Mixed Platforms.Build.0 = Release|x86 + {1A415A3F-1081-45DB-809B-EE19CEA02DC0}.Release|x86.ActiveCfg = Release|x86 + {1A415A3F-1081-45DB-809B-EE19CEA02DC0}.Release|x86.Build.0 = Release|x86 + {3944F036-7E75-47E8-AA52-C4B89A64EC3A}.Debug|Any CPU.ActiveCfg = Debug|x86 + {3944F036-7E75-47E8-AA52-C4B89A64EC3A}.Debug|Mixed Platforms.ActiveCfg = Debug|x86 + {3944F036-7E75-47E8-AA52-C4B89A64EC3A}.Debug|Mixed Platforms.Build.0 = Debug|x86 + {3944F036-7E75-47E8-AA52-C4B89A64EC3A}.Debug|x86.ActiveCfg = Debug|x86 + {3944F036-7E75-47E8-AA52-C4B89A64EC3A}.Debug|x86.Build.0 = Debug|x86 + {3944F036-7E75-47E8-AA52-C4B89A64EC3A}.Release|Any CPU.ActiveCfg = Release|x86 + {3944F036-7E75-47E8-AA52-C4B89A64EC3A}.Release|Mixed Platforms.ActiveCfg = Release|x86 + {3944F036-7E75-47E8-AA52-C4B89A64EC3A}.Release|Mixed Platforms.Build.0 = Release|x86 + {3944F036-7E75-47E8-AA52-C4B89A64EC3A}.Release|x86.ActiveCfg = Release|x86 + {3944F036-7E75-47E8-AA52-C4B89A64EC3A}.Release|x86.Build.0 = Release|x86 + {D4F18D58-52B1-435D-A012-10F2CDF158C4}.Debug|Any CPU.ActiveCfg = Debug|x86 + {D4F18D58-52B1-435D-A012-10F2CDF158C4}.Debug|Mixed Platforms.ActiveCfg = Debug|x86 + {D4F18D58-52B1-435D-A012-10F2CDF158C4}.Debug|Mixed Platforms.Build.0 = Debug|x86 + {D4F18D58-52B1-435D-A012-10F2CDF158C4}.Debug|x86.ActiveCfg = Debug|x86 + {D4F18D58-52B1-435D-A012-10F2CDF158C4}.Debug|x86.Build.0 = Debug|x86 + {D4F18D58-52B1-435D-A012-10F2CDF158C4}.Release|Any CPU.ActiveCfg = Release|x86 + {D4F18D58-52B1-435D-A012-10F2CDF158C4}.Release|Mixed Platforms.ActiveCfg = Release|x86 + {D4F18D58-52B1-435D-A012-10F2CDF158C4}.Release|Mixed Platforms.Build.0 = Release|x86 + {D4F18D58-52B1-435D-A012-10F2CDF158C4}.Release|x86.ActiveCfg = Release|x86 + {D4F18D58-52B1-435D-A012-10F2CDF158C4}.Release|x86.Build.0 = Release|x86 + {374A5B0C-3E93-4A23-A4A0-EE2AB6DF7814}.Debug|Any CPU.ActiveCfg = Debug|x86 + {374A5B0C-3E93-4A23-A4A0-EE2AB6DF7814}.Debug|Mixed Platforms.ActiveCfg = Debug|x86 + {374A5B0C-3E93-4A23-A4A0-EE2AB6DF7814}.Debug|Mixed Platforms.Build.0 = Debug|x86 + {374A5B0C-3E93-4A23-A4A0-EE2AB6DF7814}.Debug|x86.ActiveCfg = Debug|x86 + {374A5B0C-3E93-4A23-A4A0-EE2AB6DF7814}.Debug|x86.Build.0 = Debug|x86 + {374A5B0C-3E93-4A23-A4A0-EE2AB6DF7814}.Release|Any CPU.ActiveCfg = Release|x86 + {374A5B0C-3E93-4A23-A4A0-EE2AB6DF7814}.Release|Mixed Platforms.ActiveCfg = Release|x86 + {374A5B0C-3E93-4A23-A4A0-EE2AB6DF7814}.Release|Mixed Platforms.Build.0 = Release|x86 + {374A5B0C-3E93-4A23-A4A0-EE2AB6DF7814}.Release|x86.ActiveCfg = Release|x86 + {374A5B0C-3E93-4A23-A4A0-EE2AB6DF7814}.Release|x86.Build.0 = Release|x86 + {A2F321A5-3F55-4413-B357-EEF85DC0ECA6}.Debug|Any CPU.ActiveCfg = Debug|x86 + {A2F321A5-3F55-4413-B357-EEF85DC0ECA6}.Debug|Mixed Platforms.ActiveCfg = Debug|x86 + {A2F321A5-3F55-4413-B357-EEF85DC0ECA6}.Debug|Mixed Platforms.Build.0 = Debug|x86 + {A2F321A5-3F55-4413-B357-EEF85DC0ECA6}.Debug|x86.ActiveCfg = Debug|x86 + {A2F321A5-3F55-4413-B357-EEF85DC0ECA6}.Debug|x86.Build.0 = Debug|x86 + {A2F321A5-3F55-4413-B357-EEF85DC0ECA6}.Release|Any CPU.ActiveCfg = Release|x86 + {A2F321A5-3F55-4413-B357-EEF85DC0ECA6}.Release|Mixed Platforms.ActiveCfg = Release|x86 + {A2F321A5-3F55-4413-B357-EEF85DC0ECA6}.Release|Mixed Platforms.Build.0 = Release|x86 + {A2F321A5-3F55-4413-B357-EEF85DC0ECA6}.Release|x86.ActiveCfg = Release|x86 + {A2F321A5-3F55-4413-B357-EEF85DC0ECA6}.Release|x86.Build.0 = Release|x86 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection GlobalSection(NestedProjects) = preSolution - {D546290B-E280-4D99-BA9C-0D364A0AFB54} = {93FB86DB-7D2A-46CE-AFD2-0B53E6A8CF69} - {DBB72F0F-755D-41CF-8FE2-F4B6AE214E91} = {EB784E77-FD42-46EC-9C8C-502B78962407} - {80588AF3-6B14-4D11-9DC4-1EF6453B54C9} = {FEB39027-9158-4DE2-997F-7ADAEF8188D0} - {F4C7B46C-B39F-4172-9C3A-05352183D469} = {93FB86DB-7D2A-46CE-AFD2-0B53E6A8CF69} - {FD9833B9-3FB1-4612-BBB4-64F539DB0F8B} = {EB784E77-FD42-46EC-9C8C-502B78962407} - {93FB86DB-7D2A-46CE-AFD2-0B53E6A8CF69} = {E0497F39-AFFB-4819-A116-E39E361915AB} - {EB784E77-FD42-46EC-9C8C-502B78962407} = {E0497F39-AFFB-4819-A116-E39E361915AB} - {C0235BA1-9198-42C0-92D8-7578E9B9D96B} = {C30C98CD-3D69-4AE9-B680-0E0E6D8834C6} - {B5939234-73ED-4DAD-A2C6-D61AA6DFB406} = {C30C98CD-3D69-4AE9-B680-0E0E6D8834C6} - {A19DBFCE-7B43-4BC6-9C3B-A47EBB65E145} = {FEB39027-9158-4DE2-997F-7ADAEF8188D0} - {25E1550A-A73F-4E06-9F13-9F72695ADFC8} = {93FB86DB-7D2A-46CE-AFD2-0B53E6A8CF69} + {0ACB2719-9484-49B5-B8E3-117091192511} = {FEB39027-9158-4DE2-997F-7ADAEF8188D0} + {1A415A3F-1081-45DB-809B-EE19CEA02DC0} = {E0497F39-AFFB-4819-A116-E39E361915AB} + {3944F036-7E75-47E8-AA52-C4B89A64EC3A} = {E0497F39-AFFB-4819-A116-E39E361915AB} + {D4F18D58-52B1-435D-A012-10F2CDF158C4} = {FEB39027-9158-4DE2-997F-7ADAEF8188D0} + {374A5B0C-3E93-4A23-A4A0-EE2AB6DF7814} = {E0497F39-AFFB-4819-A116-E39E361915AB} + {A2F321A5-3F55-4413-B357-EEF85DC0ECA6} = {C30C98CD-3D69-4AE9-B680-0E0E6D8834C6} EndGlobalSection EndGlobal diff --git a/samples/KWebStartup/KWebStartup.kproj b/samples/KWebStartup/KWebStartup.kproj new file mode 100644 index 0000000000..0250b93f66 --- /dev/null +++ b/samples/KWebStartup/KWebStartup.kproj @@ -0,0 +1,26 @@ + + + + 12.0 + $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) + + + + a2f321a5-3f55-4413-b357-eef85dc0eca6 + Library + + + + + + + 2.0 + + + + + + + + + \ No newline at end of file diff --git a/samples/KWebStartup/project.json b/samples/KWebStartup/project.json index 9b3ca4f7cf..e7414d56e5 100644 --- a/samples/KWebStartup/project.json +++ b/samples/KWebStartup/project.json @@ -2,7 +2,7 @@ "version": "0.1-alpha-*", "dependencies": { "Microsoft.AspNet.Abstractions": "0.1-alpha-*", - "Microsoft.AspNet.Hosting": "0.1-alpha-*", + "Microsoft.AspNet.Hosting": "", "Microsoft.AspNet.Server.WebListener": "0.1-alpha-*" }, "commands": { "web": "Microsoft.AspNet.Hosting server.name=Microsoft.AspNet.Server.WebListener server.urls=http://localhost:5001" }, diff --git a/src/Microsoft.AspNet.Hosting/Microsoft.AspNet.Hosting.kproj b/src/Microsoft.AspNet.Hosting/Microsoft.AspNet.Hosting.kproj new file mode 100644 index 0000000000..537d74ac2b --- /dev/null +++ b/src/Microsoft.AspNet.Hosting/Microsoft.AspNet.Hosting.kproj @@ -0,0 +1,49 @@ + + + + 12.0 + $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) + + + + 3944f036-7e75-47e8-aa52-c4b89a64ec3a + Library + + + + + + + 2.0 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/Microsoft.AspNet.RequestContainer/Microsoft.AspNet.RequestContainer.kproj b/src/Microsoft.AspNet.RequestContainer/Microsoft.AspNet.RequestContainer.kproj new file mode 100644 index 0000000000..13fc912c56 --- /dev/null +++ b/src/Microsoft.AspNet.RequestContainer/Microsoft.AspNet.RequestContainer.kproj @@ -0,0 +1,27 @@ + + + + 12.0 + $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) + + + + 374a5b0c-3e93-4a23-a4a0-ee2ab6df7814 + Library + + + + + + + 2.0 + + + + + + + + + + \ No newline at end of file diff --git a/src/Microsoft.AspNet.TestHost/Microsoft.AspNet.TestHost.kproj b/src/Microsoft.AspNet.TestHost/Microsoft.AspNet.TestHost.kproj new file mode 100644 index 0000000000..b0b2425081 --- /dev/null +++ b/src/Microsoft.AspNet.TestHost/Microsoft.AspNet.TestHost.kproj @@ -0,0 +1,29 @@ + + + + 12.0 + $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) + + + + 1a415a3f-1081-45db-809b-ee19cea02dc0 + Library + + + + + + + 2.0 + + + + + + + + + + + + \ No newline at end of file diff --git a/src/Microsoft.AspNet.TestHost/project.json b/src/Microsoft.AspNet.TestHost/project.json index 0028a68196..96182c3ed0 100644 --- a/src/Microsoft.AspNet.TestHost/project.json +++ b/src/Microsoft.AspNet.TestHost/project.json @@ -1,19 +1,11 @@ { "version" : "0.1-alpha-*", "dependencies": { - "System.Reflection": "4.0.10.0", - "System.Runtime" : "4.0.20.0", - "Microsoft.AspNet.Abstractions": "0.1-alpha-*", - "Microsoft.AspNet.ConfigurationModel": "0.1-alpha-*", - "Microsoft.AspNet.DependencyInjection": "0.1-alpha-*", - "Microsoft.AspNet.FeatureModel": "0.1-alpha-*", - "Microsoft.AspNet.Hosting": "0.1-alpha-*", - "Microsoft.AspNet.HttpFeature": "0.1-alpha-*", - "Microsoft.AspNet.PipelineCore": "0.1-alpha-*", - "Microsoft.AspNet.Security.DataProtection": "0.1-alpha-*" + "Microsoft.AspNet.Hosting": "" }, "configurations": { - "net45": { + "net45": { }, + "k10" : { "dependencies": { "System.Collections": "4.0.0.0", "System.ComponentModel": "4.0.0.0", diff --git a/test/Microsoft.AspNet.Hosting.Tests/Microsoft.AspNet.Hosting.Tests.kproj b/test/Microsoft.AspNet.Hosting.Tests/Microsoft.AspNet.Hosting.Tests.kproj new file mode 100644 index 0000000000..48a9989141 --- /dev/null +++ b/test/Microsoft.AspNet.Hosting.Tests/Microsoft.AspNet.Hosting.Tests.kproj @@ -0,0 +1,31 @@ + + + + 12.0 + $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) + + + + d4f18d58-52b1-435d-a012-10f2cdf158c4 + Library + net45 + + + + + + + 2.0 + + + + + + + + + + + + + \ No newline at end of file diff --git a/test/Microsoft.AspNet.Hosting.Tests/project.json b/test/Microsoft.AspNet.Hosting.Tests/project.json index b99c5d336f..31f45a0967 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/project.json +++ b/test/Microsoft.AspNet.Hosting.Tests/project.json @@ -2,9 +2,6 @@ "version": "0.1-alpha-*", "dependencies": { "Microsoft.AspNet.Hosting": "", - "Microsoft.AspNet.ConfigurationModel": "0.1-alpha-*", - "Microsoft.AspNet.Abstractions":"0.1-alpha-*", - "Microsoft.AspNet.DependencyInjection":"0.1-alpha-*", "Xunit.KRunner": "0.1-alpha-*", "xunit.abstractions": "2.0.0-aspnet-*", "xunit.assert": "2.0.0-aspnet-*", diff --git a/test/Microsoft.AspNet.TestHost.Tests/Microsoft.AspNet.TestHost.Tests.kproj b/test/Microsoft.AspNet.TestHost.Tests/Microsoft.AspNet.TestHost.Tests.kproj new file mode 100644 index 0000000000..4deca87e2d --- /dev/null +++ b/test/Microsoft.AspNet.TestHost.Tests/Microsoft.AspNet.TestHost.Tests.kproj @@ -0,0 +1,29 @@ + + + + 12.0 + $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) + + + + 0acb2719-9484-49b5-b8e3-117091192511 + Library + net45 + + + + + + + 2.0 + + + + + + + + + + + \ No newline at end of file diff --git a/test/Microsoft.AspNet.TestHost.Tests/project.json b/test/Microsoft.AspNet.TestHost.Tests/project.json index 3b30a0aed7..458aa6f103 100644 --- a/test/Microsoft.AspNet.TestHost.Tests/project.json +++ b/test/Microsoft.AspNet.TestHost.Tests/project.json @@ -3,15 +3,8 @@ "dependencies": { "System.Reflection": "4.0.10.0", "System.Runtime" : "4.0.20.0", - "Microsoft.AspNet.Abstractions": "0.1-alpha-*", - "Microsoft.AspNet.ConfigurationModel": "0.1-alpha-*", - "Microsoft.AspNet.DependencyInjection": "0.1-alpha-*", - "Microsoft.AspNet.FeatureModel": "0.1-alpha-*", "Microsoft.AspNet.Hosting": "", "Microsoft.AspNet.TestHost": "", - "Microsoft.AspNet.HttpFeature": "0.1-alpha-*", - "Microsoft.AspNet.PipelineCore": "0.1-alpha-*", - "Microsoft.AspNet.Security.DataProtection": "0.1-alpha-*", "xunit.abstractions": "2.0.0-aspnet-*", "xunit.assert": "2.0.0-aspnet-*", "xunit.core": "2.0.0-aspnet-*", @@ -24,17 +17,7 @@ "configurations": { "net45": { "dependencies": { - "System.Collections": "4.0.0.0", - "System.ComponentModel": "4.0.0.0", - "System.Globalization": "4.0.10.0", - "System.Linq": "4.0.0.0", - "System.Reflection": "4.0.10.0", - "System.Runtime": "4.0.20.0", - "System.Runtime.Extensions": "4.0.10.0", - "System.Runtime.Serialization.Primitives": "4.0.0.0", - "System.Threading": "4.0.0.0", - "System.Threading.Tasks": "4.0.10.0", - "System.Threading.Thread": "4.0.0.0" + "System.Runtime": "" } } } From 0bda88145d98adb1ab89504c8a4526d97caff0b5 Mon Sep 17 00:00:00 2001 From: David Fowler Date: Wed, 9 Apr 2014 22:14:59 -0700 Subject: [PATCH 036/987] Removed declared ANIs and referenced Microsoft.Net.Runtime.Interfaces instead --- .../AssemblyNeutralAttribute.cs | 10 ---------- .../IApplicationEnvironment.cs | 14 -------------- .../Microsoft.AspNet.Hosting.kproj | 2 -- src/Microsoft.AspNet.Hosting/project.json | 3 ++- 4 files changed, 2 insertions(+), 27 deletions(-) delete mode 100644 src/Microsoft.AspNet.Hosting/AssemblyNeutralAttribute.cs delete mode 100644 src/Microsoft.AspNet.Hosting/IApplicationEnvironment.cs diff --git a/src/Microsoft.AspNet.Hosting/AssemblyNeutralAttribute.cs b/src/Microsoft.AspNet.Hosting/AssemblyNeutralAttribute.cs deleted file mode 100644 index 2191d5198d..0000000000 --- a/src/Microsoft.AspNet.Hosting/AssemblyNeutralAttribute.cs +++ /dev/null @@ -1,10 +0,0 @@ -using System; - -namespace Microsoft.Net.Runtime -{ - [AssemblyNeutral] - [AttributeUsage(AttributeTargets.All, Inherited = false, AllowMultiple = true)] - public sealed class AssemblyNeutralAttribute : Attribute - { - } -} diff --git a/src/Microsoft.AspNet.Hosting/IApplicationEnvironment.cs b/src/Microsoft.AspNet.Hosting/IApplicationEnvironment.cs deleted file mode 100644 index 1c772bc835..0000000000 --- a/src/Microsoft.AspNet.Hosting/IApplicationEnvironment.cs +++ /dev/null @@ -1,14 +0,0 @@ -using System; -using System.Runtime.Versioning; - -namespace Microsoft.Net.Runtime -{ - [AssemblyNeutral] - public interface IApplicationEnvironment - { - string ApplicationName { get; } - string Version { get; } - string ApplicationBasePath { get; } - FrameworkName TargetFramework { get; } - } -} \ No newline at end of file diff --git a/src/Microsoft.AspNet.Hosting/Microsoft.AspNet.Hosting.kproj b/src/Microsoft.AspNet.Hosting/Microsoft.AspNet.Hosting.kproj index 537d74ac2b..de22702e86 100644 --- a/src/Microsoft.AspNet.Hosting/Microsoft.AspNet.Hosting.kproj +++ b/src/Microsoft.AspNet.Hosting/Microsoft.AspNet.Hosting.kproj @@ -20,7 +20,6 @@ - @@ -28,7 +27,6 @@ - diff --git a/src/Microsoft.AspNet.Hosting/project.json b/src/Microsoft.AspNet.Hosting/project.json index be245644fd..5181a9bdac 100644 --- a/src/Microsoft.AspNet.Hosting/project.json +++ b/src/Microsoft.AspNet.Hosting/project.json @@ -6,7 +6,8 @@ "Microsoft.AspNet.PipelineCore": "0.1-alpha-*", "Microsoft.AspNet.Abstractions": "0.1-alpha-*", "Microsoft.AspNet.FeatureModel": "0.1-alpha-*", - "Microsoft.AspNet.Security.DataProtection": "0.1-alpha-*" + "Microsoft.AspNet.Security.DataProtection": "0.1-alpha-*", + "Microsoft.Net.Runtime.Interfaces": "0.1-alpha-*" }, "configurations": { "net45": {}, From e99576a4294731986a61fdcd2d2b9ccbe3903d44 Mon Sep 17 00:00:00 2001 From: David Fowler Date: Thu, 17 Apr 2014 00:12:41 -0700 Subject: [PATCH 037/987] Added callback overload to UseContainer - Allows caller to pass a delegate to configure add services via the ServiceCollection. --- .../ContainerExtensions.cs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Microsoft.AspNet.RequestContainer/ContainerExtensions.cs b/src/Microsoft.AspNet.RequestContainer/ContainerExtensions.cs index 05b56f92cd..346eb28680 100644 --- a/src/Microsoft.AspNet.RequestContainer/ContainerExtensions.cs +++ b/src/Microsoft.AspNet.RequestContainer/ContainerExtensions.cs @@ -35,9 +35,14 @@ namespace Microsoft.AspNet.RequestContainer } public static IBuilder UseContainer(this IBuilder builder, IEnumerable applicationServices) + { + return builder.UseContainer(services => services.Add(applicationServices)); + } + + public static IBuilder UseContainer(this IBuilder builder, Action configureServices) { var serviceCollection = new ServiceCollection(); - serviceCollection.Add(applicationServices); + configureServices(serviceCollection); builder.ServiceProvider = serviceCollection.BuildServiceProvider(builder.ServiceProvider); return builder.UseMiddleware(typeof(ContainerMiddleware)); From 10ee3c20e340dc5075132be408e484053c55af13 Mon Sep 17 00:00:00 2001 From: David Fowler Date: Thu, 17 Apr 2014 20:27:18 -0700 Subject: [PATCH 038/987] Rename UseContainer to UseServices --- .../Microsoft.AspNet.Hosting.kproj | 3 +++ .../ContainerExtensions.cs | 10 +++++----- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/Microsoft.AspNet.Hosting/Microsoft.AspNet.Hosting.kproj b/src/Microsoft.AspNet.Hosting/Microsoft.AspNet.Hosting.kproj index de22702e86..e09cae4005 100644 --- a/src/Microsoft.AspNet.Hosting/Microsoft.AspNet.Hosting.kproj +++ b/src/Microsoft.AspNet.Hosting/Microsoft.AspNet.Hosting.kproj @@ -43,5 +43,8 @@ + + + \ No newline at end of file diff --git a/src/Microsoft.AspNet.RequestContainer/ContainerExtensions.cs b/src/Microsoft.AspNet.RequestContainer/ContainerExtensions.cs index 346eb28680..9ae44867e1 100644 --- a/src/Microsoft.AspNet.RequestContainer/ContainerExtensions.cs +++ b/src/Microsoft.AspNet.RequestContainer/ContainerExtensions.cs @@ -22,24 +22,24 @@ namespace Microsoft.AspNet.RequestContainer }); } - public static IBuilder UseContainer(this IBuilder builder) + public static IBuilder UseServices(this IBuilder builder) { return builder.UseMiddleware(typeof(ContainerMiddleware)); } - public static IBuilder UseContainer(this IBuilder builder, IServiceProvider applicationServices) + public static IBuilder UseServices(this IBuilder builder, IServiceProvider applicationServices) { builder.ServiceProvider = applicationServices; return builder.UseMiddleware(typeof(ContainerMiddleware)); } - public static IBuilder UseContainer(this IBuilder builder, IEnumerable applicationServices) + public static IBuilder UseServices(this IBuilder builder, IEnumerable applicationServices) { - return builder.UseContainer(services => services.Add(applicationServices)); + return builder.UseServices(services => services.Add(applicationServices)); } - public static IBuilder UseContainer(this IBuilder builder, Action configureServices) + public static IBuilder UseServices(this IBuilder builder, Action configureServices) { var serviceCollection = new ServiceCollection(); configureServices(serviceCollection); From 11080a5d0699a002222c6d073be3a3bafc3abcb4 Mon Sep 17 00:00:00 2001 From: David Fowler Date: Thu, 17 Apr 2014 20:31:11 -0700 Subject: [PATCH 039/987] Removed Properties folder --- src/Microsoft.AspNet.Hosting/Microsoft.AspNet.Hosting.kproj | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/Microsoft.AspNet.Hosting/Microsoft.AspNet.Hosting.kproj b/src/Microsoft.AspNet.Hosting/Microsoft.AspNet.Hosting.kproj index e09cae4005..de22702e86 100644 --- a/src/Microsoft.AspNet.Hosting/Microsoft.AspNet.Hosting.kproj +++ b/src/Microsoft.AspNet.Hosting/Microsoft.AspNet.Hosting.kproj @@ -43,8 +43,5 @@ - - - \ No newline at end of file From 252f17e5e2e69b621fd07735e6953ae73443ee3a Mon Sep 17 00:00:00 2001 From: David Fowler Date: Thu, 17 Apr 2014 22:16:04 -0700 Subject: [PATCH 040/987] Adjusting due to API changes --- .../ContainerExtensions.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Microsoft.AspNet.RequestContainer/ContainerExtensions.cs b/src/Microsoft.AspNet.RequestContainer/ContainerExtensions.cs index 9ae44867e1..1047a44c07 100644 --- a/src/Microsoft.AspNet.RequestContainer/ContainerExtensions.cs +++ b/src/Microsoft.AspNet.RequestContainer/ContainerExtensions.cs @@ -15,8 +15,8 @@ namespace Microsoft.AspNet.RequestContainer // TODO: move this ext method someplace nice return builder.Use(next => { - var typeActivator = builder.ServiceProvider.GetService(); - var instance = typeActivator.CreateInstance(builder.ServiceProvider, middleware, new[] { next }.Concat(args).ToArray()); + var typeActivator = builder.ApplicationServices.GetService(); + var instance = typeActivator.CreateInstance(builder.ApplicationServices, middleware, new[] { next }.Concat(args).ToArray()); var methodinfo = middleware.GetTypeInfo().GetDeclaredMethod("Invoke"); return (RequestDelegate)methodinfo.CreateDelegate(typeof(RequestDelegate), instance); }); @@ -29,7 +29,7 @@ namespace Microsoft.AspNet.RequestContainer public static IBuilder UseServices(this IBuilder builder, IServiceProvider applicationServices) { - builder.ServiceProvider = applicationServices; + builder.ApplicationServices = applicationServices; return builder.UseMiddleware(typeof(ContainerMiddleware)); } @@ -43,7 +43,7 @@ namespace Microsoft.AspNet.RequestContainer { var serviceCollection = new ServiceCollection(); configureServices(serviceCollection); - builder.ServiceProvider = serviceCollection.BuildServiceProvider(builder.ServiceProvider); + builder.ApplicationServices = serviceCollection.BuildServiceProvider(builder.ApplicationServices); return builder.UseMiddleware(typeof(ContainerMiddleware)); } From bba57874bceb6fa2d3eaea33448fc4475f0939cd Mon Sep 17 00:00:00 2001 From: David Fowler Date: Fri, 18 Apr 2014 00:13:10 -0700 Subject: [PATCH 041/987] Put UseServices extension method in Microsoft.AspNet --- src/Microsoft.AspNet.RequestContainer/ContainerExtensions.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Microsoft.AspNet.RequestContainer/ContainerExtensions.cs b/src/Microsoft.AspNet.RequestContainer/ContainerExtensions.cs index 1047a44c07..8648d8b220 100644 --- a/src/Microsoft.AspNet.RequestContainer/ContainerExtensions.cs +++ b/src/Microsoft.AspNet.RequestContainer/ContainerExtensions.cs @@ -5,8 +5,9 @@ using System.Linq; using Microsoft.AspNet.Abstractions; using Microsoft.AspNet.DependencyInjection; using Microsoft.AspNet.DependencyInjection.Fallback; +using Microsoft.AspNet.RequestContainer; -namespace Microsoft.AspNet.RequestContainer +namespace Microsoft.AspNet { public static class ContainerExtensions { From aa4dfffd8435eae2406f41fddce819ab4af1fdd2 Mon Sep 17 00:00:00 2001 From: David Fowler Date: Mon, 21 Apr 2014 22:27:14 -0700 Subject: [PATCH 042/987] Fixed references in test host --- test/Microsoft.AspNet.TestHost.Tests/project.json | 2 -- 1 file changed, 2 deletions(-) diff --git a/test/Microsoft.AspNet.TestHost.Tests/project.json b/test/Microsoft.AspNet.TestHost.Tests/project.json index 458aa6f103..191a4928ef 100644 --- a/test/Microsoft.AspNet.TestHost.Tests/project.json +++ b/test/Microsoft.AspNet.TestHost.Tests/project.json @@ -1,8 +1,6 @@ { "version" : "0.1-alpha-*", "dependencies": { - "System.Reflection": "4.0.10.0", - "System.Runtime" : "4.0.20.0", "Microsoft.AspNet.Hosting": "", "Microsoft.AspNet.TestHost": "", "xunit.abstractions": "2.0.0-aspnet-*", From 4077c03a7ba7f0d84e5829878dd8651970a6d5a8 Mon Sep 17 00:00:00 2001 From: GrabYourPitchforks Date: Thu, 24 Apr 2014 12:54:50 -0700 Subject: [PATCH 043/987] Hosting: Throw if startup method isn't void-returning. --- src/Microsoft.AspNet.Hosting/Startup/StartupLoader.cs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/Microsoft.AspNet.Hosting/Startup/StartupLoader.cs b/src/Microsoft.AspNet.Hosting/Startup/StartupLoader.cs index eed8e7a6e4..0f07be61b0 100644 --- a/src/Microsoft.AspNet.Hosting/Startup/StartupLoader.cs +++ b/src/Microsoft.AspNet.Hosting/Startup/StartupLoader.cs @@ -65,6 +65,11 @@ namespace Microsoft.AspNet.Hosting.Startup throw new Exception("TODO: Configuration method not found"); } + if (methodInfo.ReturnType != typeof(void)) + { + throw new Exception("TODO: Configuration method isn't void-returning."); + } + object instance = null; if (!methodInfo.IsStatic) { From 7b4e1fd48e91408eb039b7f565ca8bfbb8fb030a Mon Sep 17 00:00:00 2001 From: David Fowler Date: Tue, 29 Apr 2014 23:58:53 -0700 Subject: [PATCH 044/987] Added DPAPI implementation that works on mono --- .../HostingServices.cs | 19 ++++++++++++++----- .../Microsoft.AspNet.Hosting.kproj | 1 + .../PlatformHelper.cs | 17 +++++++++++++++++ 3 files changed, 32 insertions(+), 5 deletions(-) create mode 100644 src/Microsoft.AspNet.Hosting/PlatformHelper.cs diff --git a/src/Microsoft.AspNet.Hosting/HostingServices.cs b/src/Microsoft.AspNet.Hosting/HostingServices.cs index 4ef1e162c6..64f50b58ad 100644 --- a/src/Microsoft.AspNet.Hosting/HostingServices.cs +++ b/src/Microsoft.AspNet.Hosting/HostingServices.cs @@ -37,11 +37,20 @@ namespace Microsoft.AspNet.Hosting Lifecycle = LifecycleKind.Scoped }; - // The default IDataProtectionProvider is a singleton. - // Note: DPAPI isn't usable in IIS where the user profile hasn't been loaded, but loading DPAPI - // is deferred until the first call to Protect / Unprotect. It's up to an IIS-based host to - // replace this service as part of application initialization. - yield return describer.Instance(DataProtectionProvider.CreateFromDpapi()); + if (PlatformHelper.IsMono) + { +#if NET45 + yield return describer.Instance(DataProtectionProvider.CreateFromLegacyDpapi()); +#endif + } + else + { + // The default IDataProtectionProvider is a singleton. + // Note: DPAPI isn't usable in IIS where the user profile hasn't been loaded, but loading DPAPI + // is deferred until the first call to Protect / Unprotect. It's up to an IIS-based host to + // replace this service as part of application initialization. + yield return describer.Instance(DataProtectionProvider.CreateFromDpapi()); + } } } } \ No newline at end of file diff --git a/src/Microsoft.AspNet.Hosting/Microsoft.AspNet.Hosting.kproj b/src/Microsoft.AspNet.Hosting/Microsoft.AspNet.Hosting.kproj index de22702e86..5e436ba601 100644 --- a/src/Microsoft.AspNet.Hosting/Microsoft.AspNet.Hosting.kproj +++ b/src/Microsoft.AspNet.Hosting/Microsoft.AspNet.Hosting.kproj @@ -29,6 +29,7 @@ + diff --git a/src/Microsoft.AspNet.Hosting/PlatformHelper.cs b/src/Microsoft.AspNet.Hosting/PlatformHelper.cs new file mode 100644 index 0000000000..2d2f0adeed --- /dev/null +++ b/src/Microsoft.AspNet.Hosting/PlatformHelper.cs @@ -0,0 +1,17 @@ +using System; + +namespace Microsoft.AspNet.Hosting +{ + internal static class PlatformHelper + { + private static Lazy _isMono = new Lazy(() => Type.GetType("Mono.Runtime") != null); + + public static bool IsMono + { + get + { + return _isMono.Value; + } + } + } +} \ No newline at end of file From 61924dd73e76c101088d28d5877df21af575e7ec Mon Sep 17 00:00:00 2001 From: Chris Ross Date: Wed, 30 Apr 2014 15:43:21 -0700 Subject: [PATCH 045/987] Fix renamed IContextAccessor APIs. --- .../ContainerMiddleware.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Microsoft.AspNet.RequestContainer/ContainerMiddleware.cs b/src/Microsoft.AspNet.RequestContainer/ContainerMiddleware.cs index 61d985fc3d..881d71ee0e 100644 --- a/src/Microsoft.AspNet.RequestContainer/ContainerMiddleware.cs +++ b/src/Microsoft.AspNet.RequestContainer/ContainerMiddleware.cs @@ -93,8 +93,8 @@ namespace Microsoft.AspNet.RequestContainer httpContext.ApplicationServices = appServiceProvider; httpContext.RequestServices = scopeServiceProvider; - var priorAppHttpContext = appHttpContextAccessor.ExchangeValue(httpContext); - var priorScopeHttpContext = scopeHttpContextAccessor.ExchangeValue(httpContext); + var priorAppHttpContext = appHttpContextAccessor.SetValue(httpContext); + var priorScopeHttpContext = scopeHttpContextAccessor.SetValue(httpContext); try { @@ -102,8 +102,8 @@ namespace Microsoft.AspNet.RequestContainer } finally { - scopeHttpContextAccessor.ExchangeValue(priorScopeHttpContext); - appHttpContextAccessor.ExchangeValue(priorAppHttpContext); + scopeHttpContextAccessor.SetValue(priorScopeHttpContext); + appHttpContextAccessor.SetValue(priorAppHttpContext); httpContext.RequestServices = priorRequestServices; httpContext.ApplicationServices = priorApplicationServices; From 95667dba69756701ee9f31414883993f69c09acc Mon Sep 17 00:00:00 2001 From: Chris Ross Date: Thu, 1 May 2014 14:15:11 -0700 Subject: [PATCH 046/987] Remove unused filesystem dependencies. --- samples/KWebStartup/project.json | 2 -- src/Microsoft.AspNet.Hosting/project.json | 2 -- 2 files changed, 4 deletions(-) diff --git a/samples/KWebStartup/project.json b/samples/KWebStartup/project.json index e7414d56e5..ab2f5706ee 100644 --- a/samples/KWebStartup/project.json +++ b/samples/KWebStartup/project.json @@ -17,8 +17,6 @@ "System.Diagnostics.Tools": "4.0.0.0", "System.Globalization": "4.0.10.0", "System.IO": "4.0.0.0", - "System.IO.FileSystem": "4.0.0.0", - "System.IO.FileSystem.Primitives": "4.0.0.0", "System.Linq": "4.0.0.0", "System.Reflection": "4.0.10.0", "System.Resources.ResourceManager": "4.0.0.0", diff --git a/src/Microsoft.AspNet.Hosting/project.json b/src/Microsoft.AspNet.Hosting/project.json index 5181a9bdac..159032003b 100644 --- a/src/Microsoft.AspNet.Hosting/project.json +++ b/src/Microsoft.AspNet.Hosting/project.json @@ -18,8 +18,6 @@ "System.ComponentModel": "4.0.0.0", "System.Diagnostics.Debug": "4.0.10.0", "System.IO": "4.0.0.0", - "System.IO.FileSystem": "4.0.0.0", - "System.IO.FileSystem.Primitives": "4.0.0.0", "System.Linq": "4.0.0.0", "System.Reflection": "4.0.10.0", "System.Runtime": "4.0.20.0", From d8c68b61f034ed7531c9609b3c3e46b2b6a56c43 Mon Sep 17 00:00:00 2001 From: Chris Ross Date: Thu, 1 May 2014 14:15:28 -0700 Subject: [PATCH 047/987] Add missing namespace to the sample. --- samples/KWebStartup/Startup.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/samples/KWebStartup/Startup.cs b/samples/KWebStartup/Startup.cs index fc82494f77..3bc58d1ba1 100644 --- a/samples/KWebStartup/Startup.cs +++ b/samples/KWebStartup/Startup.cs @@ -1,3 +1,4 @@ +using Microsoft.AspNet; using Microsoft.AspNet.Abstractions; namespace KWebStartup From e645599aa61eb4b1e499dcd50f2cc2709c8db338 Mon Sep 17 00:00:00 2001 From: anpete Date: Thu, 1 May 2014 17:39:17 -0700 Subject: [PATCH 048/987] Update file headers --- samples/KWebStartup/Startup.cs | 17 +++++++++++++++++ .../Builder/BuilderFactory.cs | 19 ++++++++++++++++++- .../Builder/HttpContextFactory.cs | 17 +++++++++++++++++ .../Builder/IBuilderFactory.cs | 19 ++++++++++++++++++- .../Builder/IHttpContextFactory.cs | 19 ++++++++++++++++++- .../HostingContext.cs | 19 ++++++++++++++++++- src/Microsoft.AspNet.Hosting/HostingEngine.cs | 17 +++++++++++++++++ .../HostingServices.cs | 19 ++++++++++++++++++- .../IHostingEngine.cs | 19 ++++++++++++++++++- .../PipelineInstance.cs | 17 +++++++++++++++++ .../PlatformHelper.cs | 17 +++++++++++++++++ src/Microsoft.AspNet.Hosting/Program.cs | 19 ++++++++++++++++++- .../Server/IServerFactory.cs | 19 ++++++++++++++++++- .../Server/IServerManager.cs | 17 +++++++++++++++++ .../Server/ServerManager.cs | 17 +++++++++++++++++ .../Startup/IStartupLoader.cs | 17 +++++++++++++++++ .../Startup/IStartupLoaderProvider.cs | 17 +++++++++++++++++ .../Startup/IStartupManager.cs | 17 +++++++++++++++++ .../Startup/NullStartupLoader.cs | 17 +++++++++++++++++ .../Startup/StartupLoader.cs | 17 +++++++++++++++++ .../Startup/StartupLoaderProvider.cs | 17 +++++++++++++++++ .../Startup/StartupManager.cs | 17 +++++++++++++++++ src/Microsoft.AspNet.Hosting/Utilities.cs | 19 ++++++++++++++++++- .../WebApplication.cs | 19 ++++++++++++++++++- .../ContainerExtensions.cs | 19 ++++++++++++++++++- .../ContainerMiddleware.cs | 19 ++++++++++++++++++- .../RequestInformation.cs | 19 ++++++++++++++++++- .../ResponseInformation.cs | 19 ++++++++++++++++++- src/Microsoft.AspNet.TestHost/TestClient.cs | 19 ++++++++++++++++++- src/Microsoft.AspNet.TestHost/TestServer.cs | 19 ++++++++++++++++++- .../Fakes/FakeStartup.cs | 17 +++++++++++++++++ .../Fakes/FakeStartupWithServices.cs | 17 +++++++++++++++++ .../Fakes/IFakeStartupCallback.cs | 17 +++++++++++++++++ .../HostingEngineTests.cs | 19 ++++++++++++++++++- .../StartupManagerTests.cs | 19 ++++++++++++++++++- .../TestApplicationEnvironment.cs | 19 ++++++++++++++++++- .../TestClientTests.cs | 19 ++++++++++++++++++- .../TestServerTests.cs | 19 ++++++++++++++++++- 38 files changed, 667 insertions(+), 21 deletions(-) diff --git a/samples/KWebStartup/Startup.cs b/samples/KWebStartup/Startup.cs index 3bc58d1ba1..003f957c97 100644 --- a/samples/KWebStartup/Startup.cs +++ b/samples/KWebStartup/Startup.cs @@ -1,3 +1,20 @@ +// Copyright (c) Microsoft Open Technologies, Inc. +// All Rights Reserved +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR +// CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING +// WITHOUT LIMITATION ANY IMPLIED WARRANTIES OR CONDITIONS OF +// TITLE, FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABLITY OR +// NON-INFRINGEMENT. +// See the Apache 2 License for the specific language governing +// permissions and limitations under the License. + using Microsoft.AspNet; using Microsoft.AspNet.Abstractions; diff --git a/src/Microsoft.AspNet.Hosting/Builder/BuilderFactory.cs b/src/Microsoft.AspNet.Hosting/Builder/BuilderFactory.cs index bee42edcd3..8a19d56ed9 100644 --- a/src/Microsoft.AspNet.Hosting/Builder/BuilderFactory.cs +++ b/src/Microsoft.AspNet.Hosting/Builder/BuilderFactory.cs @@ -1,4 +1,21 @@ -using System; +// Copyright (c) Microsoft Open Technologies, Inc. +// All Rights Reserved +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR +// CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING +// WITHOUT LIMITATION ANY IMPLIED WARRANTIES OR CONDITIONS OF +// TITLE, FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABLITY OR +// NON-INFRINGEMENT. +// See the Apache 2 License for the specific language governing +// permissions and limitations under the License. + +using System; using Microsoft.AspNet.Abstractions; namespace Microsoft.AspNet.Hosting.Builder diff --git a/src/Microsoft.AspNet.Hosting/Builder/HttpContextFactory.cs b/src/Microsoft.AspNet.Hosting/Builder/HttpContextFactory.cs index 18dc5a4341..d2e8ba071a 100644 --- a/src/Microsoft.AspNet.Hosting/Builder/HttpContextFactory.cs +++ b/src/Microsoft.AspNet.Hosting/Builder/HttpContextFactory.cs @@ -1,3 +1,20 @@ +// Copyright (c) Microsoft Open Technologies, Inc. +// All Rights Reserved +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR +// CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING +// WITHOUT LIMITATION ANY IMPLIED WARRANTIES OR CONDITIONS OF +// TITLE, FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABLITY OR +// NON-INFRINGEMENT. +// See the Apache 2 License for the specific language governing +// permissions and limitations under the License. + using Microsoft.AspNet.Abstractions; using Microsoft.AspNet.FeatureModel; using Microsoft.AspNet.Hosting.Server; diff --git a/src/Microsoft.AspNet.Hosting/Builder/IBuilderFactory.cs b/src/Microsoft.AspNet.Hosting/Builder/IBuilderFactory.cs index f69589727a..5f76b74b90 100644 --- a/src/Microsoft.AspNet.Hosting/Builder/IBuilderFactory.cs +++ b/src/Microsoft.AspNet.Hosting/Builder/IBuilderFactory.cs @@ -1,4 +1,21 @@ -using Microsoft.AspNet.Abstractions; +// Copyright (c) Microsoft Open Technologies, Inc. +// All Rights Reserved +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR +// CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING +// WITHOUT LIMITATION ANY IMPLIED WARRANTIES OR CONDITIONS OF +// TITLE, FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABLITY OR +// NON-INFRINGEMENT. +// See the Apache 2 License for the specific language governing +// permissions and limitations under the License. + +using Microsoft.AspNet.Abstractions; namespace Microsoft.AspNet.Hosting.Builder { diff --git a/src/Microsoft.AspNet.Hosting/Builder/IHttpContextFactory.cs b/src/Microsoft.AspNet.Hosting/Builder/IHttpContextFactory.cs index 3db4473167..2cdcf30a75 100644 --- a/src/Microsoft.AspNet.Hosting/Builder/IHttpContextFactory.cs +++ b/src/Microsoft.AspNet.Hosting/Builder/IHttpContextFactory.cs @@ -1,4 +1,21 @@ -using Microsoft.AspNet.Abstractions; +// Copyright (c) Microsoft Open Technologies, Inc. +// All Rights Reserved +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR +// CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING +// WITHOUT LIMITATION ANY IMPLIED WARRANTIES OR CONDITIONS OF +// TITLE, FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABLITY OR +// NON-INFRINGEMENT. +// See the Apache 2 License for the specific language governing +// permissions and limitations under the License. + +using Microsoft.AspNet.Abstractions; namespace Microsoft.AspNet.Hosting.Builder { diff --git a/src/Microsoft.AspNet.Hosting/HostingContext.cs b/src/Microsoft.AspNet.Hosting/HostingContext.cs index b1d96a88e0..974c4783f4 100644 --- a/src/Microsoft.AspNet.Hosting/HostingContext.cs +++ b/src/Microsoft.AspNet.Hosting/HostingContext.cs @@ -1,4 +1,21 @@ -using System; +// Copyright (c) Microsoft Open Technologies, Inc. +// All Rights Reserved +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR +// CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING +// WITHOUT LIMITATION ANY IMPLIED WARRANTIES OR CONDITIONS OF +// TITLE, FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABLITY OR +// NON-INFRINGEMENT. +// See the Apache 2 License for the specific language governing +// permissions and limitations under the License. + +using System; using Microsoft.AspNet.Abstractions; using Microsoft.AspNet.ConfigurationModel; using Microsoft.AspNet.Hosting.Server; diff --git a/src/Microsoft.AspNet.Hosting/HostingEngine.cs b/src/Microsoft.AspNet.Hosting/HostingEngine.cs index b04d02f65a..5346305db9 100644 --- a/src/Microsoft.AspNet.Hosting/HostingEngine.cs +++ b/src/Microsoft.AspNet.Hosting/HostingEngine.cs @@ -1,3 +1,20 @@ +// Copyright (c) Microsoft Open Technologies, Inc. +// All Rights Reserved +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR +// CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING +// WITHOUT LIMITATION ANY IMPLIED WARRANTIES OR CONDITIONS OF +// TITLE, FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABLITY OR +// NON-INFRINGEMENT. +// See the Apache 2 License for the specific language governing +// permissions and limitations under the License. + using System; using System.Threading; using Microsoft.AspNet.DependencyInjection; diff --git a/src/Microsoft.AspNet.Hosting/HostingServices.cs b/src/Microsoft.AspNet.Hosting/HostingServices.cs index 64f50b58ad..d196876873 100644 --- a/src/Microsoft.AspNet.Hosting/HostingServices.cs +++ b/src/Microsoft.AspNet.Hosting/HostingServices.cs @@ -1,4 +1,21 @@ -using System.Collections.Generic; +// Copyright (c) Microsoft Open Technologies, Inc. +// All Rights Reserved +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR +// CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING +// WITHOUT LIMITATION ANY IMPLIED WARRANTIES OR CONDITIONS OF +// TITLE, FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABLITY OR +// NON-INFRINGEMENT. +// See the Apache 2 License for the specific language governing +// permissions and limitations under the License. + +using System.Collections.Generic; using Microsoft.AspNet.ConfigurationModel; using Microsoft.AspNet.DependencyInjection; using Microsoft.AspNet.Hosting.Builder; diff --git a/src/Microsoft.AspNet.Hosting/IHostingEngine.cs b/src/Microsoft.AspNet.Hosting/IHostingEngine.cs index 89195e69f4..324e9beba8 100644 --- a/src/Microsoft.AspNet.Hosting/IHostingEngine.cs +++ b/src/Microsoft.AspNet.Hosting/IHostingEngine.cs @@ -1,4 +1,21 @@ -using System; +// Copyright (c) Microsoft Open Technologies, Inc. +// All Rights Reserved +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR +// CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING +// WITHOUT LIMITATION ANY IMPLIED WARRANTIES OR CONDITIONS OF +// TITLE, FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABLITY OR +// NON-INFRINGEMENT. +// See the Apache 2 License for the specific language governing +// permissions and limitations under the License. + +using System; namespace Microsoft.AspNet.Hosting { diff --git a/src/Microsoft.AspNet.Hosting/PipelineInstance.cs b/src/Microsoft.AspNet.Hosting/PipelineInstance.cs index cc7580b713..b6bf92de86 100644 --- a/src/Microsoft.AspNet.Hosting/PipelineInstance.cs +++ b/src/Microsoft.AspNet.Hosting/PipelineInstance.cs @@ -1,3 +1,20 @@ +// Copyright (c) Microsoft Open Technologies, Inc. +// All Rights Reserved +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR +// CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING +// WITHOUT LIMITATION ANY IMPLIED WARRANTIES OR CONDITIONS OF +// TITLE, FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABLITY OR +// NON-INFRINGEMENT. +// See the Apache 2 License for the specific language governing +// permissions and limitations under the License. + using System; using System.Threading.Tasks; using Microsoft.AspNet.Abstractions; diff --git a/src/Microsoft.AspNet.Hosting/PlatformHelper.cs b/src/Microsoft.AspNet.Hosting/PlatformHelper.cs index 2d2f0adeed..0581162444 100644 --- a/src/Microsoft.AspNet.Hosting/PlatformHelper.cs +++ b/src/Microsoft.AspNet.Hosting/PlatformHelper.cs @@ -1,3 +1,20 @@ +// Copyright (c) Microsoft Open Technologies, Inc. +// All Rights Reserved +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR +// CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING +// WITHOUT LIMITATION ANY IMPLIED WARRANTIES OR CONDITIONS OF +// TITLE, FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABLITY OR +// NON-INFRINGEMENT. +// See the Apache 2 License for the specific language governing +// permissions and limitations under the License. + using System; namespace Microsoft.AspNet.Hosting diff --git a/src/Microsoft.AspNet.Hosting/Program.cs b/src/Microsoft.AspNet.Hosting/Program.cs index e8ce97b453..7c5585bbc6 100644 --- a/src/Microsoft.AspNet.Hosting/Program.cs +++ b/src/Microsoft.AspNet.Hosting/Program.cs @@ -1,4 +1,21 @@ -using System; +// Copyright (c) Microsoft Open Technologies, Inc. +// All Rights Reserved +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR +// CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING +// WITHOUT LIMITATION ANY IMPLIED WARRANTIES OR CONDITIONS OF +// TITLE, FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABLITY OR +// NON-INFRINGEMENT. +// See the Apache 2 License for the specific language governing +// permissions and limitations under the License. + +using System; using System.IO; using Microsoft.AspNet.ConfigurationModel; using Microsoft.AspNet.DependencyInjection; diff --git a/src/Microsoft.AspNet.Hosting/Server/IServerFactory.cs b/src/Microsoft.AspNet.Hosting/Server/IServerFactory.cs index 054e5e0308..cd8e42f28b 100644 --- a/src/Microsoft.AspNet.Hosting/Server/IServerFactory.cs +++ b/src/Microsoft.AspNet.Hosting/Server/IServerFactory.cs @@ -1,4 +1,21 @@ -using System; +// Copyright (c) Microsoft Open Technologies, Inc. +// All Rights Reserved +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR +// CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING +// WITHOUT LIMITATION ANY IMPLIED WARRANTIES OR CONDITIONS OF +// TITLE, FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABLITY OR +// NON-INFRINGEMENT. +// See the Apache 2 License for the specific language governing +// permissions and limitations under the License. + +using System; using System.Threading.Tasks; using Microsoft.AspNet.Abstractions; using Microsoft.AspNet.ConfigurationModel; diff --git a/src/Microsoft.AspNet.Hosting/Server/IServerManager.cs b/src/Microsoft.AspNet.Hosting/Server/IServerManager.cs index 5a6b6b9166..169ce54cf5 100644 --- a/src/Microsoft.AspNet.Hosting/Server/IServerManager.cs +++ b/src/Microsoft.AspNet.Hosting/Server/IServerManager.cs @@ -1,3 +1,20 @@ +// Copyright (c) Microsoft Open Technologies, Inc. +// All Rights Reserved +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR +// CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING +// WITHOUT LIMITATION ANY IMPLIED WARRANTIES OR CONDITIONS OF +// TITLE, FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABLITY OR +// NON-INFRINGEMENT. +// See the Apache 2 License for the specific language governing +// permissions and limitations under the License. + namespace Microsoft.AspNet.Hosting.Server { public interface IServerManager diff --git a/src/Microsoft.AspNet.Hosting/Server/ServerManager.cs b/src/Microsoft.AspNet.Hosting/Server/ServerManager.cs index daa2eedcb7..45b902e8cc 100644 --- a/src/Microsoft.AspNet.Hosting/Server/ServerManager.cs +++ b/src/Microsoft.AspNet.Hosting/Server/ServerManager.cs @@ -1,3 +1,20 @@ +// Copyright (c) Microsoft Open Technologies, Inc. +// All Rights Reserved +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR +// CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING +// WITHOUT LIMITATION ANY IMPLIED WARRANTIES OR CONDITIONS OF +// TITLE, FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABLITY OR +// NON-INFRINGEMENT. +// See the Apache 2 License for the specific language governing +// permissions and limitations under the License. + using System; using System.Linq; using System.Reflection; diff --git a/src/Microsoft.AspNet.Hosting/Startup/IStartupLoader.cs b/src/Microsoft.AspNet.Hosting/Startup/IStartupLoader.cs index 067e5a4ebe..2115a7e57d 100644 --- a/src/Microsoft.AspNet.Hosting/Startup/IStartupLoader.cs +++ b/src/Microsoft.AspNet.Hosting/Startup/IStartupLoader.cs @@ -1,3 +1,20 @@ +// Copyright (c) Microsoft Open Technologies, Inc. +// All Rights Reserved +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR +// CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING +// WITHOUT LIMITATION ANY IMPLIED WARRANTIES OR CONDITIONS OF +// TITLE, FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABLITY OR +// NON-INFRINGEMENT. +// See the Apache 2 License for the specific language governing +// permissions and limitations under the License. + using System; using System.Collections.Generic; using Microsoft.AspNet.Abstractions; diff --git a/src/Microsoft.AspNet.Hosting/Startup/IStartupLoaderProvider.cs b/src/Microsoft.AspNet.Hosting/Startup/IStartupLoaderProvider.cs index ad96af9793..3a2f9561c2 100644 --- a/src/Microsoft.AspNet.Hosting/Startup/IStartupLoaderProvider.cs +++ b/src/Microsoft.AspNet.Hosting/Startup/IStartupLoaderProvider.cs @@ -1,3 +1,20 @@ +// Copyright (c) Microsoft Open Technologies, Inc. +// All Rights Reserved +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR +// CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING +// WITHOUT LIMITATION ANY IMPLIED WARRANTIES OR CONDITIONS OF +// TITLE, FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABLITY OR +// NON-INFRINGEMENT. +// See the Apache 2 License for the specific language governing +// permissions and limitations under the License. + namespace Microsoft.AspNet.Hosting.Startup { public interface IStartupLoaderProvider diff --git a/src/Microsoft.AspNet.Hosting/Startup/IStartupManager.cs b/src/Microsoft.AspNet.Hosting/Startup/IStartupManager.cs index 0d92e09a89..8f2a948b78 100644 --- a/src/Microsoft.AspNet.Hosting/Startup/IStartupManager.cs +++ b/src/Microsoft.AspNet.Hosting/Startup/IStartupManager.cs @@ -1,3 +1,20 @@ +// Copyright (c) Microsoft Open Technologies, Inc. +// All Rights Reserved +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR +// CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING +// WITHOUT LIMITATION ANY IMPLIED WARRANTIES OR CONDITIONS OF +// TITLE, FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABLITY OR +// NON-INFRINGEMENT. +// See the Apache 2 License for the specific language governing +// permissions and limitations under the License. + using System; using Microsoft.AspNet.Abstractions; diff --git a/src/Microsoft.AspNet.Hosting/Startup/NullStartupLoader.cs b/src/Microsoft.AspNet.Hosting/Startup/NullStartupLoader.cs index e5e63c01f7..9a6e15ac3f 100644 --- a/src/Microsoft.AspNet.Hosting/Startup/NullStartupLoader.cs +++ b/src/Microsoft.AspNet.Hosting/Startup/NullStartupLoader.cs @@ -1,3 +1,20 @@ +// Copyright (c) Microsoft Open Technologies, Inc. +// All Rights Reserved +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR +// CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING +// WITHOUT LIMITATION ANY IMPLIED WARRANTIES OR CONDITIONS OF +// TITLE, FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABLITY OR +// NON-INFRINGEMENT. +// See the Apache 2 License for the specific language governing +// permissions and limitations under the License. + using System; using System.Collections.Generic; using Microsoft.AspNet.Abstractions; diff --git a/src/Microsoft.AspNet.Hosting/Startup/StartupLoader.cs b/src/Microsoft.AspNet.Hosting/Startup/StartupLoader.cs index 0f07be61b0..73a04b4abe 100644 --- a/src/Microsoft.AspNet.Hosting/Startup/StartupLoader.cs +++ b/src/Microsoft.AspNet.Hosting/Startup/StartupLoader.cs @@ -1,3 +1,20 @@ +// Copyright (c) Microsoft Open Technologies, Inc. +// All Rights Reserved +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR +// CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING +// WITHOUT LIMITATION ANY IMPLIED WARRANTIES OR CONDITIONS OF +// TITLE, FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABLITY OR +// NON-INFRINGEMENT. +// See the Apache 2 License for the specific language governing +// permissions and limitations under the License. + using System; using System.Collections.Generic; using System.Linq; diff --git a/src/Microsoft.AspNet.Hosting/Startup/StartupLoaderProvider.cs b/src/Microsoft.AspNet.Hosting/Startup/StartupLoaderProvider.cs index a30cc50488..a5e962786e 100644 --- a/src/Microsoft.AspNet.Hosting/Startup/StartupLoaderProvider.cs +++ b/src/Microsoft.AspNet.Hosting/Startup/StartupLoaderProvider.cs @@ -1,3 +1,20 @@ +// Copyright (c) Microsoft Open Technologies, Inc. +// All Rights Reserved +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR +// CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING +// WITHOUT LIMITATION ANY IMPLIED WARRANTIES OR CONDITIONS OF +// TITLE, FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABLITY OR +// NON-INFRINGEMENT. +// See the Apache 2 License for the specific language governing +// permissions and limitations under the License. + using System; namespace Microsoft.AspNet.Hosting.Startup diff --git a/src/Microsoft.AspNet.Hosting/Startup/StartupManager.cs b/src/Microsoft.AspNet.Hosting/Startup/StartupManager.cs index 41d68b03da..4f84d583fc 100644 --- a/src/Microsoft.AspNet.Hosting/Startup/StartupManager.cs +++ b/src/Microsoft.AspNet.Hosting/Startup/StartupManager.cs @@ -1,3 +1,20 @@ +// Copyright (c) Microsoft Open Technologies, Inc. +// All Rights Reserved +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR +// CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING +// WITHOUT LIMITATION ANY IMPLIED WARRANTIES OR CONDITIONS OF +// TITLE, FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABLITY OR +// NON-INFRINGEMENT. +// See the Apache 2 License for the specific language governing +// permissions and limitations under the License. + using System; using System.Collections.Generic; using System.Linq; diff --git a/src/Microsoft.AspNet.Hosting/Utilities.cs b/src/Microsoft.AspNet.Hosting/Utilities.cs index ae98ea538f..c1795d0ab1 100644 --- a/src/Microsoft.AspNet.Hosting/Utilities.cs +++ b/src/Microsoft.AspNet.Hosting/Utilities.cs @@ -1,4 +1,21 @@ -using System; +// Copyright (c) Microsoft Open Technologies, Inc. +// All Rights Reserved +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR +// CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING +// WITHOUT LIMITATION ANY IMPLIED WARRANTIES OR CONDITIONS OF +// TITLE, FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABLITY OR +// NON-INFRINGEMENT. +// See the Apache 2 License for the specific language governing +// permissions and limitations under the License. + +using System; namespace Microsoft.AspNet.Hosting { diff --git a/src/Microsoft.AspNet.Hosting/WebApplication.cs b/src/Microsoft.AspNet.Hosting/WebApplication.cs index f01c7dea23..df3d548e84 100644 --- a/src/Microsoft.AspNet.Hosting/WebApplication.cs +++ b/src/Microsoft.AspNet.Hosting/WebApplication.cs @@ -1,4 +1,21 @@ -using System; +// Copyright (c) Microsoft Open Technologies, Inc. +// All Rights Reserved +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR +// CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING +// WITHOUT LIMITATION ANY IMPLIED WARRANTIES OR CONDITIONS OF +// TITLE, FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABLITY OR +// NON-INFRINGEMENT. +// See the Apache 2 License for the specific language governing +// permissions and limitations under the License. + +using System; using Microsoft.AspNet.DependencyInjection; using Microsoft.AspNet.DependencyInjection.Fallback; diff --git a/src/Microsoft.AspNet.RequestContainer/ContainerExtensions.cs b/src/Microsoft.AspNet.RequestContainer/ContainerExtensions.cs index 8648d8b220..0296824e4c 100644 --- a/src/Microsoft.AspNet.RequestContainer/ContainerExtensions.cs +++ b/src/Microsoft.AspNet.RequestContainer/ContainerExtensions.cs @@ -1,4 +1,21 @@ -using System; +// Copyright (c) Microsoft Open Technologies, Inc. +// All Rights Reserved +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR +// CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING +// WITHOUT LIMITATION ANY IMPLIED WARRANTIES OR CONDITIONS OF +// TITLE, FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABLITY OR +// NON-INFRINGEMENT. +// See the Apache 2 License for the specific language governing +// permissions and limitations under the License. + +using System; using System.Reflection; using System.Collections.Generic; using System.Linq; diff --git a/src/Microsoft.AspNet.RequestContainer/ContainerMiddleware.cs b/src/Microsoft.AspNet.RequestContainer/ContainerMiddleware.cs index 881d71ee0e..d72564f56c 100644 --- a/src/Microsoft.AspNet.RequestContainer/ContainerMiddleware.cs +++ b/src/Microsoft.AspNet.RequestContainer/ContainerMiddleware.cs @@ -1,4 +1,21 @@ -using System; +// Copyright (c) Microsoft Open Technologies, Inc. +// All Rights Reserved +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR +// CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING +// WITHOUT LIMITATION ANY IMPLIED WARRANTIES OR CONDITIONS OF +// TITLE, FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABLITY OR +// NON-INFRINGEMENT. +// See the Apache 2 License for the specific language governing +// permissions and limitations under the License. + +using System; #if NET45 using System.Runtime.Remoting.Messaging; #endif diff --git a/src/Microsoft.AspNet.TestHost/RequestInformation.cs b/src/Microsoft.AspNet.TestHost/RequestInformation.cs index eabfc0213a..cc1080ded0 100644 --- a/src/Microsoft.AspNet.TestHost/RequestInformation.cs +++ b/src/Microsoft.AspNet.TestHost/RequestInformation.cs @@ -1,4 +1,21 @@ -using System; +// Copyright (c) Microsoft Open Technologies, Inc. +// All Rights Reserved +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR +// CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING +// WITHOUT LIMITATION ANY IMPLIED WARRANTIES OR CONDITIONS OF +// TITLE, FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABLITY OR +// NON-INFRINGEMENT. +// See the Apache 2 License for the specific language governing +// permissions and limitations under the License. + +using System; using System.Collections.Generic; using System.IO; using Microsoft.AspNet.HttpFeature; diff --git a/src/Microsoft.AspNet.TestHost/ResponseInformation.cs b/src/Microsoft.AspNet.TestHost/ResponseInformation.cs index 7000b081c5..17851b4c2e 100644 --- a/src/Microsoft.AspNet.TestHost/ResponseInformation.cs +++ b/src/Microsoft.AspNet.TestHost/ResponseInformation.cs @@ -1,4 +1,21 @@ -using System; +// Copyright (c) Microsoft Open Technologies, Inc. +// All Rights Reserved +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR +// CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING +// WITHOUT LIMITATION ANY IMPLIED WARRANTIES OR CONDITIONS OF +// TITLE, FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABLITY OR +// NON-INFRINGEMENT. +// See the Apache 2 License for the specific language governing +// permissions and limitations under the License. + +using System; using System.Collections.Generic; using System.IO; using Microsoft.AspNet.HttpFeature; diff --git a/src/Microsoft.AspNet.TestHost/TestClient.cs b/src/Microsoft.AspNet.TestHost/TestClient.cs index e5f5fb6778..576617337b 100644 --- a/src/Microsoft.AspNet.TestHost/TestClient.cs +++ b/src/Microsoft.AspNet.TestHost/TestClient.cs @@ -1,4 +1,21 @@ -using System; +// Copyright (c) Microsoft Open Technologies, Inc. +// All Rights Reserved +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR +// CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING +// WITHOUT LIMITATION ANY IMPLIED WARRANTIES OR CONDITIONS OF +// TITLE, FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABLITY OR +// NON-INFRINGEMENT. +// See the Apache 2 License for the specific language governing +// permissions and limitations under the License. + +using System; using System.Collections.Generic; using System.Globalization; using System.IO; diff --git a/src/Microsoft.AspNet.TestHost/TestServer.cs b/src/Microsoft.AspNet.TestHost/TestServer.cs index 9256501426..0f5369578f 100644 --- a/src/Microsoft.AspNet.TestHost/TestServer.cs +++ b/src/Microsoft.AspNet.TestHost/TestServer.cs @@ -1,4 +1,21 @@ -using System; +// Copyright (c) Microsoft Open Technologies, Inc. +// All Rights Reserved +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR +// CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING +// WITHOUT LIMITATION ANY IMPLIED WARRANTIES OR CONDITIONS OF +// TITLE, FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABLITY OR +// NON-INFRINGEMENT. +// See the Apache 2 License for the specific language governing +// permissions and limitations under the License. + +using System; using System.Collections.Generic; using System.Runtime.Versioning; using System.Threading.Tasks; diff --git a/test/Microsoft.AspNet.Hosting.Tests/Fakes/FakeStartup.cs b/test/Microsoft.AspNet.Hosting.Tests/Fakes/FakeStartup.cs index 255fcf1aef..9fa8ee9668 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/Fakes/FakeStartup.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/Fakes/FakeStartup.cs @@ -1,3 +1,20 @@ +// Copyright (c) Microsoft Open Technologies, Inc. +// All Rights Reserved +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR +// CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING +// WITHOUT LIMITATION ANY IMPLIED WARRANTIES OR CONDITIONS OF +// TITLE, FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABLITY OR +// NON-INFRINGEMENT. +// See the Apache 2 License for the specific language governing +// permissions and limitations under the License. + using Microsoft.AspNet.Abstractions; namespace Microsoft.AspNet.Hosting.Fakes diff --git a/test/Microsoft.AspNet.Hosting.Tests/Fakes/FakeStartupWithServices.cs b/test/Microsoft.AspNet.Hosting.Tests/Fakes/FakeStartupWithServices.cs index ee8b28e3a5..22968394c5 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/Fakes/FakeStartupWithServices.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/Fakes/FakeStartupWithServices.cs @@ -1,3 +1,20 @@ +// Copyright (c) Microsoft Open Technologies, Inc. +// All Rights Reserved +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR +// CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING +// WITHOUT LIMITATION ANY IMPLIED WARRANTIES OR CONDITIONS OF +// TITLE, FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABLITY OR +// NON-INFRINGEMENT. +// See the Apache 2 License for the specific language governing +// permissions and limitations under the License. + using Microsoft.AspNet.Abstractions; namespace Microsoft.AspNet.Hosting.Fakes diff --git a/test/Microsoft.AspNet.Hosting.Tests/Fakes/IFakeStartupCallback.cs b/test/Microsoft.AspNet.Hosting.Tests/Fakes/IFakeStartupCallback.cs index 7fd7c9ba2b..708dac5281 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/Fakes/IFakeStartupCallback.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/Fakes/IFakeStartupCallback.cs @@ -1,3 +1,20 @@ +// Copyright (c) Microsoft Open Technologies, Inc. +// All Rights Reserved +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR +// CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING +// WITHOUT LIMITATION ANY IMPLIED WARRANTIES OR CONDITIONS OF +// TITLE, FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABLITY OR +// NON-INFRINGEMENT. +// See the Apache 2 License for the specific language governing +// permissions and limitations under the License. + namespace Microsoft.AspNet.Hosting.Fakes { public interface IFakeStartupCallback diff --git a/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs b/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs index a7fbfc88f1..884aaba514 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs @@ -1,4 +1,21 @@ -using System; +// Copyright (c) Microsoft Open Technologies, Inc. +// All Rights Reserved +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR +// CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING +// WITHOUT LIMITATION ANY IMPLIED WARRANTIES OR CONDITIONS OF +// TITLE, FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABLITY OR +// NON-INFRINGEMENT. +// See the Apache 2 License for the specific language governing +// permissions and limitations under the License. + +using System; using System.Collections.Generic; using System.Threading.Tasks; using Microsoft.AspNet.Abstractions; diff --git a/test/Microsoft.AspNet.Hosting.Tests/StartupManagerTests.cs b/test/Microsoft.AspNet.Hosting.Tests/StartupManagerTests.cs index d2693d12a1..efd7e2763a 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/StartupManagerTests.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/StartupManagerTests.cs @@ -1,4 +1,21 @@ -using System; +// Copyright (c) Microsoft Open Technologies, Inc. +// All Rights Reserved +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR +// CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING +// WITHOUT LIMITATION ANY IMPLIED WARRANTIES OR CONDITIONS OF +// TITLE, FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABLITY OR +// NON-INFRINGEMENT. +// See the Apache 2 License for the specific language governing +// permissions and limitations under the License. + +using System; using System.Collections.Generic; using Microsoft.AspNet.DependencyInjection; using Microsoft.AspNet.DependencyInjection.Fallback; diff --git a/test/Microsoft.AspNet.TestHost.Tests/TestApplicationEnvironment.cs b/test/Microsoft.AspNet.TestHost.Tests/TestApplicationEnvironment.cs index 93fb40c3f5..4e8ea2fe94 100644 --- a/test/Microsoft.AspNet.TestHost.Tests/TestApplicationEnvironment.cs +++ b/test/Microsoft.AspNet.TestHost.Tests/TestApplicationEnvironment.cs @@ -1,4 +1,21 @@ -using System; +// Copyright (c) Microsoft Open Technologies, Inc. +// All Rights Reserved +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR +// CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING +// WITHOUT LIMITATION ANY IMPLIED WARRANTIES OR CONDITIONS OF +// TITLE, FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABLITY OR +// NON-INFRINGEMENT. +// See the Apache 2 License for the specific language governing +// permissions and limitations under the License. + +using System; using System.Runtime.Versioning; using Microsoft.Net.Runtime; diff --git a/test/Microsoft.AspNet.TestHost.Tests/TestClientTests.cs b/test/Microsoft.AspNet.TestHost.Tests/TestClientTests.cs index b18dd0ccfa..e752b61e3b 100644 --- a/test/Microsoft.AspNet.TestHost.Tests/TestClientTests.cs +++ b/test/Microsoft.AspNet.TestHost.Tests/TestClientTests.cs @@ -1,4 +1,21 @@ -using System; +// Copyright (c) Microsoft Open Technologies, Inc. +// All Rights Reserved +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR +// CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING +// WITHOUT LIMITATION ANY IMPLIED WARRANTIES OR CONDITIONS OF +// TITLE, FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABLITY OR +// NON-INFRINGEMENT. +// See the Apache 2 License for the specific language governing +// permissions and limitations under the License. + +using System; using System.Collections.Generic; using System.IO; using System.Runtime.Versioning; diff --git a/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs b/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs index 62416f99f1..1c829edae6 100644 --- a/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs +++ b/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs @@ -1,4 +1,21 @@ -using System; +// Copyright (c) Microsoft Open Technologies, Inc. +// All Rights Reserved +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR +// CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING +// WITHOUT LIMITATION ANY IMPLIED WARRANTIES OR CONDITIONS OF +// TITLE, FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABLITY OR +// NON-INFRINGEMENT. +// See the Apache 2 License for the specific language governing +// permissions and limitations under the License. + +using System; using System.IO; using System.Runtime.Versioning; using System.Threading.Tasks; From 1a75e932150c14c3e4717dae92d89b79fdb7356b Mon Sep 17 00:00:00 2001 From: Louis DeJardin Date: Fri, 2 May 2014 14:45:23 -0700 Subject: [PATCH 049/987] Updating build scripts --- .gitignore | 1 + build.cmd | 3 +++ build.sh | 30 ++++++++++++++++++++++++++++++ 3 files changed, 34 insertions(+) create mode 100644 build.sh diff --git a/.gitignore b/.gitignore index 8bc217058d..aba9c594d7 100644 --- a/.gitignore +++ b/.gitignore @@ -13,6 +13,7 @@ PublishProfiles/ _ReSharper.* nuget.exe *net45.csproj +*net451.csproj *k10.csproj *.psess *.vsp diff --git a/build.cmd b/build.cmd index 7045ee1f84..2c32132fa3 100644 --- a/build.cmd +++ b/build.cmd @@ -18,6 +18,9 @@ copy %CACHED_NUGET% .nuget\nuget.exe > nul IF EXIST packages\KoreBuild goto run .nuget\NuGet.exe install KoreBuild -ExcludeVersion -o packages -nocache -pre .nuget\NuGet.exe install Sake -version 0.2 -o packages -ExcludeVersion +CALL packages\KoreBuild\build\kvm install -svr50 -x86 +CALL packages\KoreBuild\build\kvm install -svrc50 -x86 :run +CALL packages\KoreBuild\build\kvm use default -svr50 -x86 packages\Sake\tools\Sake.exe -I packages\KoreBuild\build -f makefile.shade %* diff --git a/build.sh b/build.sh new file mode 100644 index 0000000000..db1e0c3dde --- /dev/null +++ b/build.sh @@ -0,0 +1,30 @@ +#!/bin/sh + +if test `uname` = Darwin; then + cachedir=~/Library/Caches/KBuild +else + if x$XDG_DATA_HOME = x; then + cachedir=$HOME/.local/share + else + cachedir=$XDG_DATA_HOME; + fi +fi +mkdir -p $cachedir + +url=https://www.nuget.org/nuget.exe + +if test ! -f $cachedir/nuget.exe; then + wget -o $cachedir/nuget.exe $url 2>/dev/null || curl -o $cachedir/nuget.exe --location $url /dev/null +fi + +if test ! -e .nuget; then + mkdir .nuget + cp $cachedir/nuget.exe .nuget +fi + +if test ! -d packages/KoreBuild; then + mono .nuget/nuget.exe install KoreBuild -ExcludeVersion -o packages -nocache -pre + mono .nuget/nuget.exe install Sake -version 0.2 -o packages -ExcludeVersion +fi + +mono packages/Sake/tools/Sake.exe -I packages/KoreBuild/build -f makefile.shade "$@" \ No newline at end of file From 0e56ed4f3482de255c34c0766eabcb4cc040188f Mon Sep 17 00:00:00 2001 From: Louis DeJardin Date: Fri, 2 May 2014 15:07:38 -0700 Subject: [PATCH 050/987] Updating build scripts --- build.cmd | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build.cmd b/build.cmd index 2c32132fa3..903d532df3 100644 --- a/build.cmd +++ b/build.cmd @@ -18,8 +18,8 @@ copy %CACHED_NUGET% .nuget\nuget.exe > nul IF EXIST packages\KoreBuild goto run .nuget\NuGet.exe install KoreBuild -ExcludeVersion -o packages -nocache -pre .nuget\NuGet.exe install Sake -version 0.2 -o packages -ExcludeVersion -CALL packages\KoreBuild\build\kvm install -svr50 -x86 -CALL packages\KoreBuild\build\kvm install -svrc50 -x86 +CALL packages\KoreBuild\build\kvm upgrade -svr50 -x86 +CALL packages\KoreBuild\build\kvm install default -svrc50 -x86 :run CALL packages\KoreBuild\build\kvm use default -svr50 -x86 From 3141543f0439f85b10ce6fd72d2c820310e1ed47 Mon Sep 17 00:00:00 2001 From: Chris Ross Date: Mon, 5 May 2014 16:26:26 -0700 Subject: [PATCH 051/987] Fix HttpAbstractions dependency renames. --- Hosting.sln | 8 +++++++- samples/KWebStartup/Startup.cs | 2 +- samples/KWebStartup/project.json | 2 +- src/Microsoft.AspNet.Hosting/Builder/BuilderFactory.cs | 2 +- .../Builder/HttpContextFactory.cs | 2 +- src/Microsoft.AspNet.Hosting/Builder/IBuilderFactory.cs | 2 +- .../Builder/IHttpContextFactory.cs | 2 +- src/Microsoft.AspNet.Hosting/HostingContext.cs | 2 +- src/Microsoft.AspNet.Hosting/PipelineInstance.cs | 2 +- src/Microsoft.AspNet.Hosting/Server/IServerFactory.cs | 2 +- src/Microsoft.AspNet.Hosting/Startup/IStartupLoader.cs | 2 +- src/Microsoft.AspNet.Hosting/Startup/IStartupManager.cs | 2 +- src/Microsoft.AspNet.Hosting/Startup/NullStartupLoader.cs | 2 +- src/Microsoft.AspNet.Hosting/Startup/StartupLoader.cs | 2 +- src/Microsoft.AspNet.Hosting/Startup/StartupManager.cs | 2 +- src/Microsoft.AspNet.Hosting/project.json | 2 +- .../ContainerExtensions.cs | 2 +- .../ContainerMiddleware.cs | 2 +- src/Microsoft.AspNet.RequestContainer/project.json | 2 +- src/Microsoft.AspNet.TestHost/RequestInformation.cs | 2 +- src/Microsoft.AspNet.TestHost/ResponseInformation.cs | 2 +- src/Microsoft.AspNet.TestHost/TestClient.cs | 8 ++++---- src/Microsoft.AspNet.TestHost/TestServer.cs | 2 +- test/Microsoft.AspNet.Hosting.Tests/Fakes/FakeStartup.cs | 2 +- .../Fakes/FakeStartupWithServices.cs | 2 +- test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs | 2 +- test/Microsoft.AspNet.TestHost.Tests/TestClientTests.cs | 2 +- test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs | 2 +- 28 files changed, 37 insertions(+), 31 deletions(-) diff --git a/Hosting.sln b/Hosting.sln index afb4be9861..f9376adc31 100644 --- a/Hosting.sln +++ b/Hosting.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 2013 -VisualStudioVersion = 12.0.30327.0 +VisualStudioVersion = 12.0.30401.0 MinimumVisualStudioVersion = 10.0.40219.1 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{E0497F39-AFFB-4819-A116-E39E361915AB}" EndProject @@ -32,6 +32,7 @@ Global EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution {0ACB2719-9484-49B5-B8E3-117091192511}.Debug|Any CPU.ActiveCfg = Debug|x86 + {0ACB2719-9484-49B5-B8E3-117091192511}.Debug|Any CPU.Build.0 = Debug|x86 {0ACB2719-9484-49B5-B8E3-117091192511}.Debug|Mixed Platforms.ActiveCfg = Debug|x86 {0ACB2719-9484-49B5-B8E3-117091192511}.Debug|Mixed Platforms.Build.0 = Debug|x86 {0ACB2719-9484-49B5-B8E3-117091192511}.Debug|x86.ActiveCfg = Debug|x86 @@ -42,6 +43,7 @@ Global {0ACB2719-9484-49B5-B8E3-117091192511}.Release|x86.ActiveCfg = Release|x86 {0ACB2719-9484-49B5-B8E3-117091192511}.Release|x86.Build.0 = Release|x86 {1A415A3F-1081-45DB-809B-EE19CEA02DC0}.Debug|Any CPU.ActiveCfg = Debug|x86 + {1A415A3F-1081-45DB-809B-EE19CEA02DC0}.Debug|Any CPU.Build.0 = Debug|x86 {1A415A3F-1081-45DB-809B-EE19CEA02DC0}.Debug|Mixed Platforms.ActiveCfg = Debug|x86 {1A415A3F-1081-45DB-809B-EE19CEA02DC0}.Debug|Mixed Platforms.Build.0 = Debug|x86 {1A415A3F-1081-45DB-809B-EE19CEA02DC0}.Debug|x86.ActiveCfg = Debug|x86 @@ -52,6 +54,7 @@ Global {1A415A3F-1081-45DB-809B-EE19CEA02DC0}.Release|x86.ActiveCfg = Release|x86 {1A415A3F-1081-45DB-809B-EE19CEA02DC0}.Release|x86.Build.0 = Release|x86 {3944F036-7E75-47E8-AA52-C4B89A64EC3A}.Debug|Any CPU.ActiveCfg = Debug|x86 + {3944F036-7E75-47E8-AA52-C4B89A64EC3A}.Debug|Any CPU.Build.0 = Debug|x86 {3944F036-7E75-47E8-AA52-C4B89A64EC3A}.Debug|Mixed Platforms.ActiveCfg = Debug|x86 {3944F036-7E75-47E8-AA52-C4B89A64EC3A}.Debug|Mixed Platforms.Build.0 = Debug|x86 {3944F036-7E75-47E8-AA52-C4B89A64EC3A}.Debug|x86.ActiveCfg = Debug|x86 @@ -62,6 +65,7 @@ Global {3944F036-7E75-47E8-AA52-C4B89A64EC3A}.Release|x86.ActiveCfg = Release|x86 {3944F036-7E75-47E8-AA52-C4B89A64EC3A}.Release|x86.Build.0 = Release|x86 {D4F18D58-52B1-435D-A012-10F2CDF158C4}.Debug|Any CPU.ActiveCfg = Debug|x86 + {D4F18D58-52B1-435D-A012-10F2CDF158C4}.Debug|Any CPU.Build.0 = Debug|x86 {D4F18D58-52B1-435D-A012-10F2CDF158C4}.Debug|Mixed Platforms.ActiveCfg = Debug|x86 {D4F18D58-52B1-435D-A012-10F2CDF158C4}.Debug|Mixed Platforms.Build.0 = Debug|x86 {D4F18D58-52B1-435D-A012-10F2CDF158C4}.Debug|x86.ActiveCfg = Debug|x86 @@ -72,6 +76,7 @@ Global {D4F18D58-52B1-435D-A012-10F2CDF158C4}.Release|x86.ActiveCfg = Release|x86 {D4F18D58-52B1-435D-A012-10F2CDF158C4}.Release|x86.Build.0 = Release|x86 {374A5B0C-3E93-4A23-A4A0-EE2AB6DF7814}.Debug|Any CPU.ActiveCfg = Debug|x86 + {374A5B0C-3E93-4A23-A4A0-EE2AB6DF7814}.Debug|Any CPU.Build.0 = Debug|x86 {374A5B0C-3E93-4A23-A4A0-EE2AB6DF7814}.Debug|Mixed Platforms.ActiveCfg = Debug|x86 {374A5B0C-3E93-4A23-A4A0-EE2AB6DF7814}.Debug|Mixed Platforms.Build.0 = Debug|x86 {374A5B0C-3E93-4A23-A4A0-EE2AB6DF7814}.Debug|x86.ActiveCfg = Debug|x86 @@ -82,6 +87,7 @@ Global {374A5B0C-3E93-4A23-A4A0-EE2AB6DF7814}.Release|x86.ActiveCfg = Release|x86 {374A5B0C-3E93-4A23-A4A0-EE2AB6DF7814}.Release|x86.Build.0 = Release|x86 {A2F321A5-3F55-4413-B357-EEF85DC0ECA6}.Debug|Any CPU.ActiveCfg = Debug|x86 + {A2F321A5-3F55-4413-B357-EEF85DC0ECA6}.Debug|Any CPU.Build.0 = Debug|x86 {A2F321A5-3F55-4413-B357-EEF85DC0ECA6}.Debug|Mixed Platforms.ActiveCfg = Debug|x86 {A2F321A5-3F55-4413-B357-EEF85DC0ECA6}.Debug|Mixed Platforms.Build.0 = Debug|x86 {A2F321A5-3F55-4413-B357-EEF85DC0ECA6}.Debug|x86.ActiveCfg = Debug|x86 diff --git a/samples/KWebStartup/Startup.cs b/samples/KWebStartup/Startup.cs index 003f957c97..daeb4dd7d3 100644 --- a/samples/KWebStartup/Startup.cs +++ b/samples/KWebStartup/Startup.cs @@ -16,7 +16,7 @@ // permissions and limitations under the License. using Microsoft.AspNet; -using Microsoft.AspNet.Abstractions; +using Microsoft.AspNet.Http; namespace KWebStartup { diff --git a/samples/KWebStartup/project.json b/samples/KWebStartup/project.json index ab2f5706ee..627c07e0ac 100644 --- a/samples/KWebStartup/project.json +++ b/samples/KWebStartup/project.json @@ -1,7 +1,7 @@ { "version": "0.1-alpha-*", "dependencies": { - "Microsoft.AspNet.Abstractions": "0.1-alpha-*", + "Microsoft.AspNet.Http": "0.1-alpha-*", "Microsoft.AspNet.Hosting": "", "Microsoft.AspNet.Server.WebListener": "0.1-alpha-*" }, diff --git a/src/Microsoft.AspNet.Hosting/Builder/BuilderFactory.cs b/src/Microsoft.AspNet.Hosting/Builder/BuilderFactory.cs index 8a19d56ed9..64eaba6302 100644 --- a/src/Microsoft.AspNet.Hosting/Builder/BuilderFactory.cs +++ b/src/Microsoft.AspNet.Hosting/Builder/BuilderFactory.cs @@ -16,7 +16,7 @@ // permissions and limitations under the License. using System; -using Microsoft.AspNet.Abstractions; +using Microsoft.AspNet.Http; namespace Microsoft.AspNet.Hosting.Builder { diff --git a/src/Microsoft.AspNet.Hosting/Builder/HttpContextFactory.cs b/src/Microsoft.AspNet.Hosting/Builder/HttpContextFactory.cs index d2e8ba071a..288dea101d 100644 --- a/src/Microsoft.AspNet.Hosting/Builder/HttpContextFactory.cs +++ b/src/Microsoft.AspNet.Hosting/Builder/HttpContextFactory.cs @@ -15,7 +15,7 @@ // See the Apache 2 License for the specific language governing // permissions and limitations under the License. -using Microsoft.AspNet.Abstractions; +using Microsoft.AspNet.Http; using Microsoft.AspNet.FeatureModel; using Microsoft.AspNet.Hosting.Server; using Microsoft.AspNet.PipelineCore; diff --git a/src/Microsoft.AspNet.Hosting/Builder/IBuilderFactory.cs b/src/Microsoft.AspNet.Hosting/Builder/IBuilderFactory.cs index 5f76b74b90..4e80cc8730 100644 --- a/src/Microsoft.AspNet.Hosting/Builder/IBuilderFactory.cs +++ b/src/Microsoft.AspNet.Hosting/Builder/IBuilderFactory.cs @@ -15,7 +15,7 @@ // See the Apache 2 License for the specific language governing // permissions and limitations under the License. -using Microsoft.AspNet.Abstractions; +using Microsoft.AspNet.Http; namespace Microsoft.AspNet.Hosting.Builder { diff --git a/src/Microsoft.AspNet.Hosting/Builder/IHttpContextFactory.cs b/src/Microsoft.AspNet.Hosting/Builder/IHttpContextFactory.cs index 2cdcf30a75..6621c4b605 100644 --- a/src/Microsoft.AspNet.Hosting/Builder/IHttpContextFactory.cs +++ b/src/Microsoft.AspNet.Hosting/Builder/IHttpContextFactory.cs @@ -15,7 +15,7 @@ // See the Apache 2 License for the specific language governing // permissions and limitations under the License. -using Microsoft.AspNet.Abstractions; +using Microsoft.AspNet.Http; namespace Microsoft.AspNet.Hosting.Builder { diff --git a/src/Microsoft.AspNet.Hosting/HostingContext.cs b/src/Microsoft.AspNet.Hosting/HostingContext.cs index 974c4783f4..08183b88e0 100644 --- a/src/Microsoft.AspNet.Hosting/HostingContext.cs +++ b/src/Microsoft.AspNet.Hosting/HostingContext.cs @@ -16,7 +16,7 @@ // permissions and limitations under the License. using System; -using Microsoft.AspNet.Abstractions; +using Microsoft.AspNet.Http; using Microsoft.AspNet.ConfigurationModel; using Microsoft.AspNet.Hosting.Server; diff --git a/src/Microsoft.AspNet.Hosting/PipelineInstance.cs b/src/Microsoft.AspNet.Hosting/PipelineInstance.cs index b6bf92de86..40c656b9be 100644 --- a/src/Microsoft.AspNet.Hosting/PipelineInstance.cs +++ b/src/Microsoft.AspNet.Hosting/PipelineInstance.cs @@ -17,7 +17,7 @@ using System; using System.Threading.Tasks; -using Microsoft.AspNet.Abstractions; +using Microsoft.AspNet.Http; using Microsoft.AspNet.Hosting.Builder; using Microsoft.AspNet.Hosting.Server; diff --git a/src/Microsoft.AspNet.Hosting/Server/IServerFactory.cs b/src/Microsoft.AspNet.Hosting/Server/IServerFactory.cs index cd8e42f28b..0f069629e1 100644 --- a/src/Microsoft.AspNet.Hosting/Server/IServerFactory.cs +++ b/src/Microsoft.AspNet.Hosting/Server/IServerFactory.cs @@ -17,7 +17,7 @@ using System; using System.Threading.Tasks; -using Microsoft.AspNet.Abstractions; +using Microsoft.AspNet.Http; using Microsoft.AspNet.ConfigurationModel; namespace Microsoft.AspNet.Hosting.Server diff --git a/src/Microsoft.AspNet.Hosting/Startup/IStartupLoader.cs b/src/Microsoft.AspNet.Hosting/Startup/IStartupLoader.cs index 2115a7e57d..e06ea4fa1b 100644 --- a/src/Microsoft.AspNet.Hosting/Startup/IStartupLoader.cs +++ b/src/Microsoft.AspNet.Hosting/Startup/IStartupLoader.cs @@ -17,7 +17,7 @@ using System; using System.Collections.Generic; -using Microsoft.AspNet.Abstractions; +using Microsoft.AspNet.Http; namespace Microsoft.AspNet.Hosting.Startup { diff --git a/src/Microsoft.AspNet.Hosting/Startup/IStartupManager.cs b/src/Microsoft.AspNet.Hosting/Startup/IStartupManager.cs index 8f2a948b78..82e14d4b01 100644 --- a/src/Microsoft.AspNet.Hosting/Startup/IStartupManager.cs +++ b/src/Microsoft.AspNet.Hosting/Startup/IStartupManager.cs @@ -16,7 +16,7 @@ // permissions and limitations under the License. using System; -using Microsoft.AspNet.Abstractions; +using Microsoft.AspNet.Http; namespace Microsoft.AspNet.Hosting.Startup { diff --git a/src/Microsoft.AspNet.Hosting/Startup/NullStartupLoader.cs b/src/Microsoft.AspNet.Hosting/Startup/NullStartupLoader.cs index 9a6e15ac3f..1ce1553cc8 100644 --- a/src/Microsoft.AspNet.Hosting/Startup/NullStartupLoader.cs +++ b/src/Microsoft.AspNet.Hosting/Startup/NullStartupLoader.cs @@ -17,7 +17,7 @@ using System; using System.Collections.Generic; -using Microsoft.AspNet.Abstractions; +using Microsoft.AspNet.Http; namespace Microsoft.AspNet.Hosting.Startup { diff --git a/src/Microsoft.AspNet.Hosting/Startup/StartupLoader.cs b/src/Microsoft.AspNet.Hosting/Startup/StartupLoader.cs index 73a04b4abe..2c13cc06c8 100644 --- a/src/Microsoft.AspNet.Hosting/Startup/StartupLoader.cs +++ b/src/Microsoft.AspNet.Hosting/Startup/StartupLoader.cs @@ -19,7 +19,7 @@ using System; using System.Collections.Generic; using System.Linq; using System.Reflection; -using Microsoft.AspNet.Abstractions; +using Microsoft.AspNet.Http; using Microsoft.AspNet.DependencyInjection; namespace Microsoft.AspNet.Hosting.Startup diff --git a/src/Microsoft.AspNet.Hosting/Startup/StartupManager.cs b/src/Microsoft.AspNet.Hosting/Startup/StartupManager.cs index 4f84d583fc..e94d71a184 100644 --- a/src/Microsoft.AspNet.Hosting/Startup/StartupManager.cs +++ b/src/Microsoft.AspNet.Hosting/Startup/StartupManager.cs @@ -18,7 +18,7 @@ using System; using System.Collections.Generic; using System.Linq; -using Microsoft.AspNet.Abstractions; +using Microsoft.AspNet.Http; namespace Microsoft.AspNet.Hosting.Startup { diff --git a/src/Microsoft.AspNet.Hosting/project.json b/src/Microsoft.AspNet.Hosting/project.json index 159032003b..90f6209355 100644 --- a/src/Microsoft.AspNet.Hosting/project.json +++ b/src/Microsoft.AspNet.Hosting/project.json @@ -4,7 +4,7 @@ "Microsoft.AspNet.DependencyInjection": "0.1-alpha-*", "Microsoft.AspNet.ConfigurationModel": "0.1-alpha-*", "Microsoft.AspNet.PipelineCore": "0.1-alpha-*", - "Microsoft.AspNet.Abstractions": "0.1-alpha-*", + "Microsoft.AspNet.Http": "0.1-alpha-*", "Microsoft.AspNet.FeatureModel": "0.1-alpha-*", "Microsoft.AspNet.Security.DataProtection": "0.1-alpha-*", "Microsoft.Net.Runtime.Interfaces": "0.1-alpha-*" diff --git a/src/Microsoft.AspNet.RequestContainer/ContainerExtensions.cs b/src/Microsoft.AspNet.RequestContainer/ContainerExtensions.cs index 0296824e4c..e16de29de2 100644 --- a/src/Microsoft.AspNet.RequestContainer/ContainerExtensions.cs +++ b/src/Microsoft.AspNet.RequestContainer/ContainerExtensions.cs @@ -19,7 +19,7 @@ using System; using System.Reflection; using System.Collections.Generic; using System.Linq; -using Microsoft.AspNet.Abstractions; +using Microsoft.AspNet.Http; using Microsoft.AspNet.DependencyInjection; using Microsoft.AspNet.DependencyInjection.Fallback; using Microsoft.AspNet.RequestContainer; diff --git a/src/Microsoft.AspNet.RequestContainer/ContainerMiddleware.cs b/src/Microsoft.AspNet.RequestContainer/ContainerMiddleware.cs index d72564f56c..02105f8290 100644 --- a/src/Microsoft.AspNet.RequestContainer/ContainerMiddleware.cs +++ b/src/Microsoft.AspNet.RequestContainer/ContainerMiddleware.cs @@ -20,7 +20,7 @@ using System; using System.Runtime.Remoting.Messaging; #endif using System.Threading.Tasks; -using Microsoft.AspNet.Abstractions; +using Microsoft.AspNet.Http; using Microsoft.AspNet.DependencyInjection; namespace Microsoft.AspNet.RequestContainer diff --git a/src/Microsoft.AspNet.RequestContainer/project.json b/src/Microsoft.AspNet.RequestContainer/project.json index a438c15933..5b12dbaab9 100644 --- a/src/Microsoft.AspNet.RequestContainer/project.json +++ b/src/Microsoft.AspNet.RequestContainer/project.json @@ -2,7 +2,7 @@ "version": "0.1-alpha-*", "dependencies": { "Microsoft.AspNet.DependencyInjection": "0.1-alpha-*", - "Microsoft.AspNet.Abstractions": "0.1-alpha-*" + "Microsoft.AspNet.Http": "0.1-alpha-*" }, "configurations": { "net45": {}, diff --git a/src/Microsoft.AspNet.TestHost/RequestInformation.cs b/src/Microsoft.AspNet.TestHost/RequestInformation.cs index cc1080ded0..d5815ee993 100644 --- a/src/Microsoft.AspNet.TestHost/RequestInformation.cs +++ b/src/Microsoft.AspNet.TestHost/RequestInformation.cs @@ -22,7 +22,7 @@ using Microsoft.AspNet.HttpFeature; namespace Microsoft.AspNet.TestHost { - internal class RequestInformation : IHttpRequestInformation + internal class RequestInformation : IHttpRequestFeature { public RequestInformation() { diff --git a/src/Microsoft.AspNet.TestHost/ResponseInformation.cs b/src/Microsoft.AspNet.TestHost/ResponseInformation.cs index 17851b4c2e..9a8f672817 100644 --- a/src/Microsoft.AspNet.TestHost/ResponseInformation.cs +++ b/src/Microsoft.AspNet.TestHost/ResponseInformation.cs @@ -22,7 +22,7 @@ using Microsoft.AspNet.HttpFeature; namespace Microsoft.AspNet.TestHost { - internal class ResponseInformation : IHttpResponseInformation + internal class ResponseInformation : IHttpResponseFeature { public ResponseInformation() { diff --git a/src/Microsoft.AspNet.TestHost/TestClient.cs b/src/Microsoft.AspNet.TestHost/TestClient.cs index 576617337b..7f9d7e8219 100644 --- a/src/Microsoft.AspNet.TestHost/TestClient.cs +++ b/src/Microsoft.AspNet.TestHost/TestClient.cs @@ -21,7 +21,7 @@ using System.Globalization; using System.IO; using System.Text; using System.Threading.Tasks; -using Microsoft.AspNet.Abstractions; +using Microsoft.AspNet.Http; using Microsoft.AspNet.FeatureModel; using Microsoft.AspNet.HttpFeature; using Microsoft.AspNet.PipelineCore; @@ -56,8 +56,8 @@ namespace Microsoft.AspNet.TestHost var response = new ResponseInformation(); var features = new FeatureCollection(); - features.Add(typeof(IHttpRequestInformation), request); - features.Add(typeof(IHttpResponseInformation), response); + features.Add(typeof(IHttpRequestFeature), request); + features.Add(typeof(IHttpResponseFeature), response); var httpContext = new DefaultHttpContext(features); if (onSendingRequest != null) @@ -70,7 +70,7 @@ namespace Microsoft.AspNet.TestHost return httpContext.Response; } - private static IHttpRequestInformation CreateRequest( + private static IHttpRequestFeature CreateRequest( string method, Uri uri, IDictionary headers, diff --git a/src/Microsoft.AspNet.TestHost/TestServer.cs b/src/Microsoft.AspNet.TestHost/TestServer.cs index 0f5369578f..d4c39ba180 100644 --- a/src/Microsoft.AspNet.TestHost/TestServer.cs +++ b/src/Microsoft.AspNet.TestHost/TestServer.cs @@ -19,7 +19,7 @@ using System; using System.Collections.Generic; using System.Runtime.Versioning; using System.Threading.Tasks; -using Microsoft.AspNet.Abstractions; +using Microsoft.AspNet.Http; using Microsoft.AspNet.ConfigurationModel; using Microsoft.AspNet.DependencyInjection; using Microsoft.AspNet.DependencyInjection.Fallback; diff --git a/test/Microsoft.AspNet.Hosting.Tests/Fakes/FakeStartup.cs b/test/Microsoft.AspNet.Hosting.Tests/Fakes/FakeStartup.cs index 9fa8ee9668..eeb7b22470 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/Fakes/FakeStartup.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/Fakes/FakeStartup.cs @@ -15,7 +15,7 @@ // See the Apache 2 License for the specific language governing // permissions and limitations under the License. -using Microsoft.AspNet.Abstractions; +using Microsoft.AspNet.Http; namespace Microsoft.AspNet.Hosting.Fakes { diff --git a/test/Microsoft.AspNet.Hosting.Tests/Fakes/FakeStartupWithServices.cs b/test/Microsoft.AspNet.Hosting.Tests/Fakes/FakeStartupWithServices.cs index 22968394c5..cef3346562 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/Fakes/FakeStartupWithServices.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/Fakes/FakeStartupWithServices.cs @@ -15,7 +15,7 @@ // See the Apache 2 License for the specific language governing // permissions and limitations under the License. -using Microsoft.AspNet.Abstractions; +using Microsoft.AspNet.Http; namespace Microsoft.AspNet.Hosting.Fakes { diff --git a/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs b/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs index 884aaba514..847d0a056c 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs @@ -18,7 +18,7 @@ using System; using System.Collections.Generic; using System.Threading.Tasks; -using Microsoft.AspNet.Abstractions; +using Microsoft.AspNet.Http; using Microsoft.AspNet.ConfigurationModel; using Microsoft.AspNet.DependencyInjection; using Microsoft.AspNet.DependencyInjection.Fallback; diff --git a/test/Microsoft.AspNet.TestHost.Tests/TestClientTests.cs b/test/Microsoft.AspNet.TestHost.Tests/TestClientTests.cs index e752b61e3b..3c7a156069 100644 --- a/test/Microsoft.AspNet.TestHost.Tests/TestClientTests.cs +++ b/test/Microsoft.AspNet.TestHost.Tests/TestClientTests.cs @@ -20,7 +20,7 @@ using System.Collections.Generic; using System.IO; using System.Runtime.Versioning; using System.Threading.Tasks; -using Microsoft.AspNet.Abstractions; +using Microsoft.AspNet.Http; using Microsoft.AspNet.DependencyInjection; using Microsoft.AspNet.DependencyInjection.Fallback; using Microsoft.Net.Runtime; diff --git a/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs b/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs index 1c829edae6..351a74ff01 100644 --- a/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs +++ b/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs @@ -19,7 +19,7 @@ using System; using System.IO; using System.Runtime.Versioning; using System.Threading.Tasks; -using Microsoft.AspNet.Abstractions; +using Microsoft.AspNet.Http; using Microsoft.AspNet.DependencyInjection; using Microsoft.AspNet.DependencyInjection.Fallback; using Microsoft.Net.Runtime; From d8ff084dc163618ef5fb3968c9ff721351520c25 Mon Sep 17 00:00:00 2001 From: Wei Wang Date: Mon, 5 May 2014 19:55:23 -0700 Subject: [PATCH 052/987] Update dependency namespace --- src/Microsoft.AspNet.Hosting/HostingContext.cs | 2 +- src/Microsoft.AspNet.Hosting/HostingServices.cs | 2 +- src/Microsoft.AspNet.Hosting/Program.cs | 2 +- src/Microsoft.AspNet.Hosting/Server/IServerFactory.cs | 2 +- src/Microsoft.AspNet.Hosting/project.json | 2 +- src/Microsoft.AspNet.TestHost/TestServer.cs | 2 +- test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/Microsoft.AspNet.Hosting/HostingContext.cs b/src/Microsoft.AspNet.Hosting/HostingContext.cs index 08183b88e0..bb85c4d25f 100644 --- a/src/Microsoft.AspNet.Hosting/HostingContext.cs +++ b/src/Microsoft.AspNet.Hosting/HostingContext.cs @@ -17,7 +17,7 @@ using System; using Microsoft.AspNet.Http; -using Microsoft.AspNet.ConfigurationModel; +using Microsoft.Framework.ConfigurationModel; using Microsoft.AspNet.Hosting.Server; namespace Microsoft.AspNet.Hosting diff --git a/src/Microsoft.AspNet.Hosting/HostingServices.cs b/src/Microsoft.AspNet.Hosting/HostingServices.cs index d196876873..b9b0c94dbb 100644 --- a/src/Microsoft.AspNet.Hosting/HostingServices.cs +++ b/src/Microsoft.AspNet.Hosting/HostingServices.cs @@ -16,7 +16,7 @@ // permissions and limitations under the License. using System.Collections.Generic; -using Microsoft.AspNet.ConfigurationModel; +using Microsoft.Framework.ConfigurationModel; using Microsoft.AspNet.DependencyInjection; using Microsoft.AspNet.Hosting.Builder; using Microsoft.AspNet.Hosting.Server; diff --git a/src/Microsoft.AspNet.Hosting/Program.cs b/src/Microsoft.AspNet.Hosting/Program.cs index 7c5585bbc6..5f098b4bd8 100644 --- a/src/Microsoft.AspNet.Hosting/Program.cs +++ b/src/Microsoft.AspNet.Hosting/Program.cs @@ -17,7 +17,7 @@ using System; using System.IO; -using Microsoft.AspNet.ConfigurationModel; +using Microsoft.Framework.ConfigurationModel; using Microsoft.AspNet.DependencyInjection; using Microsoft.AspNet.DependencyInjection.Fallback; using Microsoft.Net.Runtime; diff --git a/src/Microsoft.AspNet.Hosting/Server/IServerFactory.cs b/src/Microsoft.AspNet.Hosting/Server/IServerFactory.cs index 0f069629e1..83a1c67c19 100644 --- a/src/Microsoft.AspNet.Hosting/Server/IServerFactory.cs +++ b/src/Microsoft.AspNet.Hosting/Server/IServerFactory.cs @@ -18,7 +18,7 @@ using System; using System.Threading.Tasks; using Microsoft.AspNet.Http; -using Microsoft.AspNet.ConfigurationModel; +using Microsoft.Framework.ConfigurationModel; namespace Microsoft.AspNet.Hosting.Server { diff --git a/src/Microsoft.AspNet.Hosting/project.json b/src/Microsoft.AspNet.Hosting/project.json index 90f6209355..0cd026f131 100644 --- a/src/Microsoft.AspNet.Hosting/project.json +++ b/src/Microsoft.AspNet.Hosting/project.json @@ -2,7 +2,7 @@ "version": "0.1-alpha-*", "dependencies": { "Microsoft.AspNet.DependencyInjection": "0.1-alpha-*", - "Microsoft.AspNet.ConfigurationModel": "0.1-alpha-*", + "Microsoft.Framework.ConfigurationModel": "0.1-alpha-*", "Microsoft.AspNet.PipelineCore": "0.1-alpha-*", "Microsoft.AspNet.Http": "0.1-alpha-*", "Microsoft.AspNet.FeatureModel": "0.1-alpha-*", diff --git a/src/Microsoft.AspNet.TestHost/TestServer.cs b/src/Microsoft.AspNet.TestHost/TestServer.cs index d4c39ba180..4c6092ac27 100644 --- a/src/Microsoft.AspNet.TestHost/TestServer.cs +++ b/src/Microsoft.AspNet.TestHost/TestServer.cs @@ -20,7 +20,7 @@ using System.Collections.Generic; using System.Runtime.Versioning; using System.Threading.Tasks; using Microsoft.AspNet.Http; -using Microsoft.AspNet.ConfigurationModel; +using Microsoft.Framework.ConfigurationModel; using Microsoft.AspNet.DependencyInjection; using Microsoft.AspNet.DependencyInjection.Fallback; using Microsoft.AspNet.Hosting; diff --git a/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs b/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs index 847d0a056c..c4ba4895c5 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs @@ -19,7 +19,7 @@ using System; using System.Collections.Generic; using System.Threading.Tasks; using Microsoft.AspNet.Http; -using Microsoft.AspNet.ConfigurationModel; +using Microsoft.Framework.ConfigurationModel; using Microsoft.AspNet.DependencyInjection; using Microsoft.AspNet.DependencyInjection.Fallback; using Microsoft.AspNet.Hosting.Server; From a4816ab78293acb1f08c686143139ebfd8c3477d Mon Sep 17 00:00:00 2001 From: David Fowler Date: Tue, 6 May 2014 00:02:26 -0700 Subject: [PATCH 053/987] React to renames --- src/Microsoft.AspNet.Hosting/Builder/BuilderFactory.cs | 3 ++- src/Microsoft.AspNet.Hosting/Builder/IBuilderFactory.cs | 1 + src/Microsoft.AspNet.Hosting/HostingContext.cs | 1 + src/Microsoft.AspNet.Hosting/PipelineInstance.cs | 1 + src/Microsoft.AspNet.Hosting/Server/IServerFactory.cs | 1 + src/Microsoft.AspNet.Hosting/Startup/IStartupLoader.cs | 1 + src/Microsoft.AspNet.Hosting/Startup/IStartupManager.cs | 1 + src/Microsoft.AspNet.Hosting/Startup/NullStartupLoader.cs | 1 + src/Microsoft.AspNet.Hosting/Startup/StartupLoader.cs | 1 + src/Microsoft.AspNet.Hosting/Startup/StartupManager.cs | 1 + src/Microsoft.AspNet.RequestContainer/ContainerExtensions.cs | 1 + src/Microsoft.AspNet.RequestContainer/ContainerMiddleware.cs | 1 + src/Microsoft.AspNet.TestHost/TestServer.cs | 1 + test/Microsoft.AspNet.Hosting.Tests/Fakes/FakeStartup.cs | 1 + .../Fakes/FakeStartupWithServices.cs | 1 + test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs | 1 + test/Microsoft.AspNet.TestHost.Tests/TestClientTests.cs | 1 + test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs | 1 + 18 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/Microsoft.AspNet.Hosting/Builder/BuilderFactory.cs b/src/Microsoft.AspNet.Hosting/Builder/BuilderFactory.cs index 64eaba6302..01a04d5df5 100644 --- a/src/Microsoft.AspNet.Hosting/Builder/BuilderFactory.cs +++ b/src/Microsoft.AspNet.Hosting/Builder/BuilderFactory.cs @@ -16,6 +16,7 @@ // permissions and limitations under the License. using System; +using Microsoft.AspNet.Builder; using Microsoft.AspNet.Http; namespace Microsoft.AspNet.Hosting.Builder @@ -31,7 +32,7 @@ namespace Microsoft.AspNet.Hosting.Builder public IBuilder CreateBuilder() { - return new PipelineCore.Builder(_serviceProvider); + return new Microsoft.AspNet.Builder.Builder(_serviceProvider); } } } diff --git a/src/Microsoft.AspNet.Hosting/Builder/IBuilderFactory.cs b/src/Microsoft.AspNet.Hosting/Builder/IBuilderFactory.cs index 4e80cc8730..ab9c2d3ba3 100644 --- a/src/Microsoft.AspNet.Hosting/Builder/IBuilderFactory.cs +++ b/src/Microsoft.AspNet.Hosting/Builder/IBuilderFactory.cs @@ -15,6 +15,7 @@ // See the Apache 2 License for the specific language governing // permissions and limitations under the License. +using Microsoft.AspNet.Builder; using Microsoft.AspNet.Http; namespace Microsoft.AspNet.Hosting.Builder diff --git a/src/Microsoft.AspNet.Hosting/HostingContext.cs b/src/Microsoft.AspNet.Hosting/HostingContext.cs index bb85c4d25f..b682e1a8c1 100644 --- a/src/Microsoft.AspNet.Hosting/HostingContext.cs +++ b/src/Microsoft.AspNet.Hosting/HostingContext.cs @@ -19,6 +19,7 @@ using System; using Microsoft.AspNet.Http; using Microsoft.Framework.ConfigurationModel; using Microsoft.AspNet.Hosting.Server; +using Microsoft.AspNet.Builder; namespace Microsoft.AspNet.Hosting { diff --git a/src/Microsoft.AspNet.Hosting/PipelineInstance.cs b/src/Microsoft.AspNet.Hosting/PipelineInstance.cs index 40c656b9be..c1a4977c24 100644 --- a/src/Microsoft.AspNet.Hosting/PipelineInstance.cs +++ b/src/Microsoft.AspNet.Hosting/PipelineInstance.cs @@ -20,6 +20,7 @@ using System.Threading.Tasks; using Microsoft.AspNet.Http; using Microsoft.AspNet.Hosting.Builder; using Microsoft.AspNet.Hosting.Server; +using Microsoft.AspNet.Builder; namespace Microsoft.AspNet.Hosting { diff --git a/src/Microsoft.AspNet.Hosting/Server/IServerFactory.cs b/src/Microsoft.AspNet.Hosting/Server/IServerFactory.cs index 83a1c67c19..21d3f06fbe 100644 --- a/src/Microsoft.AspNet.Hosting/Server/IServerFactory.cs +++ b/src/Microsoft.AspNet.Hosting/Server/IServerFactory.cs @@ -17,6 +17,7 @@ using System; using System.Threading.Tasks; +using Microsoft.AspNet.Builder; using Microsoft.AspNet.Http; using Microsoft.Framework.ConfigurationModel; diff --git a/src/Microsoft.AspNet.Hosting/Startup/IStartupLoader.cs b/src/Microsoft.AspNet.Hosting/Startup/IStartupLoader.cs index e06ea4fa1b..e8eaede1c7 100644 --- a/src/Microsoft.AspNet.Hosting/Startup/IStartupLoader.cs +++ b/src/Microsoft.AspNet.Hosting/Startup/IStartupLoader.cs @@ -17,6 +17,7 @@ using System; using System.Collections.Generic; +using Microsoft.AspNet.Builder; using Microsoft.AspNet.Http; namespace Microsoft.AspNet.Hosting.Startup diff --git a/src/Microsoft.AspNet.Hosting/Startup/IStartupManager.cs b/src/Microsoft.AspNet.Hosting/Startup/IStartupManager.cs index 82e14d4b01..7d4655f36f 100644 --- a/src/Microsoft.AspNet.Hosting/Startup/IStartupManager.cs +++ b/src/Microsoft.AspNet.Hosting/Startup/IStartupManager.cs @@ -16,6 +16,7 @@ // permissions and limitations under the License. using System; +using Microsoft.AspNet.Builder; using Microsoft.AspNet.Http; namespace Microsoft.AspNet.Hosting.Startup diff --git a/src/Microsoft.AspNet.Hosting/Startup/NullStartupLoader.cs b/src/Microsoft.AspNet.Hosting/Startup/NullStartupLoader.cs index 1ce1553cc8..c70dad2e65 100644 --- a/src/Microsoft.AspNet.Hosting/Startup/NullStartupLoader.cs +++ b/src/Microsoft.AspNet.Hosting/Startup/NullStartupLoader.cs @@ -17,6 +17,7 @@ using System; using System.Collections.Generic; +using Microsoft.AspNet.Builder; using Microsoft.AspNet.Http; namespace Microsoft.AspNet.Hosting.Startup diff --git a/src/Microsoft.AspNet.Hosting/Startup/StartupLoader.cs b/src/Microsoft.AspNet.Hosting/Startup/StartupLoader.cs index 2c13cc06c8..70adf45faa 100644 --- a/src/Microsoft.AspNet.Hosting/Startup/StartupLoader.cs +++ b/src/Microsoft.AspNet.Hosting/Startup/StartupLoader.cs @@ -21,6 +21,7 @@ using System.Linq; using System.Reflection; using Microsoft.AspNet.Http; using Microsoft.AspNet.DependencyInjection; +using Microsoft.AspNet.Builder; namespace Microsoft.AspNet.Hosting.Startup { diff --git a/src/Microsoft.AspNet.Hosting/Startup/StartupManager.cs b/src/Microsoft.AspNet.Hosting/Startup/StartupManager.cs index e94d71a184..16a6a4e2bb 100644 --- a/src/Microsoft.AspNet.Hosting/Startup/StartupManager.cs +++ b/src/Microsoft.AspNet.Hosting/Startup/StartupManager.cs @@ -18,6 +18,7 @@ using System; using System.Collections.Generic; using System.Linq; +using Microsoft.AspNet.Builder; using Microsoft.AspNet.Http; namespace Microsoft.AspNet.Hosting.Startup diff --git a/src/Microsoft.AspNet.RequestContainer/ContainerExtensions.cs b/src/Microsoft.AspNet.RequestContainer/ContainerExtensions.cs index e16de29de2..b4127db07f 100644 --- a/src/Microsoft.AspNet.RequestContainer/ContainerExtensions.cs +++ b/src/Microsoft.AspNet.RequestContainer/ContainerExtensions.cs @@ -23,6 +23,7 @@ using Microsoft.AspNet.Http; using Microsoft.AspNet.DependencyInjection; using Microsoft.AspNet.DependencyInjection.Fallback; using Microsoft.AspNet.RequestContainer; +using Microsoft.AspNet.Builder; namespace Microsoft.AspNet { diff --git a/src/Microsoft.AspNet.RequestContainer/ContainerMiddleware.cs b/src/Microsoft.AspNet.RequestContainer/ContainerMiddleware.cs index 02105f8290..edef5e2f37 100644 --- a/src/Microsoft.AspNet.RequestContainer/ContainerMiddleware.cs +++ b/src/Microsoft.AspNet.RequestContainer/ContainerMiddleware.cs @@ -22,6 +22,7 @@ using System.Runtime.Remoting.Messaging; using System.Threading.Tasks; using Microsoft.AspNet.Http; using Microsoft.AspNet.DependencyInjection; +using Microsoft.AspNet.Builder; namespace Microsoft.AspNet.RequestContainer { diff --git a/src/Microsoft.AspNet.TestHost/TestServer.cs b/src/Microsoft.AspNet.TestHost/TestServer.cs index 4c6092ac27..ebd87322b4 100644 --- a/src/Microsoft.AspNet.TestHost/TestServer.cs +++ b/src/Microsoft.AspNet.TestHost/TestServer.cs @@ -27,6 +27,7 @@ using Microsoft.AspNet.Hosting; using Microsoft.AspNet.Hosting.Server; using Microsoft.AspNet.Hosting.Startup; using Microsoft.Net.Runtime; +using Microsoft.AspNet.Builder; namespace Microsoft.AspNet.TestHost { diff --git a/test/Microsoft.AspNet.Hosting.Tests/Fakes/FakeStartup.cs b/test/Microsoft.AspNet.Hosting.Tests/Fakes/FakeStartup.cs index eeb7b22470..1df444a0af 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/Fakes/FakeStartup.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/Fakes/FakeStartup.cs @@ -15,6 +15,7 @@ // See the Apache 2 License for the specific language governing // permissions and limitations under the License. +using Microsoft.AspNet.Builder; using Microsoft.AspNet.Http; namespace Microsoft.AspNet.Hosting.Fakes diff --git a/test/Microsoft.AspNet.Hosting.Tests/Fakes/FakeStartupWithServices.cs b/test/Microsoft.AspNet.Hosting.Tests/Fakes/FakeStartupWithServices.cs index cef3346562..2150b21ea7 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/Fakes/FakeStartupWithServices.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/Fakes/FakeStartupWithServices.cs @@ -15,6 +15,7 @@ // See the Apache 2 License for the specific language governing // permissions and limitations under the License. +using Microsoft.AspNet.Builder; using Microsoft.AspNet.Http; namespace Microsoft.AspNet.Hosting.Fakes diff --git a/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs b/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs index c4ba4895c5..7bdd75f9c2 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs @@ -24,6 +24,7 @@ using Microsoft.AspNet.DependencyInjection; using Microsoft.AspNet.DependencyInjection.Fallback; using Microsoft.AspNet.Hosting.Server; using Xunit; +using Microsoft.AspNet.Builder; namespace Microsoft.AspNet.Hosting { diff --git a/test/Microsoft.AspNet.TestHost.Tests/TestClientTests.cs b/test/Microsoft.AspNet.TestHost.Tests/TestClientTests.cs index 3c7a156069..6a8dbbe2a3 100644 --- a/test/Microsoft.AspNet.TestHost.Tests/TestClientTests.cs +++ b/test/Microsoft.AspNet.TestHost.Tests/TestClientTests.cs @@ -25,6 +25,7 @@ using Microsoft.AspNet.DependencyInjection; using Microsoft.AspNet.DependencyInjection.Fallback; using Microsoft.Net.Runtime; using Xunit; +using Microsoft.AspNet.Builder; namespace Microsoft.AspNet.TestHost.Tests { diff --git a/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs b/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs index 351a74ff01..91e30a1cb2 100644 --- a/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs +++ b/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs @@ -24,6 +24,7 @@ using Microsoft.AspNet.DependencyInjection; using Microsoft.AspNet.DependencyInjection.Fallback; using Microsoft.Net.Runtime; using Xunit; +using Microsoft.AspNet.Builder; namespace Microsoft.AspNet.TestHost.Tests { From f72de34e103df9fb85b1f5076e4acfbf9fa4591f Mon Sep 17 00:00:00 2001 From: David Fowler Date: Tue, 6 May 2014 00:17:09 -0700 Subject: [PATCH 054/987] Move extension methods to builder namespace and fix sample --- samples/KWebStartup/Startup.cs | 1 + src/Microsoft.AspNet.RequestContainer/ContainerExtensions.cs | 3 +-- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/samples/KWebStartup/Startup.cs b/samples/KWebStartup/Startup.cs index daeb4dd7d3..a46d8bbc06 100644 --- a/samples/KWebStartup/Startup.cs +++ b/samples/KWebStartup/Startup.cs @@ -16,6 +16,7 @@ // permissions and limitations under the License. using Microsoft.AspNet; +using Microsoft.AspNet.Builder; using Microsoft.AspNet.Http; namespace KWebStartup diff --git a/src/Microsoft.AspNet.RequestContainer/ContainerExtensions.cs b/src/Microsoft.AspNet.RequestContainer/ContainerExtensions.cs index b4127db07f..7afc6cd6ab 100644 --- a/src/Microsoft.AspNet.RequestContainer/ContainerExtensions.cs +++ b/src/Microsoft.AspNet.RequestContainer/ContainerExtensions.cs @@ -23,9 +23,8 @@ using Microsoft.AspNet.Http; using Microsoft.AspNet.DependencyInjection; using Microsoft.AspNet.DependencyInjection.Fallback; using Microsoft.AspNet.RequestContainer; -using Microsoft.AspNet.Builder; -namespace Microsoft.AspNet +namespace Microsoft.AspNet.Builder { public static class ContainerExtensions { From 3b5767414141071c0501fbbd1cb0ed953bcf1a6a Mon Sep 17 00:00:00 2001 From: Chris Ross Date: Tue, 6 May 2014 11:11:00 -0700 Subject: [PATCH 055/987] Update DI dependency. --- src/Microsoft.AspNet.Hosting/HostingEngine.cs | 2 +- src/Microsoft.AspNet.Hosting/HostingServices.cs | 4 ++-- src/Microsoft.AspNet.Hosting/Program.cs | 4 ++-- src/Microsoft.AspNet.Hosting/Server/ServerManager.cs | 2 +- src/Microsoft.AspNet.Hosting/Startup/StartupLoader.cs | 2 +- src/Microsoft.AspNet.Hosting/WebApplication.cs | 4 ++-- src/Microsoft.AspNet.Hosting/project.json | 2 +- .../ContainerExtensions.cs | 7 +++---- .../ContainerMiddleware.cs | 4 ++-- src/Microsoft.AspNet.RequestContainer/project.json | 2 +- src/Microsoft.AspNet.TestHost/TestServer.cs | 10 ++++------ .../HostingEngineTests.cs | 11 +++++------ .../StartupManagerTests.cs | 7 +++---- .../TestClientTests.cs | 8 +++----- .../TestServerTests.cs | 8 +++----- 15 files changed, 34 insertions(+), 43 deletions(-) diff --git a/src/Microsoft.AspNet.Hosting/HostingEngine.cs b/src/Microsoft.AspNet.Hosting/HostingEngine.cs index 5346305db9..b1dd6093cb 100644 --- a/src/Microsoft.AspNet.Hosting/HostingEngine.cs +++ b/src/Microsoft.AspNet.Hosting/HostingEngine.cs @@ -17,10 +17,10 @@ using System; using System.Threading; -using Microsoft.AspNet.DependencyInjection; using Microsoft.AspNet.Hosting.Builder; using Microsoft.AspNet.Hosting.Server; using Microsoft.AspNet.Hosting.Startup; +using Microsoft.Framework.DependencyInjection; namespace Microsoft.AspNet.Hosting { diff --git a/src/Microsoft.AspNet.Hosting/HostingServices.cs b/src/Microsoft.AspNet.Hosting/HostingServices.cs index b9b0c94dbb..2ce566dbeb 100644 --- a/src/Microsoft.AspNet.Hosting/HostingServices.cs +++ b/src/Microsoft.AspNet.Hosting/HostingServices.cs @@ -16,12 +16,12 @@ // permissions and limitations under the License. using System.Collections.Generic; -using Microsoft.Framework.ConfigurationModel; -using Microsoft.AspNet.DependencyInjection; using Microsoft.AspNet.Hosting.Builder; using Microsoft.AspNet.Hosting.Server; using Microsoft.AspNet.Hosting.Startup; using Microsoft.AspNet.Security.DataProtection; +using Microsoft.Framework.ConfigurationModel; +using Microsoft.Framework.DependencyInjection; namespace Microsoft.AspNet.Hosting { diff --git a/src/Microsoft.AspNet.Hosting/Program.cs b/src/Microsoft.AspNet.Hosting/Program.cs index 5f098b4bd8..62cf645910 100644 --- a/src/Microsoft.AspNet.Hosting/Program.cs +++ b/src/Microsoft.AspNet.Hosting/Program.cs @@ -18,8 +18,8 @@ using System; using System.IO; using Microsoft.Framework.ConfigurationModel; -using Microsoft.AspNet.DependencyInjection; -using Microsoft.AspNet.DependencyInjection.Fallback; +using Microsoft.Framework.DependencyInjection; +using Microsoft.Framework.DependencyInjection.Fallback; using Microsoft.Net.Runtime; namespace Microsoft.AspNet.Hosting diff --git a/src/Microsoft.AspNet.Hosting/Server/ServerManager.cs b/src/Microsoft.AspNet.Hosting/Server/ServerManager.cs index 45b902e8cc..899e695fc0 100644 --- a/src/Microsoft.AspNet.Hosting/Server/ServerManager.cs +++ b/src/Microsoft.AspNet.Hosting/Server/ServerManager.cs @@ -18,7 +18,7 @@ using System; using System.Linq; using System.Reflection; -using Microsoft.AspNet.DependencyInjection; +using Microsoft.Framework.DependencyInjection; namespace Microsoft.AspNet.Hosting.Server { diff --git a/src/Microsoft.AspNet.Hosting/Startup/StartupLoader.cs b/src/Microsoft.AspNet.Hosting/Startup/StartupLoader.cs index 70adf45faa..b45aa4c004 100644 --- a/src/Microsoft.AspNet.Hosting/Startup/StartupLoader.cs +++ b/src/Microsoft.AspNet.Hosting/Startup/StartupLoader.cs @@ -20,7 +20,7 @@ using System.Collections.Generic; using System.Linq; using System.Reflection; using Microsoft.AspNet.Http; -using Microsoft.AspNet.DependencyInjection; +using Microsoft.Framework.DependencyInjection; using Microsoft.AspNet.Builder; namespace Microsoft.AspNet.Hosting.Startup diff --git a/src/Microsoft.AspNet.Hosting/WebApplication.cs b/src/Microsoft.AspNet.Hosting/WebApplication.cs index df3d548e84..ccd679476d 100644 --- a/src/Microsoft.AspNet.Hosting/WebApplication.cs +++ b/src/Microsoft.AspNet.Hosting/WebApplication.cs @@ -16,8 +16,8 @@ // permissions and limitations under the License. using System; -using Microsoft.AspNet.DependencyInjection; -using Microsoft.AspNet.DependencyInjection.Fallback; +using Microsoft.Framework.DependencyInjection; +using Microsoft.Framework.DependencyInjection.Fallback; namespace Microsoft.AspNet.Hosting { diff --git a/src/Microsoft.AspNet.Hosting/project.json b/src/Microsoft.AspNet.Hosting/project.json index 0cd026f131..612bea6588 100644 --- a/src/Microsoft.AspNet.Hosting/project.json +++ b/src/Microsoft.AspNet.Hosting/project.json @@ -1,7 +1,7 @@ { "version": "0.1-alpha-*", "dependencies": { - "Microsoft.AspNet.DependencyInjection": "0.1-alpha-*", + "Microsoft.Framework.DependencyInjection": "0.1-alpha-*", "Microsoft.Framework.ConfigurationModel": "0.1-alpha-*", "Microsoft.AspNet.PipelineCore": "0.1-alpha-*", "Microsoft.AspNet.Http": "0.1-alpha-*", diff --git a/src/Microsoft.AspNet.RequestContainer/ContainerExtensions.cs b/src/Microsoft.AspNet.RequestContainer/ContainerExtensions.cs index 7afc6cd6ab..8289754ef5 100644 --- a/src/Microsoft.AspNet.RequestContainer/ContainerExtensions.cs +++ b/src/Microsoft.AspNet.RequestContainer/ContainerExtensions.cs @@ -16,13 +16,12 @@ // permissions and limitations under the License. using System; -using System.Reflection; using System.Collections.Generic; using System.Linq; -using Microsoft.AspNet.Http; -using Microsoft.AspNet.DependencyInjection; -using Microsoft.AspNet.DependencyInjection.Fallback; +using System.Reflection; using Microsoft.AspNet.RequestContainer; +using Microsoft.Framework.DependencyInjection; +using Microsoft.Framework.DependencyInjection.Fallback; namespace Microsoft.AspNet.Builder { diff --git a/src/Microsoft.AspNet.RequestContainer/ContainerMiddleware.cs b/src/Microsoft.AspNet.RequestContainer/ContainerMiddleware.cs index edef5e2f37..8ef3862ac0 100644 --- a/src/Microsoft.AspNet.RequestContainer/ContainerMiddleware.cs +++ b/src/Microsoft.AspNet.RequestContainer/ContainerMiddleware.cs @@ -20,9 +20,9 @@ using System; using System.Runtime.Remoting.Messaging; #endif using System.Threading.Tasks; -using Microsoft.AspNet.Http; -using Microsoft.AspNet.DependencyInjection; using Microsoft.AspNet.Builder; +using Microsoft.AspNet.Http; +using Microsoft.Framework.DependencyInjection; namespace Microsoft.AspNet.RequestContainer { diff --git a/src/Microsoft.AspNet.RequestContainer/project.json b/src/Microsoft.AspNet.RequestContainer/project.json index 5b12dbaab9..fed205590c 100644 --- a/src/Microsoft.AspNet.RequestContainer/project.json +++ b/src/Microsoft.AspNet.RequestContainer/project.json @@ -1,7 +1,7 @@ { "version": "0.1-alpha-*", "dependencies": { - "Microsoft.AspNet.DependencyInjection": "0.1-alpha-*", + "Microsoft.Framework.DependencyInjection": "0.1-alpha-*", "Microsoft.AspNet.Http": "0.1-alpha-*" }, "configurations": { diff --git a/src/Microsoft.AspNet.TestHost/TestServer.cs b/src/Microsoft.AspNet.TestHost/TestServer.cs index ebd87322b4..79b024ad96 100644 --- a/src/Microsoft.AspNet.TestHost/TestServer.cs +++ b/src/Microsoft.AspNet.TestHost/TestServer.cs @@ -17,17 +17,15 @@ using System; using System.Collections.Generic; -using System.Runtime.Versioning; using System.Threading.Tasks; -using Microsoft.AspNet.Http; -using Microsoft.Framework.ConfigurationModel; -using Microsoft.AspNet.DependencyInjection; -using Microsoft.AspNet.DependencyInjection.Fallback; +using Microsoft.AspNet.Builder; using Microsoft.AspNet.Hosting; using Microsoft.AspNet.Hosting.Server; using Microsoft.AspNet.Hosting.Startup; +using Microsoft.Framework.ConfigurationModel; +using Microsoft.Framework.DependencyInjection; +using Microsoft.Framework.DependencyInjection.Fallback; using Microsoft.Net.Runtime; -using Microsoft.AspNet.Builder; namespace Microsoft.AspNet.TestHost { diff --git a/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs b/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs index 7bdd75f9c2..5491f92de9 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs @@ -18,13 +18,12 @@ using System; using System.Collections.Generic; using System.Threading.Tasks; -using Microsoft.AspNet.Http; -using Microsoft.Framework.ConfigurationModel; -using Microsoft.AspNet.DependencyInjection; -using Microsoft.AspNet.DependencyInjection.Fallback; -using Microsoft.AspNet.Hosting.Server; -using Xunit; using Microsoft.AspNet.Builder; +using Microsoft.AspNet.Hosting.Server; +using Microsoft.Framework.ConfigurationModel; +using Microsoft.Framework.DependencyInjection; +using Microsoft.Framework.DependencyInjection.Fallback; +using Xunit; namespace Microsoft.AspNet.Hosting { diff --git a/test/Microsoft.AspNet.Hosting.Tests/StartupManagerTests.cs b/test/Microsoft.AspNet.Hosting.Tests/StartupManagerTests.cs index efd7e2763a..b04aef9e4c 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/StartupManagerTests.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/StartupManagerTests.cs @@ -15,12 +15,11 @@ // See the Apache 2 License for the specific language governing // permissions and limitations under the License. -using System; using System.Collections.Generic; -using Microsoft.AspNet.DependencyInjection; -using Microsoft.AspNet.DependencyInjection.Fallback; -using Microsoft.AspNet.Hosting.Startup; using Microsoft.AspNet.Hosting.Fakes; +using Microsoft.AspNet.Hosting.Startup; +using Microsoft.Framework.DependencyInjection; +using Microsoft.Framework.DependencyInjection.Fallback; using Xunit; namespace Microsoft.AspNet.Hosting diff --git a/test/Microsoft.AspNet.TestHost.Tests/TestClientTests.cs b/test/Microsoft.AspNet.TestHost.Tests/TestClientTests.cs index 6a8dbbe2a3..d31abab0a4 100644 --- a/test/Microsoft.AspNet.TestHost.Tests/TestClientTests.cs +++ b/test/Microsoft.AspNet.TestHost.Tests/TestClientTests.cs @@ -18,14 +18,12 @@ using System; using System.Collections.Generic; using System.IO; -using System.Runtime.Versioning; using System.Threading.Tasks; -using Microsoft.AspNet.Http; -using Microsoft.AspNet.DependencyInjection; -using Microsoft.AspNet.DependencyInjection.Fallback; +using Microsoft.AspNet.Builder; +using Microsoft.Framework.DependencyInjection; +using Microsoft.Framework.DependencyInjection.Fallback; using Microsoft.Net.Runtime; using Xunit; -using Microsoft.AspNet.Builder; namespace Microsoft.AspNet.TestHost.Tests { diff --git a/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs b/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs index 91e30a1cb2..93561d7cc6 100644 --- a/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs +++ b/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs @@ -17,14 +17,12 @@ using System; using System.IO; -using System.Runtime.Versioning; using System.Threading.Tasks; -using Microsoft.AspNet.Http; -using Microsoft.AspNet.DependencyInjection; -using Microsoft.AspNet.DependencyInjection.Fallback; +using Microsoft.AspNet.Builder; +using Microsoft.Framework.DependencyInjection; +using Microsoft.Framework.DependencyInjection.Fallback; using Microsoft.Net.Runtime; using Xunit; -using Microsoft.AspNet.Builder; namespace Microsoft.AspNet.TestHost.Tests { From 7c7efeda57c7f4c11605d394921d90ce9ba4c1e1 Mon Sep 17 00:00:00 2001 From: Wei Wang Date: Tue, 6 May 2014 14:59:55 -0700 Subject: [PATCH 056/987] Fix ordering of usings and dependencies after namespace renaming --- src/Microsoft.AspNet.Hosting/HostingContext.cs | 6 +++--- src/Microsoft.AspNet.Hosting/PipelineInstance.cs | 2 +- src/Microsoft.AspNet.Hosting/Startup/StartupLoader.cs | 2 +- src/Microsoft.AspNet.Hosting/project.json | 8 ++++---- src/Microsoft.AspNet.RequestContainer/project.json | 4 ++-- 5 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/Microsoft.AspNet.Hosting/HostingContext.cs b/src/Microsoft.AspNet.Hosting/HostingContext.cs index b682e1a8c1..b0d430626d 100644 --- a/src/Microsoft.AspNet.Hosting/HostingContext.cs +++ b/src/Microsoft.AspNet.Hosting/HostingContext.cs @@ -16,10 +16,10 @@ // permissions and limitations under the License. using System; -using Microsoft.AspNet.Http; -using Microsoft.Framework.ConfigurationModel; -using Microsoft.AspNet.Hosting.Server; using Microsoft.AspNet.Builder; +using Microsoft.AspNet.Http; +using Microsoft.AspNet.Hosting.Server; +using Microsoft.Framework.ConfigurationModel; namespace Microsoft.AspNet.Hosting { diff --git a/src/Microsoft.AspNet.Hosting/PipelineInstance.cs b/src/Microsoft.AspNet.Hosting/PipelineInstance.cs index c1a4977c24..ec3a8f5284 100644 --- a/src/Microsoft.AspNet.Hosting/PipelineInstance.cs +++ b/src/Microsoft.AspNet.Hosting/PipelineInstance.cs @@ -17,10 +17,10 @@ using System; using System.Threading.Tasks; +using Microsoft.AspNet.Builder; using Microsoft.AspNet.Http; using Microsoft.AspNet.Hosting.Builder; using Microsoft.AspNet.Hosting.Server; -using Microsoft.AspNet.Builder; namespace Microsoft.AspNet.Hosting { diff --git a/src/Microsoft.AspNet.Hosting/Startup/StartupLoader.cs b/src/Microsoft.AspNet.Hosting/Startup/StartupLoader.cs index b45aa4c004..f9629c819f 100644 --- a/src/Microsoft.AspNet.Hosting/Startup/StartupLoader.cs +++ b/src/Microsoft.AspNet.Hosting/Startup/StartupLoader.cs @@ -19,9 +19,9 @@ using System; using System.Collections.Generic; using System.Linq; using System.Reflection; +using Microsoft.AspNet.Builder; using Microsoft.AspNet.Http; using Microsoft.Framework.DependencyInjection; -using Microsoft.AspNet.Builder; namespace Microsoft.AspNet.Hosting.Startup { diff --git a/src/Microsoft.AspNet.Hosting/project.json b/src/Microsoft.AspNet.Hosting/project.json index 612bea6588..70308d391e 100644 --- a/src/Microsoft.AspNet.Hosting/project.json +++ b/src/Microsoft.AspNet.Hosting/project.json @@ -1,12 +1,12 @@ { "version": "0.1-alpha-*", "dependencies": { - "Microsoft.Framework.DependencyInjection": "0.1-alpha-*", - "Microsoft.Framework.ConfigurationModel": "0.1-alpha-*", - "Microsoft.AspNet.PipelineCore": "0.1-alpha-*", - "Microsoft.AspNet.Http": "0.1-alpha-*", "Microsoft.AspNet.FeatureModel": "0.1-alpha-*", + "Microsoft.AspNet.Http": "0.1-alpha-*", + "Microsoft.AspNet.PipelineCore": "0.1-alpha-*", "Microsoft.AspNet.Security.DataProtection": "0.1-alpha-*", + "Microsoft.Framework.ConfigurationModel": "0.1-alpha-*", + "Microsoft.Framework.DependencyInjection": "0.1-alpha-*", "Microsoft.Net.Runtime.Interfaces": "0.1-alpha-*" }, "configurations": { diff --git a/src/Microsoft.AspNet.RequestContainer/project.json b/src/Microsoft.AspNet.RequestContainer/project.json index fed205590c..786d98c8c2 100644 --- a/src/Microsoft.AspNet.RequestContainer/project.json +++ b/src/Microsoft.AspNet.RequestContainer/project.json @@ -1,8 +1,8 @@ { "version": "0.1-alpha-*", "dependencies": { - "Microsoft.Framework.DependencyInjection": "0.1-alpha-*", - "Microsoft.AspNet.Http": "0.1-alpha-*" + "Microsoft.AspNet.Http": "0.1-alpha-*", + "Microsoft.Framework.DependencyInjection": "0.1-alpha-*" }, "configurations": { "net45": {}, From af38d26fe74a0a04b3e38934a2118296b03e0f0b Mon Sep 17 00:00:00 2001 From: Chris Ross Date: Tue, 6 May 2014 14:57:48 -0700 Subject: [PATCH 057/987] Provide empty logger factory service. --- .../HostingServices.cs | 23 +++++++++++++++++++ src/Microsoft.AspNet.Hosting/project.json | 1 + 2 files changed, 24 insertions(+) diff --git a/src/Microsoft.AspNet.Hosting/HostingServices.cs b/src/Microsoft.AspNet.Hosting/HostingServices.cs index 2ce566dbeb..c7376cd52e 100644 --- a/src/Microsoft.AspNet.Hosting/HostingServices.cs +++ b/src/Microsoft.AspNet.Hosting/HostingServices.cs @@ -15,6 +15,7 @@ // See the Apache 2 License for the specific language governing // permissions and limitations under the License. +using System; using System.Collections.Generic; using Microsoft.AspNet.Hosting.Builder; using Microsoft.AspNet.Hosting.Server; @@ -22,6 +23,7 @@ using Microsoft.AspNet.Hosting.Startup; using Microsoft.AspNet.Security.DataProtection; using Microsoft.Framework.ConfigurationModel; using Microsoft.Framework.DependencyInjection; +using Microsoft.Framework.Logging; namespace Microsoft.AspNet.Hosting { @@ -47,6 +49,9 @@ namespace Microsoft.AspNet.Hosting yield return describer.Transient(); + // TODO: We expect this to be provide by the runtime eventually. + yield return describer.Instance(new NullLoggerFactory()); + yield return new ServiceDescriptor { ServiceType = typeof(IContextAccessor<>), @@ -69,5 +74,23 @@ namespace Microsoft.AspNet.Hosting yield return describer.Instance(DataProtectionProvider.CreateFromDpapi()); } } + + // TODO: Temp workaround until the runtime reliably provides logging. + // If ILoggerFactory is never guaranteed, move this fallback into Microsoft.AspNet.Logging. + private class NullLoggerFactory : ILoggerFactory + { + public ILogger Create(string name) + { + return new NullLogger(); + } + } + + private class NullLogger : ILogger + { + public bool WriteCore(TraceType eventType, int eventId, object state, Exception exception, Func formatter) + { + return false; + } + } } } \ No newline at end of file diff --git a/src/Microsoft.AspNet.Hosting/project.json b/src/Microsoft.AspNet.Hosting/project.json index 70308d391e..bc7d383d2d 100644 --- a/src/Microsoft.AspNet.Hosting/project.json +++ b/src/Microsoft.AspNet.Hosting/project.json @@ -7,6 +7,7 @@ "Microsoft.AspNet.Security.DataProtection": "0.1-alpha-*", "Microsoft.Framework.ConfigurationModel": "0.1-alpha-*", "Microsoft.Framework.DependencyInjection": "0.1-alpha-*", + "Microsoft.Framework.Logging": "0.1-alpha-*", "Microsoft.Net.Runtime.Interfaces": "0.1-alpha-*" }, "configurations": { From 4d78121aa4264ecc31e05f28f8a68c2c03b95f93 Mon Sep 17 00:00:00 2001 From: Glenn Condron Date: Wed, 7 May 2014 15:11:50 -0700 Subject: [PATCH 058/987] Wrap HttpContext in an ObjectHandle to avoid cross domain issues --- .../ContainerMiddleware.cs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/Microsoft.AspNet.RequestContainer/ContainerMiddleware.cs b/src/Microsoft.AspNet.RequestContainer/ContainerMiddleware.cs index 8ef3862ac0..38398d3889 100644 --- a/src/Microsoft.AspNet.RequestContainer/ContainerMiddleware.cs +++ b/src/Microsoft.AspNet.RequestContainer/ContainerMiddleware.cs @@ -23,7 +23,9 @@ using System.Threading.Tasks; using Microsoft.AspNet.Builder; using Microsoft.AspNet.Http; using Microsoft.Framework.DependencyInjection; - +#if NET45 +using System.Runtime.Remoting; +#endif namespace Microsoft.AspNet.RequestContainer { public class ContainerMiddleware @@ -64,7 +66,8 @@ namespace Microsoft.AspNet.RequestContainer private HttpContext AccessRootHttpContext() { #if NET45 - return CallContext.LogicalGetData(LogicalDataKey) as HttpContext; + var handle = CallContext.LogicalGetData(LogicalDataKey) as ObjectHandle; + return handle != null ? handle.Unwrap() as HttpContext : null; #else throw new Exception("TODO: CallContext not available"); #endif @@ -73,9 +76,9 @@ namespace Microsoft.AspNet.RequestContainer private HttpContext ExchangeRootHttpContext(HttpContext httpContext) { #if NET45 - var prior = CallContext.LogicalGetData(LogicalDataKey) as HttpContext; - CallContext.LogicalSetData(LogicalDataKey, httpContext); - return prior; + var prior = CallContext.LogicalGetData(LogicalDataKey) as ObjectHandle; + CallContext.LogicalSetData(LogicalDataKey, new ObjectHandle(httpContext)); + return prior != null ? prior.Unwrap() as HttpContext : null; #else return null; #endif From 73792af79965e544a3bd9bdca20b0ae5ff87034f Mon Sep 17 00:00:00 2001 From: Wei Wang Date: Wed, 7 May 2014 16:59:22 -0700 Subject: [PATCH 059/987] Sort dependencies and remove duplicates in dependencies --- samples/KWebStartup/project.json | 4 ++-- src/Microsoft.AspNet.Hosting/project.json | 2 +- test/Microsoft.AspNet.Hosting.Tests/project.json | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/samples/KWebStartup/project.json b/samples/KWebStartup/project.json index 627c07e0ac..3ed8d30072 100644 --- a/samples/KWebStartup/project.json +++ b/samples/KWebStartup/project.json @@ -1,8 +1,8 @@ { "version": "0.1-alpha-*", "dependencies": { - "Microsoft.AspNet.Http": "0.1-alpha-*", "Microsoft.AspNet.Hosting": "", + "Microsoft.AspNet.Http": "0.1-alpha-*", "Microsoft.AspNet.Server.WebListener": "0.1-alpha-*" }, "commands": { "web": "Microsoft.AspNet.Hosting server.name=Microsoft.AspNet.Server.WebListener server.urls=http://localhost:5001" }, @@ -11,8 +11,8 @@ }, "k10": { "dependencies": { - "System.Console": "4.0.0.0", "System.Collections": "4.0.0.0", + "System.Console": "4.0.0.0", "System.Diagnostics.Debug": "4.0.10.0", "System.Diagnostics.Tools": "4.0.0.0", "System.Globalization": "4.0.10.0", diff --git a/src/Microsoft.AspNet.Hosting/project.json b/src/Microsoft.AspNet.Hosting/project.json index bc7d383d2d..a79ae473f1 100644 --- a/src/Microsoft.AspNet.Hosting/project.json +++ b/src/Microsoft.AspNet.Hosting/project.json @@ -15,8 +15,8 @@ "k10": { "dependencies": { "System.Collections": "4.0.0.0", - "System.Console": "4.0.0.0", "System.ComponentModel": "4.0.0.0", + "System.Console": "4.0.0.0", "System.Diagnostics.Debug": "4.0.10.0", "System.IO": "4.0.0.0", "System.Linq": "4.0.0.0", diff --git a/test/Microsoft.AspNet.Hosting.Tests/project.json b/test/Microsoft.AspNet.Hosting.Tests/project.json index 31f45a0967..50ffba28ed 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/project.json +++ b/test/Microsoft.AspNet.Hosting.Tests/project.json @@ -2,11 +2,11 @@ "version": "0.1-alpha-*", "dependencies": { "Microsoft.AspNet.Hosting": "", - "Xunit.KRunner": "0.1-alpha-*", "xunit.abstractions": "2.0.0-aspnet-*", "xunit.assert": "2.0.0-aspnet-*", "xunit.core": "2.0.0-aspnet-*", - "xunit.execution": "2.0.0-aspnet-*" + "xunit.execution": "2.0.0-aspnet-*", + "Xunit.KRunner": "0.1-alpha-*" }, "configurations": { "net45": { From 03cffeb451bf6e7cd42d615c355115dfca16249c Mon Sep 17 00:00:00 2001 From: David Fowler Date: Thu, 8 May 2014 03:49:01 -0700 Subject: [PATCH 060/987] React to renames --- src/Microsoft.AspNet.Hosting/Program.cs | 2 +- src/Microsoft.AspNet.Hosting/project.json | 2 +- src/Microsoft.AspNet.TestHost/TestServer.cs | 2 +- .../TestApplicationEnvironment.cs | 2 +- test/Microsoft.AspNet.TestHost.Tests/TestClientTests.cs | 2 +- test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Microsoft.AspNet.Hosting/Program.cs b/src/Microsoft.AspNet.Hosting/Program.cs index 62cf645910..2834105153 100644 --- a/src/Microsoft.AspNet.Hosting/Program.cs +++ b/src/Microsoft.AspNet.Hosting/Program.cs @@ -20,7 +20,7 @@ using System.IO; using Microsoft.Framework.ConfigurationModel; using Microsoft.Framework.DependencyInjection; using Microsoft.Framework.DependencyInjection.Fallback; -using Microsoft.Net.Runtime; +using Microsoft.Framework.Runtime; namespace Microsoft.AspNet.Hosting { diff --git a/src/Microsoft.AspNet.Hosting/project.json b/src/Microsoft.AspNet.Hosting/project.json index bc7d383d2d..467ea3f868 100644 --- a/src/Microsoft.AspNet.Hosting/project.json +++ b/src/Microsoft.AspNet.Hosting/project.json @@ -8,7 +8,7 @@ "Microsoft.Framework.ConfigurationModel": "0.1-alpha-*", "Microsoft.Framework.DependencyInjection": "0.1-alpha-*", "Microsoft.Framework.Logging": "0.1-alpha-*", - "Microsoft.Net.Runtime.Interfaces": "0.1-alpha-*" + "Microsoft.Framework.Runtime.Interfaces": "0.1-alpha-*" }, "configurations": { "net45": {}, diff --git a/src/Microsoft.AspNet.TestHost/TestServer.cs b/src/Microsoft.AspNet.TestHost/TestServer.cs index 79b024ad96..16684a4bd8 100644 --- a/src/Microsoft.AspNet.TestHost/TestServer.cs +++ b/src/Microsoft.AspNet.TestHost/TestServer.cs @@ -25,7 +25,7 @@ using Microsoft.AspNet.Hosting.Startup; using Microsoft.Framework.ConfigurationModel; using Microsoft.Framework.DependencyInjection; using Microsoft.Framework.DependencyInjection.Fallback; -using Microsoft.Net.Runtime; +using Microsoft.Framework.Runtime; namespace Microsoft.AspNet.TestHost { diff --git a/test/Microsoft.AspNet.TestHost.Tests/TestApplicationEnvironment.cs b/test/Microsoft.AspNet.TestHost.Tests/TestApplicationEnvironment.cs index 4e8ea2fe94..14495b9fdb 100644 --- a/test/Microsoft.AspNet.TestHost.Tests/TestApplicationEnvironment.cs +++ b/test/Microsoft.AspNet.TestHost.Tests/TestApplicationEnvironment.cs @@ -17,7 +17,7 @@ using System; using System.Runtime.Versioning; -using Microsoft.Net.Runtime; +using Microsoft.Framework.Runtime; namespace Microsoft.AspNet.TestHost.Tests { diff --git a/test/Microsoft.AspNet.TestHost.Tests/TestClientTests.cs b/test/Microsoft.AspNet.TestHost.Tests/TestClientTests.cs index d31abab0a4..91730ee12c 100644 --- a/test/Microsoft.AspNet.TestHost.Tests/TestClientTests.cs +++ b/test/Microsoft.AspNet.TestHost.Tests/TestClientTests.cs @@ -22,7 +22,7 @@ using System.Threading.Tasks; using Microsoft.AspNet.Builder; using Microsoft.Framework.DependencyInjection; using Microsoft.Framework.DependencyInjection.Fallback; -using Microsoft.Net.Runtime; +using Microsoft.Framework.Runtime; using Xunit; namespace Microsoft.AspNet.TestHost.Tests diff --git a/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs b/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs index 93561d7cc6..f2a2f436a1 100644 --- a/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs +++ b/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs @@ -21,7 +21,7 @@ using System.Threading.Tasks; using Microsoft.AspNet.Builder; using Microsoft.Framework.DependencyInjection; using Microsoft.Framework.DependencyInjection.Fallback; -using Microsoft.Net.Runtime; +using Microsoft.Framework.Runtime; using Xunit; namespace Microsoft.AspNet.TestHost.Tests From 7580a9a2913f32b5fdf0af5622e7d745c186531c Mon Sep 17 00:00:00 2001 From: Javier Calvarro Nelson Date: Thu, 8 May 2014 11:36:44 -0700 Subject: [PATCH 061/987] Changed the default status code of ResponseInformation to 200 in order to be consistent with the behavior of the rest of the hosts. --- .../Microsoft.AspNet.TestHost.kproj | 1 + .../Properties/AssemblyInfo.cs | 38 +++++++++++++++++++ .../ResponseInformation.cs | 4 ++ .../Microsoft.AspNet.TestHost.Tests.kproj | 2 + .../Properties/AssemblyInfo.cs | 36 ++++++++++++++++++ .../ResponseInformationTests.cs | 34 +++++++++++++++++ 6 files changed, 115 insertions(+) create mode 100644 src/Microsoft.AspNet.TestHost/Properties/AssemblyInfo.cs create mode 100644 test/Microsoft.AspNet.TestHost.Tests/Properties/AssemblyInfo.cs create mode 100644 test/Microsoft.AspNet.TestHost.Tests/ResponseInformationTests.cs diff --git a/src/Microsoft.AspNet.TestHost/Microsoft.AspNet.TestHost.kproj b/src/Microsoft.AspNet.TestHost/Microsoft.AspNet.TestHost.kproj index b0b2425081..0711ff81b0 100644 --- a/src/Microsoft.AspNet.TestHost/Microsoft.AspNet.TestHost.kproj +++ b/src/Microsoft.AspNet.TestHost/Microsoft.AspNet.TestHost.kproj @@ -20,6 +20,7 @@ + diff --git a/src/Microsoft.AspNet.TestHost/Properties/AssemblyInfo.cs b/src/Microsoft.AspNet.TestHost/Properties/AssemblyInfo.cs new file mode 100644 index 0000000000..5eb8f1ffac --- /dev/null +++ b/src/Microsoft.AspNet.TestHost/Properties/AssemblyInfo.cs @@ -0,0 +1,38 @@ +// Copyright (c) Microsoft Open Technologies, Inc. +// All Rights Reserved +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR +// CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING +// WITHOUT LIMITATION ANY IMPLIED WARRANTIES OR CONDITIONS OF +// TITLE, FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABLITY OR +// NON-INFRINGEMENT. +// See the Apache 2 License for the specific language governing +// permissions and limitations under the License. + +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("Microsoft.AspNet.TestHost")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyProduct("Microsoft.AspNet.TestHost")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("12A3EDBB-65B6-4D47-98FC-2B80CEC71E51")] + +[assembly: InternalsVisibleTo("Microsoft.AspNet.TestHost.Tests")] \ No newline at end of file diff --git a/src/Microsoft.AspNet.TestHost/ResponseInformation.cs b/src/Microsoft.AspNet.TestHost/ResponseInformation.cs index 9a8f672817..7cccbafc53 100644 --- a/src/Microsoft.AspNet.TestHost/ResponseInformation.cs +++ b/src/Microsoft.AspNet.TestHost/ResponseInformation.cs @@ -28,6 +28,10 @@ namespace Microsoft.AspNet.TestHost { Headers = new Dictionary(StringComparer.OrdinalIgnoreCase); Body = new MemoryStream(); + + // 200 is the default status code all the way down to the host, so we set it + // here to be consistent with the rest of the hosts when writing tests. + StatusCode = 200; } public int StatusCode { get; set; } diff --git a/test/Microsoft.AspNet.TestHost.Tests/Microsoft.AspNet.TestHost.Tests.kproj b/test/Microsoft.AspNet.TestHost.Tests/Microsoft.AspNet.TestHost.Tests.kproj index 4deca87e2d..cb04e9bc60 100644 --- a/test/Microsoft.AspNet.TestHost.Tests/Microsoft.AspNet.TestHost.Tests.kproj +++ b/test/Microsoft.AspNet.TestHost.Tests/Microsoft.AspNet.TestHost.Tests.kproj @@ -21,6 +21,8 @@ + + diff --git a/test/Microsoft.AspNet.TestHost.Tests/Properties/AssemblyInfo.cs b/test/Microsoft.AspNet.TestHost.Tests/Properties/AssemblyInfo.cs new file mode 100644 index 0000000000..64d1e18c97 --- /dev/null +++ b/test/Microsoft.AspNet.TestHost.Tests/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +// Copyright (c) Microsoft Open Technologies, Inc. +// All Rights Reserved +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR +// CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING +// WITHOUT LIMITATION ANY IMPLIED WARRANTIES OR CONDITIONS OF +// TITLE, FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABLITY OR +// NON-INFRINGEMENT. +// See the Apache 2 License for the specific language governing +// permissions and limitations under the License. + +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("Microsoft.AspNet.TestHost.Tests")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyProduct("Microsoft.AspNet.TestHost.Tests")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("82F61927-58D7-465C-9100-92D202FEA300")] \ No newline at end of file diff --git a/test/Microsoft.AspNet.TestHost.Tests/ResponseInformationTests.cs b/test/Microsoft.AspNet.TestHost.Tests/ResponseInformationTests.cs new file mode 100644 index 0000000000..1717152773 --- /dev/null +++ b/test/Microsoft.AspNet.TestHost.Tests/ResponseInformationTests.cs @@ -0,0 +1,34 @@ +// Copyright (c) Microsoft Open Technologies, Inc. +// All Rights Reserved +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR +// CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING +// WITHOUT LIMITATION ANY IMPLIED WARRANTIES OR CONDITIONS OF +// TITLE, FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABLITY OR +// NON-INFRINGEMENT. +// See the Apache 2 License for the specific language governing +// permissions and limitations under the License. + +using Xunit; + +namespace Microsoft.AspNet.TestHost.Tests +{ + public class ResponseInformationTests + { + [Fact] + public void StatusCode_DefaultsTo200() + { + // Arrange & Act + var responseInformation = new ResponseInformation(); + + // Assert + Assert.Equal(200, responseInformation.StatusCode); + } + } +} \ No newline at end of file From e8ce130315a46c6eef6acf4ccb074189169043af Mon Sep 17 00:00:00 2001 From: Eilon Lipton Date: Thu, 8 May 2014 16:34:52 -0700 Subject: [PATCH 062/987] Create LICENSE.txt --- LICENSE.txt | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 LICENSE.txt diff --git a/LICENSE.txt b/LICENSE.txt new file mode 100644 index 0000000000..d85a1524ad --- /dev/null +++ b/LICENSE.txt @@ -0,0 +1,12 @@ +Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); you may not use +these files except in compliance with the License. You may obtain a copy of the +License at + +http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software distributed +under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR +CONDITIONS OF ANY KIND, either express or implied. See the License for the +specific language governing permissions and limitations under the License. From 55271e8719b3f06381f0f77da9e67ea8d357ff2e Mon Sep 17 00:00:00 2001 From: Louis DeJardin Date: Thu, 8 May 2014 20:38:36 -0700 Subject: [PATCH 063/987] Supporting Startup method dependency injection also changes method name from Configuration to Configure also supports enviroment name command line and --- samples/KWebStartup/Startup.cs | 7 +- samples/KWebStartup/project.json | 2 +- .../HostingContext.cs | 1 + src/Microsoft.AspNet.Hosting/HostingEngine.cs | 4 +- src/Microsoft.AspNet.Hosting/Program.cs | 7 +- .../Startup/IStartupLoader.cs | 5 +- .../Startup/IStartupManager.cs | 4 +- .../Startup/NullStartupLoader.cs | 5 +- .../Startup/StartupLoader.cs | 89 ++++++++++++++----- .../Startup/StartupManager.cs | 6 +- 10 files changed, 96 insertions(+), 34 deletions(-) diff --git a/samples/KWebStartup/Startup.cs b/samples/KWebStartup/Startup.cs index a46d8bbc06..dbe847a1be 100644 --- a/samples/KWebStartup/Startup.cs +++ b/samples/KWebStartup/Startup.cs @@ -18,18 +18,19 @@ using Microsoft.AspNet; using Microsoft.AspNet.Builder; using Microsoft.AspNet.Http; +using Microsoft.Framework.Runtime; namespace KWebStartup { public class Startup { - public void Configuration(IBuilder app) + public void Configure(IBuilder app, IApplicationEnvironment env) { app.Run(async context => { context.Response.ContentType = "text/plain"; - await context.Response.WriteAsync("Hello world"); + await context.Response.WriteAsync("Hello world, from " + env.ApplicationName); }); } } -} \ No newline at end of file +} diff --git a/samples/KWebStartup/project.json b/samples/KWebStartup/project.json index 3ed8d30072..e2d56265b7 100644 --- a/samples/KWebStartup/project.json +++ b/samples/KWebStartup/project.json @@ -5,7 +5,7 @@ "Microsoft.AspNet.Http": "0.1-alpha-*", "Microsoft.AspNet.Server.WebListener": "0.1-alpha-*" }, - "commands": { "web": "Microsoft.AspNet.Hosting server.name=Microsoft.AspNet.Server.WebListener server.urls=http://localhost:5001" }, + "commands": { "web": "Microsoft.AspNet.Hosting server=Microsoft.AspNet.Server.WebListener server.urls=http://localhost:5001" }, "configurations": { "net45": { }, diff --git a/src/Microsoft.AspNet.Hosting/HostingContext.cs b/src/Microsoft.AspNet.Hosting/HostingContext.cs index b0d430626d..ea5685e6bb 100644 --- a/src/Microsoft.AspNet.Hosting/HostingContext.cs +++ b/src/Microsoft.AspNet.Hosting/HostingContext.cs @@ -31,6 +31,7 @@ namespace Microsoft.AspNet.Hosting public IBuilder Builder { get; set; } public string ApplicationName { get; set; } + public string EnvironmentName { get; set; } public Action ApplicationStartup { get; set; } public RequestDelegate ApplicationDelegate { get; set; } diff --git a/src/Microsoft.AspNet.Hosting/HostingEngine.cs b/src/Microsoft.AspNet.Hosting/HostingEngine.cs index b1dd6093cb..b8cecf5752 100644 --- a/src/Microsoft.AspNet.Hosting/HostingEngine.cs +++ b/src/Microsoft.AspNet.Hosting/HostingEngine.cs @@ -117,7 +117,9 @@ namespace Microsoft.AspNet.Hosting return; } - context.ApplicationStartup = _startupManager.LoadStartup(context.ApplicationName); + context.ApplicationStartup = _startupManager.LoadStartup( + context.ApplicationName, + context.EnvironmentName); } private class Disposable : IDisposable diff --git a/src/Microsoft.AspNet.Hosting/Program.cs b/src/Microsoft.AspNet.Hosting/Program.cs index 2834105153..00b4a6af5c 100644 --- a/src/Microsoft.AspNet.Hosting/Program.cs +++ b/src/Microsoft.AspNet.Hosting/Program.cs @@ -38,12 +38,12 @@ namespace Microsoft.AspNet.Hosting public void Main(string[] args) { var config = new Configuration(); - config.AddCommandLine(args); if (File.Exists(HostingIniFile)) { config.AddIniFile(HostingIniFile); } config.AddEnvironmentVariables(); + config.AddCommandLine(args); var serviceCollection = new ServiceCollection(); serviceCollection.Add(HostingServices.GetDefaultServices(config)); @@ -55,9 +55,10 @@ namespace Microsoft.AspNet.Hosting { Services = services, Configuration = config, - ServerName = config.Get("server.name"), // TODO: Key names - ApplicationName = config.Get("app.name") // TODO: Key names + ServerName = config.Get("server"), // TODO: Key names + ApplicationName = config.Get("app") // TODO: Key names ?? appEnvironment.ApplicationName, + EnvironmentName = config.Get("env") ?? "Development" }; var engine = services.GetService(); diff --git a/src/Microsoft.AspNet.Hosting/Startup/IStartupLoader.cs b/src/Microsoft.AspNet.Hosting/Startup/IStartupLoader.cs index e8eaede1c7..a6a0741ad7 100644 --- a/src/Microsoft.AspNet.Hosting/Startup/IStartupLoader.cs +++ b/src/Microsoft.AspNet.Hosting/Startup/IStartupLoader.cs @@ -24,6 +24,9 @@ namespace Microsoft.AspNet.Hosting.Startup { public interface IStartupLoader { - Action LoadStartup(string applicationName, IList diagnosticMessages); + Action LoadStartup( + string applicationName, + string environmentName, + IList diagnosticMessages); } } diff --git a/src/Microsoft.AspNet.Hosting/Startup/IStartupManager.cs b/src/Microsoft.AspNet.Hosting/Startup/IStartupManager.cs index 7d4655f36f..1b8b9f19cc 100644 --- a/src/Microsoft.AspNet.Hosting/Startup/IStartupManager.cs +++ b/src/Microsoft.AspNet.Hosting/Startup/IStartupManager.cs @@ -23,6 +23,8 @@ namespace Microsoft.AspNet.Hosting.Startup { public interface IStartupManager { - Action LoadStartup(string applicationName); + Action LoadStartup( + string applicationName, + string environmentName); } } \ No newline at end of file diff --git a/src/Microsoft.AspNet.Hosting/Startup/NullStartupLoader.cs b/src/Microsoft.AspNet.Hosting/Startup/NullStartupLoader.cs index c70dad2e65..559d44d5e2 100644 --- a/src/Microsoft.AspNet.Hosting/Startup/NullStartupLoader.cs +++ b/src/Microsoft.AspNet.Hosting/Startup/NullStartupLoader.cs @@ -31,7 +31,10 @@ namespace Microsoft.AspNet.Hosting.Startup public static IStartupLoader Instance { get; private set; } - public Action LoadStartup(string applicationName, IList diagnosticMessages) + public Action LoadStartup( + string applicationName, + string environmentName, + IList diagnosticMessages) { return null; } diff --git a/src/Microsoft.AspNet.Hosting/Startup/StartupLoader.cs b/src/Microsoft.AspNet.Hosting/Startup/StartupLoader.cs index f9629c819f..98aec36c67 100644 --- a/src/Microsoft.AspNet.Hosting/Startup/StartupLoader.cs +++ b/src/Microsoft.AspNet.Hosting/Startup/StartupLoader.cs @@ -30,42 +30,49 @@ namespace Microsoft.AspNet.Hosting.Startup private readonly IServiceProvider _services; private readonly IStartupLoader _next; - public StartupLoader(IServiceProvider services, IStartupLoader next) + public StartupLoader( + IServiceProvider services, + IStartupLoader next) { _services = services; _next = next; } - public Action LoadStartup(string applicationName, IList diagnosticMessages) + public Action LoadStartup( + string applicationName, + string environmentName, + IList diagnosticMessages) { if (String.IsNullOrEmpty(applicationName)) { - return _next.LoadStartup(applicationName, diagnosticMessages); + return _next.LoadStartup(applicationName, environmentName, diagnosticMessages); } - var nameParts = Utilities.SplitTypeName(applicationName); - string typeName = nameParts.Item1; - string assemblyName = nameParts.Item2; - - var assembly = Assembly.Load(new AssemblyName(assemblyName)); + var assembly = Assembly.Load(new AssemblyName(applicationName)); if (assembly == null) { - throw new Exception(String.Format("TODO: assembly {0} failed to load message", assemblyName)); + throw new Exception(String.Format("TODO: assembly {0} failed to load message", applicationName)); } - Type type = null; - if (string.IsNullOrEmpty(typeName)) - { - typeName = "Startup"; - } + var startupName1 = "Startup" + environmentName; + var startupName2 = "Startup"; // Check the most likely places first - type = assembly.GetType(typeName) ?? assembly.GetType(assembly.GetName().Name + "." + typeName); + var type = + assembly.GetType(startupName1) ?? + assembly.GetType(applicationName + "." + startupName1) ?? + assembly.GetType(startupName2) ?? + assembly.GetType(applicationName + "." + startupName2); if (type == null) { // Full scan - var typeInfo = assembly.DefinedTypes.FirstOrDefault(aType => aType.Name.Equals(typeName, StringComparison.OrdinalIgnoreCase)); + var definedTypes = assembly.DefinedTypes.ToList(); + + var startupType1 = definedTypes.Where(info => info.Name.Equals(startupName1, StringComparison.Ordinal)); + var startupType2 = definedTypes.Where(info => info.Name.Equals(startupName2, StringComparison.Ordinal)); + + var typeInfo = startupType1.Concat(startupType2).FirstOrDefault(); if (typeInfo != null) { type = typeInfo.AsType(); @@ -74,18 +81,30 @@ namespace Microsoft.AspNet.Hosting.Startup if (type == null) { - throw new Exception(String.Format("TODO: type {0} failed to load message", typeName)); + throw new Exception(String.Format("TODO: {0} or {1} class not found in assembly {2}", + startupName1, + startupName2, + applicationName)); } - var methodInfo = type.GetTypeInfo().GetDeclaredMethod("Configuration"); + var configureMethod1 = "Configure" + environmentName; + var configureMethod2 = "Configure"; + var methodInfo = type.GetTypeInfo().GetDeclaredMethod(configureMethod1); if (methodInfo == null) { - throw new Exception("TODO: Configuration method not found"); + methodInfo = type.GetTypeInfo().GetDeclaredMethod(configureMethod2); + } + if (methodInfo == null) + { + throw new Exception(string.Format("TODO: {0} or {1} method not found", + configureMethod1, + configureMethod2)); } if (methodInfo.ReturnType != typeof(void)) { - throw new Exception("TODO: Configuration method isn't void-returning."); + throw new Exception(string.Format("TODO: {0} method isn't void-returning.", + methodInfo.Name)); } object instance = null; @@ -93,7 +112,35 @@ namespace Microsoft.AspNet.Hosting.Startup { instance = ActivatorUtilities.GetServiceOrCreateInstance(_services, type); } - return builder => methodInfo.Invoke(instance, new object[] { builder }); + + return builder => + { + var parameterInfos = methodInfo.GetParameters(); + var parameters = new object[parameterInfos.Length]; + for (var index = 0; index != parameterInfos.Length; ++index) + { + var parameterInfo = parameterInfos[index]; + if (parameterInfo.ParameterType == typeof(IBuilder)) + { + parameters[index] = builder; + } + else + { + try + { + parameters[index] = _services.GetService(parameterInfo.ParameterType); + } + catch (Exception ex) + { + throw new Exception(string.Format( + "TODO: Unable to resolve service for startup method {0} {1}", + parameterInfo.Name, + parameterInfo.ParameterType.FullName)); + } + } + } + methodInfo.Invoke(instance, parameters); + }; } } } diff --git a/src/Microsoft.AspNet.Hosting/Startup/StartupManager.cs b/src/Microsoft.AspNet.Hosting/Startup/StartupManager.cs index 16a6a4e2bb..8c4bc7b1ff 100644 --- a/src/Microsoft.AspNet.Hosting/Startup/StartupManager.cs +++ b/src/Microsoft.AspNet.Hosting/Startup/StartupManager.cs @@ -32,7 +32,9 @@ namespace Microsoft.AspNet.Hosting.Startup _providers = providers; } - public Action LoadStartup(string applicationName) + public Action LoadStartup( + string applicationName, + string environmentName) { // build ordered chain of application loaders var chain = _providers @@ -41,7 +43,7 @@ namespace Microsoft.AspNet.Hosting.Startup // invoke chain to acquire application entrypoint and diagnostic messages var diagnosticMessages = new List(); - var application = chain.LoadStartup(applicationName, diagnosticMessages); + var application = chain.LoadStartup(applicationName, environmentName, diagnosticMessages); if (application == null) { From 7edc2dfbe96b3d485b33dcc0bcadfce7ca806a5c Mon Sep 17 00:00:00 2001 From: Louis DeJardin Date: Thu, 8 May 2014 22:36:56 -0700 Subject: [PATCH 064/987] Fixing unit tests --- src/Microsoft.AspNet.TestHost/TestServer.cs | 14 ++++----- .../Fakes/{FakeStartup.cs => Startup.cs} | 8 +++-- ...WithServices.cs => StartupWithServices.cs} | 7 +++-- .../HostingEngineTests.cs | 2 +- .../Microsoft.AspNet.Hosting.Tests.kproj | 1 - .../StartupManagerTests.cs | 19 ++---------- .../TestServerTests.cs | 30 +++++++++---------- 7 files changed, 35 insertions(+), 46 deletions(-) rename test/Microsoft.AspNet.Hosting.Tests/Fakes/{FakeStartup.cs => Startup.cs} (87%) rename test/Microsoft.AspNet.Hosting.Tests/Fakes/{FakeStartupWithServices.cs => StartupWithServices.cs} (79%) diff --git a/src/Microsoft.AspNet.TestHost/TestServer.cs b/src/Microsoft.AspNet.TestHost/TestServer.cs index 16684a4bd8..48f1679f05 100644 --- a/src/Microsoft.AspNet.TestHost/TestServer.cs +++ b/src/Microsoft.AspNet.TestHost/TestServer.cs @@ -57,13 +57,13 @@ namespace Microsoft.AspNet.TestHost var disposable = engine.Start(hostContext); } - public static TestServer Create(IServiceProvider provider) - { - var startupLoader = new StartupLoader(provider, new NullStartupLoader()); - var name = typeof(TStartup).AssemblyQualifiedName; - var diagnosticMessages = new List(); - return Create(provider, startupLoader.LoadStartup(name, diagnosticMessages)); - } + //public static TestServer Create(IServiceProvider provider) + //{ + // var startupLoader = new StartupLoader(provider, new NullStartupLoader()); + // var name = typeof(TStartup).AssemblyQualifiedName; + // var diagnosticMessages = new List(); + // return Create(provider, startupLoader.LoadStartup(name, "Test", diagnosticMessages)); + //} public static TestServer Create(IServiceProvider provider, Action app) { diff --git a/test/Microsoft.AspNet.Hosting.Tests/Fakes/FakeStartup.cs b/test/Microsoft.AspNet.Hosting.Tests/Fakes/Startup.cs similarity index 87% rename from test/Microsoft.AspNet.Hosting.Tests/Fakes/FakeStartup.cs rename to test/Microsoft.AspNet.Hosting.Tests/Fakes/Startup.cs index 1df444a0af..da91cbeca0 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/Fakes/FakeStartup.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/Fakes/Startup.cs @@ -20,9 +20,13 @@ using Microsoft.AspNet.Http; namespace Microsoft.AspNet.Hosting.Fakes { - public class FakeStartup + public class Startup { - public void Configuration(IBuilder builder) + public Startup() + { + } + + public void Configure(IBuilder builder) { } } diff --git a/test/Microsoft.AspNet.Hosting.Tests/Fakes/FakeStartupWithServices.cs b/test/Microsoft.AspNet.Hosting.Tests/Fakes/StartupWithServices.cs similarity index 79% rename from test/Microsoft.AspNet.Hosting.Tests/Fakes/FakeStartupWithServices.cs rename to test/Microsoft.AspNet.Hosting.Tests/Fakes/StartupWithServices.cs index 2150b21ea7..166b4ff5c5 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/Fakes/FakeStartupWithServices.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/Fakes/StartupWithServices.cs @@ -20,18 +20,19 @@ using Microsoft.AspNet.Http; namespace Microsoft.AspNet.Hosting.Fakes { - public class FakeStartupWithServices + public class StartupWithServices { private readonly IFakeStartupCallback _fakeStartupCallback; - public FakeStartupWithServices(IFakeStartupCallback fakeStartupCallback) + public StartupWithServices(IFakeStartupCallback fakeStartupCallback) { _fakeStartupCallback = fakeStartupCallback; } - public void Configuration(IBuilder builder) + public void Configure(IBuilder builder, IFakeStartupCallback fakeStartupCallback2) { _fakeStartupCallback.ConfigurationMethodCalled(this); + fakeStartupCallback2.ConfigurationMethodCalled(this); } } } \ No newline at end of file diff --git a/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs b/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs index 5491f92de9..d6cbf86841 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs @@ -55,7 +55,7 @@ namespace Microsoft.AspNet.Hosting var context = new HostingContext { ServerFactory = this, - ApplicationName = "Microsoft.AspNet.Hosting.Fakes.FakeStartup, Microsoft.AspNet.Hosting.Tests" + ApplicationName = "Microsoft.AspNet.Hosting.Tests" }; var engineStart = engine.Start(context); diff --git a/test/Microsoft.AspNet.Hosting.Tests/Microsoft.AspNet.Hosting.Tests.kproj b/test/Microsoft.AspNet.Hosting.Tests/Microsoft.AspNet.Hosting.Tests.kproj index 48a9989141..65a7bd78f0 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/Microsoft.AspNet.Hosting.Tests.kproj +++ b/test/Microsoft.AspNet.Hosting.Tests/Microsoft.AspNet.Hosting.Tests.kproj @@ -21,7 +21,6 @@ - diff --git a/test/Microsoft.AspNet.Hosting.Tests/StartupManagerTests.cs b/test/Microsoft.AspNet.Hosting.Tests/StartupManagerTests.cs index b04aef9e4c..6684a56205 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/StartupManagerTests.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/StartupManagerTests.cs @@ -29,21 +29,6 @@ namespace Microsoft.AspNet.Hosting { private readonly IList _configurationMethodCalledList = new List(); - [Fact] - public void DefaultServicesLocateStartupByNameAndNamespace() - { - var serviceCollection = new ServiceCollection(); - serviceCollection.Add(HostingServices.GetDefaultServices()); - var services = serviceCollection.BuildServiceProvider(); - - var manager = services.GetService(); - - var startup = manager.LoadStartup("Microsoft.AspNet.Hosting.Fakes.FakeStartup, Microsoft.AspNet.Hosting.Tests"); - - Assert.IsType(manager); - Assert.NotNull(startup); - } - [Fact] public void StartupClassMayHaveHostingServicesInjected() { @@ -54,11 +39,11 @@ namespace Microsoft.AspNet.Hosting var manager = services.GetService(); - var startup = manager.LoadStartup("Microsoft.AspNet.Hosting.Fakes.FakeStartupWithServices, Microsoft.AspNet.Hosting.Tests"); + var startup = manager.LoadStartup("Microsoft.AspNet.Hosting.Tests", "WithServices"); startup.Invoke(null); - Assert.Equal(1, _configurationMethodCalledList.Count); + Assert.Equal(2, _configurationMethodCalledList.Count); } public void ConfigurationMethodCalled(object instance) diff --git a/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs b/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs index f2a2f436a1..c1b0ea1fb3 100644 --- a/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs +++ b/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs @@ -40,23 +40,23 @@ namespace Microsoft.AspNet.TestHost.Tests Assert.DoesNotThrow(() => TestServer.Create(services, app => { })); } - [Fact] - public async Task CreateWithGeneric() - { - // Arrange - var services = new ServiceCollection() - .AddSingleton() - .BuildServiceProvider(); + //[Fact] + //public async Task CreateWithGeneric() + //{ + // // Arrange + // var services = new ServiceCollection() + // .AddSingleton() + // .BuildServiceProvider(); - var server = TestServer.Create(services); - var client = server.Handler; + // var server = TestServer.Create(services); + // var client = server.Handler; - // Act - var response = await client.GetAsync("http://any"); + // // Act + // var response = await client.GetAsync("http://any"); - // Assert - Assert.Equal("Startup", new StreamReader(response.Body).ReadToEnd()); - } + // // Assert + // Assert.Equal("Startup", new StreamReader(response.Body).ReadToEnd()); + //} [Fact] public void ThrowsIfNoApplicationEnvironmentIsRegisteredWithTheProvider() @@ -68,7 +68,7 @@ namespace Microsoft.AspNet.TestHost.Tests // Act & Assert Assert.Throws( "serviceProvider", - () => TestServer.Create(services)); + () => TestServer.Create(services, new Startup().Configuration)); } public class Startup From afa87bf8573590e5ee02fc7dd434e6f8d133c11c Mon Sep 17 00:00:00 2001 From: Chris Ross Date: Fri, 9 May 2014 09:11:21 -0700 Subject: [PATCH 065/987] #22 - Make UseMiddleware look for any Invoke method. --- .../ContainerExtensions.cs | 7 ++++++- src/Microsoft.AspNet.RequestContainer/project.json | 1 + 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/Microsoft.AspNet.RequestContainer/ContainerExtensions.cs b/src/Microsoft.AspNet.RequestContainer/ContainerExtensions.cs index 8289754ef5..df630d1794 100644 --- a/src/Microsoft.AspNet.RequestContainer/ContainerExtensions.cs +++ b/src/Microsoft.AspNet.RequestContainer/ContainerExtensions.cs @@ -27,6 +27,11 @@ namespace Microsoft.AspNet.Builder { public static class ContainerExtensions { + public static IBuilder UseMiddleware(this IBuilder builder, params object[] args) + { + return builder.UseMiddleware(typeof(T), args); + } + public static IBuilder UseMiddleware(this IBuilder builder, Type middleware, params object[] args) { // TODO: move this ext method someplace nice @@ -34,7 +39,7 @@ namespace Microsoft.AspNet.Builder { var typeActivator = builder.ApplicationServices.GetService(); var instance = typeActivator.CreateInstance(builder.ApplicationServices, middleware, new[] { next }.Concat(args).ToArray()); - var methodinfo = middleware.GetTypeInfo().GetDeclaredMethod("Invoke"); + var methodinfo = middleware.GetRuntimeMethods().Single(info => info.Name.Equals("Invoke")); return (RequestDelegate)methodinfo.CreateDelegate(typeof(RequestDelegate), instance); }); } diff --git a/src/Microsoft.AspNet.RequestContainer/project.json b/src/Microsoft.AspNet.RequestContainer/project.json index 786d98c8c2..91bf41f1fa 100644 --- a/src/Microsoft.AspNet.RequestContainer/project.json +++ b/src/Microsoft.AspNet.RequestContainer/project.json @@ -13,6 +13,7 @@ "System.Diagnostics.Debug": "4.0.10.0", "System.Linq": "4.0.0.0", "System.Reflection": "4.0.10.0", + "System.Reflection.Extensions": "4.0.0.0", "System.Runtime": "4.0.20.0", "System.Runtime.Extensions": "4.0.10.0", "System.Threading": "4.0.0.0", From 5a0969044761d8fc77ffd37266f5aaa22579fd6b Mon Sep 17 00:00:00 2001 From: Chris Ross Date: Fri, 9 May 2014 11:19:17 -0700 Subject: [PATCH 066/987] #22 - Use binding flags to locate method. --- src/Microsoft.AspNet.RequestContainer/ContainerExtensions.cs | 2 +- src/Microsoft.AspNet.RequestContainer/project.json | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Microsoft.AspNet.RequestContainer/ContainerExtensions.cs b/src/Microsoft.AspNet.RequestContainer/ContainerExtensions.cs index df630d1794..7db63fe5ff 100644 --- a/src/Microsoft.AspNet.RequestContainer/ContainerExtensions.cs +++ b/src/Microsoft.AspNet.RequestContainer/ContainerExtensions.cs @@ -39,7 +39,7 @@ namespace Microsoft.AspNet.Builder { var typeActivator = builder.ApplicationServices.GetService(); var instance = typeActivator.CreateInstance(builder.ApplicationServices, middleware, new[] { next }.Concat(args).ToArray()); - var methodinfo = middleware.GetRuntimeMethods().Single(info => info.Name.Equals("Invoke")); + var methodinfo = middleware.GetMethod("Invoke", BindingFlags.Instance | BindingFlags.Public); return (RequestDelegate)methodinfo.CreateDelegate(typeof(RequestDelegate), instance); }); } diff --git a/src/Microsoft.AspNet.RequestContainer/project.json b/src/Microsoft.AspNet.RequestContainer/project.json index 91bf41f1fa..1a1a36198f 100644 --- a/src/Microsoft.AspNet.RequestContainer/project.json +++ b/src/Microsoft.AspNet.RequestContainer/project.json @@ -14,6 +14,7 @@ "System.Linq": "4.0.0.0", "System.Reflection": "4.0.10.0", "System.Reflection.Extensions": "4.0.0.0", + "System.Reflection.TypeExtensions": "4.0.0.0", "System.Runtime": "4.0.20.0", "System.Runtime.Extensions": "4.0.10.0", "System.Threading": "4.0.0.0", From fb937c509d4f75757186c25bbe139f9fc227c00d Mon Sep 17 00:00:00 2001 From: Glenn Date: Mon, 12 May 2014 19:12:08 -0700 Subject: [PATCH 067/987] Create README.md --- README.md | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000000..1dbf89ce85 --- /dev/null +++ b/README.md @@ -0,0 +1,6 @@ +Hosting +======= + +The Hosting repo contains code required to host an ASP.NET vNext application, it is the entry point used when self-hosting an application. + +This project is part of ASP.NET vNext. You can find samples, documentation and getting started instructions for ASP.NET vNext at the [Home](https://github.com/aspnet/home) repo. From 71d19e9f7145932a246c62cc3d204d04ee3a7ff3 Mon Sep 17 00:00:00 2001 From: Eilon Lipton Date: Tue, 13 May 2014 01:02:29 -0700 Subject: [PATCH 068/987] Create CONTRIBUTING.md --- CONTRIBUTING.md | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 CONTRIBUTING.md diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000000..eac4268e4c --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,4 @@ +Contributing +====== + +Information on contributing to this repo is in the [Contributing Guide](https://github.com/aspnet/Home/blob/master/CONTRIBUTING.md) in the Home repo. From 8695da085be21a6f524faba2435d8dd86210ab0d Mon Sep 17 00:00:00 2001 From: Hao Kung Date: Thu, 15 May 2014 16:24:39 -0700 Subject: [PATCH 069/987] Add IOptionsAccessor as a default service --- src/Microsoft.AspNet.Hosting/HostingServices.cs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/Microsoft.AspNet.Hosting/HostingServices.cs b/src/Microsoft.AspNet.Hosting/HostingServices.cs index c7376cd52e..5403f190fb 100644 --- a/src/Microsoft.AspNet.Hosting/HostingServices.cs +++ b/src/Microsoft.AspNet.Hosting/HostingServices.cs @@ -59,6 +59,14 @@ namespace Microsoft.AspNet.Hosting Lifecycle = LifecycleKind.Scoped }; + // TODO: Review whether this is the right long term home, and whether Scoped is correct lifetime + yield return new ServiceDescriptor + { + ServiceType = typeof(IOptionsAccessor<>), + ImplementationType = typeof(OptionsAccessor<>), + Lifecycle = LifecycleKind.Scoped + }; + if (PlatformHelper.IsMono) { #if NET45 From 1189f10ba81af8a67d17464b4c6fb5289ea06e7b Mon Sep 17 00:00:00 2001 From: Hao Kung Date: Thu, 15 May 2014 18:11:51 -0700 Subject: [PATCH 070/987] Move Options to UseServices Hosting default services wasn't working as expected, UseServices --- src/Microsoft.AspNet.Hosting/HostingServices.cs | 8 -------- .../ContainerExtensions.cs | 9 +++++++++ 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/Microsoft.AspNet.Hosting/HostingServices.cs b/src/Microsoft.AspNet.Hosting/HostingServices.cs index 5403f190fb..c7376cd52e 100644 --- a/src/Microsoft.AspNet.Hosting/HostingServices.cs +++ b/src/Microsoft.AspNet.Hosting/HostingServices.cs @@ -59,14 +59,6 @@ namespace Microsoft.AspNet.Hosting Lifecycle = LifecycleKind.Scoped }; - // TODO: Review whether this is the right long term home, and whether Scoped is correct lifetime - yield return new ServiceDescriptor - { - ServiceType = typeof(IOptionsAccessor<>), - ImplementationType = typeof(OptionsAccessor<>), - Lifecycle = LifecycleKind.Scoped - }; - if (PlatformHelper.IsMono) { #if NET45 diff --git a/src/Microsoft.AspNet.RequestContainer/ContainerExtensions.cs b/src/Microsoft.AspNet.RequestContainer/ContainerExtensions.cs index 7db63fe5ff..d2ae5e3619 100644 --- a/src/Microsoft.AspNet.RequestContainer/ContainerExtensions.cs +++ b/src/Microsoft.AspNet.RequestContainer/ContainerExtensions.cs @@ -64,6 +64,15 @@ namespace Microsoft.AspNet.Builder public static IBuilder UseServices(this IBuilder builder, Action configureServices) { var serviceCollection = new ServiceCollection(); + + // TODO: Review whether this is the right long term home, and whether Scoped is correct lifetime + serviceCollection.Add(new ServiceDescriptor + { + ServiceType = typeof(IOptionsAccessor<>), + ImplementationType = typeof(OptionsAccessor<>), + Lifecycle = LifecycleKind.Scoped + }); + configureServices(serviceCollection); builder.ApplicationServices = serviceCollection.BuildServiceProvider(builder.ApplicationServices); From cab0d80f9d864c2a66013a7bb6260f7fb0e48950 Mon Sep 17 00:00:00 2001 From: Pranav K Date: Sun, 18 May 2014 20:13:55 -0700 Subject: [PATCH 071/987] Updating kproj file to match tooling changes --- .gitignore | 3 ++- samples/KWebStartup/KWebStartup.kproj | 6 +++--- src/Microsoft.AspNet.Hosting/Microsoft.AspNet.Hosting.kproj | 6 +++--- .../Microsoft.AspNet.RequestContainer.kproj | 6 +++--- .../Microsoft.AspNet.TestHost.kproj | 6 +++--- .../Microsoft.AspNet.Hosting.Tests.kproj | 6 +++--- .../Microsoft.AspNet.TestHost.Tests.kproj | 6 +++--- 7 files changed, 20 insertions(+), 19 deletions(-) diff --git a/.gitignore b/.gitignore index aba9c594d7..08e21e25bf 100644 --- a/.gitignore +++ b/.gitignore @@ -22,4 +22,5 @@ nuget.exe *DS_Store *.ncrunchsolution *.*sdf -*.ipch \ No newline at end of file +*.ipch +*.sln.ide \ No newline at end of file diff --git a/samples/KWebStartup/KWebStartup.kproj b/samples/KWebStartup/KWebStartup.kproj index 0250b93f66..a776cdc9db 100644 --- a/samples/KWebStartup/KWebStartup.kproj +++ b/samples/KWebStartup/KWebStartup.kproj @@ -1,10 +1,10 @@ - + 12.0 $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) - + a2f321a5-3f55-4413-b357-eef85dc0eca6 Library @@ -22,5 +22,5 @@ - + \ No newline at end of file diff --git a/src/Microsoft.AspNet.Hosting/Microsoft.AspNet.Hosting.kproj b/src/Microsoft.AspNet.Hosting/Microsoft.AspNet.Hosting.kproj index 5e436ba601..102ee4062c 100644 --- a/src/Microsoft.AspNet.Hosting/Microsoft.AspNet.Hosting.kproj +++ b/src/Microsoft.AspNet.Hosting/Microsoft.AspNet.Hosting.kproj @@ -1,10 +1,10 @@ - + 12.0 $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) - + 3944f036-7e75-47e8-aa52-c4b89a64ec3a Library @@ -44,5 +44,5 @@ - + \ No newline at end of file diff --git a/src/Microsoft.AspNet.RequestContainer/Microsoft.AspNet.RequestContainer.kproj b/src/Microsoft.AspNet.RequestContainer/Microsoft.AspNet.RequestContainer.kproj index 13fc912c56..35422bca16 100644 --- a/src/Microsoft.AspNet.RequestContainer/Microsoft.AspNet.RequestContainer.kproj +++ b/src/Microsoft.AspNet.RequestContainer/Microsoft.AspNet.RequestContainer.kproj @@ -1,10 +1,10 @@ - + 12.0 $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) - + 374a5b0c-3e93-4a23-a4a0-ee2ab6df7814 Library @@ -23,5 +23,5 @@ - + \ No newline at end of file diff --git a/src/Microsoft.AspNet.TestHost/Microsoft.AspNet.TestHost.kproj b/src/Microsoft.AspNet.TestHost/Microsoft.AspNet.TestHost.kproj index 0711ff81b0..3e50a40255 100644 --- a/src/Microsoft.AspNet.TestHost/Microsoft.AspNet.TestHost.kproj +++ b/src/Microsoft.AspNet.TestHost/Microsoft.AspNet.TestHost.kproj @@ -1,10 +1,10 @@ - + 12.0 $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) - + 1a415a3f-1081-45db-809b-ee19cea02dc0 Library @@ -26,5 +26,5 @@ - + \ No newline at end of file diff --git a/test/Microsoft.AspNet.Hosting.Tests/Microsoft.AspNet.Hosting.Tests.kproj b/test/Microsoft.AspNet.Hosting.Tests/Microsoft.AspNet.Hosting.Tests.kproj index 65a7bd78f0..2afbd680d6 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/Microsoft.AspNet.Hosting.Tests.kproj +++ b/test/Microsoft.AspNet.Hosting.Tests/Microsoft.AspNet.Hosting.Tests.kproj @@ -1,10 +1,10 @@ - + 12.0 $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) - + d4f18d58-52b1-435d-a012-10f2cdf158c4 Library @@ -26,5 +26,5 @@ - + \ No newline at end of file diff --git a/test/Microsoft.AspNet.TestHost.Tests/Microsoft.AspNet.TestHost.Tests.kproj b/test/Microsoft.AspNet.TestHost.Tests/Microsoft.AspNet.TestHost.Tests.kproj index cb04e9bc60..2c5387a97e 100644 --- a/test/Microsoft.AspNet.TestHost.Tests/Microsoft.AspNet.TestHost.Tests.kproj +++ b/test/Microsoft.AspNet.TestHost.Tests/Microsoft.AspNet.TestHost.Tests.kproj @@ -1,10 +1,10 @@ - + 12.0 $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) - + 0acb2719-9484-49b5-b8e3-117091192511 Library @@ -27,5 +27,5 @@ - + \ No newline at end of file From d8ef441454d5910051e7eff051cd0fb9b00889d8 Mon Sep 17 00:00:00 2001 From: David Fowler Date: Fri, 23 May 2014 04:16:20 -0700 Subject: [PATCH 072/987] Updated build.sh --- build.sh | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) mode change 100644 => 100755 build.sh diff --git a/build.sh b/build.sh old mode 100644 new mode 100755 index db1e0c3dde..a918165425 --- a/build.sh +++ b/build.sh @@ -4,9 +4,9 @@ if test `uname` = Darwin; then cachedir=~/Library/Caches/KBuild else if x$XDG_DATA_HOME = x; then - cachedir=$HOME/.local/share + cachedir=$HOME/.local/share else - cachedir=$XDG_DATA_HOME; + cachedir=$XDG_DATA_HOME; fi fi mkdir -p $cachedir @@ -27,4 +27,14 @@ if test ! -d packages/KoreBuild; then mono .nuget/nuget.exe install Sake -version 0.2 -o packages -ExcludeVersion fi +KRE_VERSION=$(mono .nuget/nuget.exe install KRE-mono45-x86 -pre -o ~/.kre/packages | head -1 | sed "s/.*KRE-mono45-x86 \([^']*\).*/\1/") +KRE_BIN=~/.kre/packages/KRE-mono45-x86.$KRE_VERSION/bin + +chmod +x $KRE_BIN/k +chmod +x $KRE_BIN/klr +chmod +x $KRE_BIN/kpm +chmod +x $KRE_BIN/k-build + +export PATH=$KRE_BIN:$PATH + mono packages/Sake/tools/Sake.exe -I packages/KoreBuild/build -f makefile.shade "$@" \ No newline at end of file From 07daba445745c4398ba8cb14e738b6a5d3861cc8 Mon Sep 17 00:00:00 2001 From: David Fowler Date: Sun, 25 May 2014 10:03:44 -0700 Subject: [PATCH 073/987] Renamed Project.json to Project.json2 --- src/Microsoft.AspNet.TestHost/{project.json => Project.json2} | 0 .../{project.json => Project.json2} | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename src/Microsoft.AspNet.TestHost/{project.json => Project.json2} (100%) rename test/Microsoft.AspNet.TestHost.Tests/{project.json => Project.json2} (100%) diff --git a/src/Microsoft.AspNet.TestHost/project.json b/src/Microsoft.AspNet.TestHost/Project.json2 similarity index 100% rename from src/Microsoft.AspNet.TestHost/project.json rename to src/Microsoft.AspNet.TestHost/Project.json2 diff --git a/test/Microsoft.AspNet.TestHost.Tests/project.json b/test/Microsoft.AspNet.TestHost.Tests/Project.json2 similarity index 100% rename from test/Microsoft.AspNet.TestHost.Tests/project.json rename to test/Microsoft.AspNet.TestHost.Tests/Project.json2 From f656f0dfe20942d43c9486e0b8b2b9ab25360782 Mon Sep 17 00:00:00 2001 From: David Fowler Date: Sun, 25 May 2014 10:03:44 -0700 Subject: [PATCH 074/987] Fixed casing of project.json --- src/Microsoft.AspNet.TestHost/{Project.json2 => project.json} | 0 .../{Project.json2 => project.json} | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename src/Microsoft.AspNet.TestHost/{Project.json2 => project.json} (100%) rename test/Microsoft.AspNet.TestHost.Tests/{Project.json2 => project.json} (100%) diff --git a/src/Microsoft.AspNet.TestHost/Project.json2 b/src/Microsoft.AspNet.TestHost/project.json similarity index 100% rename from src/Microsoft.AspNet.TestHost/Project.json2 rename to src/Microsoft.AspNet.TestHost/project.json diff --git a/test/Microsoft.AspNet.TestHost.Tests/Project.json2 b/test/Microsoft.AspNet.TestHost.Tests/project.json similarity index 100% rename from test/Microsoft.AspNet.TestHost.Tests/Project.json2 rename to test/Microsoft.AspNet.TestHost.Tests/project.json From aa76fe3b4ffd9537aed10f7f58825dd17090bab3 Mon Sep 17 00:00:00 2001 From: David Fowler Date: Tue, 27 May 2014 00:23:05 -0700 Subject: [PATCH 075/987] Fixed project.json casing --- samples/KWebStartup/KWebStartup.kproj | 6 +++--- src/Microsoft.AspNet.Hosting/Microsoft.AspNet.Hosting.kproj | 6 +++--- .../Microsoft.AspNet.RequestContainer.kproj | 6 +++--- .../Microsoft.AspNet.TestHost.kproj | 6 +++--- .../Microsoft.AspNet.Hosting.Tests.kproj | 6 +++--- .../Microsoft.AspNet.TestHost.Tests.kproj | 6 +++--- 6 files changed, 18 insertions(+), 18 deletions(-) diff --git a/samples/KWebStartup/KWebStartup.kproj b/samples/KWebStartup/KWebStartup.kproj index a776cdc9db..b900357cfd 100644 --- a/samples/KWebStartup/KWebStartup.kproj +++ b/samples/KWebStartup/KWebStartup.kproj @@ -1,4 +1,4 @@ - + 12.0 @@ -17,10 +17,10 @@ 2.0 - + - \ No newline at end of file + diff --git a/src/Microsoft.AspNet.Hosting/Microsoft.AspNet.Hosting.kproj b/src/Microsoft.AspNet.Hosting/Microsoft.AspNet.Hosting.kproj index 102ee4062c..60f6546eb4 100644 --- a/src/Microsoft.AspNet.Hosting/Microsoft.AspNet.Hosting.kproj +++ b/src/Microsoft.AspNet.Hosting/Microsoft.AspNet.Hosting.kproj @@ -1,4 +1,4 @@ - + 12.0 @@ -17,7 +17,7 @@ 2.0 - + @@ -45,4 +45,4 @@ - \ No newline at end of file + diff --git a/src/Microsoft.AspNet.RequestContainer/Microsoft.AspNet.RequestContainer.kproj b/src/Microsoft.AspNet.RequestContainer/Microsoft.AspNet.RequestContainer.kproj index 35422bca16..dbadd459f2 100644 --- a/src/Microsoft.AspNet.RequestContainer/Microsoft.AspNet.RequestContainer.kproj +++ b/src/Microsoft.AspNet.RequestContainer/Microsoft.AspNet.RequestContainer.kproj @@ -1,4 +1,4 @@ - + 12.0 @@ -17,11 +17,11 @@ 2.0 - + - \ No newline at end of file + diff --git a/src/Microsoft.AspNet.TestHost/Microsoft.AspNet.TestHost.kproj b/src/Microsoft.AspNet.TestHost/Microsoft.AspNet.TestHost.kproj index 3e50a40255..882610a036 100644 --- a/src/Microsoft.AspNet.TestHost/Microsoft.AspNet.TestHost.kproj +++ b/src/Microsoft.AspNet.TestHost/Microsoft.AspNet.TestHost.kproj @@ -1,4 +1,4 @@ - + 12.0 @@ -17,7 +17,7 @@ 2.0 - + @@ -27,4 +27,4 @@ - \ No newline at end of file + diff --git a/test/Microsoft.AspNet.Hosting.Tests/Microsoft.AspNet.Hosting.Tests.kproj b/test/Microsoft.AspNet.Hosting.Tests/Microsoft.AspNet.Hosting.Tests.kproj index 2afbd680d6..8ead4b5c01 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/Microsoft.AspNet.Hosting.Tests.kproj +++ b/test/Microsoft.AspNet.Hosting.Tests/Microsoft.AspNet.Hosting.Tests.kproj @@ -1,4 +1,4 @@ - + 12.0 @@ -18,7 +18,7 @@ 2.0 - + @@ -27,4 +27,4 @@ - \ No newline at end of file + diff --git a/test/Microsoft.AspNet.TestHost.Tests/Microsoft.AspNet.TestHost.Tests.kproj b/test/Microsoft.AspNet.TestHost.Tests/Microsoft.AspNet.TestHost.Tests.kproj index 2c5387a97e..0ce16dcb3d 100644 --- a/test/Microsoft.AspNet.TestHost.Tests/Microsoft.AspNet.TestHost.Tests.kproj +++ b/test/Microsoft.AspNet.TestHost.Tests/Microsoft.AspNet.TestHost.Tests.kproj @@ -1,4 +1,4 @@ - + 12.0 @@ -18,7 +18,7 @@ 2.0 - + @@ -28,4 +28,4 @@ - \ No newline at end of file + From a2fd1e1d908bc3ea7ff6969f5a850c68f8c476b0 Mon Sep 17 00:00:00 2001 From: Hao Kung Date: Wed, 28 May 2014 12:09:29 -0700 Subject: [PATCH 076/987] Remove options services from UseServices Add OptionsModel.OptionServices.DefaultServices instead --- .../ContainerExtensions.cs | 8 -------- 1 file changed, 8 deletions(-) diff --git a/src/Microsoft.AspNet.RequestContainer/ContainerExtensions.cs b/src/Microsoft.AspNet.RequestContainer/ContainerExtensions.cs index d2ae5e3619..0a17cdb806 100644 --- a/src/Microsoft.AspNet.RequestContainer/ContainerExtensions.cs +++ b/src/Microsoft.AspNet.RequestContainer/ContainerExtensions.cs @@ -65,14 +65,6 @@ namespace Microsoft.AspNet.Builder { var serviceCollection = new ServiceCollection(); - // TODO: Review whether this is the right long term home, and whether Scoped is correct lifetime - serviceCollection.Add(new ServiceDescriptor - { - ServiceType = typeof(IOptionsAccessor<>), - ImplementationType = typeof(OptionsAccessor<>), - Lifecycle = LifecycleKind.Scoped - }); - configureServices(serviceCollection); builder.ApplicationServices = serviceCollection.BuildServiceProvider(builder.ApplicationServices); From 43ae61f7bcdb1cd3221d9fdfd4015cfd013aac7c Mon Sep 17 00:00:00 2001 From: Chris Ross Date: Fri, 30 May 2014 15:49:14 -0700 Subject: [PATCH 077/987] #23 - Implement graceful shutdown. --- .../ApplicationLifetime.cs | 72 +++++++++++++++++++ .../HostingContext.cs | 1 + src/Microsoft.AspNet.Hosting/HostingEngine.cs | 15 ++++ .../IApplicationLifetime.cs | 30 ++++++++ .../Microsoft.AspNet.Hosting.kproj | 4 +- src/Microsoft.AspNet.Hosting/Program.cs | 24 ++++++- 6 files changed, 143 insertions(+), 3 deletions(-) create mode 100644 src/Microsoft.AspNet.Hosting/ApplicationLifetime.cs create mode 100644 src/Microsoft.AspNet.Hosting/IApplicationLifetime.cs diff --git a/src/Microsoft.AspNet.Hosting/ApplicationLifetime.cs b/src/Microsoft.AspNet.Hosting/ApplicationLifetime.cs new file mode 100644 index 0000000000..d1db40def4 --- /dev/null +++ b/src/Microsoft.AspNet.Hosting/ApplicationLifetime.cs @@ -0,0 +1,72 @@ +// 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 System; +using System.Threading; + +namespace Microsoft.AspNet.Hosting +{ + /// + /// Allows consumers to perform cleanup during a graceful shutdown. + /// + public class ApplicationLifetime : IApplicationLifetime + { + private readonly CancellationTokenSource _stoppingSource = new CancellationTokenSource(); + private readonly CancellationTokenSource _stoppedSource = new CancellationTokenSource(); + + public ApplicationLifetime() + { + } + + /// + /// Triggered when the application host is performing a graceful shutdown. + /// Request may still be in flight. Shutdown will block until this event completes. + /// + /// + public CancellationToken ApplicationStopping + { + get { return _stoppingSource.Token; } + } + + /// + /// Triggered when the application host is performing a graceful shutdown. + /// All requests should be complete at this point. Shutdown will block + /// until this event completes. + /// + /// + public CancellationToken ApplicationStopped + { + get { return _stoppedSource.Token; } + } + + /// + /// Signals the ApplicationStopping event and blocks until it completes. + /// + public void SignalStopping() + { + try + { + _stoppingSource.Cancel(throwOnFirstException: false); + } + catch (Exception) + { + // TODO: LOG + } + } + + /// + /// Signals the ApplicationStopped event and blocks until it completes. + /// + public void SignalStopped() + { + try + { + _stoppedSource.Cancel(throwOnFirstException: false); + } + catch (Exception) + { + // TODO: LOG + } + } + } +} \ No newline at end of file diff --git a/src/Microsoft.AspNet.Hosting/HostingContext.cs b/src/Microsoft.AspNet.Hosting/HostingContext.cs index ea5685e6bb..7ad428b722 100644 --- a/src/Microsoft.AspNet.Hosting/HostingContext.cs +++ b/src/Microsoft.AspNet.Hosting/HostingContext.cs @@ -27,6 +27,7 @@ namespace Microsoft.AspNet.Hosting { public IServiceProvider Services { get; set; } public IConfiguration Configuration { get; set; } + public ApplicationLifetime Lifetime { get; set; } public IBuilder Builder { get; set; } diff --git a/src/Microsoft.AspNet.Hosting/HostingEngine.cs b/src/Microsoft.AspNet.Hosting/HostingEngine.cs index b8cecf5752..7458f5713b 100644 --- a/src/Microsoft.AspNet.Hosting/HostingEngine.cs +++ b/src/Microsoft.AspNet.Hosting/HostingEngine.cs @@ -21,6 +21,7 @@ using Microsoft.AspNet.Hosting.Builder; using Microsoft.AspNet.Hosting.Server; using Microsoft.AspNet.Hosting.Startup; using Microsoft.Framework.DependencyInjection; +using Microsoft.Framework.DependencyInjection.Fallback; namespace Microsoft.AspNet.Hosting { @@ -45,6 +46,7 @@ namespace Microsoft.AspNet.Hosting public IDisposable Start(HostingContext context) { + EnsureLifetime(context); EnsureBuilder(context); EnsureServerFactory(context); InitalizeServerFactory(context); @@ -55,11 +57,24 @@ namespace Microsoft.AspNet.Hosting return new Disposable(() => { + context.Lifetime.SignalStopping(); server.Dispose(); + context.Lifetime.SignalStopped(); pipeline.Dispose(); }); } + private void EnsureLifetime(HostingContext context) + { + if (context.Lifetime == null) + { + context.Lifetime = new ApplicationLifetime(); + } + var serviceCollection = new ServiceCollection(); + serviceCollection.AddInstance(context.Lifetime); + context.Services = serviceCollection.BuildServiceProvider(context.Services); + } + private void EnsureBuilder(HostingContext context) { if (context.Builder != null) diff --git a/src/Microsoft.AspNet.Hosting/IApplicationLifetime.cs b/src/Microsoft.AspNet.Hosting/IApplicationLifetime.cs new file mode 100644 index 0000000000..df20556da1 --- /dev/null +++ b/src/Microsoft.AspNet.Hosting/IApplicationLifetime.cs @@ -0,0 +1,30 @@ +// 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 System.Threading; +using Microsoft.Framework.Runtime; + +namespace Microsoft.AspNet.Hosting +{ + /// + /// Allows consumers to perform cleanup during a graceful shutdown. + /// + [AssemblyNeutral] + public interface IApplicationLifetime + { + /// + /// Triggered when the application host is performing a graceful shutdown. + /// Request may still be in flight. Shutdown will block until this event completes. + /// + /// + CancellationToken ApplicationStopping { get; } + + /// + /// Triggered when the application host is performing a graceful shutdown. + /// All requests should be complete at this point. Shutdown will block + /// until this event completes. + /// + /// + CancellationToken ApplicationStopped { get; } + } +} \ No newline at end of file diff --git a/src/Microsoft.AspNet.Hosting/Microsoft.AspNet.Hosting.kproj b/src/Microsoft.AspNet.Hosting/Microsoft.AspNet.Hosting.kproj index 60f6546eb4..c58f27a50a 100644 --- a/src/Microsoft.AspNet.Hosting/Microsoft.AspNet.Hosting.kproj +++ b/src/Microsoft.AspNet.Hosting/Microsoft.AspNet.Hosting.kproj @@ -20,6 +20,7 @@ + @@ -27,6 +28,7 @@ + @@ -45,4 +47,4 @@ - + \ No newline at end of file diff --git a/src/Microsoft.AspNet.Hosting/Program.cs b/src/Microsoft.AspNet.Hosting/Program.cs index 00b4a6af5c..8599267216 100644 --- a/src/Microsoft.AspNet.Hosting/Program.cs +++ b/src/Microsoft.AspNet.Hosting/Program.cs @@ -17,6 +17,8 @@ using System; using System.IO; +using System.Threading; +using System.Threading.Tasks; using Microsoft.Framework.ConfigurationModel; using Microsoft.Framework.DependencyInjection; using Microsoft.Framework.DependencyInjection.Fallback; @@ -67,11 +69,29 @@ namespace Microsoft.AspNet.Hosting throw new Exception("TODO: IHostingEngine service not available exception"); } - using (engine.Start(context)) + var appShutdownService = _serviceProvider.GetService(); + if (appShutdownService == null) + { + throw new Exception("TODO: IApplicationShutdown service not available"); + } + var shutdownHandle = new ManualResetEvent(false); + + var serverShutdown = engine.Start(context); + + appShutdownService.ShutdownRequested.Register(() => + { + serverShutdown.Dispose(); + shutdownHandle.Set(); + }); + + Task ignored = Task.Run(() => { Console.WriteLine("Started"); Console.ReadLine(); - } + appShutdownService.RequestShutdown(); + }); + + shutdownHandle.WaitOne(); } } } From 25db4123324908bca1f417cba2b4ed9e23598306 Mon Sep 17 00:00:00 2001 From: Chris Ross Date: Fri, 30 May 2014 16:30:51 -0700 Subject: [PATCH 078/987] Clean up IApplicaitonLifetime service injection. --- src/Microsoft.AspNet.Hosting/HostingContext.cs | 1 - src/Microsoft.AspNet.Hosting/HostingEngine.cs | 17 +++-------------- src/Microsoft.AspNet.Hosting/HostingServices.cs | 2 ++ src/Microsoft.AspNet.Hosting/Program.cs | 2 +- 4 files changed, 6 insertions(+), 16 deletions(-) diff --git a/src/Microsoft.AspNet.Hosting/HostingContext.cs b/src/Microsoft.AspNet.Hosting/HostingContext.cs index 7ad428b722..ea5685e6bb 100644 --- a/src/Microsoft.AspNet.Hosting/HostingContext.cs +++ b/src/Microsoft.AspNet.Hosting/HostingContext.cs @@ -27,7 +27,6 @@ namespace Microsoft.AspNet.Hosting { public IServiceProvider Services { get; set; } public IConfiguration Configuration { get; set; } - public ApplicationLifetime Lifetime { get; set; } public IBuilder Builder { get; set; } diff --git a/src/Microsoft.AspNet.Hosting/HostingEngine.cs b/src/Microsoft.AspNet.Hosting/HostingEngine.cs index 7458f5713b..eac137bb38 100644 --- a/src/Microsoft.AspNet.Hosting/HostingEngine.cs +++ b/src/Microsoft.AspNet.Hosting/HostingEngine.cs @@ -46,35 +46,24 @@ namespace Microsoft.AspNet.Hosting public IDisposable Start(HostingContext context) { - EnsureLifetime(context); EnsureBuilder(context); EnsureServerFactory(context); InitalizeServerFactory(context); EnsureApplicationDelegate(context); + var applicationLifetime = (ApplicationLifetime)context.Services.GetService(); var pipeline = new PipelineInstance(_httpContextFactory, context.ApplicationDelegate); var server = context.ServerFactory.Start(context.Server, pipeline.Invoke); return new Disposable(() => { - context.Lifetime.SignalStopping(); + applicationLifetime.SignalStopping(); server.Dispose(); - context.Lifetime.SignalStopped(); pipeline.Dispose(); + applicationLifetime.SignalStopped(); }); } - private void EnsureLifetime(HostingContext context) - { - if (context.Lifetime == null) - { - context.Lifetime = new ApplicationLifetime(); - } - var serviceCollection = new ServiceCollection(); - serviceCollection.AddInstance(context.Lifetime); - context.Services = serviceCollection.BuildServiceProvider(context.Services); - } - private void EnsureBuilder(HostingContext context) { if (context.Builder != null) diff --git a/src/Microsoft.AspNet.Hosting/HostingServices.cs b/src/Microsoft.AspNet.Hosting/HostingServices.cs index c7376cd52e..e0995468d9 100644 --- a/src/Microsoft.AspNet.Hosting/HostingServices.cs +++ b/src/Microsoft.AspNet.Hosting/HostingServices.cs @@ -49,6 +49,8 @@ namespace Microsoft.AspNet.Hosting yield return describer.Transient(); + yield return describer.Instance(new ApplicationLifetime()); + // TODO: We expect this to be provide by the runtime eventually. yield return describer.Instance(new NullLoggerFactory()); diff --git a/src/Microsoft.AspNet.Hosting/Program.cs b/src/Microsoft.AspNet.Hosting/Program.cs index 8599267216..b1f694e018 100644 --- a/src/Microsoft.AspNet.Hosting/Program.cs +++ b/src/Microsoft.AspNet.Hosting/Program.cs @@ -84,7 +84,7 @@ namespace Microsoft.AspNet.Hosting shutdownHandle.Set(); }); - Task ignored = Task.Run(() => + var ignored = Task.Run(() => { Console.WriteLine("Started"); Console.ReadLine(); From 04ca5e968d748e963c136187be9c69c1fc5115a7 Mon Sep 17 00:00:00 2001 From: David Fowler Date: Fri, 30 May 2014 22:32:37 -0700 Subject: [PATCH 079/987] Fixed tests --- test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs b/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs index d6cbf86841..96915f09fd 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs @@ -55,6 +55,7 @@ namespace Microsoft.AspNet.Hosting var context = new HostingContext { ServerFactory = this, + Services = services, ApplicationName = "Microsoft.AspNet.Hosting.Tests" }; From 63f643e0c1d9be3485300a297a74b13c8ed8299e Mon Sep 17 00:00:00 2001 From: David Fowler Date: Sat, 31 May 2014 00:04:06 -0700 Subject: [PATCH 080/987] Fix up the project/sln files --- Hosting.sln | 130 +++++++++--------- .../Microsoft.AspNet.Hosting.Tests.kproj | 5 +- 2 files changed, 65 insertions(+), 70 deletions(-) diff --git a/Hosting.sln b/Hosting.sln index f9376adc31..66ecdc97c7 100644 --- a/Hosting.sln +++ b/Hosting.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 2013 -VisualStudioVersion = 12.0.30401.0 +# Visual Studio 14 +VisualStudioVersion = 14.0.21723.0 MinimumVisualStudioVersion = 10.0.40219.1 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{E0497F39-AFFB-4819-A116-E39E361915AB}" EndProject @@ -31,72 +31,66 @@ Global Release|x86 = Release|x86 EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution - {0ACB2719-9484-49B5-B8E3-117091192511}.Debug|Any CPU.ActiveCfg = Debug|x86 - {0ACB2719-9484-49B5-B8E3-117091192511}.Debug|Any CPU.Build.0 = Debug|x86 - {0ACB2719-9484-49B5-B8E3-117091192511}.Debug|Mixed Platforms.ActiveCfg = Debug|x86 - {0ACB2719-9484-49B5-B8E3-117091192511}.Debug|Mixed Platforms.Build.0 = Debug|x86 - {0ACB2719-9484-49B5-B8E3-117091192511}.Debug|x86.ActiveCfg = Debug|x86 - {0ACB2719-9484-49B5-B8E3-117091192511}.Debug|x86.Build.0 = Debug|x86 - {0ACB2719-9484-49B5-B8E3-117091192511}.Release|Any CPU.ActiveCfg = Release|x86 - {0ACB2719-9484-49B5-B8E3-117091192511}.Release|Mixed Platforms.ActiveCfg = Release|x86 - {0ACB2719-9484-49B5-B8E3-117091192511}.Release|Mixed Platforms.Build.0 = Release|x86 - {0ACB2719-9484-49B5-B8E3-117091192511}.Release|x86.ActiveCfg = Release|x86 - {0ACB2719-9484-49B5-B8E3-117091192511}.Release|x86.Build.0 = Release|x86 - {1A415A3F-1081-45DB-809B-EE19CEA02DC0}.Debug|Any CPU.ActiveCfg = Debug|x86 - {1A415A3F-1081-45DB-809B-EE19CEA02DC0}.Debug|Any CPU.Build.0 = Debug|x86 - {1A415A3F-1081-45DB-809B-EE19CEA02DC0}.Debug|Mixed Platforms.ActiveCfg = Debug|x86 - {1A415A3F-1081-45DB-809B-EE19CEA02DC0}.Debug|Mixed Platforms.Build.0 = Debug|x86 - {1A415A3F-1081-45DB-809B-EE19CEA02DC0}.Debug|x86.ActiveCfg = Debug|x86 - {1A415A3F-1081-45DB-809B-EE19CEA02DC0}.Debug|x86.Build.0 = Debug|x86 - {1A415A3F-1081-45DB-809B-EE19CEA02DC0}.Release|Any CPU.ActiveCfg = Release|x86 - {1A415A3F-1081-45DB-809B-EE19CEA02DC0}.Release|Mixed Platforms.ActiveCfg = Release|x86 - {1A415A3F-1081-45DB-809B-EE19CEA02DC0}.Release|Mixed Platforms.Build.0 = Release|x86 - {1A415A3F-1081-45DB-809B-EE19CEA02DC0}.Release|x86.ActiveCfg = Release|x86 - {1A415A3F-1081-45DB-809B-EE19CEA02DC0}.Release|x86.Build.0 = Release|x86 - {3944F036-7E75-47E8-AA52-C4B89A64EC3A}.Debug|Any CPU.ActiveCfg = Debug|x86 - {3944F036-7E75-47E8-AA52-C4B89A64EC3A}.Debug|Any CPU.Build.0 = Debug|x86 - {3944F036-7E75-47E8-AA52-C4B89A64EC3A}.Debug|Mixed Platforms.ActiveCfg = Debug|x86 - {3944F036-7E75-47E8-AA52-C4B89A64EC3A}.Debug|Mixed Platforms.Build.0 = Debug|x86 - {3944F036-7E75-47E8-AA52-C4B89A64EC3A}.Debug|x86.ActiveCfg = Debug|x86 - {3944F036-7E75-47E8-AA52-C4B89A64EC3A}.Debug|x86.Build.0 = Debug|x86 - {3944F036-7E75-47E8-AA52-C4B89A64EC3A}.Release|Any CPU.ActiveCfg = Release|x86 - {3944F036-7E75-47E8-AA52-C4B89A64EC3A}.Release|Mixed Platforms.ActiveCfg = Release|x86 - {3944F036-7E75-47E8-AA52-C4B89A64EC3A}.Release|Mixed Platforms.Build.0 = Release|x86 - {3944F036-7E75-47E8-AA52-C4B89A64EC3A}.Release|x86.ActiveCfg = Release|x86 - {3944F036-7E75-47E8-AA52-C4B89A64EC3A}.Release|x86.Build.0 = Release|x86 - {D4F18D58-52B1-435D-A012-10F2CDF158C4}.Debug|Any CPU.ActiveCfg = Debug|x86 - {D4F18D58-52B1-435D-A012-10F2CDF158C4}.Debug|Any CPU.Build.0 = Debug|x86 - {D4F18D58-52B1-435D-A012-10F2CDF158C4}.Debug|Mixed Platforms.ActiveCfg = Debug|x86 - {D4F18D58-52B1-435D-A012-10F2CDF158C4}.Debug|Mixed Platforms.Build.0 = Debug|x86 - {D4F18D58-52B1-435D-A012-10F2CDF158C4}.Debug|x86.ActiveCfg = Debug|x86 - {D4F18D58-52B1-435D-A012-10F2CDF158C4}.Debug|x86.Build.0 = Debug|x86 - {D4F18D58-52B1-435D-A012-10F2CDF158C4}.Release|Any CPU.ActiveCfg = Release|x86 - {D4F18D58-52B1-435D-A012-10F2CDF158C4}.Release|Mixed Platforms.ActiveCfg = Release|x86 - {D4F18D58-52B1-435D-A012-10F2CDF158C4}.Release|Mixed Platforms.Build.0 = Release|x86 - {D4F18D58-52B1-435D-A012-10F2CDF158C4}.Release|x86.ActiveCfg = Release|x86 - {D4F18D58-52B1-435D-A012-10F2CDF158C4}.Release|x86.Build.0 = Release|x86 - {374A5B0C-3E93-4A23-A4A0-EE2AB6DF7814}.Debug|Any CPU.ActiveCfg = Debug|x86 - {374A5B0C-3E93-4A23-A4A0-EE2AB6DF7814}.Debug|Any CPU.Build.0 = Debug|x86 - {374A5B0C-3E93-4A23-A4A0-EE2AB6DF7814}.Debug|Mixed Platforms.ActiveCfg = Debug|x86 - {374A5B0C-3E93-4A23-A4A0-EE2AB6DF7814}.Debug|Mixed Platforms.Build.0 = Debug|x86 - {374A5B0C-3E93-4A23-A4A0-EE2AB6DF7814}.Debug|x86.ActiveCfg = Debug|x86 - {374A5B0C-3E93-4A23-A4A0-EE2AB6DF7814}.Debug|x86.Build.0 = Debug|x86 - {374A5B0C-3E93-4A23-A4A0-EE2AB6DF7814}.Release|Any CPU.ActiveCfg = Release|x86 - {374A5B0C-3E93-4A23-A4A0-EE2AB6DF7814}.Release|Mixed Platforms.ActiveCfg = Release|x86 - {374A5B0C-3E93-4A23-A4A0-EE2AB6DF7814}.Release|Mixed Platforms.Build.0 = Release|x86 - {374A5B0C-3E93-4A23-A4A0-EE2AB6DF7814}.Release|x86.ActiveCfg = Release|x86 - {374A5B0C-3E93-4A23-A4A0-EE2AB6DF7814}.Release|x86.Build.0 = Release|x86 - {A2F321A5-3F55-4413-B357-EEF85DC0ECA6}.Debug|Any CPU.ActiveCfg = Debug|x86 - {A2F321A5-3F55-4413-B357-EEF85DC0ECA6}.Debug|Any CPU.Build.0 = Debug|x86 - {A2F321A5-3F55-4413-B357-EEF85DC0ECA6}.Debug|Mixed Platforms.ActiveCfg = Debug|x86 - {A2F321A5-3F55-4413-B357-EEF85DC0ECA6}.Debug|Mixed Platforms.Build.0 = Debug|x86 - {A2F321A5-3F55-4413-B357-EEF85DC0ECA6}.Debug|x86.ActiveCfg = Debug|x86 - {A2F321A5-3F55-4413-B357-EEF85DC0ECA6}.Debug|x86.Build.0 = Debug|x86 - {A2F321A5-3F55-4413-B357-EEF85DC0ECA6}.Release|Any CPU.ActiveCfg = Release|x86 - {A2F321A5-3F55-4413-B357-EEF85DC0ECA6}.Release|Mixed Platforms.ActiveCfg = Release|x86 - {A2F321A5-3F55-4413-B357-EEF85DC0ECA6}.Release|Mixed Platforms.Build.0 = Release|x86 - {A2F321A5-3F55-4413-B357-EEF85DC0ECA6}.Release|x86.ActiveCfg = Release|x86 - {A2F321A5-3F55-4413-B357-EEF85DC0ECA6}.Release|x86.Build.0 = Release|x86 + {0ACB2719-9484-49B5-B8E3-117091192511}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {0ACB2719-9484-49B5-B8E3-117091192511}.Debug|Any CPU.Build.0 = Debug|Any CPU + {0ACB2719-9484-49B5-B8E3-117091192511}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU + {0ACB2719-9484-49B5-B8E3-117091192511}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU + {0ACB2719-9484-49B5-B8E3-117091192511}.Debug|x86.ActiveCfg = Debug|Any CPU + {0ACB2719-9484-49B5-B8E3-117091192511}.Release|Any CPU.ActiveCfg = Release|Any CPU + {0ACB2719-9484-49B5-B8E3-117091192511}.Release|Any CPU.Build.0 = Release|Any CPU + {0ACB2719-9484-49B5-B8E3-117091192511}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU + {0ACB2719-9484-49B5-B8E3-117091192511}.Release|Mixed Platforms.Build.0 = Release|Any CPU + {0ACB2719-9484-49B5-B8E3-117091192511}.Release|x86.ActiveCfg = Release|Any CPU + {1A415A3F-1081-45DB-809B-EE19CEA02DC0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {1A415A3F-1081-45DB-809B-EE19CEA02DC0}.Debug|Any CPU.Build.0 = Debug|Any CPU + {1A415A3F-1081-45DB-809B-EE19CEA02DC0}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU + {1A415A3F-1081-45DB-809B-EE19CEA02DC0}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU + {1A415A3F-1081-45DB-809B-EE19CEA02DC0}.Debug|x86.ActiveCfg = Debug|Any CPU + {1A415A3F-1081-45DB-809B-EE19CEA02DC0}.Release|Any CPU.ActiveCfg = Release|Any CPU + {1A415A3F-1081-45DB-809B-EE19CEA02DC0}.Release|Any CPU.Build.0 = Release|Any CPU + {1A415A3F-1081-45DB-809B-EE19CEA02DC0}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU + {1A415A3F-1081-45DB-809B-EE19CEA02DC0}.Release|Mixed Platforms.Build.0 = Release|Any CPU + {1A415A3F-1081-45DB-809B-EE19CEA02DC0}.Release|x86.ActiveCfg = Release|Any CPU + {3944F036-7E75-47E8-AA52-C4B89A64EC3A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {3944F036-7E75-47E8-AA52-C4B89A64EC3A}.Debug|Any CPU.Build.0 = Debug|Any CPU + {3944F036-7E75-47E8-AA52-C4B89A64EC3A}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU + {3944F036-7E75-47E8-AA52-C4B89A64EC3A}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU + {3944F036-7E75-47E8-AA52-C4B89A64EC3A}.Debug|x86.ActiveCfg = Debug|Any CPU + {3944F036-7E75-47E8-AA52-C4B89A64EC3A}.Release|Any CPU.ActiveCfg = Release|Any CPU + {3944F036-7E75-47E8-AA52-C4B89A64EC3A}.Release|Any CPU.Build.0 = Release|Any CPU + {3944F036-7E75-47E8-AA52-C4B89A64EC3A}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU + {3944F036-7E75-47E8-AA52-C4B89A64EC3A}.Release|Mixed Platforms.Build.0 = Release|Any CPU + {3944F036-7E75-47E8-AA52-C4B89A64EC3A}.Release|x86.ActiveCfg = Release|Any CPU + {D4F18D58-52B1-435D-A012-10F2CDF158C4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {D4F18D58-52B1-435D-A012-10F2CDF158C4}.Debug|Any CPU.Build.0 = Debug|Any CPU + {D4F18D58-52B1-435D-A012-10F2CDF158C4}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU + {D4F18D58-52B1-435D-A012-10F2CDF158C4}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU + {D4F18D58-52B1-435D-A012-10F2CDF158C4}.Debug|x86.ActiveCfg = Debug|Any CPU + {D4F18D58-52B1-435D-A012-10F2CDF158C4}.Release|Any CPU.ActiveCfg = Release|Any CPU + {D4F18D58-52B1-435D-A012-10F2CDF158C4}.Release|Any CPU.Build.0 = Release|Any CPU + {D4F18D58-52B1-435D-A012-10F2CDF158C4}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU + {D4F18D58-52B1-435D-A012-10F2CDF158C4}.Release|Mixed Platforms.Build.0 = Release|Any CPU + {D4F18D58-52B1-435D-A012-10F2CDF158C4}.Release|x86.ActiveCfg = Release|Any CPU + {374A5B0C-3E93-4A23-A4A0-EE2AB6DF7814}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {374A5B0C-3E93-4A23-A4A0-EE2AB6DF7814}.Debug|Any CPU.Build.0 = Debug|Any CPU + {374A5B0C-3E93-4A23-A4A0-EE2AB6DF7814}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU + {374A5B0C-3E93-4A23-A4A0-EE2AB6DF7814}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU + {374A5B0C-3E93-4A23-A4A0-EE2AB6DF7814}.Debug|x86.ActiveCfg = Debug|Any CPU + {374A5B0C-3E93-4A23-A4A0-EE2AB6DF7814}.Release|Any CPU.ActiveCfg = Release|Any CPU + {374A5B0C-3E93-4A23-A4A0-EE2AB6DF7814}.Release|Any CPU.Build.0 = Release|Any CPU + {374A5B0C-3E93-4A23-A4A0-EE2AB6DF7814}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU + {374A5B0C-3E93-4A23-A4A0-EE2AB6DF7814}.Release|Mixed Platforms.Build.0 = Release|Any CPU + {374A5B0C-3E93-4A23-A4A0-EE2AB6DF7814}.Release|x86.ActiveCfg = Release|Any CPU + {A2F321A5-3F55-4413-B357-EEF85DC0ECA6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {A2F321A5-3F55-4413-B357-EEF85DC0ECA6}.Debug|Any CPU.Build.0 = Debug|Any CPU + {A2F321A5-3F55-4413-B357-EEF85DC0ECA6}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU + {A2F321A5-3F55-4413-B357-EEF85DC0ECA6}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU + {A2F321A5-3F55-4413-B357-EEF85DC0ECA6}.Debug|x86.ActiveCfg = Debug|Any CPU + {A2F321A5-3F55-4413-B357-EEF85DC0ECA6}.Release|Any CPU.ActiveCfg = Release|Any CPU + {A2F321A5-3F55-4413-B357-EEF85DC0ECA6}.Release|Any CPU.Build.0 = Release|Any CPU + {A2F321A5-3F55-4413-B357-EEF85DC0ECA6}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU + {A2F321A5-3F55-4413-B357-EEF85DC0ECA6}.Release|Mixed Platforms.Build.0 = Release|Any CPU + {A2F321A5-3F55-4413-B357-EEF85DC0ECA6}.Release|x86.ActiveCfg = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/test/Microsoft.AspNet.Hosting.Tests/Microsoft.AspNet.Hosting.Tests.kproj b/test/Microsoft.AspNet.Hosting.Tests/Microsoft.AspNet.Hosting.Tests.kproj index 8ead4b5c01..0ffb62252d 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/Microsoft.AspNet.Hosting.Tests.kproj +++ b/test/Microsoft.AspNet.Hosting.Tests/Microsoft.AspNet.Hosting.Tests.kproj @@ -21,10 +21,11 @@ - + + - + \ No newline at end of file From 44503744a37bfeee687ceb05ebc4d930c82e6a8d Mon Sep 17 00:00:00 2001 From: Pranav K Date: Tue, 3 Jun 2014 10:15:37 -0700 Subject: [PATCH 081/987] Adding switch to build.cmd to skip KRE install --- build.cmd | 2 ++ 1 file changed, 2 insertions(+) diff --git a/build.cmd b/build.cmd index 903d532df3..3aaf957583 100644 --- a/build.cmd +++ b/build.cmd @@ -18,6 +18,8 @@ copy %CACHED_NUGET% .nuget\nuget.exe > nul IF EXIST packages\KoreBuild goto run .nuget\NuGet.exe install KoreBuild -ExcludeVersion -o packages -nocache -pre .nuget\NuGet.exe install Sake -version 0.2 -o packages -ExcludeVersion + +IF "%SKIP_KRE_INSTALL%"=="1" goto run CALL packages\KoreBuild\build\kvm upgrade -svr50 -x86 CALL packages\KoreBuild\build\kvm install default -svrc50 -x86 From 3fb1a06e258ebad0a13c84a1c2f524dd2aace2ec Mon Sep 17 00:00:00 2001 From: Hao Kung Date: Tue, 3 Jun 2014 15:03:57 -0700 Subject: [PATCH 082/987] Add OptionsServices in UseServices --- src/Microsoft.AspNet.RequestContainer/ContainerExtensions.cs | 2 ++ src/Microsoft.AspNet.RequestContainer/project.json | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Microsoft.AspNet.RequestContainer/ContainerExtensions.cs b/src/Microsoft.AspNet.RequestContainer/ContainerExtensions.cs index 0a17cdb806..5e60f67127 100644 --- a/src/Microsoft.AspNet.RequestContainer/ContainerExtensions.cs +++ b/src/Microsoft.AspNet.RequestContainer/ContainerExtensions.cs @@ -22,6 +22,7 @@ using System.Reflection; using Microsoft.AspNet.RequestContainer; using Microsoft.Framework.DependencyInjection; using Microsoft.Framework.DependencyInjection.Fallback; +using Microsoft.Framework.OptionsModel; namespace Microsoft.AspNet.Builder { @@ -65,6 +66,7 @@ namespace Microsoft.AspNet.Builder { var serviceCollection = new ServiceCollection(); + serviceCollection.Add(OptionsServices.GetDefaultServices()); configureServices(serviceCollection); builder.ApplicationServices = serviceCollection.BuildServiceProvider(builder.ApplicationServices); diff --git a/src/Microsoft.AspNet.RequestContainer/project.json b/src/Microsoft.AspNet.RequestContainer/project.json index 1a1a36198f..75819c8802 100644 --- a/src/Microsoft.AspNet.RequestContainer/project.json +++ b/src/Microsoft.AspNet.RequestContainer/project.json @@ -2,7 +2,8 @@ "version": "0.1-alpha-*", "dependencies": { "Microsoft.AspNet.Http": "0.1-alpha-*", - "Microsoft.Framework.DependencyInjection": "0.1-alpha-*" + "Microsoft.Framework.DependencyInjection": "0.1-alpha-*", + "Microsoft.Framework.OptionsModel": "0.1-alpha-*" }, "configurations": { "net45": {}, From 45dcd20268974bd113d6c39ebef8b177f0f46091 Mon Sep 17 00:00:00 2001 From: Pranav K Date: Tue, 10 Jun 2014 17:22:35 -0700 Subject: [PATCH 083/987] Updating build.sh based on KRuntime changes --- build.sh | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/build.sh b/build.sh index a918165425..4323aefc48 100755 --- a/build.sh +++ b/build.sh @@ -3,10 +3,10 @@ if test `uname` = Darwin; then cachedir=~/Library/Caches/KBuild else - if x$XDG_DATA_HOME = x; then - cachedir=$HOME/.local/share + if [ -z $XDG_DATA_HOME ]; then + cachedir=$HOME/.local/share else - cachedir=$XDG_DATA_HOME; + cachedir=$XDG_DATA_HOME; fi fi mkdir -p $cachedir @@ -14,12 +14,12 @@ mkdir -p $cachedir url=https://www.nuget.org/nuget.exe if test ! -f $cachedir/nuget.exe; then - wget -o $cachedir/nuget.exe $url 2>/dev/null || curl -o $cachedir/nuget.exe --location $url /dev/null + wget -O $cachedir/nuget.exe $url 2>/dev/null || curl -o $cachedir/nuget.exe --location $url /dev/null fi if test ! -e .nuget; then mkdir .nuget - cp $cachedir/nuget.exe .nuget + cp $cachedir/nuget.exe .nuget/nuget.exe fi if test ! -d packages/KoreBuild; then @@ -27,14 +27,12 @@ if test ! -d packages/KoreBuild; then mono .nuget/nuget.exe install Sake -version 0.2 -o packages -ExcludeVersion fi -KRE_VERSION=$(mono .nuget/nuget.exe install KRE-mono45-x86 -pre -o ~/.kre/packages | head -1 | sed "s/.*KRE-mono45-x86 \([^']*\).*/\1/") -KRE_BIN=~/.kre/packages/KRE-mono45-x86.$KRE_VERSION/bin +if ! type k > /dev/null 2>&1; then + source setup/kvm.sh +fi -chmod +x $KRE_BIN/k -chmod +x $KRE_BIN/klr -chmod +x $KRE_BIN/kpm -chmod +x $KRE_BIN/k-build +if ! type k > /dev/null 2>&1; then + kvm upgrade +fi -export PATH=$KRE_BIN:$PATH - -mono packages/Sake/tools/Sake.exe -I packages/KoreBuild/build -f makefile.shade "$@" \ No newline at end of file +mono packages/Sake/tools/Sake.exe -I packages/KoreBuild/build -f makefile.shade "$@" From 25bbfa7165dcffccbe1969a1635a2ec8e95a6a8f Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Wed, 11 Jun 2014 12:14:37 -0700 Subject: [PATCH 084/987] Fix test now that ServiceProvider throws a generic exception aspnet/DependencyInjection#87 --- test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs b/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs index c1b0ea1fb3..b486dd3ffb 100644 --- a/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs +++ b/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs @@ -66,9 +66,7 @@ namespace Microsoft.AspNet.TestHost.Tests .BuildServiceProvider(); // Act & Assert - Assert.Throws( - "serviceProvider", - () => TestServer.Create(services, new Startup().Configuration)); + Assert.Throws(() => TestServer.Create(services, new Startup().Configuration)); } public class Startup From abbd763f0f9d8e835c53fb28e7c4c0e14df5889f Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Wed, 11 Jun 2014 18:32:40 -0700 Subject: [PATCH 085/987] Use GetServiceOrDefault for optional dependency --- src/Microsoft.AspNet.Hosting/HostingEngine.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Microsoft.AspNet.Hosting/HostingEngine.cs b/src/Microsoft.AspNet.Hosting/HostingEngine.cs index eac137bb38..88f1dc5184 100644 --- a/src/Microsoft.AspNet.Hosting/HostingEngine.cs +++ b/src/Microsoft.AspNet.Hosting/HostingEngine.cs @@ -78,7 +78,7 @@ namespace Microsoft.AspNet.Hosting { if (context.ServerFactory == null) { - context.ServerFactory = context.Services.GetService(); + context.ServerFactory = context.Services.GetServiceOrDefault(); } if (context.ServerFactory != null) { From 0ab560e08695e709fc650eb31026c8c0b2a44b31 Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Mon, 16 Jun 2014 18:30:51 -0700 Subject: [PATCH 086/987] Add UseServices overload that takes a Func returning IServiceProvider - This should be useful for third-party IoC containers --- .../ContainerExtensions.cs | 12 +++++- .../Microsoft.AspNet.Hosting.Tests.kproj | 1 + .../UseServicesFacts.cs | 43 +++++++++++++++++++ .../project.json | 1 + 4 files changed, 55 insertions(+), 2 deletions(-) create mode 100644 test/Microsoft.AspNet.Hosting.Tests/UseServicesFacts.cs diff --git a/src/Microsoft.AspNet.RequestContainer/ContainerExtensions.cs b/src/Microsoft.AspNet.RequestContainer/ContainerExtensions.cs index 5e60f67127..45b7375683 100644 --- a/src/Microsoft.AspNet.RequestContainer/ContainerExtensions.cs +++ b/src/Microsoft.AspNet.RequestContainer/ContainerExtensions.cs @@ -63,12 +63,20 @@ namespace Microsoft.AspNet.Builder } public static IBuilder UseServices(this IBuilder builder, Action configureServices) + { + return builder.UseServices(serviceCollection => + { + configureServices(serviceCollection); + return serviceCollection.BuildServiceProvider(builder.ApplicationServices); + }); + } + + public static IBuilder UseServices(this IBuilder builder, Func configureServices) { var serviceCollection = new ServiceCollection(); serviceCollection.Add(OptionsServices.GetDefaultServices()); - configureServices(serviceCollection); - builder.ApplicationServices = serviceCollection.BuildServiceProvider(builder.ApplicationServices); + builder.ApplicationServices = configureServices(serviceCollection); return builder.UseMiddleware(typeof(ContainerMiddleware)); } diff --git a/test/Microsoft.AspNet.Hosting.Tests/Microsoft.AspNet.Hosting.Tests.kproj b/test/Microsoft.AspNet.Hosting.Tests/Microsoft.AspNet.Hosting.Tests.kproj index 0ffb62252d..412181c036 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/Microsoft.AspNet.Hosting.Tests.kproj +++ b/test/Microsoft.AspNet.Hosting.Tests/Microsoft.AspNet.Hosting.Tests.kproj @@ -26,6 +26,7 @@ + \ No newline at end of file diff --git a/test/Microsoft.AspNet.Hosting.Tests/UseServicesFacts.cs b/test/Microsoft.AspNet.Hosting.Tests/UseServicesFacts.cs new file mode 100644 index 0000000000..df88e1e855 --- /dev/null +++ b/test/Microsoft.AspNet.Hosting.Tests/UseServicesFacts.cs @@ -0,0 +1,43 @@ +using System; +using Microsoft.AspNet.Builder; +using Microsoft.Framework.DependencyInjection; +using Microsoft.Framework.DependencyInjection.Fallback; +using Microsoft.Framework.OptionsModel; +using Xunit; + +namespace Microsoft.AspNet.Hosting.Tests +{ + public class UseServicesFacts + { + [Fact] + public void OptionsAccessorCanBeResolvedAfterCallingUseServicesWithAction() + { + var baseServiceProvider = new ServiceCollection().BuildServiceProvider(); + var builder = new Microsoft.AspNet.Builder.Builder(baseServiceProvider); + + builder.UseServices(serviceCollection => { }); + + var optionsAccessor = builder.ApplicationServices.GetService>(); + Assert.NotNull(optionsAccessor); + } + + + [Fact] + public void OptionsAccessorCanBeResolvedAfterCallingUseServicesWithFunc() + { + var baseServiceProvider = new ServiceCollection().BuildServiceProvider(); + var builder = new Microsoft.AspNet.Builder.Builder(baseServiceProvider); + IServiceProvider serviceProvider = null; + + builder.UseServices(serviceCollection => + { + serviceProvider = serviceCollection.BuildServiceProvider(builder.ApplicationServices); + return serviceProvider; + }); + + Assert.Same(serviceProvider, builder.ApplicationServices); + var optionsAccessor = builder.ApplicationServices.GetService>(); + Assert.NotNull(optionsAccessor); + } + } +} \ No newline at end of file diff --git a/test/Microsoft.AspNet.Hosting.Tests/project.json b/test/Microsoft.AspNet.Hosting.Tests/project.json index 50ffba28ed..7ad9bce822 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/project.json +++ b/test/Microsoft.AspNet.Hosting.Tests/project.json @@ -2,6 +2,7 @@ "version": "0.1-alpha-*", "dependencies": { "Microsoft.AspNet.Hosting": "", + "Microsoft.AspNet.RequestContainer": "", "xunit.abstractions": "2.0.0-aspnet-*", "xunit.assert": "2.0.0-aspnet-*", "xunit.core": "2.0.0-aspnet-*", From 45933b149e2198c147354d843c745286e6c6f637 Mon Sep 17 00:00:00 2001 From: Louis DeJardin Date: Tue, 17 Jun 2014 15:10:13 -0700 Subject: [PATCH 087/987] IServerFactory is never a registered service IServerManager is registered when needed Or the caller may provide context.ServerFactory instance when an override is needed --- src/Microsoft.AspNet.Hosting/HostingEngine.cs | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/Microsoft.AspNet.Hosting/HostingEngine.cs b/src/Microsoft.AspNet.Hosting/HostingEngine.cs index 88f1dc5184..f921780c8e 100644 --- a/src/Microsoft.AspNet.Hosting/HostingEngine.cs +++ b/src/Microsoft.AspNet.Hosting/HostingEngine.cs @@ -76,10 +76,6 @@ namespace Microsoft.AspNet.Hosting private void EnsureServerFactory(HostingContext context) { - if (context.ServerFactory == null) - { - context.ServerFactory = context.Services.GetServiceOrDefault(); - } if (context.ServerFactory != null) { return; From e34a149f858964c468ae7f818789478237a74e6a Mon Sep 17 00:00:00 2001 From: Wei Wang Date: Wed, 18 Jun 2014 16:28:11 -0700 Subject: [PATCH 088/987] Change the default author in makefile.shade --- makefile.shade | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/makefile.shade b/makefile.shade index 6357ea2841..562494d144 100644 --- a/makefile.shade +++ b/makefile.shade @@ -1,7 +1,7 @@ var VERSION='0.1' var FULL_VERSION='0.1' -var AUTHORS='Microsoft' +var AUTHORS='Microsoft Open Technologies, Inc.' use-standard-lifecycle k-standard-goals From 64850167a118142c83b99c23b7f83641c87c920a Mon Sep 17 00:00:00 2001 From: Brice Lambson Date: Thu, 19 Jun 2014 10:54:07 -0700 Subject: [PATCH 089/987] Bump version to 1.0.0-* --- samples/KWebStartup/project.json | 5 ++--- src/Microsoft.AspNet.Hosting/project.json | 18 +++++++++--------- .../project.json | 8 ++++---- src/Microsoft.AspNet.TestHost/project.json | 2 +- .../project.json | 7 +------ .../project.json | 7 +------ 6 files changed, 18 insertions(+), 29 deletions(-) diff --git a/samples/KWebStartup/project.json b/samples/KWebStartup/project.json index e2d56265b7..37e00580c2 100644 --- a/samples/KWebStartup/project.json +++ b/samples/KWebStartup/project.json @@ -1,9 +1,8 @@ { - "version": "0.1-alpha-*", "dependencies": { "Microsoft.AspNet.Hosting": "", - "Microsoft.AspNet.Http": "0.1-alpha-*", - "Microsoft.AspNet.Server.WebListener": "0.1-alpha-*" + "Microsoft.AspNet.Http": "1.0.0-*", + "Microsoft.AspNet.Server.WebListener": "1.0.0-*" }, "commands": { "web": "Microsoft.AspNet.Hosting server=Microsoft.AspNet.Server.WebListener server.urls=http://localhost:5001" }, "configurations": { diff --git a/src/Microsoft.AspNet.Hosting/project.json b/src/Microsoft.AspNet.Hosting/project.json index db0c026552..333585a93c 100644 --- a/src/Microsoft.AspNet.Hosting/project.json +++ b/src/Microsoft.AspNet.Hosting/project.json @@ -1,14 +1,14 @@ { - "version": "0.1-alpha-*", + "version": "1.0.0-*", "dependencies": { - "Microsoft.AspNet.FeatureModel": "0.1-alpha-*", - "Microsoft.AspNet.Http": "0.1-alpha-*", - "Microsoft.AspNet.PipelineCore": "0.1-alpha-*", - "Microsoft.AspNet.Security.DataProtection": "0.1-alpha-*", - "Microsoft.Framework.ConfigurationModel": "0.1-alpha-*", - "Microsoft.Framework.DependencyInjection": "0.1-alpha-*", - "Microsoft.Framework.Logging": "0.1-alpha-*", - "Microsoft.Framework.Runtime.Interfaces": "0.1-alpha-*" + "Microsoft.AspNet.FeatureModel": "1.0.0-*", + "Microsoft.AspNet.Http": "1.0.0-*", + "Microsoft.AspNet.PipelineCore": "1.0.0-*", + "Microsoft.AspNet.Security.DataProtection": "1.0.0-*", + "Microsoft.Framework.ConfigurationModel": "1.0.0-*", + "Microsoft.Framework.DependencyInjection": "1.0.0-*", + "Microsoft.Framework.Logging": "1.0.0-*", + "Microsoft.Framework.Runtime.Interfaces": "1.0.0-*" }, "configurations": { "net45": {}, diff --git a/src/Microsoft.AspNet.RequestContainer/project.json b/src/Microsoft.AspNet.RequestContainer/project.json index 75819c8802..cb4dec51ef 100644 --- a/src/Microsoft.AspNet.RequestContainer/project.json +++ b/src/Microsoft.AspNet.RequestContainer/project.json @@ -1,9 +1,9 @@ { - "version": "0.1-alpha-*", + "version": "1.0.0-*", "dependencies": { - "Microsoft.AspNet.Http": "0.1-alpha-*", - "Microsoft.Framework.DependencyInjection": "0.1-alpha-*", - "Microsoft.Framework.OptionsModel": "0.1-alpha-*" + "Microsoft.AspNet.Http": "1.0.0-*", + "Microsoft.Framework.DependencyInjection": "1.0.0-*", + "Microsoft.Framework.OptionsModel": "1.0.0-*" }, "configurations": { "net45": {}, diff --git a/src/Microsoft.AspNet.TestHost/project.json b/src/Microsoft.AspNet.TestHost/project.json index 96182c3ed0..8002f95317 100644 --- a/src/Microsoft.AspNet.TestHost/project.json +++ b/src/Microsoft.AspNet.TestHost/project.json @@ -1,5 +1,5 @@ { - "version" : "0.1-alpha-*", + "version" : "1.0.0-*", "dependencies": { "Microsoft.AspNet.Hosting": "" }, diff --git a/test/Microsoft.AspNet.Hosting.Tests/project.json b/test/Microsoft.AspNet.Hosting.Tests/project.json index 7ad9bce822..5218599846 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/project.json +++ b/test/Microsoft.AspNet.Hosting.Tests/project.json @@ -1,13 +1,8 @@ { - "version": "0.1-alpha-*", "dependencies": { "Microsoft.AspNet.Hosting": "", "Microsoft.AspNet.RequestContainer": "", - "xunit.abstractions": "2.0.0-aspnet-*", - "xunit.assert": "2.0.0-aspnet-*", - "xunit.core": "2.0.0-aspnet-*", - "xunit.execution": "2.0.0-aspnet-*", - "Xunit.KRunner": "0.1-alpha-*" + "Xunit.KRunner": "1.0.0-*" }, "configurations": { "net45": { diff --git a/test/Microsoft.AspNet.TestHost.Tests/project.json b/test/Microsoft.AspNet.TestHost.Tests/project.json index 191a4928ef..5f960dc372 100644 --- a/test/Microsoft.AspNet.TestHost.Tests/project.json +++ b/test/Microsoft.AspNet.TestHost.Tests/project.json @@ -1,13 +1,8 @@ { - "version" : "0.1-alpha-*", "dependencies": { "Microsoft.AspNet.Hosting": "", "Microsoft.AspNet.TestHost": "", - "xunit.abstractions": "2.0.0-aspnet-*", - "xunit.assert": "2.0.0-aspnet-*", - "xunit.core": "2.0.0-aspnet-*", - "xunit.execution": "2.0.0-aspnet-*", - "Xunit.KRunner": "0.1-alpha-*" + "Xunit.KRunner": "1.0.0-*" }, "commands": { "test": "Xunit.KRunner" From 3cd3e31644ec25583bbe910048a6ff8cefd262c6 Mon Sep 17 00:00:00 2001 From: Brice Lambson Date: Thu, 19 Jun 2014 17:46:28 -0700 Subject: [PATCH 090/987] Temporarily reference Microsoft.AspNet.Server.WebListener 0.1-* --- samples/KWebStartup/project.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/KWebStartup/project.json b/samples/KWebStartup/project.json index 37e00580c2..c6ae4c11a8 100644 --- a/samples/KWebStartup/project.json +++ b/samples/KWebStartup/project.json @@ -2,7 +2,7 @@ "dependencies": { "Microsoft.AspNet.Hosting": "", "Microsoft.AspNet.Http": "1.0.0-*", - "Microsoft.AspNet.Server.WebListener": "1.0.0-*" + "Microsoft.AspNet.Server.WebListener": "0.1-*" }, "commands": { "web": "Microsoft.AspNet.Hosting server=Microsoft.AspNet.Server.WebListener server.urls=http://localhost:5001" }, "configurations": { From a0e30591f861283d1f58b0aa3a5ebe5e6dad73d0 Mon Sep 17 00:00:00 2001 From: Brice Lambson Date: Thu, 19 Jun 2014 18:35:34 -0700 Subject: [PATCH 091/987] Revert "Temporarily reference Microsoft.AspNet.Server.WebListener 0.1-*" This reverts commit 3cd3e31644ec25583bbe910048a6ff8cefd262c6. --- samples/KWebStartup/project.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/KWebStartup/project.json b/samples/KWebStartup/project.json index c6ae4c11a8..37e00580c2 100644 --- a/samples/KWebStartup/project.json +++ b/samples/KWebStartup/project.json @@ -2,7 +2,7 @@ "dependencies": { "Microsoft.AspNet.Hosting": "", "Microsoft.AspNet.Http": "1.0.0-*", - "Microsoft.AspNet.Server.WebListener": "0.1-*" + "Microsoft.AspNet.Server.WebListener": "1.0.0-*" }, "commands": { "web": "Microsoft.AspNet.Hosting server=Microsoft.AspNet.Server.WebListener server.urls=http://localhost:5001" }, "configurations": { From a9fb12a597c2c26abcac77cc6284be680689730a Mon Sep 17 00:00:00 2001 From: Brice Lambson Date: Fri, 20 Jun 2014 12:06:58 -0700 Subject: [PATCH 092/987] Removing sample --- samples/KWebStartup/KWebStartup.kproj | 26 ------------------- samples/KWebStartup/Startup.cs | 36 --------------------------- samples/KWebStartup/project.json | 30 ---------------------- 3 files changed, 92 deletions(-) delete mode 100644 samples/KWebStartup/KWebStartup.kproj delete mode 100644 samples/KWebStartup/Startup.cs delete mode 100644 samples/KWebStartup/project.json diff --git a/samples/KWebStartup/KWebStartup.kproj b/samples/KWebStartup/KWebStartup.kproj deleted file mode 100644 index b900357cfd..0000000000 --- a/samples/KWebStartup/KWebStartup.kproj +++ /dev/null @@ -1,26 +0,0 @@ - - - - 12.0 - $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) - - - - a2f321a5-3f55-4413-b357-eef85dc0eca6 - Library - - - - - - - 2.0 - - - - - - - - - diff --git a/samples/KWebStartup/Startup.cs b/samples/KWebStartup/Startup.cs deleted file mode 100644 index dbe847a1be..0000000000 --- a/samples/KWebStartup/Startup.cs +++ /dev/null @@ -1,36 +0,0 @@ -// Copyright (c) Microsoft Open Technologies, Inc. -// All Rights Reserved -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR -// CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING -// WITHOUT LIMITATION ANY IMPLIED WARRANTIES OR CONDITIONS OF -// TITLE, FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABLITY OR -// NON-INFRINGEMENT. -// See the Apache 2 License for the specific language governing -// permissions and limitations under the License. - -using Microsoft.AspNet; -using Microsoft.AspNet.Builder; -using Microsoft.AspNet.Http; -using Microsoft.Framework.Runtime; - -namespace KWebStartup -{ - public class Startup - { - public void Configure(IBuilder app, IApplicationEnvironment env) - { - app.Run(async context => - { - context.Response.ContentType = "text/plain"; - await context.Response.WriteAsync("Hello world, from " + env.ApplicationName); - }); - } - } -} diff --git a/samples/KWebStartup/project.json b/samples/KWebStartup/project.json deleted file mode 100644 index 37e00580c2..0000000000 --- a/samples/KWebStartup/project.json +++ /dev/null @@ -1,30 +0,0 @@ -{ - "dependencies": { - "Microsoft.AspNet.Hosting": "", - "Microsoft.AspNet.Http": "1.0.0-*", - "Microsoft.AspNet.Server.WebListener": "1.0.0-*" - }, - "commands": { "web": "Microsoft.AspNet.Hosting server=Microsoft.AspNet.Server.WebListener server.urls=http://localhost:5001" }, - "configurations": { - "net45": { - }, - "k10": { - "dependencies": { - "System.Collections": "4.0.0.0", - "System.Console": "4.0.0.0", - "System.Diagnostics.Debug": "4.0.10.0", - "System.Diagnostics.Tools": "4.0.0.0", - "System.Globalization": "4.0.10.0", - "System.IO": "4.0.0.0", - "System.Linq": "4.0.0.0", - "System.Reflection": "4.0.10.0", - "System.Resources.ResourceManager": "4.0.0.0", - "System.Runtime": "4.0.20.0", - "System.Runtime.Extensions": "4.0.10.0", - "System.Runtime.InteropServices": "4.0.20.0", - "System.Text.Encoding": "4.0.20.0", - "System.Threading.Tasks": "4.0.10.0" - } - } - } -} \ No newline at end of file From 53d1a62eaa4885785a25e6d1aa074a2b7bfb4075 Mon Sep 17 00:00:00 2001 From: Brice Lambson Date: Fri, 20 Jun 2014 14:32:55 -0700 Subject: [PATCH 093/987] Updating release Nuget.config --- NuGet.Config | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/NuGet.Config b/NuGet.Config index a059188b09..1ce6b9e257 100644 --- a/NuGet.Config +++ b/NuGet.Config @@ -1,13 +1,7 @@ - + - + - - - - - - - \ No newline at end of file + From 2e291cf033525e07de5ff00a7196009e8ab7ca57 Mon Sep 17 00:00:00 2001 From: Brice Lambson Date: Fri, 20 Jun 2014 14:32:56 -0700 Subject: [PATCH 094/987] Updating dev Nuget.config --- NuGet.Config | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/NuGet.Config b/NuGet.Config index 1ce6b9e257..f41e9c631d 100644 --- a/NuGet.Config +++ b/NuGet.Config @@ -1,7 +1,7 @@ - + - + From 8f316654788bd5fab8ccd944e417c5d71dead5aa Mon Sep 17 00:00:00 2001 From: Chris Ross Date: Fri, 20 Jun 2014 14:14:52 -0700 Subject: [PATCH 095/987] Make IServerFactory AssemblyNeutral. --- src/Microsoft.AspNet.Hosting/Server/IServerFactory.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Microsoft.AspNet.Hosting/Server/IServerFactory.cs b/src/Microsoft.AspNet.Hosting/Server/IServerFactory.cs index 21d3f06fbe..0b75dbe5e9 100644 --- a/src/Microsoft.AspNet.Hosting/Server/IServerFactory.cs +++ b/src/Microsoft.AspNet.Hosting/Server/IServerFactory.cs @@ -18,12 +18,12 @@ using System; using System.Threading.Tasks; using Microsoft.AspNet.Builder; -using Microsoft.AspNet.Http; using Microsoft.Framework.ConfigurationModel; +using Microsoft.Framework.Runtime; namespace Microsoft.AspNet.Hosting.Server { - // TODO: [AssemblyNeutral] + [AssemblyNeutral] public interface IServerFactory { IServerInformation Initialize(IConfiguration configuration); From 8eb8cc1154d770dad42174b338f5257a634eb91d Mon Sep 17 00:00:00 2001 From: Chris Ross Date: Fri, 20 Jun 2014 14:18:49 -0700 Subject: [PATCH 096/987] Remove deleted sample from sln. --- Hosting.sln | 17 +---------------- 1 file changed, 1 insertion(+), 16 deletions(-) diff --git a/Hosting.sln b/Hosting.sln index 66ecdc97c7..a1be8041c3 100644 --- a/Hosting.sln +++ b/Hosting.sln @@ -1,14 +1,12 @@  Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 14 -VisualStudioVersion = 14.0.21723.0 +VisualStudioVersion = 14.0.21730.1 MinimumVisualStudioVersion = 10.0.40219.1 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{E0497F39-AFFB-4819-A116-E39E361915AB}" EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{FEB39027-9158-4DE2-997F-7ADAEF8188D0}" EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "samples", "samples", "{C30C98CD-3D69-4AE9-B680-0E0E6D8834C6}" -EndProject Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNet.TestHost.Tests", "test\Microsoft.AspNet.TestHost.Tests\Microsoft.AspNet.TestHost.Tests.kproj", "{0ACB2719-9484-49B5-B8E3-117091192511}" EndProject Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNet.TestHost", "src\Microsoft.AspNet.TestHost\Microsoft.AspNet.TestHost.kproj", "{1A415A3F-1081-45DB-809B-EE19CEA02DC0}" @@ -19,8 +17,6 @@ Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNet.Hosting.Te EndProject Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNet.RequestContainer", "src\Microsoft.AspNet.RequestContainer\Microsoft.AspNet.RequestContainer.kproj", "{374A5B0C-3E93-4A23-A4A0-EE2AB6DF7814}" EndProject -Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "KWebStartup", "samples\KWebStartup\KWebStartup.kproj", "{A2F321A5-3F55-4413-B357-EEF85DC0ECA6}" -EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -81,16 +77,6 @@ Global {374A5B0C-3E93-4A23-A4A0-EE2AB6DF7814}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU {374A5B0C-3E93-4A23-A4A0-EE2AB6DF7814}.Release|Mixed Platforms.Build.0 = Release|Any CPU {374A5B0C-3E93-4A23-A4A0-EE2AB6DF7814}.Release|x86.ActiveCfg = Release|Any CPU - {A2F321A5-3F55-4413-B357-EEF85DC0ECA6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {A2F321A5-3F55-4413-B357-EEF85DC0ECA6}.Debug|Any CPU.Build.0 = Debug|Any CPU - {A2F321A5-3F55-4413-B357-EEF85DC0ECA6}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU - {A2F321A5-3F55-4413-B357-EEF85DC0ECA6}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU - {A2F321A5-3F55-4413-B357-EEF85DC0ECA6}.Debug|x86.ActiveCfg = Debug|Any CPU - {A2F321A5-3F55-4413-B357-EEF85DC0ECA6}.Release|Any CPU.ActiveCfg = Release|Any CPU - {A2F321A5-3F55-4413-B357-EEF85DC0ECA6}.Release|Any CPU.Build.0 = Release|Any CPU - {A2F321A5-3F55-4413-B357-EEF85DC0ECA6}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU - {A2F321A5-3F55-4413-B357-EEF85DC0ECA6}.Release|Mixed Platforms.Build.0 = Release|Any CPU - {A2F321A5-3F55-4413-B357-EEF85DC0ECA6}.Release|x86.ActiveCfg = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -101,6 +87,5 @@ Global {3944F036-7E75-47E8-AA52-C4B89A64EC3A} = {E0497F39-AFFB-4819-A116-E39E361915AB} {D4F18D58-52B1-435D-A012-10F2CDF158C4} = {FEB39027-9158-4DE2-997F-7ADAEF8188D0} {374A5B0C-3E93-4A23-A4A0-EE2AB6DF7814} = {E0497F39-AFFB-4819-A116-E39E361915AB} - {A2F321A5-3F55-4413-B357-EEF85DC0ECA6} = {C30C98CD-3D69-4AE9-B680-0E0E6D8834C6} EndGlobalSection EndGlobal From 0f9e23275934467aa1f49a497bc10761a3639707 Mon Sep 17 00:00:00 2001 From: Ben Brown Date: Thu, 3 Jul 2014 20:06:11 -0700 Subject: [PATCH 097/987] Updating ILogger descendants for interface change. --- src/Microsoft.AspNet.Hosting/HostingServices.cs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/Microsoft.AspNet.Hosting/HostingServices.cs b/src/Microsoft.AspNet.Hosting/HostingServices.cs index e0995468d9..0a0950d559 100644 --- a/src/Microsoft.AspNet.Hosting/HostingServices.cs +++ b/src/Microsoft.AspNet.Hosting/HostingServices.cs @@ -93,6 +93,21 @@ namespace Microsoft.AspNet.Hosting { return false; } + + public IDisposable BeginScope(object state) + { + return NullScope.Instance; + } + } + + private class NullScope : IDisposable + { + public static NullScope Instance = new NullScope(); + + public void Dispose() + { + // intentionally does nothing + } } } } \ No newline at end of file From 6afcadd66a68d9812bbd8f99ee81c726497598de Mon Sep 17 00:00:00 2001 From: Chris Ross Date: Tue, 8 Jul 2014 09:59:13 -0700 Subject: [PATCH 098/987] Add using statement for extension methods. --- test/Microsoft.AspNet.TestHost.Tests/TestClientTests.cs | 1 + test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs | 1 + 2 files changed, 2 insertions(+) diff --git a/test/Microsoft.AspNet.TestHost.Tests/TestClientTests.cs b/test/Microsoft.AspNet.TestHost.Tests/TestClientTests.cs index 91730ee12c..48d416b266 100644 --- a/test/Microsoft.AspNet.TestHost.Tests/TestClientTests.cs +++ b/test/Microsoft.AspNet.TestHost.Tests/TestClientTests.cs @@ -20,6 +20,7 @@ using System.Collections.Generic; using System.IO; using System.Threading.Tasks; using Microsoft.AspNet.Builder; +using Microsoft.AspNet.Http; using Microsoft.Framework.DependencyInjection; using Microsoft.Framework.DependencyInjection.Fallback; using Microsoft.Framework.Runtime; diff --git a/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs b/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs index b486dd3ffb..13793b8cea 100644 --- a/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs +++ b/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs @@ -19,6 +19,7 @@ using System; using System.IO; using System.Threading.Tasks; using Microsoft.AspNet.Builder; +using Microsoft.AspNet.Http; using Microsoft.Framework.DependencyInjection; using Microsoft.Framework.DependencyInjection.Fallback; using Microsoft.Framework.Runtime; From fbd2c4a08ea86ab1374e2668c1a881f7d9d577f4 Mon Sep 17 00:00:00 2001 From: David Fowler Date: Thu, 10 Jul 2014 10:00:14 -0700 Subject: [PATCH 099/987] Added Configuration to TestApplicationEnvironment --- .../TestApplicationEnvironment.cs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/test/Microsoft.AspNet.TestHost.Tests/TestApplicationEnvironment.cs b/test/Microsoft.AspNet.TestHost.Tests/TestApplicationEnvironment.cs index 14495b9fdb..800570f20a 100644 --- a/test/Microsoft.AspNet.TestHost.Tests/TestApplicationEnvironment.cs +++ b/test/Microsoft.AspNet.TestHost.Tests/TestApplicationEnvironment.cs @@ -38,6 +38,14 @@ namespace Microsoft.AspNet.TestHost.Tests get { return Environment.CurrentDirectory; } } + public string Configuration + { + get + { + return "debug"; + } + } + public FrameworkName TargetFramework { get { return new FrameworkName(".NETFramework", new Version(4, 5)); } From 5208421ad59c64997e0c7f1f4102ae9d36058106 Mon Sep 17 00:00:00 2001 From: David Fowler Date: Thu, 10 Jul 2014 10:16:24 -0700 Subject: [PATCH 100/987] Fixed dependencies to get the right version of IApplicationEnvironment --- test/Microsoft.AspNet.TestHost.Tests/project.json | 1 + 1 file changed, 1 insertion(+) diff --git a/test/Microsoft.AspNet.TestHost.Tests/project.json b/test/Microsoft.AspNet.TestHost.Tests/project.json index 5f960dc372..3f762eda5f 100644 --- a/test/Microsoft.AspNet.TestHost.Tests/project.json +++ b/test/Microsoft.AspNet.TestHost.Tests/project.json @@ -2,6 +2,7 @@ "dependencies": { "Microsoft.AspNet.Hosting": "", "Microsoft.AspNet.TestHost": "", + "Microsoft.Framework.Runtime.Interfaces":"1.0.0-*", "Xunit.KRunner": "1.0.0-*" }, "commands": { From b6243326c3d43844ef22c17d19542789091876c4 Mon Sep 17 00:00:00 2001 From: David Fowler Date: Sun, 13 Jul 2014 21:50:14 -0700 Subject: [PATCH 101/987] Renamed configurations to frameworks in project.json --- src/Microsoft.AspNet.Hosting/project.json | 6 +++--- src/Microsoft.AspNet.RequestContainer/project.json | 6 +++--- src/Microsoft.AspNet.TestHost/project.json | 6 +++--- test/Microsoft.AspNet.Hosting.Tests/project.json | 6 +++--- test/Microsoft.AspNet.TestHost.Tests/project.json | 6 +++--- 5 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/Microsoft.AspNet.Hosting/project.json b/src/Microsoft.AspNet.Hosting/project.json index 333585a93c..6ae4213509 100644 --- a/src/Microsoft.AspNet.Hosting/project.json +++ b/src/Microsoft.AspNet.Hosting/project.json @@ -1,4 +1,4 @@ -{ +{ "version": "1.0.0-*", "dependencies": { "Microsoft.AspNet.FeatureModel": "1.0.0-*", @@ -10,7 +10,7 @@ "Microsoft.Framework.Logging": "1.0.0-*", "Microsoft.Framework.Runtime.Interfaces": "1.0.0-*" }, - "configurations": { + "frameworks": { "net45": {}, "k10": { "dependencies": { @@ -28,4 +28,4 @@ } } } -} \ No newline at end of file +} diff --git a/src/Microsoft.AspNet.RequestContainer/project.json b/src/Microsoft.AspNet.RequestContainer/project.json index cb4dec51ef..eb0b844d0f 100644 --- a/src/Microsoft.AspNet.RequestContainer/project.json +++ b/src/Microsoft.AspNet.RequestContainer/project.json @@ -1,11 +1,11 @@ -{ +{ "version": "1.0.0-*", "dependencies": { "Microsoft.AspNet.Http": "1.0.0-*", "Microsoft.Framework.DependencyInjection": "1.0.0-*", "Microsoft.Framework.OptionsModel": "1.0.0-*" }, - "configurations": { + "frameworks": { "net45": {}, "k10": { "dependencies": { @@ -23,4 +23,4 @@ } } } -} \ No newline at end of file +} diff --git a/src/Microsoft.AspNet.TestHost/project.json b/src/Microsoft.AspNet.TestHost/project.json index 8002f95317..9d38c71bfe 100644 --- a/src/Microsoft.AspNet.TestHost/project.json +++ b/src/Microsoft.AspNet.TestHost/project.json @@ -1,9 +1,9 @@ -{ +{ "version" : "1.0.0-*", "dependencies": { "Microsoft.AspNet.Hosting": "" }, - "configurations": { + "frameworks": { "net45": { }, "k10" : { "dependencies": { @@ -21,4 +21,4 @@ } } } -} \ No newline at end of file +} diff --git a/test/Microsoft.AspNet.Hosting.Tests/project.json b/test/Microsoft.AspNet.Hosting.Tests/project.json index 5218599846..f106512168 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/project.json +++ b/test/Microsoft.AspNet.Hosting.Tests/project.json @@ -1,10 +1,10 @@ -{ +{ "dependencies": { "Microsoft.AspNet.Hosting": "", "Microsoft.AspNet.RequestContainer": "", "Xunit.KRunner": "1.0.0-*" }, - "configurations": { + "frameworks": { "net45": { "dependencies": { "System.Runtime" : "" @@ -14,4 +14,4 @@ "commands": { "test": "Xunit.KRunner" } -} \ No newline at end of file +} diff --git a/test/Microsoft.AspNet.TestHost.Tests/project.json b/test/Microsoft.AspNet.TestHost.Tests/project.json index 3f762eda5f..e4f8d10796 100644 --- a/test/Microsoft.AspNet.TestHost.Tests/project.json +++ b/test/Microsoft.AspNet.TestHost.Tests/project.json @@ -1,4 +1,4 @@ -{ +{ "dependencies": { "Microsoft.AspNet.Hosting": "", "Microsoft.AspNet.TestHost": "", @@ -8,11 +8,11 @@ "commands": { "test": "Xunit.KRunner" }, - "configurations": { + "frameworks": { "net45": { "dependencies": { "System.Runtime": "" } } } -} \ No newline at end of file +} From 0385438ed0a3808fbef282cda560b2b6d6f61e29 Mon Sep 17 00:00:00 2001 From: Pranav K Date: Mon, 14 Jul 2014 16:51:46 -0700 Subject: [PATCH 102/987] Reacting to System.Collections versioning change --- src/Microsoft.AspNet.Hosting/project.json | 4 ++-- src/Microsoft.AspNet.RequestContainer/project.json | 4 ++-- src/Microsoft.AspNet.TestHost/project.json | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Microsoft.AspNet.Hosting/project.json b/src/Microsoft.AspNet.Hosting/project.json index 6ae4213509..d77f6393d3 100644 --- a/src/Microsoft.AspNet.Hosting/project.json +++ b/src/Microsoft.AspNet.Hosting/project.json @@ -1,4 +1,4 @@ -{ +{ "version": "1.0.0-*", "dependencies": { "Microsoft.AspNet.FeatureModel": "1.0.0-*", @@ -14,7 +14,7 @@ "net45": {}, "k10": { "dependencies": { - "System.Collections": "4.0.0.0", + "System.Collections": "4.0.10.0", "System.ComponentModel": "4.0.0.0", "System.Console": "4.0.0.0", "System.Diagnostics.Debug": "4.0.10.0", diff --git a/src/Microsoft.AspNet.RequestContainer/project.json b/src/Microsoft.AspNet.RequestContainer/project.json index eb0b844d0f..7c3a92c05e 100644 --- a/src/Microsoft.AspNet.RequestContainer/project.json +++ b/src/Microsoft.AspNet.RequestContainer/project.json @@ -1,4 +1,4 @@ -{ +{ "version": "1.0.0-*", "dependencies": { "Microsoft.AspNet.Http": "1.0.0-*", @@ -9,7 +9,7 @@ "net45": {}, "k10": { "dependencies": { - "System.Collections": "4.0.0.0", + "System.Collections": "4.0.10.0", "System.ComponentModel": "4.0.0.0", "System.Diagnostics.Debug": "4.0.10.0", "System.Linq": "4.0.0.0", diff --git a/src/Microsoft.AspNet.TestHost/project.json b/src/Microsoft.AspNet.TestHost/project.json index 9d38c71bfe..1592b1a2c3 100644 --- a/src/Microsoft.AspNet.TestHost/project.json +++ b/src/Microsoft.AspNet.TestHost/project.json @@ -1,4 +1,4 @@ -{ +{ "version" : "1.0.0-*", "dependencies": { "Microsoft.AspNet.Hosting": "" @@ -7,7 +7,7 @@ "net45": { }, "k10" : { "dependencies": { - "System.Collections": "4.0.0.0", + "System.Collections": "4.0.10.0", "System.ComponentModel": "4.0.0.0", "System.Globalization": "4.0.10.0", "System.Linq": "4.0.0.0", From ed38d28db44460d172376f003797eccd7df14f72 Mon Sep 17 00:00:00 2001 From: Chris Ross Date: Thu, 31 Jul 2014 11:37:27 -0700 Subject: [PATCH 103/987] #65 - Port more TestHost funcationality. --- Hosting.sln | 7 +- .../ClientHandler.cs | 207 ++++++++++ .../Microsoft.AspNet.TestHost.kproj | 9 +- .../RequestBuilder.cs | 111 +++++ .../RequestFeature.cs | 41 ++ .../RequestInformation.cs | 51 --- .../ResponseFeature.cs | 48 +++ .../ResponseInformation.cs | 50 --- .../ResponseStream.cs | 380 ++++++++++++++++++ src/Microsoft.AspNet.TestHost/TestClient.cs | 22 +- src/Microsoft.AspNet.TestHost/TestServer.cs | 89 ++-- src/Microsoft.AspNet.TestHost/project.json | 3 +- .../ClientHandlerTests.cs | 231 +++++++++++ .../Microsoft.AspNet.TestHost.Tests.kproj | 6 +- .../RequestBuilderTests.cs | 35 ++ .../ResponseFeatureTests.cs | 20 + .../ResponseInformationTests.cs | 34 -- .../TestApplicationEnvironment.cs | 20 +- .../TestClientTests.cs | 20 +- .../TestServerTests.cs | 107 +++-- 20 files changed, 1223 insertions(+), 268 deletions(-) create mode 100644 src/Microsoft.AspNet.TestHost/ClientHandler.cs create mode 100644 src/Microsoft.AspNet.TestHost/RequestBuilder.cs create mode 100644 src/Microsoft.AspNet.TestHost/RequestFeature.cs delete mode 100644 src/Microsoft.AspNet.TestHost/RequestInformation.cs create mode 100644 src/Microsoft.AspNet.TestHost/ResponseFeature.cs delete mode 100644 src/Microsoft.AspNet.TestHost/ResponseInformation.cs create mode 100644 src/Microsoft.AspNet.TestHost/ResponseStream.cs create mode 100644 test/Microsoft.AspNet.TestHost.Tests/ClientHandlerTests.cs create mode 100644 test/Microsoft.AspNet.TestHost.Tests/RequestBuilderTests.cs create mode 100644 test/Microsoft.AspNet.TestHost.Tests/ResponseFeatureTests.cs delete mode 100644 test/Microsoft.AspNet.TestHost.Tests/ResponseInformationTests.cs diff --git a/Hosting.sln b/Hosting.sln index a1be8041c3..52888aa65a 100644 --- a/Hosting.sln +++ b/Hosting.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 14 -VisualStudioVersion = 14.0.21730.1 +VisualStudioVersion = 14.0.21916.0 MinimumVisualStudioVersion = 10.0.40219.1 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{E0497F39-AFFB-4819-A116-E39E361915AB}" EndProject @@ -17,6 +17,11 @@ Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNet.Hosting.Te EndProject Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNet.RequestContainer", "src\Microsoft.AspNet.RequestContainer\Microsoft.AspNet.RequestContainer.kproj", "{374A5B0C-3E93-4A23-A4A0-EE2AB6DF7814}" EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{A66E3673-3976-4152-B902-2D0EC1428EA2}" + ProjectSection(SolutionItems) = preProject + global.json = global.json + EndProjectSection +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU diff --git a/src/Microsoft.AspNet.TestHost/ClientHandler.cs b/src/Microsoft.AspNet.TestHost/ClientHandler.cs new file mode 100644 index 0000000000..d92eaffdda --- /dev/null +++ b/src/Microsoft.AspNet.TestHost/ClientHandler.cs @@ -0,0 +1,207 @@ +// 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 System; +using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; +using System.Diagnostics.Contracts; +using System.IO; +using System.Linq; +using System.Net; +using System.Net.Http; +using System.Threading; +using System.Threading.Tasks; +using Microsoft.AspNet.FeatureModel; +using Microsoft.AspNet.Http; +using Microsoft.AspNet.HttpFeature; +using Microsoft.AspNet.PipelineCore; + +namespace Microsoft.AspNet.TestHost +{ + /// + /// This adapts HttpRequestMessages to ASP.NET requests, dispatches them through the pipeline, and returns the + /// associated HttpResponseMessage. + /// + public class ClientHandler : HttpMessageHandler + { + private readonly Func _next; + + /// + /// Create a new handler. + /// + /// The pipeline entry point. + public ClientHandler(Func next) + { + if (next == null) + { + throw new ArgumentNullException("next"); + } + + _next = next; + } + + /// + /// This adapts HttpRequestMessages to ASP.NET requests, dispatches them through the pipeline, and returns the + /// associated HttpResponseMessage. + /// + /// + /// + /// + protected override async Task SendAsync( + HttpRequestMessage request, + CancellationToken cancellationToken) + { + if (request == null) + { + throw new ArgumentNullException("request"); + } + + var state = new RequestState(request, cancellationToken); + HttpContent requestContent = request.Content ?? new StreamContent(Stream.Null); + Stream body = await requestContent.ReadAsStreamAsync(); + if (body.CanSeek) + { + // This body may have been consumed before, rewind it. + body.Seek(0, SeekOrigin.Begin); + } + state.HttpContext.Request.Body = body; + CancellationTokenRegistration registration = cancellationToken.Register(state.Abort); + + // Async offload, don't let the test code block the caller. + Task offload = Task.Factory.StartNew(async () => + { + try + { + await _next(state.FeatureCollection); + state.CompleteResponse(); + } + catch (Exception ex) + { + state.Abort(ex); + } + finally + { + registration.Dispose(); + state.Dispose(); + } + }); + + return await state.ResponseTask; + } + + private class RequestState : IDisposable + { + private readonly HttpRequestMessage _request; + private TaskCompletionSource _responseTcs; + private ResponseStream _responseStream; + private ResponseFeature _responseFeature; + + internal RequestState(HttpRequestMessage request, CancellationToken cancellationToken) + { + _request = request; + _responseTcs = new TaskCompletionSource(); + + if (request.RequestUri.IsDefaultPort) + { + request.Headers.Host = request.RequestUri.Host; + } + else + { + request.Headers.Host = request.RequestUri.GetComponents(UriComponents.HostAndPort, UriFormat.UriEscaped); + } + + FeatureCollection = new FeatureCollection(); + HttpContext = new DefaultHttpContext(FeatureCollection); + HttpContext.SetFeature(new RequestFeature()); + _responseFeature = new ResponseFeature(); + HttpContext.SetFeature(_responseFeature); + var serverRequest = HttpContext.Request; + serverRequest.Protocol = "HTTP/" + request.Version.ToString(2); + serverRequest.Scheme = request.RequestUri.Scheme; + serverRequest.Method = request.Method.ToString(); + serverRequest.Path = PathString.FromUriComponent(request.RequestUri); + serverRequest.PathBase = PathString.Empty; + serverRequest.QueryString = QueryString.FromUriComponent(request.RequestUri); + // TODO: serverRequest.CallCancelled = cancellationToken; + + foreach (var header in request.Headers) + { + serverRequest.Headers.AppendValues(header.Key, header.Value.ToArray()); + } + HttpContent requestContent = request.Content; + if (requestContent != null) + { + foreach (var header in request.Content.Headers) + { + serverRequest.Headers.AppendValues(header.Key, header.Value.ToArray()); + } + } + + _responseStream = new ResponseStream(CompleteResponse); + HttpContext.Response.Body = _responseStream; + HttpContext.Response.StatusCode = 200; + } + + public HttpContext HttpContext { get; private set; } + + public IFeatureCollection FeatureCollection { get; private set; } + + public Task ResponseTask + { + get { return _responseTcs.Task; } + } + + internal void CompleteResponse() + { + if (!_responseTcs.Task.IsCompleted) + { + HttpResponseMessage response = GenerateResponse(); + // Dispatch, as TrySetResult will synchronously execute the waiters callback and block our Write. + Task.Factory.StartNew(() => _responseTcs.TrySetResult(response)); + } + } + + [SuppressMessage("Microsoft.Reliability", "CA2000:DisposeObjectsBeforeLosingScope", + Justification = "HttpResposneMessage must be returned to the caller.")] + internal HttpResponseMessage GenerateResponse() + { + _responseFeature.FireOnSendingHeaders(); + + var response = new HttpResponseMessage(); + response.StatusCode = (HttpStatusCode)HttpContext.Response.StatusCode; + response.ReasonPhrase = HttpContext.GetFeature().ReasonPhrase; + response.RequestMessage = _request; + // response.Version = owinResponse.Protocol; + + response.Content = new StreamContent(_responseStream); + + foreach (var header in HttpContext.Response.Headers) + { + if (!response.Headers.TryAddWithoutValidation(header.Key, header.Value)) + { + bool success = response.Content.Headers.TryAddWithoutValidation(header.Key, header.Value); + Contract.Assert(success, "Bad header"); + } + } + return response; + } + + internal void Abort() + { + Abort(new OperationCanceledException()); + } + + internal void Abort(Exception exception) + { + _responseStream.Abort(exception); + _responseTcs.TrySetException(exception); + } + + public void Dispose() + { + _responseStream.Dispose(); + // Do not dispose the request, that will be disposed by the caller. + } + } + } +} diff --git a/src/Microsoft.AspNet.TestHost/Microsoft.AspNet.TestHost.kproj b/src/Microsoft.AspNet.TestHost/Microsoft.AspNet.TestHost.kproj index 882610a036..4bba9328cc 100644 --- a/src/Microsoft.AspNet.TestHost/Microsoft.AspNet.TestHost.kproj +++ b/src/Microsoft.AspNet.TestHost/Microsoft.AspNet.TestHost.kproj @@ -20,11 +20,14 @@ + - - + + + + - + \ No newline at end of file diff --git a/src/Microsoft.AspNet.TestHost/RequestBuilder.cs b/src/Microsoft.AspNet.TestHost/RequestBuilder.cs new file mode 100644 index 0000000000..57422b4b33 --- /dev/null +++ b/src/Microsoft.AspNet.TestHost/RequestBuilder.cs @@ -0,0 +1,111 @@ +// 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 System; +using System.Diagnostics.CodeAnalysis; +using System.Globalization; +using System.IO; +using System.Net.Http; +using System.Threading.Tasks; + +namespace Microsoft.AspNet.TestHost +{ + /// + /// Used to construct a HttpRequestMessage object. + /// + [SuppressMessage("Microsoft.Design", "CA1001:TypesThatOwnDisposableFieldsShouldBeDisposable", + Justification = "HttpRequestMessage is disposed by HttpClient in SendAsync")] + public class RequestBuilder + { + private readonly TestServer _server; + private readonly HttpRequestMessage _req; + + /// + /// Construct a new HttpRequestMessage with the given path. + /// + /// + /// + [SuppressMessage("Microsoft.Usage", "CA2234:PassSystemUriObjectsInsteadOfStrings", Justification = "Not a full URI")] + public RequestBuilder(TestServer server, string path) + { + if (server == null) + { + throw new ArgumentNullException("server"); + } + + _server = server; + _req = new HttpRequestMessage(HttpMethod.Get, path); + } + + /// + /// Configure any HttpRequestMessage properties. + /// + /// + /// + public RequestBuilder And(Action configure) + { + if (configure == null) + { + throw new ArgumentNullException("configure"); + } + + configure(_req); + return this; + } + + /// + /// Add the given header and value to the request or request content. + /// + /// + /// + /// + public RequestBuilder AddHeader(string name, string value) + { + if (!_req.Headers.TryAddWithoutValidation(name, value)) + { + if (_req.Content == null) + { + _req.Content = new StreamContent(Stream.Null); + } + if (!_req.Content.Headers.TryAddWithoutValidation(name, value)) + { + // TODO: throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Resources.InvalidHeaderName, name), "name"); + throw new ArgumentException("Invalid header name: " + name, "name"); + } + } + return this; + } + + /// + /// Set the request method and start processing the request. + /// + /// + /// + public Task SendAsync(string method) + { + _req.Method = new HttpMethod(method); + return _server.CreateClient().SendAsync(_req); + } + + /// + /// Set the request method to GET and start processing the request. + /// + /// + [SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate", Justification = "GET is an HTTP verb.")] + public Task GetAsync() + { + _req.Method = HttpMethod.Get; + return _server.CreateClient().SendAsync(_req); + } + + /// + /// Set the request method to POST and start processing the request. + /// + /// + public Task PostAsync() + { + _req.Method = HttpMethod.Post; + return _server.CreateClient().SendAsync(_req); + } + } +} diff --git a/src/Microsoft.AspNet.TestHost/RequestFeature.cs b/src/Microsoft.AspNet.TestHost/RequestFeature.cs new file mode 100644 index 0000000000..2ea5ae5127 --- /dev/null +++ b/src/Microsoft.AspNet.TestHost/RequestFeature.cs @@ -0,0 +1,41 @@ +// 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 System; +using System.Collections.Generic; +using System.IO; +using Microsoft.AspNet.HttpFeature; + +namespace Microsoft.AspNet.TestHost +{ + internal class RequestFeature : IHttpRequestFeature + { + public RequestFeature() + { + Body = Stream.Null; + Headers = new Dictionary(StringComparer.OrdinalIgnoreCase); + Method = "GET"; + Path = ""; + PathBase = ""; + Protocol = "HTTP/1.1"; + QueryString = ""; + Scheme = "http"; + } + + public Stream Body { get; set; } + + public IDictionary Headers { get; set; } + + public string Method { get; set; } + + public string Path { get; set; } + + public string PathBase { get; set; } + + public string Protocol { get; set; } + + public string QueryString { get; set; } + + public string Scheme { get; set; } + } +} diff --git a/src/Microsoft.AspNet.TestHost/RequestInformation.cs b/src/Microsoft.AspNet.TestHost/RequestInformation.cs deleted file mode 100644 index d5815ee993..0000000000 --- a/src/Microsoft.AspNet.TestHost/RequestInformation.cs +++ /dev/null @@ -1,51 +0,0 @@ -// Copyright (c) Microsoft Open Technologies, Inc. -// All Rights Reserved -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR -// CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING -// WITHOUT LIMITATION ANY IMPLIED WARRANTIES OR CONDITIONS OF -// TITLE, FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABLITY OR -// NON-INFRINGEMENT. -// See the Apache 2 License for the specific language governing -// permissions and limitations under the License. - -using System; -using System.Collections.Generic; -using System.IO; -using Microsoft.AspNet.HttpFeature; - -namespace Microsoft.AspNet.TestHost -{ - internal class RequestInformation : IHttpRequestFeature - { - public RequestInformation() - { - Headers = new Dictionary(StringComparer.OrdinalIgnoreCase); - PathBase = ""; - Body = Stream.Null; - Protocol = "HTTP/1.1"; - } - - public Stream Body { get; set; } - - public IDictionary Headers { get; set; } - - public string Method { get; set; } - - public string Path { get; set; } - - public string PathBase { get; set; } - - public string Protocol { get; set; } - - public string QueryString { get; set; } - - public string Scheme { get; set; } - } -} diff --git a/src/Microsoft.AspNet.TestHost/ResponseFeature.cs b/src/Microsoft.AspNet.TestHost/ResponseFeature.cs new file mode 100644 index 0000000000..5b7d230a13 --- /dev/null +++ b/src/Microsoft.AspNet.TestHost/ResponseFeature.cs @@ -0,0 +1,48 @@ +// 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 System; +using System.Collections.Generic; +using System.IO; +using Microsoft.AspNet.HttpFeature; + +namespace Microsoft.AspNet.TestHost +{ + internal class ResponseFeature : IHttpResponseFeature + { + private Action _sendingHeaders = () => { }; + + public ResponseFeature() + { + Headers = new Dictionary(StringComparer.OrdinalIgnoreCase); + Body = new MemoryStream(); + + // 200 is the default status code all the way down to the host, so we set it + // here to be consistent with the rest of the hosts when writing tests. + StatusCode = 200; + } + + public int StatusCode { get; set; } + + public string ReasonPhrase { get; set; } + + public IDictionary Headers { get; set; } + + public Stream Body { get; set; } + + public void OnSendingHeaders(Action callback, object state) + { + var prior = _sendingHeaders; + _sendingHeaders = () => + { + callback(state); + prior(); + }; + } + + public void FireOnSendingHeaders() + { + _sendingHeaders(); + } + } +} diff --git a/src/Microsoft.AspNet.TestHost/ResponseInformation.cs b/src/Microsoft.AspNet.TestHost/ResponseInformation.cs deleted file mode 100644 index 7cccbafc53..0000000000 --- a/src/Microsoft.AspNet.TestHost/ResponseInformation.cs +++ /dev/null @@ -1,50 +0,0 @@ -// Copyright (c) Microsoft Open Technologies, Inc. -// All Rights Reserved -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR -// CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING -// WITHOUT LIMITATION ANY IMPLIED WARRANTIES OR CONDITIONS OF -// TITLE, FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABLITY OR -// NON-INFRINGEMENT. -// See the Apache 2 License for the specific language governing -// permissions and limitations under the License. - -using System; -using System.Collections.Generic; -using System.IO; -using Microsoft.AspNet.HttpFeature; - -namespace Microsoft.AspNet.TestHost -{ - internal class ResponseInformation : IHttpResponseFeature - { - public ResponseInformation() - { - Headers = new Dictionary(StringComparer.OrdinalIgnoreCase); - Body = new MemoryStream(); - - // 200 is the default status code all the way down to the host, so we set it - // here to be consistent with the rest of the hosts when writing tests. - StatusCode = 200; - } - - public int StatusCode { get; set; } - - public string ReasonPhrase { get; set; } - - public IDictionary Headers { get; set; } - - public Stream Body { get; set; } - - public void OnSendingHeaders(Action callback, object state) - { - // TODO: Figure out how to implement this thing. - } - } -} diff --git a/src/Microsoft.AspNet.TestHost/ResponseStream.cs b/src/Microsoft.AspNet.TestHost/ResponseStream.cs new file mode 100644 index 0000000000..cae4eba46f --- /dev/null +++ b/src/Microsoft.AspNet.TestHost/ResponseStream.cs @@ -0,0 +1,380 @@ +// 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 System; +using System.Collections.Concurrent; +using System.Diagnostics.CodeAnalysis; +using System.Diagnostics.Contracts; +using System.IO; +using System.Threading; +using System.Threading.Tasks; + +namespace Microsoft.AspNet.TestHost +{ + // This steam accepts writes from the server/app, buffers them internally, and returns the data via Reads + // when requested by the client. + internal class ResponseStream : Stream + { + private bool _disposed; + private bool _aborted; + private Exception _abortException; + private ConcurrentQueue _bufferedData; + private ArraySegment _topBuffer; + private SemaphoreSlim _readLock; + private SemaphoreSlim _writeLock; + private TaskCompletionSource _readWaitingForData; + private object _signalReadLock; + + private Action _onFirstWrite; + private bool _firstWrite; + + internal ResponseStream(Action onFirstWrite) + { + if (onFirstWrite == null) + { + throw new ArgumentNullException("onFirstWrite"); + } + _onFirstWrite = onFirstWrite; + _firstWrite = true; + + _readLock = new SemaphoreSlim(1, 1); + _writeLock = new SemaphoreSlim(1, 1); + _bufferedData = new ConcurrentQueue(); + _readWaitingForData = new TaskCompletionSource(); + _signalReadLock = new object(); + } + + public override bool CanRead + { + get { return true; } + } + + public override bool CanSeek + { + get { return false; } + } + + public override bool CanWrite + { + get { return true; } + } + + #region NotSupported + + public override long Length + { + get { throw new NotSupportedException(); } + } + + public override long Position + { + get { throw new NotSupportedException(); } + set { throw new NotSupportedException(); } + } + + public override long Seek(long offset, SeekOrigin origin) + { + throw new NotSupportedException(); + } + + public override void SetLength(long value) + { + throw new NotSupportedException(); + } + + #endregion NotSupported + + public override void Flush() + { + CheckDisposed(); + + _writeLock.Wait(); + try + { + FirstWrite(); + } + finally + { + _writeLock.Release(); + } + + // TODO: Wait for data to drain? + } + + public override Task FlushAsync(CancellationToken cancellationToken) + { + if (cancellationToken.IsCancellationRequested) + { + TaskCompletionSource tcs = new TaskCompletionSource(); + tcs.TrySetCanceled(); + return tcs.Task; + } + + Flush(); + + // TODO: Wait for data to drain? + + return Task.FromResult(null); + } + + public override int Read(byte[] buffer, int offset, int count) + { + VerifyBuffer(buffer, offset, count, allowEmpty: false); + _readLock.Wait(); + try + { + int totalRead = 0; + do + { + // Don't drain buffered data when signaling an abort. + CheckAborted(); + if (_topBuffer.Count <= 0) + { + byte[] topBuffer = null; + while (!_bufferedData.TryDequeue(out topBuffer)) + { + if (_disposed) + { + CheckAborted(); + // Graceful close + return totalRead; + } + WaitForDataAsync().Wait(); + } + _topBuffer = new ArraySegment(topBuffer); + } + int actualCount = Math.Min(count, _topBuffer.Count); + Buffer.BlockCopy(_topBuffer.Array, _topBuffer.Offset, buffer, offset, actualCount); + _topBuffer = new ArraySegment(_topBuffer.Array, + _topBuffer.Offset + actualCount, + _topBuffer.Count - actualCount); + totalRead += actualCount; + offset += actualCount; + count -= actualCount; + } + while (count > 0 && (_topBuffer.Count > 0 || _bufferedData.Count > 0)); + // Keep reading while there is more data available and we have more space to put it in. + return totalRead; + } + finally + { + _readLock.Release(); + } + } +#if NET45 + public override IAsyncResult BeginRead(byte[] buffer, int offset, int count, AsyncCallback callback, object state) + { + // TODO: This option doesn't preserve the state object. + // return ReadAsync(buffer, offset, count); + return base.BeginRead(buffer, offset, count, callback, state); + } + + public override int EndRead(IAsyncResult asyncResult) + { + // return ((Task)asyncResult).Result; + return base.EndRead(asyncResult); + } +#endif + public async override Task ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken) + { + VerifyBuffer(buffer, offset, count, allowEmpty: false); + CancellationTokenRegistration registration = cancellationToken.Register(Abort); + await _readLock.WaitAsync(cancellationToken); + try + { + int totalRead = 0; + do + { + // Don't drained buffered data on abort. + CheckAborted(); + if (_topBuffer.Count <= 0) + { + byte[] topBuffer = null; + while (!_bufferedData.TryDequeue(out topBuffer)) + { + if (_disposed) + { + CheckAborted(); + // Graceful close + return totalRead; + } + await WaitForDataAsync(); + } + _topBuffer = new ArraySegment(topBuffer); + } + int actualCount = Math.Min(count, _topBuffer.Count); + Buffer.BlockCopy(_topBuffer.Array, _topBuffer.Offset, buffer, offset, actualCount); + _topBuffer = new ArraySegment(_topBuffer.Array, + _topBuffer.Offset + actualCount, + _topBuffer.Count - actualCount); + totalRead += actualCount; + offset += actualCount; + count -= actualCount; + } + while (count > 0 && (_topBuffer.Count > 0 || _bufferedData.Count > 0)); + // Keep reading while there is more data available and we have more space to put it in. + return totalRead; + } + finally + { + registration.Dispose(); + _readLock.Release(); + } + } + + // Called under write-lock. + private void FirstWrite() + { + if (_firstWrite) + { + _firstWrite = false; + _onFirstWrite(); + } + } + + // Write with count 0 will still trigger OnFirstWrite + public override void Write(byte[] buffer, int offset, int count) + { + VerifyBuffer(buffer, offset, count, allowEmpty: true); + CheckDisposed(); + + _writeLock.Wait(); + try + { + FirstWrite(); + if (count == 0) + { + return; + } + // Copies are necessary because we don't know what the caller is going to do with the buffer afterwards. + byte[] internalBuffer = new byte[count]; + Buffer.BlockCopy(buffer, offset, internalBuffer, 0, count); + _bufferedData.Enqueue(internalBuffer); + + SignalDataAvailable(); + } + finally + { + _writeLock.Release(); + } + } +#if NET45 + public override IAsyncResult BeginWrite(byte[] buffer, int offset, int count, AsyncCallback callback, object state) + { + Write(buffer, offset, count); + TaskCompletionSource tcs = new TaskCompletionSource(state); + tcs.TrySetResult(null); + IAsyncResult result = tcs.Task; + if (callback != null) + { + callback(result); + } + return result; + } + + public override void EndWrite(IAsyncResult asyncResult) + { + } +#endif + public override Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken) + { + VerifyBuffer(buffer, offset, count, allowEmpty: true); + if (cancellationToken.IsCancellationRequested) + { + TaskCompletionSource tcs = new TaskCompletionSource(); + tcs.TrySetCanceled(); + return tcs.Task; + } + + Write(buffer, offset, count); + return Task.FromResult(null); + } + + private static void VerifyBuffer(byte[] buffer, int offset, int count, bool allowEmpty) + { + if (buffer == null) + { + throw new ArgumentNullException("buffer"); + } + if (offset < 0 || offset > buffer.Length) + { + throw new ArgumentOutOfRangeException("offset", offset, string.Empty); + } + if (count < 0 || count > buffer.Length - offset + || (!allowEmpty && count == 0)) + { + throw new ArgumentOutOfRangeException("count", count, string.Empty); + } + } + + private void SignalDataAvailable() + { + // Dispatch, as TrySetResult will synchronously execute the waiters callback and block our Write. + Task.Factory.StartNew(() => _readWaitingForData.TrySetResult(null)); + } + + private Task WaitForDataAsync() + { + // Prevent race with Dispose + lock (_signalReadLock) + { + _readWaitingForData = new TaskCompletionSource(); + + if (!_bufferedData.IsEmpty || _disposed) + { + // Race, data could have arrived before we created the TCS. + _readWaitingForData.TrySetResult(null); + } + + return _readWaitingForData.Task; + } + } + + internal void Abort() + { + Abort(new OperationCanceledException()); + } + + internal void Abort(Exception innerException) + { + Contract.Requires(innerException != null); + _aborted = true; + _abortException = innerException; + Dispose(); + } + + private void CheckAborted() + { + if (_aborted) + { + throw new IOException(string.Empty, _abortException); + } + } + + [SuppressMessage("Microsoft.Usage", "CA2213:DisposableFieldsShouldBeDisposed", MessageId = "_writeLock", Justification = "ODEs from the locks would mask IOEs from abort.")] + [SuppressMessage("Microsoft.Usage", "CA2213:DisposableFieldsShouldBeDisposed", MessageId = "_readLock", Justification = "Data can still be read unless we get aborted.")] + protected override void Dispose(bool disposing) + { + if (disposing) + { + // Prevent race with WaitForDataAsync + lock (_signalReadLock) + { + // Throw for further writes, but not reads. Allow reads to drain the buffered data and then return 0 for further reads. + _disposed = true; + _readWaitingForData.TrySetResult(null); + } + } + + base.Dispose(disposing); + } + + private void CheckDisposed() + { + if (_disposed) + { + throw new ObjectDisposedException(GetType().FullName); + } + } + } +} diff --git a/src/Microsoft.AspNet.TestHost/TestClient.cs b/src/Microsoft.AspNet.TestHost/TestClient.cs index 7f9d7e8219..57886e56f9 100644 --- a/src/Microsoft.AspNet.TestHost/TestClient.cs +++ b/src/Microsoft.AspNet.TestHost/TestClient.cs @@ -1,19 +1,5 @@ -// Copyright (c) Microsoft Open Technologies, Inc. -// All Rights Reserved -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR -// CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING -// WITHOUT LIMITATION ANY IMPLIED WARRANTIES OR CONDITIONS OF -// TITLE, FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABLITY OR -// NON-INFRINGEMENT. -// See the Apache 2 License for the specific language governing -// permissions and limitations under the License. +// 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 System; using System.Collections.Generic; @@ -53,7 +39,7 @@ namespace Microsoft.AspNet.TestHost Action onSendingRequest = null) { var request = CreateRequest(method, uri, headers, body); - var response = new ResponseInformation(); + var response = new ResponseFeature(); var features = new FeatureCollection(); features.Add(typeof(IHttpRequestFeature), request); @@ -76,7 +62,7 @@ namespace Microsoft.AspNet.TestHost IDictionary headers, Stream body) { - var request = new RequestInformation(); + var request = new RequestFeature(); request.Method = method; request.Scheme = uri.Scheme; request.Path = PathString.FromUriComponent(uri).Value; diff --git a/src/Microsoft.AspNet.TestHost/TestServer.cs b/src/Microsoft.AspNet.TestHost/TestServer.cs index 48f1679f05..88f25d083f 100644 --- a/src/Microsoft.AspNet.TestHost/TestServer.cs +++ b/src/Microsoft.AspNet.TestHost/TestServer.cs @@ -1,31 +1,17 @@ -// Copyright (c) Microsoft Open Technologies, Inc. -// All Rights Reserved -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR -// CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING -// WITHOUT LIMITATION ANY IMPLIED WARRANTIES OR CONDITIONS OF -// TITLE, FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABLITY OR -// NON-INFRINGEMENT. -// See the Apache 2 License for the specific language governing -// permissions and limitations under the License. +// 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 System; -using System.Collections.Generic; +using System.Net.Http; using System.Threading.Tasks; using Microsoft.AspNet.Builder; using Microsoft.AspNet.Hosting; using Microsoft.AspNet.Hosting.Server; -using Microsoft.AspNet.Hosting.Startup; using Microsoft.Framework.ConfigurationModel; using Microsoft.Framework.DependencyInjection; using Microsoft.Framework.DependencyInjection.Fallback; using Microsoft.Framework.Runtime; +using Microsoft.Framework.Runtime.Infrastructure; namespace Microsoft.AspNet.TestHost { @@ -35,6 +21,8 @@ namespace Microsoft.AspNet.TestHost private static readonly ServerInformation ServerInfo = new ServerInformation(); private Func _appDelegate; private TestClient _handler; + private IDisposable _appInstance; + private bool _disposed = false; public TestServer(IConfiguration config, IServiceProvider serviceProvider, Action appStartup) { @@ -54,16 +42,26 @@ namespace Microsoft.AspNet.TestHost }; var engine = serviceProvider.GetService(); - var disposable = engine.Start(hostContext); + _appInstance = engine.Start(hostContext); } - //public static TestServer Create(IServiceProvider provider) - //{ - // var startupLoader = new StartupLoader(provider, new NullStartupLoader()); - // var name = typeof(TStartup).AssemblyQualifiedName; - // var diagnosticMessages = new List(); - // return Create(provider, startupLoader.LoadStartup(name, "Test", diagnosticMessages)); - //} + public TestClient Handler + { + get + { + if (_handler == null) + { + _handler = new TestClient(Invoke); + } + + return _handler; + } + } + + public static TestServer Create(Action app) + { + return Create(provider: CallContextServiceLocator.Locator.ServiceProvider, app: app); + } public static TestServer Create(IServiceProvider provider, Action app) { @@ -77,17 +75,24 @@ namespace Microsoft.AspNet.TestHost return new TestServer(config, serviceProvider, app); } - public TestClient Handler + public HttpMessageHandler CreateHandler() { - get - { - if (_handler == null) - { - _handler = new TestClient(_appDelegate); - } + return new ClientHandler(Invoke); + } - return _handler; - } + public HttpClient CreateClient() + { + return new HttpClient(CreateHandler()) { BaseAddress = new Uri("http://localhost/") }; + } + + /// + /// Begins constructing a request message for submission. + /// + /// + /// to use in constructing additional request details. + public RequestBuilder CreateRequest(string path) + { + return new RequestBuilder(this, path); } public IServerInformation Initialize(IConfiguration configuration) @@ -107,11 +112,19 @@ namespace Microsoft.AspNet.TestHost return this; } + public Task Invoke(object env) + { + if (_disposed) + { + throw new ObjectDisposedException(GetType().FullName); + } + return _appDelegate(env); + } + public void Dispose() { - // IServerFactory.Start needs to return an IDisposable. Typically this IDisposable instance is used to - // clear any server resources when tearing down the host. In our case we don't have anything to clear - // so we just implement IDisposable and do nothing. + _disposed = true; + _appInstance.Dispose(); } private class ServerInformation : IServerInformation diff --git a/src/Microsoft.AspNet.TestHost/project.json b/src/Microsoft.AspNet.TestHost/project.json index 1592b1a2c3..0effba0b63 100644 --- a/src/Microsoft.AspNet.TestHost/project.json +++ b/src/Microsoft.AspNet.TestHost/project.json @@ -1,7 +1,8 @@ { "version" : "1.0.0-*", "dependencies": { - "Microsoft.AspNet.Hosting": "" + "Microsoft.AspNet.Hosting": "", + "System.Net.Http": "4.0.0.0" }, "frameworks": { "net45": { }, diff --git a/test/Microsoft.AspNet.TestHost.Tests/ClientHandlerTests.cs b/test/Microsoft.AspNet.TestHost.Tests/ClientHandlerTests.cs new file mode 100644 index 0000000000..623a0bc395 --- /dev/null +++ b/test/Microsoft.AspNet.TestHost.Tests/ClientHandlerTests.cs @@ -0,0 +1,231 @@ +// 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 System; +using System.IO; +using System.Linq; +using System.Net.Http; +using System.Threading; +using System.Threading.Tasks; +using Microsoft.AspNet.FeatureModel; +using Microsoft.AspNet.Http; +using Microsoft.AspNet.HttpFeature; +using Microsoft.AspNet.PipelineCore; +using Xunit; + +namespace Microsoft.AspNet.TestHost +{ + public class ClientHandlerTests + { + [Fact] + public Task ExpectedKeysAreAvailable() + { + var handler = new ClientHandler(env => + { + var context = new DefaultHttpContext((IFeatureCollection)env); + + // TODO: Assert.True(context.RequestAborted.CanBeCanceled); + Assert.Equal("HTTP/1.1", context.Request.Protocol); + Assert.Equal("GET", context.Request.Method); + Assert.Equal("https", context.Request.Scheme); + Assert.Equal(string.Empty, context.Request.PathBase.Value); + Assert.Equal("/A/Path/and/file.txt", context.Request.Path.Value); + Assert.Equal("?and=query", context.Request.QueryString.Value); + Assert.NotNull(context.Request.Body); + Assert.NotNull(context.Request.Headers); + Assert.NotNull(context.Response.Headers); + Assert.NotNull(context.Response.Body); + Assert.Equal(200, context.Response.StatusCode); + Assert.Null(context.GetFeature().ReasonPhrase); + Assert.Equal("example.com", context.Request.Host.Value); + + return Task.FromResult(0); + }); + var httpClient = new HttpClient(handler); + return httpClient.GetAsync("https://example.com/A/Path/and/file.txt?and=query"); + } + + [Fact] + public async Task ResubmitRequestWorks() + { + int requestCount = 1; + var handler = new ClientHandler(env => + { + var context = new DefaultHttpContext((IFeatureCollection)env); + int read = context.Request.Body.Read(new byte[100], 0, 100); + Assert.Equal(11, read); + + context.Response.Headers["TestHeader"] = "TestValue:" + requestCount++; + return Task.FromResult(0); + }); + + HttpMessageInvoker invoker = new HttpMessageInvoker(handler); + HttpRequestMessage message = new HttpRequestMessage(HttpMethod.Post, "https://example.com/"); + message.Content = new StringContent("Hello World"); + + HttpResponseMessage response = await invoker.SendAsync(message, CancellationToken.None); + Assert.Equal("TestValue:1", response.Headers.GetValues("TestHeader").First()); + + response = await invoker.SendAsync(message, CancellationToken.None); + Assert.Equal("TestValue:2", response.Headers.GetValues("TestHeader").First()); + } + + [Fact] + public async Task MiddlewareOnlySetsHeaders() + { + var handler = new ClientHandler(env => + { + var context = new DefaultHttpContext((IFeatureCollection)env); + + context.Response.Headers["TestHeader"] = "TestValue"; + return Task.FromResult(0); + }); + var httpClient = new HttpClient(handler); + HttpResponseMessage response = await httpClient.GetAsync("https://example.com/"); + Assert.Equal("TestValue", response.Headers.GetValues("TestHeader").First()); + } + + [Fact] + public async Task BlockingMiddlewareShouldNotBlockClient() + { + ManualResetEvent block = new ManualResetEvent(false); + var handler = new ClientHandler(env => + { + block.WaitOne(); + return Task.FromResult(0); + }); + var httpClient = new HttpClient(handler); + Task task = httpClient.GetAsync("https://example.com/"); + Assert.False(task.IsCompleted); + Assert.False(task.Wait(50)); + block.Set(); + HttpResponseMessage response = await task; + } + + [Fact] + public async Task HeadersAvailableBeforeBodyFinished() + { + ManualResetEvent block = new ManualResetEvent(false); + var handler = new ClientHandler(async env => + { + var context = new DefaultHttpContext((IFeatureCollection)env); + context.Response.Headers["TestHeader"] = "TestValue"; + await context.Response.WriteAsync("BodyStarted,"); + block.WaitOne(); + await context.Response.WriteAsync("BodyFinished"); + }); + var httpClient = new HttpClient(handler); + HttpResponseMessage response = await httpClient.GetAsync("https://example.com/", + HttpCompletionOption.ResponseHeadersRead); + Assert.Equal("TestValue", response.Headers.GetValues("TestHeader").First()); + block.Set(); + Assert.Equal("BodyStarted,BodyFinished", await response.Content.ReadAsStringAsync()); + } + + [Fact] + public async Task FlushSendsHeaders() + { + ManualResetEvent block = new ManualResetEvent(false); + var handler = new ClientHandler(async env => + { + var context = new DefaultHttpContext((IFeatureCollection)env); + context.Response.Headers["TestHeader"] = "TestValue"; + context.Response.Body.Flush(); + block.WaitOne(); + await context.Response.WriteAsync("BodyFinished"); + }); + var httpClient = new HttpClient(handler); + HttpResponseMessage response = await httpClient.GetAsync("https://example.com/", + HttpCompletionOption.ResponseHeadersRead); + Assert.Equal("TestValue", response.Headers.GetValues("TestHeader").First()); + block.Set(); + Assert.Equal("BodyFinished", await response.Content.ReadAsStringAsync()); + } + + [Fact] + public async Task ClientDisposalCloses() + { + ManualResetEvent block = new ManualResetEvent(false); + var handler = new ClientHandler(env => + { + var context = new DefaultHttpContext((IFeatureCollection)env); + context.Response.Headers["TestHeader"] = "TestValue"; + context.Response.Body.Flush(); + block.WaitOne(); + return Task.FromResult(0); + }); + var httpClient = new HttpClient(handler); + HttpResponseMessage response = await httpClient.GetAsync("https://example.com/", + HttpCompletionOption.ResponseHeadersRead); + Assert.Equal("TestValue", response.Headers.GetValues("TestHeader").First()); + Stream responseStream = await response.Content.ReadAsStreamAsync(); + Task readTask = responseStream.ReadAsync(new byte[100], 0, 100); + Assert.False(readTask.IsCompleted); + responseStream.Dispose(); + Thread.Sleep(50); + Assert.True(readTask.IsCompleted); + Assert.Equal(0, readTask.Result); + block.Set(); + } + + [Fact] + public async Task ClientCancellationAborts() + { + ManualResetEvent block = new ManualResetEvent(false); + var handler = new ClientHandler(env => + { + var context = new DefaultHttpContext((IFeatureCollection)env); + context.Response.Headers["TestHeader"] = "TestValue"; + context.Response.Body.Flush(); + block.WaitOne(); + return Task.FromResult(0); + }); + var httpClient = new HttpClient(handler); + HttpResponseMessage response = await httpClient.GetAsync("https://example.com/", + HttpCompletionOption.ResponseHeadersRead); + Assert.Equal("TestValue", response.Headers.GetValues("TestHeader").First()); + Stream responseStream = await response.Content.ReadAsStreamAsync(); + CancellationTokenSource cts = new CancellationTokenSource(); + Task readTask = responseStream.ReadAsync(new byte[100], 0, 100, cts.Token); + Assert.False(readTask.IsCompleted); + cts.Cancel(); + Thread.Sleep(50); + Assert.True(readTask.IsCompleted); + Assert.True(readTask.IsFaulted); + block.Set(); + } + + [Fact] + public Task ExceptionBeforeFirstWriteIsReported() + { + var handler = new ClientHandler(env => + { + throw new InvalidOperationException("Test Exception"); + }); + var httpClient = new HttpClient(handler); + return Assert.ThrowsAsync(() => httpClient.GetAsync("https://example.com/", + HttpCompletionOption.ResponseHeadersRead)); + } + + [Fact] + public async Task ExceptionAfterFirstWriteIsReported() + { + ManualResetEvent block = new ManualResetEvent(false); + var handler = new ClientHandler(async env => + { + var context = new DefaultHttpContext((IFeatureCollection)env); + context.Response.Headers["TestHeader"] = "TestValue"; + await context.Response.WriteAsync("BodyStarted"); + block.WaitOne(); + throw new InvalidOperationException("Test Exception"); + }); + var httpClient = new HttpClient(handler); + HttpResponseMessage response = await httpClient.GetAsync("https://example.com/", + HttpCompletionOption.ResponseHeadersRead); + Assert.Equal("TestValue", response.Headers.GetValues("TestHeader").First()); + block.Set(); + var ex = await Assert.ThrowsAsync(() => response.Content.ReadAsStringAsync()); + Assert.IsType(ex.GetBaseException()); + } + } +} diff --git a/test/Microsoft.AspNet.TestHost.Tests/Microsoft.AspNet.TestHost.Tests.kproj b/test/Microsoft.AspNet.TestHost.Tests/Microsoft.AspNet.TestHost.Tests.kproj index 0ce16dcb3d..7ec4a03d46 100644 --- a/test/Microsoft.AspNet.TestHost.Tests/Microsoft.AspNet.TestHost.Tests.kproj +++ b/test/Microsoft.AspNet.TestHost.Tests/Microsoft.AspNet.TestHost.Tests.kproj @@ -21,11 +21,13 @@ + - + + - + \ No newline at end of file diff --git a/test/Microsoft.AspNet.TestHost.Tests/RequestBuilderTests.cs b/test/Microsoft.AspNet.TestHost.Tests/RequestBuilderTests.cs new file mode 100644 index 0000000000..0f637c7d24 --- /dev/null +++ b/test/Microsoft.AspNet.TestHost.Tests/RequestBuilderTests.cs @@ -0,0 +1,35 @@ +// 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 Xunit; + +namespace Microsoft.AspNet.TestHost +{ + public class RequestBuilderTests + { + [Fact] + public void AddRequestHeader() + { + TestServer server = TestServer.Create(app => { }); + server.CreateRequest("/") + .AddHeader("Host", "MyHost:90") + .And(request => + { + Assert.Equal("MyHost:90", request.Headers.Host.ToString()); + }); + } + + [Fact] + public void AddContentHeaders() + { + TestServer server = TestServer.Create(app => { }); + server.CreateRequest("/") + .AddHeader("Content-Type", "Test/Value") + .And(request => + { + Assert.NotNull(request.Content); + Assert.Equal("Test/Value", request.Content.Headers.ContentType.ToString()); + }); + } + } +} diff --git a/test/Microsoft.AspNet.TestHost.Tests/ResponseFeatureTests.cs b/test/Microsoft.AspNet.TestHost.Tests/ResponseFeatureTests.cs new file mode 100644 index 0000000000..ebf601cb82 --- /dev/null +++ b/test/Microsoft.AspNet.TestHost.Tests/ResponseFeatureTests.cs @@ -0,0 +1,20 @@ +// 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 Xunit; + +namespace Microsoft.AspNet.TestHost +{ + public class ResponseFeatureTests + { + [Fact] + public void StatusCode_DefaultsTo200() + { + // Arrange & Act + var responseInformation = new ResponseFeature(); + + // Assert + Assert.Equal(200, responseInformation.StatusCode); + } + } +} \ No newline at end of file diff --git a/test/Microsoft.AspNet.TestHost.Tests/ResponseInformationTests.cs b/test/Microsoft.AspNet.TestHost.Tests/ResponseInformationTests.cs deleted file mode 100644 index 1717152773..0000000000 --- a/test/Microsoft.AspNet.TestHost.Tests/ResponseInformationTests.cs +++ /dev/null @@ -1,34 +0,0 @@ -// Copyright (c) Microsoft Open Technologies, Inc. -// All Rights Reserved -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR -// CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING -// WITHOUT LIMITATION ANY IMPLIED WARRANTIES OR CONDITIONS OF -// TITLE, FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABLITY OR -// NON-INFRINGEMENT. -// See the Apache 2 License for the specific language governing -// permissions and limitations under the License. - -using Xunit; - -namespace Microsoft.AspNet.TestHost.Tests -{ - public class ResponseInformationTests - { - [Fact] - public void StatusCode_DefaultsTo200() - { - // Arrange & Act - var responseInformation = new ResponseInformation(); - - // Assert - Assert.Equal(200, responseInformation.StatusCode); - } - } -} \ No newline at end of file diff --git a/test/Microsoft.AspNet.TestHost.Tests/TestApplicationEnvironment.cs b/test/Microsoft.AspNet.TestHost.Tests/TestApplicationEnvironment.cs index 800570f20a..417a903d0d 100644 --- a/test/Microsoft.AspNet.TestHost.Tests/TestApplicationEnvironment.cs +++ b/test/Microsoft.AspNet.TestHost.Tests/TestApplicationEnvironment.cs @@ -1,25 +1,11 @@ -// Copyright (c) Microsoft Open Technologies, Inc. -// All Rights Reserved -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR -// CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING -// WITHOUT LIMITATION ANY IMPLIED WARRANTIES OR CONDITIONS OF -// TITLE, FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABLITY OR -// NON-INFRINGEMENT. -// See the Apache 2 License for the specific language governing -// permissions and limitations under the License. +// 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 System; using System.Runtime.Versioning; using Microsoft.Framework.Runtime; -namespace Microsoft.AspNet.TestHost.Tests +namespace Microsoft.AspNet.TestHost { public class TestApplicationEnvironment : IApplicationEnvironment { diff --git a/test/Microsoft.AspNet.TestHost.Tests/TestClientTests.cs b/test/Microsoft.AspNet.TestHost.Tests/TestClientTests.cs index 48d416b266..96fbfc04b0 100644 --- a/test/Microsoft.AspNet.TestHost.Tests/TestClientTests.cs +++ b/test/Microsoft.AspNet.TestHost.Tests/TestClientTests.cs @@ -1,19 +1,5 @@ -// Copyright (c) Microsoft Open Technologies, Inc. -// All Rights Reserved -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR -// CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING -// WITHOUT LIMITATION ANY IMPLIED WARRANTIES OR CONDITIONS OF -// TITLE, FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABLITY OR -// NON-INFRINGEMENT. -// See the Apache 2 License for the specific language governing -// permissions and limitations under the License. +// 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 System; using System.Collections.Generic; @@ -26,7 +12,7 @@ using Microsoft.Framework.DependencyInjection.Fallback; using Microsoft.Framework.Runtime; using Xunit; -namespace Microsoft.AspNet.TestHost.Tests +namespace Microsoft.AspNet.TestHost { public class TestClientTests { diff --git a/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs b/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs index 13793b8cea..5f27cc89f1 100644 --- a/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs +++ b/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs @@ -1,22 +1,9 @@ -// Copyright (c) Microsoft Open Technologies, Inc. -// All Rights Reserved -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR -// CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING -// WITHOUT LIMITATION ANY IMPLIED WARRANTIES OR CONDITIONS OF -// TITLE, FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABLITY OR -// NON-INFRINGEMENT. -// See the Apache 2 License for the specific language governing -// permissions and limitations under the License. +// 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 System; -using System.IO; +using System.Net; +using System.Net.Http; using System.Threading.Tasks; using Microsoft.AspNet.Builder; using Microsoft.AspNet.Http; @@ -25,7 +12,7 @@ using Microsoft.Framework.DependencyInjection.Fallback; using Microsoft.Framework.Runtime; using Xunit; -namespace Microsoft.AspNet.TestHost.Tests +namespace Microsoft.AspNet.TestHost { public class TestServerTests { @@ -41,24 +28,6 @@ namespace Microsoft.AspNet.TestHost.Tests Assert.DoesNotThrow(() => TestServer.Create(services, app => { })); } - //[Fact] - //public async Task CreateWithGeneric() - //{ - // // Arrange - // var services = new ServiceCollection() - // .AddSingleton() - // .BuildServiceProvider(); - - // var server = TestServer.Create(services); - // var client = server.Handler; - - // // Act - // var response = await client.GetAsync("http://any"); - - // // Assert - // Assert.Equal("Startup", new StreamReader(response.Body).ReadToEnd()); - //} - [Fact] public void ThrowsIfNoApplicationEnvironmentIsRegisteredWithTheProvider() { @@ -70,6 +39,72 @@ namespace Microsoft.AspNet.TestHost.Tests Assert.Throws(() => TestServer.Create(services, new Startup().Configuration)); } + [Fact] + public async Task CreateInvokesApp() + { + TestServer server = TestServer.Create(app => + { + app.Run(context => + { + return context.Response.WriteAsync("CreateInvokesApp"); + }); + }); + + string result = await server.CreateClient().GetStringAsync("/path"); + Assert.Equal("CreateInvokesApp", result); + } + + [Fact] + public async Task DisposeStreamIgnored() + { + TestServer server = TestServer.Create(app => + { + app.Run(async context => + { + await context.Response.WriteAsync("Response"); + context.Response.Body.Dispose(); + }); + }); + + HttpResponseMessage result = await server.CreateClient().GetAsync("/"); + Assert.Equal(HttpStatusCode.OK, result.StatusCode); + Assert.Equal("Response", await result.Content.ReadAsStringAsync()); + } + + [Fact] + public async Task DisposedServerThrows() + { + TestServer server = TestServer.Create(app => + { + app.Run(async context => + { + await context.Response.WriteAsync("Response"); + context.Response.Body.Dispose(); + }); + }); + + HttpResponseMessage result = await server.CreateClient().GetAsync("/"); + Assert.Equal(HttpStatusCode.OK, result.StatusCode); + server.Dispose(); + await Assert.ThrowsAsync(() => server.CreateClient().GetAsync("/")); + } + + [Fact] + public void CancelAborts() + { + TestServer server = TestServer.Create(app => + { + app.Run(context => + { + TaskCompletionSource tcs = new TaskCompletionSource(); + tcs.SetCanceled(); + return tcs.Task; + }); + }); + + Assert.Throws(() => { string result = server.CreateClient().GetStringAsync("/path").Result; }); + } + public class Startup { public void Configuration(IBuilder builder) From 9e950fba270d92e790fb56971e29ec535789232e Mon Sep 17 00:00:00 2001 From: Chris Ross Date: Mon, 4 Aug 2014 12:28:20 -0700 Subject: [PATCH 104/987] More var. --- src/Microsoft.AspNet.TestHost/ClientHandler.cs | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/Microsoft.AspNet.TestHost/ClientHandler.cs b/src/Microsoft.AspNet.TestHost/ClientHandler.cs index d92eaffdda..29400083e8 100644 --- a/src/Microsoft.AspNet.TestHost/ClientHandler.cs +++ b/src/Microsoft.AspNet.TestHost/ClientHandler.cs @@ -2,7 +2,6 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; using System.Diagnostics.Contracts; using System.IO; @@ -57,18 +56,18 @@ namespace Microsoft.AspNet.TestHost } var state = new RequestState(request, cancellationToken); - HttpContent requestContent = request.Content ?? new StreamContent(Stream.Null); - Stream body = await requestContent.ReadAsStreamAsync(); + var requestContent = request.Content ?? new StreamContent(Stream.Null); + var body = await requestContent.ReadAsStreamAsync(); if (body.CanSeek) { // This body may have been consumed before, rewind it. body.Seek(0, SeekOrigin.Begin); } state.HttpContext.Request.Body = body; - CancellationTokenRegistration registration = cancellationToken.Register(state.Abort); + var registration = cancellationToken.Register(state.Abort); // Async offload, don't let the test code block the caller. - Task offload = Task.Factory.StartNew(async () => + var offload = Task.Factory.StartNew(async () => { try { @@ -128,7 +127,7 @@ namespace Microsoft.AspNet.TestHost { serverRequest.Headers.AppendValues(header.Key, header.Value.ToArray()); } - HttpContent requestContent = request.Content; + var requestContent = request.Content; if (requestContent != null) { foreach (var header in request.Content.Headers) @@ -155,7 +154,7 @@ namespace Microsoft.AspNet.TestHost { if (!_responseTcs.Task.IsCompleted) { - HttpResponseMessage response = GenerateResponse(); + var response = GenerateResponse(); // Dispatch, as TrySetResult will synchronously execute the waiters callback and block our Write. Task.Factory.StartNew(() => _responseTcs.TrySetResult(response)); } From 10cbe6bab3ac88cf20bc179cd1759a5ce6817e55 Mon Sep 17 00:00:00 2001 From: Pranav K Date: Tue, 5 Aug 2014 15:49:35 -0700 Subject: [PATCH 105/987] Updating release Nuget.config --- NuGet.Config | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/NuGet.Config b/NuGet.Config index f41e9c631d..1ce6b9e257 100644 --- a/NuGet.Config +++ b/NuGet.Config @@ -1,7 +1,7 @@ - + - + From faf406736d9c96d8a827381e4948f862d5b616be Mon Sep 17 00:00:00 2001 From: Pranav K Date: Wed, 6 Aug 2014 12:30:43 -0700 Subject: [PATCH 106/987] Updating dev Nuget.config --- NuGet.Config | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/NuGet.Config b/NuGet.Config index 1ce6b9e257..f41e9c631d 100644 --- a/NuGet.Config +++ b/NuGet.Config @@ -1,7 +1,7 @@ - + - + From 58468e9509a914368c6ca65bce43d96cdbae3763 Mon Sep 17 00:00:00 2001 From: David Fowler Date: Fri, 15 Aug 2014 08:13:03 -0700 Subject: [PATCH 107/987] Removed source files from the project --- .../Microsoft.AspNet.Hosting.kproj | 30 ------------------- .../Microsoft.AspNet.RequestContainer.kproj | 9 +----- .../Microsoft.AspNet.TestHost.kproj | 13 -------- .../Microsoft.AspNet.Hosting.Tests.kproj | 11 ------- .../Microsoft.AspNet.TestHost.Tests.kproj | 12 -------- 5 files changed, 1 insertion(+), 74 deletions(-) diff --git a/src/Microsoft.AspNet.Hosting/Microsoft.AspNet.Hosting.kproj b/src/Microsoft.AspNet.Hosting/Microsoft.AspNet.Hosting.kproj index c58f27a50a..c677b192d6 100644 --- a/src/Microsoft.AspNet.Hosting/Microsoft.AspNet.Hosting.kproj +++ b/src/Microsoft.AspNet.Hosting/Microsoft.AspNet.Hosting.kproj @@ -16,35 +16,5 @@ 2.0 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/src/Microsoft.AspNet.RequestContainer/Microsoft.AspNet.RequestContainer.kproj b/src/Microsoft.AspNet.RequestContainer/Microsoft.AspNet.RequestContainer.kproj index dbadd459f2..e3e12065f7 100644 --- a/src/Microsoft.AspNet.RequestContainer/Microsoft.AspNet.RequestContainer.kproj +++ b/src/Microsoft.AspNet.RequestContainer/Microsoft.AspNet.RequestContainer.kproj @@ -16,12 +16,5 @@ 2.0 - - - - - - - - + \ No newline at end of file diff --git a/src/Microsoft.AspNet.TestHost/Microsoft.AspNet.TestHost.kproj b/src/Microsoft.AspNet.TestHost/Microsoft.AspNet.TestHost.kproj index 4bba9328cc..f68105749b 100644 --- a/src/Microsoft.AspNet.TestHost/Microsoft.AspNet.TestHost.kproj +++ b/src/Microsoft.AspNet.TestHost/Microsoft.AspNet.TestHost.kproj @@ -16,18 +16,5 @@ 2.0 - - - - - - - - - - - - - \ No newline at end of file diff --git a/test/Microsoft.AspNet.Hosting.Tests/Microsoft.AspNet.Hosting.Tests.kproj b/test/Microsoft.AspNet.Hosting.Tests/Microsoft.AspNet.Hosting.Tests.kproj index 412181c036..d20ea65b15 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/Microsoft.AspNet.Hosting.Tests.kproj +++ b/test/Microsoft.AspNet.Hosting.Tests/Microsoft.AspNet.Hosting.Tests.kproj @@ -17,16 +17,5 @@ 2.0 - - - - - - - - - - - \ No newline at end of file diff --git a/test/Microsoft.AspNet.TestHost.Tests/Microsoft.AspNet.TestHost.Tests.kproj b/test/Microsoft.AspNet.TestHost.Tests/Microsoft.AspNet.TestHost.Tests.kproj index 7ec4a03d46..777a4d4460 100644 --- a/test/Microsoft.AspNet.TestHost.Tests/Microsoft.AspNet.TestHost.Tests.kproj +++ b/test/Microsoft.AspNet.TestHost.Tests/Microsoft.AspNet.TestHost.Tests.kproj @@ -17,17 +17,5 @@ 2.0 - - - - - - - - - - - - \ No newline at end of file From c720364d0e0baed836ba5ecc3335ea4f36a49723 Mon Sep 17 00:00:00 2001 From: Louis DeJardin Date: Fri, 15 Aug 2014 15:42:01 -0700 Subject: [PATCH 108/987] Registering standard LoggerFactory : ILoggerFactory implementation --- .../HostingServices.cs | 37 +------------------ .../TestApplicationEnvironment.cs | 5 +++ 2 files changed, 7 insertions(+), 35 deletions(-) diff --git a/src/Microsoft.AspNet.Hosting/HostingServices.cs b/src/Microsoft.AspNet.Hosting/HostingServices.cs index 0a0950d559..91e1ef5f31 100644 --- a/src/Microsoft.AspNet.Hosting/HostingServices.cs +++ b/src/Microsoft.AspNet.Hosting/HostingServices.cs @@ -51,8 +51,8 @@ namespace Microsoft.AspNet.Hosting yield return describer.Instance(new ApplicationLifetime()); - // TODO: We expect this to be provide by the runtime eventually. - yield return describer.Instance(new NullLoggerFactory()); + // TODO: Do we expect this to be provide by the runtime eventually? + yield return describer.Singleton(); yield return new ServiceDescriptor { @@ -76,38 +76,5 @@ namespace Microsoft.AspNet.Hosting yield return describer.Instance(DataProtectionProvider.CreateFromDpapi()); } } - - // TODO: Temp workaround until the runtime reliably provides logging. - // If ILoggerFactory is never guaranteed, move this fallback into Microsoft.AspNet.Logging. - private class NullLoggerFactory : ILoggerFactory - { - public ILogger Create(string name) - { - return new NullLogger(); - } - } - - private class NullLogger : ILogger - { - public bool WriteCore(TraceType eventType, int eventId, object state, Exception exception, Func formatter) - { - return false; - } - - public IDisposable BeginScope(object state) - { - return NullScope.Instance; - } - } - - private class NullScope : IDisposable - { - public static NullScope Instance = new NullScope(); - - public void Dispose() - { - // intentionally does nothing - } - } } } \ No newline at end of file diff --git a/test/Microsoft.AspNet.TestHost.Tests/TestApplicationEnvironment.cs b/test/Microsoft.AspNet.TestHost.Tests/TestApplicationEnvironment.cs index 417a903d0d..28d5ba7b24 100644 --- a/test/Microsoft.AspNet.TestHost.Tests/TestApplicationEnvironment.cs +++ b/test/Microsoft.AspNet.TestHost.Tests/TestApplicationEnvironment.cs @@ -36,5 +36,10 @@ namespace Microsoft.AspNet.TestHost { get { return new FrameworkName(".NETFramework", new Version(4, 5)); } } + + public string Configuration + { + get { return "Test"; } + } } } From 70972fb7a19ec9728b97a98cb4a7ac36fa0b0aae Mon Sep 17 00:00:00 2001 From: Louis DeJardin Date: Fri, 15 Aug 2014 16:08:47 -0700 Subject: [PATCH 109/987] Rebase cleanup --- .../TestApplicationEnvironment.cs | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/test/Microsoft.AspNet.TestHost.Tests/TestApplicationEnvironment.cs b/test/Microsoft.AspNet.TestHost.Tests/TestApplicationEnvironment.cs index 28d5ba7b24..a81d1da0e8 100644 --- a/test/Microsoft.AspNet.TestHost.Tests/TestApplicationEnvironment.cs +++ b/test/Microsoft.AspNet.TestHost.Tests/TestApplicationEnvironment.cs @@ -26,20 +26,12 @@ namespace Microsoft.AspNet.TestHost public string Configuration { - get - { - return "debug"; - } + get { return "Test"; } } - + public FrameworkName TargetFramework { get { return new FrameworkName(".NETFramework", new Version(4, 5)); } } - - public string Configuration - { - get { return "Test"; } - } } } From 6551a30391af922551fd070a36b69e5ec992f5ce Mon Sep 17 00:00:00 2001 From: Pranav K Date: Wed, 20 Aug 2014 06:56:32 -0700 Subject: [PATCH 110/987] Reacting to System.IO package version change --- src/Microsoft.AspNet.Hosting/project.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Microsoft.AspNet.Hosting/project.json b/src/Microsoft.AspNet.Hosting/project.json index d77f6393d3..40bc831099 100644 --- a/src/Microsoft.AspNet.Hosting/project.json +++ b/src/Microsoft.AspNet.Hosting/project.json @@ -18,7 +18,7 @@ "System.ComponentModel": "4.0.0.0", "System.Console": "4.0.0.0", "System.Diagnostics.Debug": "4.0.10.0", - "System.IO": "4.0.0.0", + "System.IO": "4.0.10.0", "System.Linq": "4.0.0.0", "System.Reflection": "4.0.10.0", "System.Runtime": "4.0.20.0", From 630abe6a5d329de11cd28058dede8fe365640ebe Mon Sep 17 00:00:00 2001 From: David Fowler Date: Thu, 28 Aug 2014 23:29:57 -0700 Subject: [PATCH 111/987] Updated to use the new target framework in project.json --- src/Microsoft.AspNet.Hosting/project.json | 2 +- src/Microsoft.AspNet.RequestContainer/project.json | 2 +- src/Microsoft.AspNet.TestHost/project.json | 2 +- test/Microsoft.AspNet.Hosting.Tests/project.json | 2 +- test/Microsoft.AspNet.TestHost.Tests/project.json | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Microsoft.AspNet.Hosting/project.json b/src/Microsoft.AspNet.Hosting/project.json index 40bc831099..4415b2a039 100644 --- a/src/Microsoft.AspNet.Hosting/project.json +++ b/src/Microsoft.AspNet.Hosting/project.json @@ -12,7 +12,7 @@ }, "frameworks": { "net45": {}, - "k10": { + "aspnetcore50": { "dependencies": { "System.Collections": "4.0.10.0", "System.ComponentModel": "4.0.0.0", diff --git a/src/Microsoft.AspNet.RequestContainer/project.json b/src/Microsoft.AspNet.RequestContainer/project.json index 7c3a92c05e..de23d763da 100644 --- a/src/Microsoft.AspNet.RequestContainer/project.json +++ b/src/Microsoft.AspNet.RequestContainer/project.json @@ -7,7 +7,7 @@ }, "frameworks": { "net45": {}, - "k10": { + "aspnetcore50": { "dependencies": { "System.Collections": "4.0.10.0", "System.ComponentModel": "4.0.0.0", diff --git a/src/Microsoft.AspNet.TestHost/project.json b/src/Microsoft.AspNet.TestHost/project.json index 0effba0b63..5386ddc409 100644 --- a/src/Microsoft.AspNet.TestHost/project.json +++ b/src/Microsoft.AspNet.TestHost/project.json @@ -6,7 +6,7 @@ }, "frameworks": { "net45": { }, - "k10" : { + "aspnetcore50" : { "dependencies": { "System.Collections": "4.0.10.0", "System.ComponentModel": "4.0.0.0", diff --git a/test/Microsoft.AspNet.Hosting.Tests/project.json b/test/Microsoft.AspNet.Hosting.Tests/project.json index f106512168..d60b8d2cb8 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/project.json +++ b/test/Microsoft.AspNet.Hosting.Tests/project.json @@ -1,4 +1,4 @@ -{ +{ "dependencies": { "Microsoft.AspNet.Hosting": "", "Microsoft.AspNet.RequestContainer": "", diff --git a/test/Microsoft.AspNet.TestHost.Tests/project.json b/test/Microsoft.AspNet.TestHost.Tests/project.json index e4f8d10796..60d12ad07b 100644 --- a/test/Microsoft.AspNet.TestHost.Tests/project.json +++ b/test/Microsoft.AspNet.TestHost.Tests/project.json @@ -1,4 +1,4 @@ -{ +{ "dependencies": { "Microsoft.AspNet.Hosting": "", "Microsoft.AspNet.TestHost": "", From 904eeb76f91c8629538689280155ea8bffeaefee Mon Sep 17 00:00:00 2001 From: Pranav K Date: Mon, 1 Sep 2014 11:56:11 -0700 Subject: [PATCH 112/987] Removing TestClient from TestServer --- src/Microsoft.AspNet.TestHost/TestClient.cs | 209 ------------------ src/Microsoft.AspNet.TestHost/TestServer.cs | 14 -- .../TestClientTests.cs | 116 ++-------- 3 files changed, 21 insertions(+), 318 deletions(-) delete mode 100644 src/Microsoft.AspNet.TestHost/TestClient.cs diff --git a/src/Microsoft.AspNet.TestHost/TestClient.cs b/src/Microsoft.AspNet.TestHost/TestClient.cs deleted file mode 100644 index 57886e56f9..0000000000 --- a/src/Microsoft.AspNet.TestHost/TestClient.cs +++ /dev/null @@ -1,209 +0,0 @@ -// 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 System; -using System.Collections.Generic; -using System.Globalization; -using System.IO; -using System.Text; -using System.Threading.Tasks; -using Microsoft.AspNet.Http; -using Microsoft.AspNet.FeatureModel; -using Microsoft.AspNet.HttpFeature; -using Microsoft.AspNet.PipelineCore; - -namespace Microsoft.AspNet.TestHost -{ - public class TestClient - { - private readonly Func _pipeline; - - public TestClient(Func pipeline) - { - _pipeline = pipeline; - } - - public async Task SendAsync(string method, - string url, - IDictionary headers = null, - Stream body = null, - Action onSendingRequest = null) - { - return await SendAsync(method, new Uri(url), headers, body, onSendingRequest); - } - - public async Task SendAsync(string method, - Uri uri, - IDictionary headers = null, - Stream body = null, - Action onSendingRequest = null) - { - var request = CreateRequest(method, uri, headers, body); - var response = new ResponseFeature(); - - var features = new FeatureCollection(); - features.Add(typeof(IHttpRequestFeature), request); - features.Add(typeof(IHttpResponseFeature), response); - var httpContext = new DefaultHttpContext(features); - - if (onSendingRequest != null) - { - onSendingRequest(httpContext.Request); - } - await _pipeline(features); - - response.Body.Seek(0, SeekOrigin.Begin); - return httpContext.Response; - } - - private static IHttpRequestFeature CreateRequest( - string method, - Uri uri, - IDictionary headers, - Stream body) - { - var request = new RequestFeature(); - request.Method = method; - request.Scheme = uri.Scheme; - request.Path = PathString.FromUriComponent(uri).Value; - request.QueryString = QueryString.FromUriComponent(uri).Value; - request.Headers = headers ?? request.Headers; - if (!request.Headers.ContainsKey("Host")) - { - var host = new string[1]; - if (uri.IsDefaultPort) - { - host[0] = uri.Host; - } - else - { - host[0] = uri.GetComponents(UriComponents.HostAndPort, UriFormat.UriEscaped); - } - request.Headers["Host"] = host; - } - - if (body != null) - { - EnsureContentLength(request.Headers, body); - request.Body = body; - } - else - { - request.Body = Stream.Null; - } - return request; - } - - public async Task GetAsync(string url) - { - var uri = new Uri(url); - return await GetAsync(uri); - } - - public async Task GetAsync(Uri uri) - { - return await SendAsync("GET", uri); - } - - public async Task GetStringAsync(string url) - { - var uri = new Uri(url); - return await GetStringAsync(uri); - } - - public async Task GetStringAsync(Uri uri) - { - var response = await GetAsync(uri); - return await new StreamReader(response.Body).ReadToEndAsync(); - } - - public async Task GetStreamAsync(string url) - { - var uri = new Uri(url); - return await GetStreamAsync(uri); - } - - public async Task GetStreamAsync(Uri uri) - { - var response = await GetAsync(uri); - return response.Body; - } - - public async Task PostAsync( - string url, - string content, - string contentType, - Action onSendingRequest = null) - { - return await PostAsync(new Uri(url), content, contentType, onSendingRequest); - } - - public async Task PostAsync( - Uri url, - string content, - string contentType, - Action onSendingRequest = null) - { - var bytes = GetBytes(content); - var headers = CreateContentHeaders(contentType, bytes.Length); - var body = new MemoryStream(bytes); - - return await SendAsync("POST", url, headers, body, onSendingRequest); - } - - public async Task PutAsync( - string url, - string content, - string contentType, - Action onSendingRequest = null) - { - return await PutAsync(new Uri(url), content, contentType, onSendingRequest); - } - - public async Task PutAsync( - Uri url, - string content, - string contentType, - Action onSendingRequest = null) - { - var bytes = GetBytes(content); - var headers = CreateContentHeaders(contentType, bytes.Length); - var body = new MemoryStream(bytes); - - return await SendAsync("PUT", url, headers, body, onSendingRequest); - } - - public async Task DeleteAsync(string url) - { - return await DeleteAsync(new Uri(url)); - } - - public async Task DeleteAsync(Uri uri) - { - return await SendAsync("DELETE", uri); - } - - private static void EnsureContentLength(IDictionary dictionary, Stream body) - { - if (!dictionary.ContainsKey("Content-Length")) - { - dictionary["Content-Length"] = new[] { body.Length.ToString(CultureInfo.InvariantCulture) }; - } - } - - private static byte[] GetBytes(string content) - { - var bytes = Encoding.UTF8.GetBytes(content); - return bytes; - } - - private static Dictionary CreateContentHeaders(string contentType, int contentLength) - { - return new Dictionary(StringComparer.OrdinalIgnoreCase) - { - { "Content-Type", new [] { contentType } }, - { "Content-Length", new [] { contentLength.ToString(CultureInfo.InvariantCulture) } } - }; - } - } -} diff --git a/src/Microsoft.AspNet.TestHost/TestServer.cs b/src/Microsoft.AspNet.TestHost/TestServer.cs index 88f25d083f..b8df467d80 100644 --- a/src/Microsoft.AspNet.TestHost/TestServer.cs +++ b/src/Microsoft.AspNet.TestHost/TestServer.cs @@ -20,7 +20,6 @@ namespace Microsoft.AspNet.TestHost private static readonly string ServerName = typeof(TestServer).FullName; private static readonly ServerInformation ServerInfo = new ServerInformation(); private Func _appDelegate; - private TestClient _handler; private IDisposable _appInstance; private bool _disposed = false; @@ -45,19 +44,6 @@ namespace Microsoft.AspNet.TestHost _appInstance = engine.Start(hostContext); } - public TestClient Handler - { - get - { - if (_handler == null) - { - _handler = new TestClient(Invoke); - } - - return _handler; - } - } - public static TestServer Create(Action app) { return Create(provider: CallContextServiceLocator.Locator.ServiceProvider, app: app); diff --git a/test/Microsoft.AspNet.TestHost.Tests/TestClientTests.cs b/test/Microsoft.AspNet.TestHost.Tests/TestClientTests.cs index 96fbfc04b0..d9843657dd 100644 --- a/test/Microsoft.AspNet.TestHost.Tests/TestClientTests.cs +++ b/test/Microsoft.AspNet.TestHost.Tests/TestClientTests.cs @@ -2,8 +2,8 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using System.Collections.Generic; using System.IO; +using System.Net.Http; using System.Threading.Tasks; using Microsoft.AspNet.Builder; using Microsoft.AspNet.Http; @@ -25,114 +25,41 @@ namespace Microsoft.AspNet.TestHost .AddSingleton() .BuildServiceProvider(); - _server = TestServer.Create(_services, app => app.Run(async ctx => { })); + _server = TestServer.Create(_services, app => app.Run(ctx => Task.FromResult(0))); } [Fact] - public async Task SendAsync_ConfiguresRequestProperly() + public async Task GetAsyncWorks() { // Arrange - var client = _server.Handler; + var expected = "GET Response"; + RequestDelegate appDelegate = ctx => + ctx.Response.WriteAsync(expected); + var server = TestServer.Create(_services, app => app.Run(appDelegate)); + var client = server.CreateClient(); // Act - var response = await client.SendAsync("GET", "http://localhost:12345/Home/Index?id=3&name=peter#fragment"); - var request = response.HttpContext.Request; + var actual = await client.GetStringAsync("http://localhost:12345"); // Assert - Assert.NotNull(request); - Assert.Equal("HTTP/1.1", request.Protocol); - Assert.Equal("GET", request.Method); - Assert.Equal("http", request.Scheme); - Assert.Equal("localhost:12345", request.Host.Value); - Assert.Equal("", request.PathBase.Value); - Assert.True(request.Path.HasValue); - Assert.Equal("/Home/Index", request.Path.Value); - Assert.Equal("?id=3&name=peter", request.QueryString.Value); - Assert.Null(request.ContentLength); - Assert.Equal(1, request.Headers.Count); - Assert.True(request.Headers.ContainsKey("Host")); - } - - [Fact] - public async Task SendAsync_InvokesCallbackWhenPassed() - { - // Arrange - var client = _server.Handler; - var invoked = false; - - // Act - var response = await client.SendAsync("GET", "http://localhost:12345/", null, null, _ => invoked = true); - - // Assert - Assert.True(invoked); - } - - [Fact] - public async Task SendAsync_RespectsExistingHost() - { - // Arrange - var client = _server.Handler; - var headers = new Dictionary { { "Host", new string[] { "server:12345" } } }; - - // Act - var response = await client.SendAsync("GET", "http://localhost:12345/Home/", headers); - var request = response.HttpContext.Request; - - // Assert - Assert.Equal("server:12345", request.Host.Value); - } - - [Fact] - public async Task SendAsync_RespectsArgumentBody() - { - // Arrange - var client = _server.Handler; - var headers = new Dictionary { { "Content-Type", new string[] { "text/plain" } } }; - var body = new MemoryStream(); - new StreamWriter(body).Write("Hello world"); - body.Position = 0; - - // Act - var response = await client.SendAsync("POST", "http://host/", headers, body); - var request = response.HttpContext.Request; - - // Assert - Assert.Same(body, request.Body); - Assert.Equal(0, request.Body.Position); - Assert.Equal(body.Length, request.ContentLength); - } - - [Fact] - public async Task SendAsync_RewindsTheResponseStream() - { - // Arrange - var server = TestServer.Create(_services, app => app.Run(ctx => ctx.Response.WriteAsync("Hello world"))); - var client = server.Handler; - - // Act - var response = await client.SendAsync("GET", "http://localhost"); - - // Assert - Assert.Equal(0, response.Body.Position); - Assert.Equal("Hello world", new StreamReader(response.Body).ReadToEnd()); + Assert.Equal(expected, actual); } [Fact] public async Task PutAsyncWorks() { // Arrange - RequestDelegate appDelegate = async ctx => - await ctx.Response.WriteAsync(new StreamReader(ctx.Request.Body).ReadToEnd()); + RequestDelegate appDelegate = ctx => + ctx.Response.WriteAsync(new StreamReader(ctx.Request.Body).ReadToEnd() + " PUT Response"); var server = TestServer.Create(_services, app => app.Run(appDelegate)); - var client = server.Handler; + var client = server.CreateClient(); // Act - var response = await client.PutAsync("http://localhost:12345", "Hello world", "text/plain"); - var request = response.HttpContext.Request; + var content = new StringContent("Hello world"); + var response = await client.PutAsync("http://localhost:12345", content); // Assert - Assert.Equal("PUT", request.Method); - Assert.Equal("Hello world", new StreamReader(response.Body).ReadToEnd()); + Assert.Equal("Hello world PUT Response", await response.Content.ReadAsStringAsync()); } [Fact] @@ -140,17 +67,16 @@ namespace Microsoft.AspNet.TestHost { // Arrange RequestDelegate appDelegate = async ctx => - await ctx.Response.WriteAsync(new StreamReader(ctx.Request.Body).ReadToEnd()); + await ctx.Response.WriteAsync(new StreamReader(ctx.Request.Body).ReadToEnd() + " POST Response"); var server = TestServer.Create(_services, app => app.Run(appDelegate)); - var client = server.Handler; + var client = server.CreateClient(); // Act - var response = await client.PostAsync("http://localhost:12345", "Hello world", "text/plain"); - var request = response.HttpContext.Request; + var content = new StringContent("Hello world"); + var response = await client.PostAsync("http://localhost:12345", content); // Assert - Assert.Equal("POST", request.Method); - Assert.Equal("Hello world", new StreamReader(response.Body).ReadToEnd()); + Assert.Equal("Hello world POST Response", await response.Content.ReadAsStringAsync()); } } } From a9ec7cfb62586ae0d0d999133695c64a4c0e5741 Mon Sep 17 00:00:00 2001 From: David Fowler Date: Thu, 4 Sep 2014 01:22:48 -0700 Subject: [PATCH 113/987] Changing net45 to aspnet50 --- src/Microsoft.AspNet.Hosting/project.json | 2 +- src/Microsoft.AspNet.RequestContainer/project.json | 2 +- src/Microsoft.AspNet.TestHost/project.json | 2 +- test/Microsoft.AspNet.Hosting.Tests/project.json | 2 +- test/Microsoft.AspNet.TestHost.Tests/project.json | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Microsoft.AspNet.Hosting/project.json b/src/Microsoft.AspNet.Hosting/project.json index 4415b2a039..34fc3ef4fe 100644 --- a/src/Microsoft.AspNet.Hosting/project.json +++ b/src/Microsoft.AspNet.Hosting/project.json @@ -11,7 +11,7 @@ "Microsoft.Framework.Runtime.Interfaces": "1.0.0-*" }, "frameworks": { - "net45": {}, + "aspnet50": {}, "aspnetcore50": { "dependencies": { "System.Collections": "4.0.10.0", diff --git a/src/Microsoft.AspNet.RequestContainer/project.json b/src/Microsoft.AspNet.RequestContainer/project.json index de23d763da..d381b0bb3d 100644 --- a/src/Microsoft.AspNet.RequestContainer/project.json +++ b/src/Microsoft.AspNet.RequestContainer/project.json @@ -6,7 +6,7 @@ "Microsoft.Framework.OptionsModel": "1.0.0-*" }, "frameworks": { - "net45": {}, + "aspnet50": {}, "aspnetcore50": { "dependencies": { "System.Collections": "4.0.10.0", diff --git a/src/Microsoft.AspNet.TestHost/project.json b/src/Microsoft.AspNet.TestHost/project.json index 5386ddc409..53b6d1f466 100644 --- a/src/Microsoft.AspNet.TestHost/project.json +++ b/src/Microsoft.AspNet.TestHost/project.json @@ -5,7 +5,7 @@ "System.Net.Http": "4.0.0.0" }, "frameworks": { - "net45": { }, + "aspnet50": { }, "aspnetcore50" : { "dependencies": { "System.Collections": "4.0.10.0", diff --git a/test/Microsoft.AspNet.Hosting.Tests/project.json b/test/Microsoft.AspNet.Hosting.Tests/project.json index d60b8d2cb8..7ec2873fb0 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/project.json +++ b/test/Microsoft.AspNet.Hosting.Tests/project.json @@ -5,7 +5,7 @@ "Xunit.KRunner": "1.0.0-*" }, "frameworks": { - "net45": { + "aspnet50": { "dependencies": { "System.Runtime" : "" } diff --git a/test/Microsoft.AspNet.TestHost.Tests/project.json b/test/Microsoft.AspNet.TestHost.Tests/project.json index 60d12ad07b..61635fd5d9 100644 --- a/test/Microsoft.AspNet.TestHost.Tests/project.json +++ b/test/Microsoft.AspNet.TestHost.Tests/project.json @@ -9,7 +9,7 @@ "test": "Xunit.KRunner" }, "frameworks": { - "net45": { + "aspnet50": { "dependencies": { "System.Runtime": "" } From 4b1c1f35528d24cf60bc37448bf4a55d58bb8f7e Mon Sep 17 00:00:00 2001 From: David Fowler Date: Fri, 5 Sep 2014 01:48:12 -0700 Subject: [PATCH 114/987] Updated build.cmd --- build.cmd | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/build.cmd b/build.cmd index 3aaf957583..86ca5bbbf1 100644 --- a/build.cmd +++ b/build.cmd @@ -20,9 +20,9 @@ IF EXIST packages\KoreBuild goto run .nuget\NuGet.exe install Sake -version 0.2 -o packages -ExcludeVersion IF "%SKIP_KRE_INSTALL%"=="1" goto run -CALL packages\KoreBuild\build\kvm upgrade -svr50 -x86 -CALL packages\KoreBuild\build\kvm install default -svrc50 -x86 +CALL packages\KoreBuild\build\kvm upgrade -runtime CLR -x86 +CALL packages\KoreBuild\build\kvm install default -runtime CoreCLR -x86 :run -CALL packages\KoreBuild\build\kvm use default -svr50 -x86 +CALL packages\KoreBuild\build\kvm use default -runtime CLR -x86 packages\Sake\tools\Sake.exe -I packages\KoreBuild\build -f makefile.shade %* From f4953a0b29d373406178b53c1b922628f217cb1a Mon Sep 17 00:00:00 2001 From: David Fowler Date: Fri, 5 Sep 2014 09:06:01 -0700 Subject: [PATCH 115/987] Updated to use the new target framework in project.json --- src/Microsoft.AspNet.Hosting/HostingServices.cs | 4 ++-- .../ContainerMiddleware.cs | 8 ++++---- src/Microsoft.AspNet.TestHost/ResponseStream.cs | 6 +++--- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/Microsoft.AspNet.Hosting/HostingServices.cs b/src/Microsoft.AspNet.Hosting/HostingServices.cs index 91e1ef5f31..29a46304ac 100644 --- a/src/Microsoft.AspNet.Hosting/HostingServices.cs +++ b/src/Microsoft.AspNet.Hosting/HostingServices.cs @@ -63,7 +63,7 @@ namespace Microsoft.AspNet.Hosting if (PlatformHelper.IsMono) { -#if NET45 +#if ASPNET50 yield return describer.Instance(DataProtectionProvider.CreateFromLegacyDpapi()); #endif } @@ -77,4 +77,4 @@ namespace Microsoft.AspNet.Hosting } } } -} \ No newline at end of file +} diff --git a/src/Microsoft.AspNet.RequestContainer/ContainerMiddleware.cs b/src/Microsoft.AspNet.RequestContainer/ContainerMiddleware.cs index 38398d3889..518eac189c 100644 --- a/src/Microsoft.AspNet.RequestContainer/ContainerMiddleware.cs +++ b/src/Microsoft.AspNet.RequestContainer/ContainerMiddleware.cs @@ -16,14 +16,14 @@ // permissions and limitations under the License. using System; -#if NET45 +#if ASPNET50 using System.Runtime.Remoting.Messaging; #endif using System.Threading.Tasks; using Microsoft.AspNet.Builder; using Microsoft.AspNet.Http; using Microsoft.Framework.DependencyInjection; -#if NET45 +#if ASPNET50 using System.Runtime.Remoting; #endif namespace Microsoft.AspNet.RequestContainer @@ -65,7 +65,7 @@ namespace Microsoft.AspNet.RequestContainer private HttpContext AccessRootHttpContext() { -#if NET45 +#if ASPNET50 var handle = CallContext.LogicalGetData(LogicalDataKey) as ObjectHandle; return handle != null ? handle.Unwrap() as HttpContext : null; #else @@ -75,7 +75,7 @@ namespace Microsoft.AspNet.RequestContainer private HttpContext ExchangeRootHttpContext(HttpContext httpContext) { -#if NET45 +#if ASPNET50 var prior = CallContext.LogicalGetData(LogicalDataKey) as ObjectHandle; CallContext.LogicalSetData(LogicalDataKey, new ObjectHandle(httpContext)); return prior != null ? prior.Unwrap() as HttpContext : null; diff --git a/src/Microsoft.AspNet.TestHost/ResponseStream.cs b/src/Microsoft.AspNet.TestHost/ResponseStream.cs index cae4eba46f..64e64c0c64 100644 --- a/src/Microsoft.AspNet.TestHost/ResponseStream.cs +++ b/src/Microsoft.AspNet.TestHost/ResponseStream.cs @@ -1,4 +1,4 @@ -// 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. using System; @@ -161,7 +161,7 @@ namespace Microsoft.AspNet.TestHost _readLock.Release(); } } -#if NET45 +#if ASPNET50 public override IAsyncResult BeginRead(byte[] buffer, int offset, int count, AsyncCallback callback, object state) { // TODO: This option doesn't preserve the state object. @@ -258,7 +258,7 @@ namespace Microsoft.AspNet.TestHost _writeLock.Release(); } } -#if NET45 +#if ASPNET50 public override IAsyncResult BeginWrite(byte[] buffer, int offset, int count, AsyncCallback callback, object state) { Write(buffer, offset, count); From 200f894b5b74788e0b620e774a577a0de77c0138 Mon Sep 17 00:00:00 2001 From: Chris Ross Date: Wed, 10 Sep 2014 10:25:41 -0700 Subject: [PATCH 116/987] Handle IBuilder rename to IApplicationBuilder. --- ...lderFactory.cs => ApplicationBuilderFactory.cs} | 9 ++++----- ...derFactory.cs => IApplicationBuilderFactory.cs} | 5 ++--- src/Microsoft.AspNet.Hosting/HostingContext.cs | 4 ++-- src/Microsoft.AspNet.Hosting/HostingEngine.cs | 4 ++-- src/Microsoft.AspNet.Hosting/HostingServices.cs | 2 +- .../Startup/IStartupLoader.cs | 2 +- .../Startup/IStartupManager.cs | 2 +- .../Startup/NullStartupLoader.cs | 2 +- .../Startup/StartupLoader.cs | 4 ++-- .../Startup/StartupManager.cs | 2 +- .../ContainerExtensions.cs | 14 +++++++------- src/Microsoft.AspNet.TestHost/TestServer.cs | 6 +++--- .../Fakes/Startup.cs | 2 +- .../Fakes/StartupWithServices.cs | 2 +- .../HostingEngineTests.cs | 2 +- .../UseServicesFacts.cs | 4 ++-- .../TestServerTests.cs | 4 ++-- 17 files changed, 34 insertions(+), 36 deletions(-) rename src/Microsoft.AspNet.Hosting/Builder/{BuilderFactory.cs => ApplicationBuilderFactory.cs} (78%) rename src/Microsoft.AspNet.Hosting/Builder/{IBuilderFactory.cs => IApplicationBuilderFactory.cs} (88%) diff --git a/src/Microsoft.AspNet.Hosting/Builder/BuilderFactory.cs b/src/Microsoft.AspNet.Hosting/Builder/ApplicationBuilderFactory.cs similarity index 78% rename from src/Microsoft.AspNet.Hosting/Builder/BuilderFactory.cs rename to src/Microsoft.AspNet.Hosting/Builder/ApplicationBuilderFactory.cs index 01a04d5df5..7b17e587f8 100644 --- a/src/Microsoft.AspNet.Hosting/Builder/BuilderFactory.cs +++ b/src/Microsoft.AspNet.Hosting/Builder/ApplicationBuilderFactory.cs @@ -17,22 +17,21 @@ using System; using Microsoft.AspNet.Builder; -using Microsoft.AspNet.Http; namespace Microsoft.AspNet.Hosting.Builder { - public class BuilderFactory : IBuilderFactory + public class ApplicationBuilderFactory : IApplicationBuilderFactory { private readonly IServiceProvider _serviceProvider; - public BuilderFactory(IServiceProvider serviceProvider) + public ApplicationBuilderFactory(IServiceProvider serviceProvider) { _serviceProvider = serviceProvider; } - public IBuilder CreateBuilder() + public IApplicationBuilder CreateBuilder() { - return new Microsoft.AspNet.Builder.Builder(_serviceProvider); + return new ApplicationBuilder(_serviceProvider); } } } diff --git a/src/Microsoft.AspNet.Hosting/Builder/IBuilderFactory.cs b/src/Microsoft.AspNet.Hosting/Builder/IApplicationBuilderFactory.cs similarity index 88% rename from src/Microsoft.AspNet.Hosting/Builder/IBuilderFactory.cs rename to src/Microsoft.AspNet.Hosting/Builder/IApplicationBuilderFactory.cs index ab9c2d3ba3..dd60b0693a 100644 --- a/src/Microsoft.AspNet.Hosting/Builder/IBuilderFactory.cs +++ b/src/Microsoft.AspNet.Hosting/Builder/IApplicationBuilderFactory.cs @@ -16,12 +16,11 @@ // permissions and limitations under the License. using Microsoft.AspNet.Builder; -using Microsoft.AspNet.Http; namespace Microsoft.AspNet.Hosting.Builder { - public interface IBuilderFactory + public interface IApplicationBuilderFactory { - IBuilder CreateBuilder(); + IApplicationBuilder CreateBuilder(); } } \ No newline at end of file diff --git a/src/Microsoft.AspNet.Hosting/HostingContext.cs b/src/Microsoft.AspNet.Hosting/HostingContext.cs index ea5685e6bb..b3bc2e550c 100644 --- a/src/Microsoft.AspNet.Hosting/HostingContext.cs +++ b/src/Microsoft.AspNet.Hosting/HostingContext.cs @@ -28,11 +28,11 @@ namespace Microsoft.AspNet.Hosting public IServiceProvider Services { get; set; } public IConfiguration Configuration { get; set; } - public IBuilder Builder { get; set; } + public IApplicationBuilder Builder { get; set; } public string ApplicationName { get; set; } public string EnvironmentName { get; set; } - public Action ApplicationStartup { get; set; } + public Action ApplicationStartup { get; set; } public RequestDelegate ApplicationDelegate { get; set; } public string ServerName { get; set; } diff --git a/src/Microsoft.AspNet.Hosting/HostingEngine.cs b/src/Microsoft.AspNet.Hosting/HostingEngine.cs index f921780c8e..7f75c88e5e 100644 --- a/src/Microsoft.AspNet.Hosting/HostingEngine.cs +++ b/src/Microsoft.AspNet.Hosting/HostingEngine.cs @@ -29,13 +29,13 @@ namespace Microsoft.AspNet.Hosting { private readonly IServerManager _serverManager; private readonly IStartupManager _startupManager; - private readonly IBuilderFactory _builderFactory; + private readonly IApplicationBuilderFactory _builderFactory; private readonly IHttpContextFactory _httpContextFactory; public HostingEngine( IServerManager serverManager, IStartupManager startupManager, - IBuilderFactory builderFactory, + IApplicationBuilderFactory builderFactory, IHttpContextFactory httpContextFactory) { _serverManager = serverManager; diff --git a/src/Microsoft.AspNet.Hosting/HostingServices.cs b/src/Microsoft.AspNet.Hosting/HostingServices.cs index 29a46304ac..ec932efaff 100644 --- a/src/Microsoft.AspNet.Hosting/HostingServices.cs +++ b/src/Microsoft.AspNet.Hosting/HostingServices.cs @@ -44,7 +44,7 @@ namespace Microsoft.AspNet.Hosting yield return describer.Transient(); yield return describer.Transient(); - yield return describer.Transient(); + yield return describer.Transient(); yield return describer.Transient(); yield return describer.Transient(); diff --git a/src/Microsoft.AspNet.Hosting/Startup/IStartupLoader.cs b/src/Microsoft.AspNet.Hosting/Startup/IStartupLoader.cs index a6a0741ad7..faba106da5 100644 --- a/src/Microsoft.AspNet.Hosting/Startup/IStartupLoader.cs +++ b/src/Microsoft.AspNet.Hosting/Startup/IStartupLoader.cs @@ -24,7 +24,7 @@ namespace Microsoft.AspNet.Hosting.Startup { public interface IStartupLoader { - Action LoadStartup( + Action LoadStartup( string applicationName, string environmentName, IList diagnosticMessages); diff --git a/src/Microsoft.AspNet.Hosting/Startup/IStartupManager.cs b/src/Microsoft.AspNet.Hosting/Startup/IStartupManager.cs index 1b8b9f19cc..8cdd089054 100644 --- a/src/Microsoft.AspNet.Hosting/Startup/IStartupManager.cs +++ b/src/Microsoft.AspNet.Hosting/Startup/IStartupManager.cs @@ -23,7 +23,7 @@ namespace Microsoft.AspNet.Hosting.Startup { public interface IStartupManager { - Action LoadStartup( + Action LoadStartup( string applicationName, string environmentName); } diff --git a/src/Microsoft.AspNet.Hosting/Startup/NullStartupLoader.cs b/src/Microsoft.AspNet.Hosting/Startup/NullStartupLoader.cs index 559d44d5e2..c40983087a 100644 --- a/src/Microsoft.AspNet.Hosting/Startup/NullStartupLoader.cs +++ b/src/Microsoft.AspNet.Hosting/Startup/NullStartupLoader.cs @@ -31,7 +31,7 @@ namespace Microsoft.AspNet.Hosting.Startup public static IStartupLoader Instance { get; private set; } - public Action LoadStartup( + public Action LoadStartup( string applicationName, string environmentName, IList diagnosticMessages) diff --git a/src/Microsoft.AspNet.Hosting/Startup/StartupLoader.cs b/src/Microsoft.AspNet.Hosting/Startup/StartupLoader.cs index 98aec36c67..cce003a648 100644 --- a/src/Microsoft.AspNet.Hosting/Startup/StartupLoader.cs +++ b/src/Microsoft.AspNet.Hosting/Startup/StartupLoader.cs @@ -38,7 +38,7 @@ namespace Microsoft.AspNet.Hosting.Startup _next = next; } - public Action LoadStartup( + public Action LoadStartup( string applicationName, string environmentName, IList diagnosticMessages) @@ -120,7 +120,7 @@ namespace Microsoft.AspNet.Hosting.Startup for (var index = 0; index != parameterInfos.Length; ++index) { var parameterInfo = parameterInfos[index]; - if (parameterInfo.ParameterType == typeof(IBuilder)) + if (parameterInfo.ParameterType == typeof(IApplicationBuilder)) { parameters[index] = builder; } diff --git a/src/Microsoft.AspNet.Hosting/Startup/StartupManager.cs b/src/Microsoft.AspNet.Hosting/Startup/StartupManager.cs index 8c4bc7b1ff..cc722eafb5 100644 --- a/src/Microsoft.AspNet.Hosting/Startup/StartupManager.cs +++ b/src/Microsoft.AspNet.Hosting/Startup/StartupManager.cs @@ -32,7 +32,7 @@ namespace Microsoft.AspNet.Hosting.Startup _providers = providers; } - public Action LoadStartup( + public Action LoadStartup( string applicationName, string environmentName) { diff --git a/src/Microsoft.AspNet.RequestContainer/ContainerExtensions.cs b/src/Microsoft.AspNet.RequestContainer/ContainerExtensions.cs index 45b7375683..3ae3541481 100644 --- a/src/Microsoft.AspNet.RequestContainer/ContainerExtensions.cs +++ b/src/Microsoft.AspNet.RequestContainer/ContainerExtensions.cs @@ -28,12 +28,12 @@ namespace Microsoft.AspNet.Builder { public static class ContainerExtensions { - public static IBuilder UseMiddleware(this IBuilder builder, params object[] args) + public static IApplicationBuilder UseMiddleware(this IApplicationBuilder builder, params object[] args) { return builder.UseMiddleware(typeof(T), args); } - public static IBuilder UseMiddleware(this IBuilder builder, Type middleware, params object[] args) + public static IApplicationBuilder UseMiddleware(this IApplicationBuilder builder, Type middleware, params object[] args) { // TODO: move this ext method someplace nice return builder.Use(next => @@ -45,24 +45,24 @@ namespace Microsoft.AspNet.Builder }); } - public static IBuilder UseServices(this IBuilder builder) + public static IApplicationBuilder UseServices(this IApplicationBuilder builder) { return builder.UseMiddleware(typeof(ContainerMiddleware)); } - public static IBuilder UseServices(this IBuilder builder, IServiceProvider applicationServices) + public static IApplicationBuilder UseServices(this IApplicationBuilder builder, IServiceProvider applicationServices) { builder.ApplicationServices = applicationServices; return builder.UseMiddleware(typeof(ContainerMiddleware)); } - public static IBuilder UseServices(this IBuilder builder, IEnumerable applicationServices) + public static IApplicationBuilder UseServices(this IApplicationBuilder builder, IEnumerable applicationServices) { return builder.UseServices(services => services.Add(applicationServices)); } - public static IBuilder UseServices(this IBuilder builder, Action configureServices) + public static IApplicationBuilder UseServices(this IApplicationBuilder builder, Action configureServices) { return builder.UseServices(serviceCollection => { @@ -71,7 +71,7 @@ namespace Microsoft.AspNet.Builder }); } - public static IBuilder UseServices(this IBuilder builder, Func configureServices) + public static IApplicationBuilder UseServices(this IApplicationBuilder builder, Func configureServices) { var serviceCollection = new ServiceCollection(); diff --git a/src/Microsoft.AspNet.TestHost/TestServer.cs b/src/Microsoft.AspNet.TestHost/TestServer.cs index b8df467d80..e1e3ac37dd 100644 --- a/src/Microsoft.AspNet.TestHost/TestServer.cs +++ b/src/Microsoft.AspNet.TestHost/TestServer.cs @@ -23,7 +23,7 @@ namespace Microsoft.AspNet.TestHost private IDisposable _appInstance; private bool _disposed = false; - public TestServer(IConfiguration config, IServiceProvider serviceProvider, Action appStartup) + public TestServer(IConfiguration config, IServiceProvider serviceProvider, Action appStartup) { var env = serviceProvider.GetService(); if (env == null) @@ -44,12 +44,12 @@ namespace Microsoft.AspNet.TestHost _appInstance = engine.Start(hostContext); } - public static TestServer Create(Action app) + public static TestServer Create(Action app) { return Create(provider: CallContextServiceLocator.Locator.ServiceProvider, app: app); } - public static TestServer Create(IServiceProvider provider, Action app) + public static TestServer Create(IServiceProvider provider, Action app) { var collection = new ServiceCollection(); var hostingServices = HostingServices.GetDefaultServices(); diff --git a/test/Microsoft.AspNet.Hosting.Tests/Fakes/Startup.cs b/test/Microsoft.AspNet.Hosting.Tests/Fakes/Startup.cs index da91cbeca0..fb05a63b60 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/Fakes/Startup.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/Fakes/Startup.cs @@ -26,7 +26,7 @@ namespace Microsoft.AspNet.Hosting.Fakes { } - public void Configure(IBuilder builder) + public void Configure(IApplicationBuilder builder) { } } diff --git a/test/Microsoft.AspNet.Hosting.Tests/Fakes/StartupWithServices.cs b/test/Microsoft.AspNet.Hosting.Tests/Fakes/StartupWithServices.cs index 166b4ff5c5..c13ec7eb7f 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/Fakes/StartupWithServices.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/Fakes/StartupWithServices.cs @@ -29,7 +29,7 @@ namespace Microsoft.AspNet.Hosting.Fakes _fakeStartupCallback = fakeStartupCallback; } - public void Configure(IBuilder builder, IFakeStartupCallback fakeStartupCallback2) + public void Configure(IApplicationBuilder builder, IFakeStartupCallback fakeStartupCallback2) { _fakeStartupCallback.ConfigurationMethodCalled(this); fakeStartupCallback2.ConfigurationMethodCalled(this); diff --git a/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs b/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs index 96915f09fd..6091c7ae12 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs @@ -70,7 +70,7 @@ namespace Microsoft.AspNet.Hosting Assert.Equal(1, _startInstances[0].DisposeCalls); } - public void Initialize(IBuilder builder) + public void Initialize(IApplicationBuilder builder) { } diff --git a/test/Microsoft.AspNet.Hosting.Tests/UseServicesFacts.cs b/test/Microsoft.AspNet.Hosting.Tests/UseServicesFacts.cs index df88e1e855..3da2beebdb 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/UseServicesFacts.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/UseServicesFacts.cs @@ -13,7 +13,7 @@ namespace Microsoft.AspNet.Hosting.Tests public void OptionsAccessorCanBeResolvedAfterCallingUseServicesWithAction() { var baseServiceProvider = new ServiceCollection().BuildServiceProvider(); - var builder = new Microsoft.AspNet.Builder.Builder(baseServiceProvider); + var builder = new ApplicationBuilder(baseServiceProvider); builder.UseServices(serviceCollection => { }); @@ -26,7 +26,7 @@ namespace Microsoft.AspNet.Hosting.Tests public void OptionsAccessorCanBeResolvedAfterCallingUseServicesWithFunc() { var baseServiceProvider = new ServiceCollection().BuildServiceProvider(); - var builder = new Microsoft.AspNet.Builder.Builder(baseServiceProvider); + var builder = new ApplicationBuilder(baseServiceProvider); IServiceProvider serviceProvider = null; builder.UseServices(serviceCollection => diff --git a/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs b/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs index 5f27cc89f1..2a5ee973d2 100644 --- a/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs +++ b/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs @@ -107,7 +107,7 @@ namespace Microsoft.AspNet.TestHost public class Startup { - public void Configuration(IBuilder builder) + public void Configuration(IApplicationBuilder builder) { builder.Run(ctx => ctx.Response.WriteAsync("Startup")); } @@ -115,7 +115,7 @@ namespace Microsoft.AspNet.TestHost public class AnotherStartup { - public void Configuration(IBuilder builder) + public void Configuration(IApplicationBuilder builder) { builder.Run(ctx => ctx.Response.WriteAsync("Another Startup")); } From 64455620a02bcf972e729a3f78f4716cbf033b90 Mon Sep 17 00:00:00 2001 From: Wei Wang Date: Wed, 10 Sep 2014 12:31:50 -0700 Subject: [PATCH 117/987] React to renaming TargetFramework to RuntimeFramework --- .../TestApplicationEnvironment.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/Microsoft.AspNet.TestHost.Tests/TestApplicationEnvironment.cs b/test/Microsoft.AspNet.TestHost.Tests/TestApplicationEnvironment.cs index a81d1da0e8..de715c253c 100644 --- a/test/Microsoft.AspNet.TestHost.Tests/TestApplicationEnvironment.cs +++ b/test/Microsoft.AspNet.TestHost.Tests/TestApplicationEnvironment.cs @@ -29,7 +29,7 @@ namespace Microsoft.AspNet.TestHost get { return "Test"; } } - public FrameworkName TargetFramework + public FrameworkName RuntimeFramework { get { return new FrameworkName(".NETFramework", new Version(4, 5)); } } From 8a66871139d19b999c4bd07f2f14685c141119cb Mon Sep 17 00:00:00 2001 From: Chris Ross Date: Thu, 11 Sep 2014 12:32:24 -0700 Subject: [PATCH 118/987] #71 - Create IHostingEnvironment. --- .../HostingEnvironment.cs | 12 ++++++++ .../{Utilities.cs => HostingUtilities.cs} | 19 +++++++++++- .../IHostingEnvironment.cs | 15 ++++++++++ src/Microsoft.AspNet.Hosting/Program.cs | 26 ++++++++--------- .../Server/ServerManager.cs | 2 +- src/Microsoft.AspNet.Hosting/project.json | 1 + src/Microsoft.AspNet.TestHost/TestServer.cs | 29 +++++++++++-------- .../HostingUtilitiesTests.cs | 17 +++++++++++ .../project.json | 3 +- .../TestServerTests.cs | 12 ++++++++ .../project.json | 3 +- 11 files changed, 110 insertions(+), 29 deletions(-) create mode 100644 src/Microsoft.AspNet.Hosting/HostingEnvironment.cs rename src/Microsoft.AspNet.Hosting/{Utilities.cs => HostingUtilities.cs} (66%) create mode 100644 src/Microsoft.AspNet.Hosting/IHostingEnvironment.cs create mode 100644 test/Microsoft.AspNet.Hosting.Tests/HostingUtilitiesTests.cs diff --git a/src/Microsoft.AspNet.Hosting/HostingEnvironment.cs b/src/Microsoft.AspNet.Hosting/HostingEnvironment.cs new file mode 100644 index 0000000000..3881faa333 --- /dev/null +++ b/src/Microsoft.AspNet.Hosting/HostingEnvironment.cs @@ -0,0 +1,12 @@ +// 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. + +namespace Microsoft.AspNet.Hosting +{ + public class HostingEnvironment : IHostingEnvironment + { + public string EnvironmentName { get; set; } + + public string WebRoot { get; set; } + } +} \ No newline at end of file diff --git a/src/Microsoft.AspNet.Hosting/Utilities.cs b/src/Microsoft.AspNet.Hosting/HostingUtilities.cs similarity index 66% rename from src/Microsoft.AspNet.Hosting/Utilities.cs rename to src/Microsoft.AspNet.Hosting/HostingUtilities.cs index c1795d0ab1..873fd87f8c 100644 --- a/src/Microsoft.AspNet.Hosting/Utilities.cs +++ b/src/Microsoft.AspNet.Hosting/HostingUtilities.cs @@ -16,10 +16,12 @@ // permissions and limitations under the License. using System; +using System.IO; +using Microsoft.Framework.ConfigurationModel; namespace Microsoft.AspNet.Hosting { - internal static class Utilities + public static class HostingUtilities { internal static Tuple SplitTypeName(string identifier) { @@ -33,5 +35,20 @@ namespace Microsoft.AspNet.Hosting } return new Tuple(typeName, assemblyName); } + + public static string GetWebRoot(string applicationBasePath) + { + try + { + var config = new Configuration(); + config.AddJsonFile(Path.Combine(applicationBasePath, "project.json")); + var webroot = config.Get("webroot") ?? string.Empty; + return Path.GetFullPath(Path.Combine(applicationBasePath, webroot)); + } + catch (Exception) + { + return applicationBasePath; + } + } } } diff --git a/src/Microsoft.AspNet.Hosting/IHostingEnvironment.cs b/src/Microsoft.AspNet.Hosting/IHostingEnvironment.cs new file mode 100644 index 0000000000..d510d0ba23 --- /dev/null +++ b/src/Microsoft.AspNet.Hosting/IHostingEnvironment.cs @@ -0,0 +1,15 @@ +// 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.Framework.Runtime; + +namespace Microsoft.AspNet.Hosting +{ + [AssemblyNeutral] + public interface IHostingEnvironment + { + string EnvironmentName { get; } + + string WebRoot { get; } + } +} \ No newline at end of file diff --git a/src/Microsoft.AspNet.Hosting/Program.cs b/src/Microsoft.AspNet.Hosting/Program.cs index b1f694e018..6afeacd0ee 100644 --- a/src/Microsoft.AspNet.Hosting/Program.cs +++ b/src/Microsoft.AspNet.Hosting/Program.cs @@ -29,6 +29,8 @@ namespace Microsoft.AspNet.Hosting public class Program { private const string HostingIniFile = "Microsoft.AspNet.Hosting.ini"; + private const string DefaultEnvironmentName = "Development"; + private const string EnvironmentKey = "KRE_ENV"; private readonly IServiceProvider _serviceProvider; @@ -47,33 +49,31 @@ namespace Microsoft.AspNet.Hosting config.AddEnvironmentVariables(); config.AddCommandLine(args); + var appEnv = _serviceProvider.GetService(); + + var hostingEnv = new HostingEnvironment() + { + EnvironmentName = config.Get(EnvironmentKey) ?? DefaultEnvironmentName, + WebRoot = HostingUtilities.GetWebRoot(appEnv.ApplicationBasePath), + }; + var serviceCollection = new ServiceCollection(); serviceCollection.Add(HostingServices.GetDefaultServices(config)); + serviceCollection.AddInstance(hostingEnv); var services = serviceCollection.BuildServiceProvider(_serviceProvider); - var appEnvironment = _serviceProvider.GetService(); - var context = new HostingContext() { Services = services, Configuration = config, ServerName = config.Get("server"), // TODO: Key names ApplicationName = config.Get("app") // TODO: Key names - ?? appEnvironment.ApplicationName, - EnvironmentName = config.Get("env") ?? "Development" + ?? appEnv.ApplicationName, + EnvironmentName = hostingEnv.EnvironmentName, }; var engine = services.GetService(); - if (engine == null) - { - throw new Exception("TODO: IHostingEngine service not available exception"); - } - var appShutdownService = _serviceProvider.GetService(); - if (appShutdownService == null) - { - throw new Exception("TODO: IApplicationShutdown service not available"); - } var shutdownHandle = new ManualResetEvent(false); var serverShutdown = engine.Start(context); diff --git a/src/Microsoft.AspNet.Hosting/Server/ServerManager.cs b/src/Microsoft.AspNet.Hosting/Server/ServerManager.cs index 899e695fc0..726e6746cc 100644 --- a/src/Microsoft.AspNet.Hosting/Server/ServerManager.cs +++ b/src/Microsoft.AspNet.Hosting/Server/ServerManager.cs @@ -38,7 +38,7 @@ namespace Microsoft.AspNet.Hosting.Server throw new ArgumentException(string.Empty, "serverFactoryIdentifier"); } - var nameParts = Utilities.SplitTypeName(serverFactoryIdentifier); + var nameParts = HostingUtilities.SplitTypeName(serverFactoryIdentifier); string typeName = nameParts.Item1; string assemblyName = nameParts.Item2; diff --git a/src/Microsoft.AspNet.Hosting/project.json b/src/Microsoft.AspNet.Hosting/project.json index 34fc3ef4fe..de0e1d5305 100644 --- a/src/Microsoft.AspNet.Hosting/project.json +++ b/src/Microsoft.AspNet.Hosting/project.json @@ -6,6 +6,7 @@ "Microsoft.AspNet.PipelineCore": "1.0.0-*", "Microsoft.AspNet.Security.DataProtection": "1.0.0-*", "Microsoft.Framework.ConfigurationModel": "1.0.0-*", + "Microsoft.Framework.ConfigurationModel.Json": "1.0.0-*", "Microsoft.Framework.DependencyInjection": "1.0.0-*", "Microsoft.Framework.Logging": "1.0.0-*", "Microsoft.Framework.Runtime.Interfaces": "1.0.0-*" diff --git a/src/Microsoft.AspNet.TestHost/TestServer.cs b/src/Microsoft.AspNet.TestHost/TestServer.cs index e1e3ac37dd..dee516dd2d 100644 --- a/src/Microsoft.AspNet.TestHost/TestServer.cs +++ b/src/Microsoft.AspNet.TestHost/TestServer.cs @@ -17,7 +17,8 @@ namespace Microsoft.AspNet.TestHost { public class TestServer : IServerFactory, IDisposable { - private static readonly string ServerName = typeof(TestServer).FullName; + private const string DefaultEnvironmentName = "Development"; + private const string ServerName = nameof(TestServer); private static readonly ServerInformation ServerInfo = new ServerInformation(); private Func _appDelegate; private IDisposable _appInstance; @@ -25,15 +26,11 @@ namespace Microsoft.AspNet.TestHost public TestServer(IConfiguration config, IServiceProvider serviceProvider, Action appStartup) { - var env = serviceProvider.GetService(); - if (env == null) - { - throw new ArgumentException("IApplicationEnvironment couldn't be resolved.", "serviceProvider"); - } + var appEnv = serviceProvider.GetService(); HostingContext hostContext = new HostingContext() { - ApplicationName = env.ApplicationName, + ApplicationName = appEnv.ApplicationName, Configuration = config, ServerFactory = this, Services = serviceProvider, @@ -51,14 +48,22 @@ namespace Microsoft.AspNet.TestHost public static TestServer Create(IServiceProvider provider, Action app) { + var appEnv = provider.GetService(); + + var hostingEnv = new HostingEnvironment() + { + EnvironmentName = DefaultEnvironmentName, + WebRoot = HostingUtilities.GetWebRoot(appEnv.ApplicationBasePath), + }; + var collection = new ServiceCollection(); - var hostingServices = HostingServices.GetDefaultServices(); + collection.Add(HostingServices.GetDefaultServices()); + collection.AddInstance(hostingEnv); + + var appServices = collection.BuildServiceProvider(provider); var config = new Configuration(); - collection.Add(hostingServices); - - var serviceProvider = collection.BuildServiceProvider(provider); - return new TestServer(config, serviceProvider, app); + return new TestServer(config, appServices, app); } public HttpMessageHandler CreateHandler() diff --git a/test/Microsoft.AspNet.Hosting.Tests/HostingUtilitiesTests.cs b/test/Microsoft.AspNet.Hosting.Tests/HostingUtilitiesTests.cs new file mode 100644 index 0000000000..08daee6c9b --- /dev/null +++ b/test/Microsoft.AspNet.Hosting.Tests/HostingUtilitiesTests.cs @@ -0,0 +1,17 @@ +// 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 Xunit; + +namespace Microsoft.AspNet.Hosting.Tests +{ + public class HostingUtilitiesTests + { + [Fact] + public void ReadWebRootFromProjectJson() + { + var root = HostingUtilities.GetWebRoot("."); + Assert.True(root.EndsWith("testroot")); + } + } +} \ No newline at end of file diff --git a/test/Microsoft.AspNet.Hosting.Tests/project.json b/test/Microsoft.AspNet.Hosting.Tests/project.json index 7ec2873fb0..2233a0fa4c 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/project.json +++ b/test/Microsoft.AspNet.Hosting.Tests/project.json @@ -13,5 +13,6 @@ }, "commands": { "test": "Xunit.KRunner" - } + }, + "webroot" : "testroot" } diff --git a/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs b/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs index 2a5ee973d2..025d3a7a21 100644 --- a/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs +++ b/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs @@ -2,10 +2,12 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.IO; using System.Net; using System.Net.Http; using System.Threading.Tasks; using Microsoft.AspNet.Builder; +using Microsoft.AspNet.Hosting; using Microsoft.AspNet.Http; using Microsoft.Framework.DependencyInjection; using Microsoft.Framework.DependencyInjection.Fallback; @@ -54,6 +56,16 @@ namespace Microsoft.AspNet.TestHost Assert.Equal("CreateInvokesApp", result); } + [Fact] + public void WebRootCanBeResolvedFromProjectJson() + { + TestServer server = TestServer.Create(app => + { + var env = app.ApplicationServices.GetService(); + Assert.Equal(Path.GetFullPath("testroot"), env.WebRoot); + }); + } + [Fact] public async Task DisposeStreamIgnored() { diff --git a/test/Microsoft.AspNet.TestHost.Tests/project.json b/test/Microsoft.AspNet.TestHost.Tests/project.json index 61635fd5d9..d071d1486b 100644 --- a/test/Microsoft.AspNet.TestHost.Tests/project.json +++ b/test/Microsoft.AspNet.TestHost.Tests/project.json @@ -14,5 +14,6 @@ "System.Runtime": "" } } - } + }, + "webroot" : "testroot" } From c47d6d0c78520ec04c1e5b5cc35ee2afb851e5c2 Mon Sep 17 00:00:00 2001 From: Chris Ross Date: Mon, 15 Sep 2014 14:54:56 -0700 Subject: [PATCH 119/987] #74 - Parse the project.json file with Newtonsoft directly. --- .../HostingUtilities.cs | 23 +++++++++++-------- src/Microsoft.AspNet.Hosting/project.json | 4 ++-- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/src/Microsoft.AspNet.Hosting/HostingUtilities.cs b/src/Microsoft.AspNet.Hosting/HostingUtilities.cs index 873fd87f8c..2f1eeb6826 100644 --- a/src/Microsoft.AspNet.Hosting/HostingUtilities.cs +++ b/src/Microsoft.AspNet.Hosting/HostingUtilities.cs @@ -17,7 +17,8 @@ using System; using System.IO; -using Microsoft.Framework.ConfigurationModel; +using Newtonsoft.Json; +using Newtonsoft.Json.Linq; namespace Microsoft.AspNet.Hosting { @@ -38,17 +39,19 @@ namespace Microsoft.AspNet.Hosting public static string GetWebRoot(string applicationBasePath) { - try + var webroot = applicationBasePath; + using (var stream = File.OpenRead(Path.Combine(applicationBasePath, "project.json"))) { - var config = new Configuration(); - config.AddJsonFile(Path.Combine(applicationBasePath, "project.json")); - var webroot = config.Get("webroot") ?? string.Empty; - return Path.GetFullPath(Path.Combine(applicationBasePath, webroot)); - } - catch (Exception) - { - return applicationBasePath; + using (var reader = new JsonTextReader(new StreamReader(stream))) + { + var project = JObject.Load(reader); + if (project.TryGetValue("webroot", out var token)) + { + webroot = Path.Combine(applicationBasePath, token.ToString()); + } + } } + return Path.GetFullPath(webroot); } } } diff --git a/src/Microsoft.AspNet.Hosting/project.json b/src/Microsoft.AspNet.Hosting/project.json index de0e1d5305..bcf21cbd0b 100644 --- a/src/Microsoft.AspNet.Hosting/project.json +++ b/src/Microsoft.AspNet.Hosting/project.json @@ -6,10 +6,10 @@ "Microsoft.AspNet.PipelineCore": "1.0.0-*", "Microsoft.AspNet.Security.DataProtection": "1.0.0-*", "Microsoft.Framework.ConfigurationModel": "1.0.0-*", - "Microsoft.Framework.ConfigurationModel.Json": "1.0.0-*", "Microsoft.Framework.DependencyInjection": "1.0.0-*", "Microsoft.Framework.Logging": "1.0.0-*", - "Microsoft.Framework.Runtime.Interfaces": "1.0.0-*" + "Microsoft.Framework.Runtime.Interfaces": "1.0.0-*", + "Newtonsoft.Json": "6.0.4" }, "frameworks": { "aspnet50": {}, From 425e2c55274744df7b5d83a39da4a1e0da916852 Mon Sep 17 00:00:00 2001 From: Pranav K Date: Wed, 17 Sep 2014 09:57:51 -0700 Subject: [PATCH 120/987] Updating release NuGet.config --- NuGet.Config | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/NuGet.Config b/NuGet.Config index f41e9c631d..1ce6b9e257 100644 --- a/NuGet.Config +++ b/NuGet.Config @@ -1,7 +1,7 @@ - + - + From 0c6dd83ac27d661f057db8460837605e99ebadca Mon Sep 17 00:00:00 2001 From: Pranav K Date: Wed, 17 Sep 2014 09:57:53 -0700 Subject: [PATCH 121/987] Updating dev NuGet.config --- NuGet.Config | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/NuGet.Config b/NuGet.Config index 1ce6b9e257..f41e9c631d 100644 --- a/NuGet.Config +++ b/NuGet.Config @@ -1,7 +1,7 @@ - + - + From 7574378d37891d1be753f99e79ccead0dc3c5788 Mon Sep 17 00:00:00 2001 From: Pranav K Date: Wed, 1 Oct 2014 14:45:04 -0700 Subject: [PATCH 122/987] Removing declaration expressions --- src/Microsoft.AspNet.Hosting/HostingUtilities.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Microsoft.AspNet.Hosting/HostingUtilities.cs b/src/Microsoft.AspNet.Hosting/HostingUtilities.cs index 2f1eeb6826..946e3c9613 100644 --- a/src/Microsoft.AspNet.Hosting/HostingUtilities.cs +++ b/src/Microsoft.AspNet.Hosting/HostingUtilities.cs @@ -45,7 +45,8 @@ namespace Microsoft.AspNet.Hosting using (var reader = new JsonTextReader(new StreamReader(stream))) { var project = JObject.Load(reader); - if (project.TryGetValue("webroot", out var token)) + JToken token; + if (project.TryGetValue("webroot", out token)) { webroot = Path.Combine(applicationBasePath, token.ToString()); } From 07ccfe880bc2933a9e1c87e797469a95f83a4268 Mon Sep 17 00:00:00 2001 From: David Fowler Date: Sun, 5 Oct 2014 04:59:24 -0700 Subject: [PATCH 123/987] Fixup references --- src/Microsoft.AspNet.Hosting/project.json | 58 +++++++++---------- src/Microsoft.AspNet.TestHost/project.json | 46 ++++++++------- .../project.json | 28 ++++----- .../project.json | 30 +++++----- 4 files changed, 79 insertions(+), 83 deletions(-) diff --git a/src/Microsoft.AspNet.Hosting/project.json b/src/Microsoft.AspNet.Hosting/project.json index bcf21cbd0b..143ab70d0f 100644 --- a/src/Microsoft.AspNet.Hosting/project.json +++ b/src/Microsoft.AspNet.Hosting/project.json @@ -1,32 +1,32 @@ { - "version": "1.0.0-*", - "dependencies": { - "Microsoft.AspNet.FeatureModel": "1.0.0-*", - "Microsoft.AspNet.Http": "1.0.0-*", - "Microsoft.AspNet.PipelineCore": "1.0.0-*", - "Microsoft.AspNet.Security.DataProtection": "1.0.0-*", - "Microsoft.Framework.ConfigurationModel": "1.0.0-*", - "Microsoft.Framework.DependencyInjection": "1.0.0-*", - "Microsoft.Framework.Logging": "1.0.0-*", - "Microsoft.Framework.Runtime.Interfaces": "1.0.0-*", - "Newtonsoft.Json": "6.0.4" - }, - "frameworks": { - "aspnet50": {}, - "aspnetcore50": { - "dependencies": { - "System.Collections": "4.0.10.0", - "System.ComponentModel": "4.0.0.0", - "System.Console": "4.0.0.0", - "System.Diagnostics.Debug": "4.0.10.0", - "System.IO": "4.0.10.0", - "System.Linq": "4.0.0.0", - "System.Reflection": "4.0.10.0", - "System.Runtime": "4.0.20.0", - "System.Runtime.Extensions": "4.0.10.0", - "System.Threading": "4.0.0.0", - "System.Threading.Tasks": "4.0.10.0" - } + "version": "1.0.0-*", + "dependencies": { + "Microsoft.AspNet.FeatureModel": "1.0.0-*", + "Microsoft.AspNet.Http": "1.0.0-*", + "Microsoft.AspNet.PipelineCore": "1.0.0-*", + "Microsoft.AspNet.Security.DataProtection": "1.0.0-*", + "Microsoft.Framework.ConfigurationModel": "1.0.0-*", + "Microsoft.Framework.DependencyInjection": "1.0.0-*", + "Microsoft.Framework.Logging": "1.0.0-*", + "Microsoft.Framework.Runtime.Interfaces": { "version": "1.0.0-*", "type": "build" }, + "Newtonsoft.Json": "6.0.4" + }, + "frameworks": { + "aspnet50": { }, + "aspnetcore50": { + "dependencies": { + "System.Collections": "4.0.10.0", + "System.ComponentModel": "4.0.0.0", + "System.Console": "4.0.0.0", + "System.Diagnostics.Debug": "4.0.10.0", + "System.IO": "4.0.10.0", + "System.Linq": "4.0.0.0", + "System.Reflection": "4.0.10.0", + "System.Runtime": "4.0.20.0", + "System.Runtime.Extensions": "4.0.10.0", + "System.Threading": "4.0.0.0", + "System.Threading.Tasks": "4.0.10.0" + } + } } - } } diff --git a/src/Microsoft.AspNet.TestHost/project.json b/src/Microsoft.AspNet.TestHost/project.json index 53b6d1f466..0364f0bf2c 100644 --- a/src/Microsoft.AspNet.TestHost/project.json +++ b/src/Microsoft.AspNet.TestHost/project.json @@ -1,25 +1,29 @@ { - "version" : "1.0.0-*", - "dependencies": { - "Microsoft.AspNet.Hosting": "", - "System.Net.Http": "4.0.0.0" - }, - "frameworks": { - "aspnet50": { }, - "aspnetcore50" : { - "dependencies": { - "System.Collections": "4.0.10.0", - "System.ComponentModel": "4.0.0.0", - "System.Globalization": "4.0.10.0", - "System.Linq": "4.0.0.0", - "System.Reflection": "4.0.10.0", - "System.Runtime": "4.0.20.0", - "System.Runtime.Extensions": "4.0.10.0", - "System.Runtime.Serialization.Primitives": "4.0.0.0", - "System.Threading": "4.0.0.0", - "System.Threading.Tasks": "4.0.10.0", - "System.Threading.Thread": "4.0.0.0" + "version": "1.0.0-*", + "dependencies": { + "Microsoft.AspNet.Hosting": "1.0.0-*" + }, + "frameworks": { + "aspnet50": { + "frameworkAssemblies": { + "System.Net.Http": "4.0.0.0" + } + }, + "aspnetcore50": { + "dependencies": { + "System.Collections": "4.0.10.0", + "System.ComponentModel": "4.0.0.0", + "System.Globalization": "4.0.10.0", + "System.Linq": "4.0.0.0", + "System.Reflection": "4.0.10.0", + "System.Runtime": "4.0.20.0", + "System.Runtime.Extensions": "4.0.10.0", + "System.Runtime.Serialization.Primitives": "4.0.0.0", + "System.Threading": "4.0.0.0", + "System.Threading.Tasks": "4.0.10.0", + "System.Threading.Thread": "4.0.0.0", + "System.Net.Http": "4.0.0.0" + } } } - } } diff --git a/test/Microsoft.AspNet.Hosting.Tests/project.json b/test/Microsoft.AspNet.Hosting.Tests/project.json index 2233a0fa4c..5c8c65cacf 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/project.json +++ b/test/Microsoft.AspNet.Hosting.Tests/project.json @@ -1,18 +1,14 @@ { - "dependencies": { - "Microsoft.AspNet.Hosting": "", - "Microsoft.AspNet.RequestContainer": "", - "Xunit.KRunner": "1.0.0-*" - }, - "frameworks": { - "aspnet50": { - "dependencies": { - "System.Runtime" : "" - } - } - }, - "commands": { - "test": "Xunit.KRunner" - }, - "webroot" : "testroot" + "dependencies": { + "Microsoft.AspNet.Hosting": "1.0.0-*", + "Microsoft.AspNet.RequestContainer": "1.0.0-*", + "Xunit.KRunner": "1.0.0-*" + }, + "frameworks": { + "aspnet50": { } + }, + "commands": { + "test": "Xunit.KRunner" + }, + "webroot": "testroot" } diff --git a/test/Microsoft.AspNet.TestHost.Tests/project.json b/test/Microsoft.AspNet.TestHost.Tests/project.json index d071d1486b..b9d539b2fa 100644 --- a/test/Microsoft.AspNet.TestHost.Tests/project.json +++ b/test/Microsoft.AspNet.TestHost.Tests/project.json @@ -1,19 +1,15 @@ { - "dependencies": { - "Microsoft.AspNet.Hosting": "", - "Microsoft.AspNet.TestHost": "", - "Microsoft.Framework.Runtime.Interfaces":"1.0.0-*", - "Xunit.KRunner": "1.0.0-*" - }, - "commands": { - "test": "Xunit.KRunner" - }, - "frameworks": { - "aspnet50": { - "dependencies": { - "System.Runtime": "" - } - } - }, - "webroot" : "testroot" + "dependencies": { + "Microsoft.AspNet.Hosting": "1.0.0-*", + "Microsoft.AspNet.TestHost": "1.0.0-*", + "Microsoft.Framework.Runtime.Interfaces": "1.0.0-*", + "Xunit.KRunner": "1.0.0-*" + }, + "commands": { + "test": "Xunit.KRunner" + }, + "frameworks": { + "aspnet50": { } + }, + "webroot": "testroot" } From 78cb314dd2073516d2337d94adae01f10e06d2c2 Mon Sep 17 00:00:00 2001 From: shhsu Date: Mon, 6 Oct 2014 09:28:18 -0700 Subject: [PATCH 124/987] Activator change requires TypeActivator to be singlton --- src/Microsoft.AspNet.Hosting/HostingServices.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Microsoft.AspNet.Hosting/HostingServices.cs b/src/Microsoft.AspNet.Hosting/HostingServices.cs index ec932efaff..a90b3232bc 100644 --- a/src/Microsoft.AspNet.Hosting/HostingServices.cs +++ b/src/Microsoft.AspNet.Hosting/HostingServices.cs @@ -47,7 +47,7 @@ namespace Microsoft.AspNet.Hosting yield return describer.Transient(); yield return describer.Transient(); - yield return describer.Transient(); + yield return describer.Singleton(); yield return describer.Instance(new ApplicationLifetime()); From 53eea70c067e47763f3cbf3f9039116f77ed62fa Mon Sep 17 00:00:00 2001 From: Hao Kung Date: Fri, 3 Oct 2014 18:23:50 -0700 Subject: [PATCH 125/987] Startup: Call ConfigureServices if exists --- .../Startup/StartupLoader.cs | 118 +++++++++++------- src/Microsoft.AspNet.Hosting/project.json | 1 + .../Fakes/FakeOptions.cs | 25 ++++ .../Fakes/Startup.cs | 34 +++++ .../Fakes/StartupNoServices.cs | 34 +++++ .../StartupManagerTests.cs | 46 +++++++ 6 files changed, 214 insertions(+), 44 deletions(-) create mode 100644 test/Microsoft.AspNet.Hosting.Tests/Fakes/FakeOptions.cs create mode 100644 test/Microsoft.AspNet.Hosting.Tests/Fakes/StartupNoServices.cs diff --git a/src/Microsoft.AspNet.Hosting/Startup/StartupLoader.cs b/src/Microsoft.AspNet.Hosting/Startup/StartupLoader.cs index cce003a648..c87a47cafc 100644 --- a/src/Microsoft.AspNet.Hosting/Startup/StartupLoader.cs +++ b/src/Microsoft.AspNet.Hosting/Startup/StartupLoader.cs @@ -20,8 +20,9 @@ using System.Collections.Generic; using System.Linq; using System.Reflection; using Microsoft.AspNet.Builder; -using Microsoft.AspNet.Http; using Microsoft.Framework.DependencyInjection; +using Microsoft.Framework.DependencyInjection.Fallback; +using Microsoft.Framework.OptionsModel; namespace Microsoft.AspNet.Hosting.Startup { @@ -38,6 +39,66 @@ namespace Microsoft.AspNet.Hosting.Startup _next = next; } + private MethodInfo FindMethod(Type startupType, string methodName, string environmentName, Type returnType = null, bool required = true) + { + var methodNameWithEnv = methodName + environmentName; + var methodInfo = startupType.GetTypeInfo().GetDeclaredMethod(methodNameWithEnv) + ?? startupType.GetTypeInfo().GetDeclaredMethod(methodName); + if (methodInfo == null) + { + if (required) + { + throw new Exception(string.Format("TODO: {0} or {1} method not found", + methodNameWithEnv, + methodName)); + + } + return null; + } + + if (returnType != null && methodInfo.ReturnType != returnType) + { + throw new Exception(string.Format("TODO: {0} method does not return " + returnType.Name, + methodInfo.Name)); + } + + return methodInfo; + } + + private void Invoke(MethodInfo methodInfo, object instance, IApplicationBuilder builder, IServiceCollection services = null) + { + var parameterInfos = methodInfo.GetParameters(); + var parameters = new object[parameterInfos.Length]; + for (var index = 0; index != parameterInfos.Length; ++index) + { + var parameterInfo = parameterInfos[index]; + if (parameterInfo.ParameterType == typeof(IApplicationBuilder)) + { + parameters[index] = builder; + } + else if (services != null && parameterInfo.ParameterType == typeof(IServiceCollection)) + { + parameters[index] = services; + } + else + { + try + { + parameters[index] = _services.GetService(parameterInfo.ParameterType); + } + catch (Exception) + { + throw new Exception(string.Format( + "TODO: Unable to resolve service for {0} method {1} {2}", + methodInfo.Name, + parameterInfo.Name, + parameterInfo.ParameterType.FullName)); + } + } + } + methodInfo.Invoke(instance, parameters); + } + public Action LoadStartup( string applicationName, string environmentName, @@ -81,65 +142,34 @@ namespace Microsoft.AspNet.Hosting.Startup if (type == null) { - throw new Exception(String.Format("TODO: {0} or {1} class not found in assembly {2}", + throw new Exception(String.Format("TODO: {0} or {1} class not found in assembly {2}", startupName1, startupName2, applicationName)); } - var configureMethod1 = "Configure" + environmentName; - var configureMethod2 = "Configure"; - var methodInfo = type.GetTypeInfo().GetDeclaredMethod(configureMethod1); - if (methodInfo == null) - { - methodInfo = type.GetTypeInfo().GetDeclaredMethod(configureMethod2); - } - if (methodInfo == null) - { - throw new Exception(string.Format("TODO: {0} or {1} method not found", - configureMethod1, - configureMethod2)); - } - - if (methodInfo.ReturnType != typeof(void)) - { - throw new Exception(string.Format("TODO: {0} method isn't void-returning.", - methodInfo.Name)); - } + var configureMethod = FindMethod(type, "Configure", environmentName, typeof(void), required: true); + // TODO: accept IServiceProvider method as well? + var servicesMethod = FindMethod(type, "ConfigureServices", environmentName, typeof(void), required: false); object instance = null; - if (!methodInfo.IsStatic) + if (!configureMethod.IsStatic || (servicesMethod != null && !servicesMethod.IsStatic)) { instance = ActivatorUtilities.GetServiceOrCreateInstance(_services, type); } - return builder => { - var parameterInfos = methodInfo.GetParameters(); - var parameters = new object[parameterInfos.Length]; - for (var index = 0; index != parameterInfos.Length; ++index) + if (servicesMethod != null) { - var parameterInfo = parameterInfos[index]; - if (parameterInfo.ParameterType == typeof(IApplicationBuilder)) + var services = new ServiceCollection(); + services.Add(OptionsServices.GetDefaultServices()); + Invoke(servicesMethod, instance, builder, services); + if (builder != null) { - parameters[index] = builder; - } - else - { - try - { - parameters[index] = _services.GetService(parameterInfo.ParameterType); - } - catch (Exception ex) - { - throw new Exception(string.Format( - "TODO: Unable to resolve service for startup method {0} {1}", - parameterInfo.Name, - parameterInfo.ParameterType.FullName)); - } + builder.ApplicationServices = services.BuildServiceProvider(builder.ApplicationServices); } } - methodInfo.Invoke(instance, parameters); + Invoke(configureMethod, instance, builder); }; } } diff --git a/src/Microsoft.AspNet.Hosting/project.json b/src/Microsoft.AspNet.Hosting/project.json index 143ab70d0f..3bc77a7eb6 100644 --- a/src/Microsoft.AspNet.Hosting/project.json +++ b/src/Microsoft.AspNet.Hosting/project.json @@ -8,6 +8,7 @@ "Microsoft.Framework.ConfigurationModel": "1.0.0-*", "Microsoft.Framework.DependencyInjection": "1.0.0-*", "Microsoft.Framework.Logging": "1.0.0-*", + "Microsoft.Framework.OptionsModel": "1.0.0-*", "Microsoft.Framework.Runtime.Interfaces": { "version": "1.0.0-*", "type": "build" }, "Newtonsoft.Json": "6.0.4" }, diff --git a/test/Microsoft.AspNet.Hosting.Tests/Fakes/FakeOptions.cs b/test/Microsoft.AspNet.Hosting.Tests/Fakes/FakeOptions.cs new file mode 100644 index 0000000000..6d6d2c0982 --- /dev/null +++ b/test/Microsoft.AspNet.Hosting.Tests/Fakes/FakeOptions.cs @@ -0,0 +1,25 @@ +// Copyright (c) Microsoft Open Technologies, Inc. +// All Rights Reserved +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR +// CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING +// WITHOUT LIMITATION ANY IMPLIED WARRANTIES OR CONDITIONS OF +// TITLE, FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABLITY OR +// NON-INFRINGEMENT. +// See the Apache 2 License for the specific language governing +// permissions and limitations under the License. + +namespace Microsoft.AspNet.Hosting.Fakes +{ + public class FakeOptions + { + public bool Configured { get; set; } + public string Environment { get; set; } + } +} \ No newline at end of file diff --git a/test/Microsoft.AspNet.Hosting.Tests/Fakes/Startup.cs b/test/Microsoft.AspNet.Hosting.Tests/Fakes/Startup.cs index fb05a63b60..1421544258 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/Fakes/Startup.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/Fakes/Startup.cs @@ -17,6 +17,7 @@ using Microsoft.AspNet.Builder; using Microsoft.AspNet.Http; +using Microsoft.Framework.DependencyInjection; namespace Microsoft.AspNet.Hosting.Fakes { @@ -26,6 +27,39 @@ namespace Microsoft.AspNet.Hosting.Fakes { } + public void ConfigureServices(IServiceCollection services) + { + services.ConfigureOptions(o => o.Configured = true); + } + + public void ConfigureServicesDev(IServiceCollection services) + { + services.ConfigureOptions(o => + { + o.Configured = true; + o.Environment = "Dev"; + }); + } + + public void ConfigureServicesRetail(IServiceCollection services) + { + services.ConfigureOptions(o => + { + o.Configured = true; + o.Environment = "Retail"; + }); + } + + public static void ConfigureServicesStatic(IServiceCollection services) + { + services.ConfigureOptions(o => + { + o.Configured = true; + o.Environment = "Static"; + }); + } + + public void Configure(IApplicationBuilder builder) { } diff --git a/test/Microsoft.AspNet.Hosting.Tests/Fakes/StartupNoServices.cs b/test/Microsoft.AspNet.Hosting.Tests/Fakes/StartupNoServices.cs new file mode 100644 index 0000000000..24a329073a --- /dev/null +++ b/test/Microsoft.AspNet.Hosting.Tests/Fakes/StartupNoServices.cs @@ -0,0 +1,34 @@ +// Copyright (c) Microsoft Open Technologies, Inc. +// All Rights Reserved +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR +// CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING +// WITHOUT LIMITATION ANY IMPLIED WARRANTIES OR CONDITIONS OF +// TITLE, FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABLITY OR +// NON-INFRINGEMENT. +// See the Apache 2 License for the specific language governing +// permissions and limitations under the License. + +using Microsoft.AspNet.Builder; +using Microsoft.AspNet.Http; +using Microsoft.Framework.DependencyInjection; + +namespace Microsoft.AspNet.Hosting.Fakes +{ + public class StartupNoServices + { + public StartupNoServices() + { + } + + public void Configure(IApplicationBuilder builder) + { + } + } +} \ No newline at end of file diff --git a/test/Microsoft.AspNet.Hosting.Tests/StartupManagerTests.cs b/test/Microsoft.AspNet.Hosting.Tests/StartupManagerTests.cs index 6684a56205..97248b78c6 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/StartupManagerTests.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/StartupManagerTests.cs @@ -21,6 +21,9 @@ using Microsoft.AspNet.Hosting.Startup; using Microsoft.Framework.DependencyInjection; using Microsoft.Framework.DependencyInjection.Fallback; using Xunit; +using Microsoft.Framework.OptionsModel; +using Microsoft.AspNet.Builder; +using System; namespace Microsoft.AspNet.Hosting { @@ -46,6 +49,49 @@ namespace Microsoft.AspNet.Hosting Assert.Equal(2, _configurationMethodCalledList.Count); } + [Theory] + [InlineData(null)] + [InlineData("Dev")] + [InlineData("Retail")] + [InlineData("Static")] + public void StartupClassAddsConfigureServicesToApplicationServices(string environment) + { + var serviceCollection = new ServiceCollection(); + serviceCollection.Add(HostingServices.GetDefaultServices()); + var services = serviceCollection.BuildServiceProvider(); + var manager = services.GetService(); + + var startup = manager.LoadStartup("Microsoft.AspNet.Hosting.Tests", environment ?? ""); + + var app = new ApplicationBuilder(services); + + startup.Invoke(app); + + var options = app.ApplicationServices.GetService>().Options; + Assert.NotNull(options); + Assert.True(options.Configured); + Assert.Equal(environment, options.Environment); + } + + [Fact] + public void StartupClassDoesNotRegisterOptionsWithNoConfigureServices() + { + var serviceCollection = new ServiceCollection(); + serviceCollection.Add(HostingServices.GetDefaultServices()); + serviceCollection.AddInstance(this); + var services = serviceCollection.BuildServiceProvider(); + var manager = services.GetService(); + + var startup = manager.LoadStartup("Microsoft.AspNet.Hosting.Tests", "NoServices"); + + var app = new ApplicationBuilder(services); + + startup.Invoke(app); + + var ex = Assert.Throws(() => app.ApplicationServices.GetService>()); + Assert.True(ex.Message.Contains("No service for type 'Microsoft.Framework.OptionsModel.IOptionsAccessor")); + } + public void ConfigurationMethodCalled(object instance) { _configurationMethodCalledList.Add(instance); From da102032b5dd3e4f8acaee1412a1ff38a87ad871 Mon Sep 17 00:00:00 2001 From: Pranav K Date: Wed, 8 Oct 2014 19:28:37 -0700 Subject: [PATCH 126/987] Reacting to Dependency Injection changes --- src/Microsoft.AspNet.Hosting/HostingServices.cs | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/Microsoft.AspNet.Hosting/HostingServices.cs b/src/Microsoft.AspNet.Hosting/HostingServices.cs index a90b3232bc..ed8ac10442 100644 --- a/src/Microsoft.AspNet.Hosting/HostingServices.cs +++ b/src/Microsoft.AspNet.Hosting/HostingServices.cs @@ -54,12 +54,7 @@ namespace Microsoft.AspNet.Hosting // TODO: Do we expect this to be provide by the runtime eventually? yield return describer.Singleton(); - yield return new ServiceDescriptor - { - ServiceType = typeof(IContextAccessor<>), - ImplementationType = typeof(ContextAccessor<>), - Lifecycle = LifecycleKind.Scoped - }; + yield return describer.Scoped(typeof(IContextAccessor<>), typeof(ContextAccessor<>)); if (PlatformHelper.IsMono) { From 684aaed9bdade5c44964ab5ef89427c28463f39a Mon Sep 17 00:00:00 2001 From: Hao Kung Date: Wed, 8 Oct 2014 13:23:12 -0700 Subject: [PATCH 127/987] Cleanup headers --- .../Builder/ApplicationBuilderFactory.cs | 18 ++--------------- .../Builder/HttpContextFactory.cs | 19 ++---------------- .../Builder/IApplicationBuilderFactory.cs | 18 ++--------------- .../Builder/IHttpContextFactory.cs | 18 ++--------------- .../HostingContext.cs | 18 ++--------------- src/Microsoft.AspNet.Hosting/HostingEngine.cs | 18 ++--------------- .../HostingServices.cs | 19 ++---------------- .../HostingUtilities.cs | 18 ++--------------- .../IHostingEngine.cs | 18 ++--------------- .../PipelineInstance.cs | 18 ++--------------- .../PlatformHelper.cs | 18 ++--------------- src/Microsoft.AspNet.Hosting/Program.cs | 18 ++--------------- .../Server/IServerFactory.cs | 18 ++--------------- .../Server/IServerManager.cs | 18 ++--------------- .../Server/ServerManager.cs | 18 ++--------------- .../Startup/IStartupLoader.cs | 19 ++---------------- .../Startup/IStartupLoaderProvider.cs | 18 ++--------------- .../Startup/IStartupManager.cs | 18 ++--------------- .../Startup/NullStartupLoader.cs | 18 ++--------------- .../Startup/StartupLoader.cs | 18 ++--------------- .../Startup/StartupLoaderProvider.cs | 18 ++--------------- .../Startup/StartupManager.cs | 18 ++--------------- .../WebApplication.cs | 18 ++--------------- .../ContainerExtensions.cs | 18 ++--------------- .../ContainerMiddleware.cs | 18 ++--------------- .../Fakes/FakeOptions.cs | 18 ++--------------- .../Fakes/IFakeStartupCallback.cs | 18 ++--------------- .../Fakes/Startup.cs | 20 ++----------------- .../Fakes/StartupNoServices.cs | 20 ++----------------- .../Fakes/StartupWithServices.cs | 19 ++---------------- .../HostingEngineTests.cs | 18 ++--------------- .../StartupManagerTests.cs | 18 ++--------------- .../UseServicesFacts.cs | 5 ++++- 33 files changed, 68 insertions(+), 521 deletions(-) diff --git a/src/Microsoft.AspNet.Hosting/Builder/ApplicationBuilderFactory.cs b/src/Microsoft.AspNet.Hosting/Builder/ApplicationBuilderFactory.cs index 7b17e587f8..7bf1f59c23 100644 --- a/src/Microsoft.AspNet.Hosting/Builder/ApplicationBuilderFactory.cs +++ b/src/Microsoft.AspNet.Hosting/Builder/ApplicationBuilderFactory.cs @@ -1,19 +1,5 @@ -// Copyright (c) Microsoft Open Technologies, Inc. -// All Rights Reserved -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR -// CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING -// WITHOUT LIMITATION ANY IMPLIED WARRANTIES OR CONDITIONS OF -// TITLE, FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABLITY OR -// NON-INFRINGEMENT. -// See the Apache 2 License for the specific language governing -// permissions and limitations under the License. +// 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 System; using Microsoft.AspNet.Builder; diff --git a/src/Microsoft.AspNet.Hosting/Builder/HttpContextFactory.cs b/src/Microsoft.AspNet.Hosting/Builder/HttpContextFactory.cs index 288dea101d..1b01ed6b17 100644 --- a/src/Microsoft.AspNet.Hosting/Builder/HttpContextFactory.cs +++ b/src/Microsoft.AspNet.Hosting/Builder/HttpContextFactory.cs @@ -1,23 +1,8 @@ -// Copyright (c) Microsoft Open Technologies, Inc. -// All Rights Reserved -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR -// CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING -// WITHOUT LIMITATION ANY IMPLIED WARRANTIES OR CONDITIONS OF -// TITLE, FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABLITY OR -// NON-INFRINGEMENT. -// See the Apache 2 License for the specific language governing -// permissions and limitations under the License. +// 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.Http; using Microsoft.AspNet.FeatureModel; -using Microsoft.AspNet.Hosting.Server; using Microsoft.AspNet.PipelineCore; namespace Microsoft.AspNet.Hosting.Builder diff --git a/src/Microsoft.AspNet.Hosting/Builder/IApplicationBuilderFactory.cs b/src/Microsoft.AspNet.Hosting/Builder/IApplicationBuilderFactory.cs index dd60b0693a..45194717bc 100644 --- a/src/Microsoft.AspNet.Hosting/Builder/IApplicationBuilderFactory.cs +++ b/src/Microsoft.AspNet.Hosting/Builder/IApplicationBuilderFactory.cs @@ -1,19 +1,5 @@ -// Copyright (c) Microsoft Open Technologies, Inc. -// All Rights Reserved -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR -// CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING -// WITHOUT LIMITATION ANY IMPLIED WARRANTIES OR CONDITIONS OF -// TITLE, FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABLITY OR -// NON-INFRINGEMENT. -// See the Apache 2 License for the specific language governing -// permissions and limitations under the License. +// 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.Builder; diff --git a/src/Microsoft.AspNet.Hosting/Builder/IHttpContextFactory.cs b/src/Microsoft.AspNet.Hosting/Builder/IHttpContextFactory.cs index 6621c4b605..cdd6be9fac 100644 --- a/src/Microsoft.AspNet.Hosting/Builder/IHttpContextFactory.cs +++ b/src/Microsoft.AspNet.Hosting/Builder/IHttpContextFactory.cs @@ -1,19 +1,5 @@ -// Copyright (c) Microsoft Open Technologies, Inc. -// All Rights Reserved -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR -// CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING -// WITHOUT LIMITATION ANY IMPLIED WARRANTIES OR CONDITIONS OF -// TITLE, FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABLITY OR -// NON-INFRINGEMENT. -// See the Apache 2 License for the specific language governing -// permissions and limitations under the License. +// 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.Http; diff --git a/src/Microsoft.AspNet.Hosting/HostingContext.cs b/src/Microsoft.AspNet.Hosting/HostingContext.cs index b3bc2e550c..e7ddd9b863 100644 --- a/src/Microsoft.AspNet.Hosting/HostingContext.cs +++ b/src/Microsoft.AspNet.Hosting/HostingContext.cs @@ -1,19 +1,5 @@ -// Copyright (c) Microsoft Open Technologies, Inc. -// All Rights Reserved -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR -// CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING -// WITHOUT LIMITATION ANY IMPLIED WARRANTIES OR CONDITIONS OF -// TITLE, FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABLITY OR -// NON-INFRINGEMENT. -// See the Apache 2 License for the specific language governing -// permissions and limitations under the License. +// 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 System; using Microsoft.AspNet.Builder; diff --git a/src/Microsoft.AspNet.Hosting/HostingEngine.cs b/src/Microsoft.AspNet.Hosting/HostingEngine.cs index 7f75c88e5e..f7642f14f8 100644 --- a/src/Microsoft.AspNet.Hosting/HostingEngine.cs +++ b/src/Microsoft.AspNet.Hosting/HostingEngine.cs @@ -1,19 +1,5 @@ -// Copyright (c) Microsoft Open Technologies, Inc. -// All Rights Reserved -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR -// CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING -// WITHOUT LIMITATION ANY IMPLIED WARRANTIES OR CONDITIONS OF -// TITLE, FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABLITY OR -// NON-INFRINGEMENT. -// See the Apache 2 License for the specific language governing -// permissions and limitations under the License. +// 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 System; using System.Threading; diff --git a/src/Microsoft.AspNet.Hosting/HostingServices.cs b/src/Microsoft.AspNet.Hosting/HostingServices.cs index ed8ac10442..6bedf61f50 100644 --- a/src/Microsoft.AspNet.Hosting/HostingServices.cs +++ b/src/Microsoft.AspNet.Hosting/HostingServices.cs @@ -1,21 +1,6 @@ -// Copyright (c) Microsoft Open Technologies, Inc. -// All Rights Reserved -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR -// CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING -// WITHOUT LIMITATION ANY IMPLIED WARRANTIES OR CONDITIONS OF -// TITLE, FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABLITY OR -// NON-INFRINGEMENT. -// See the Apache 2 License for the specific language governing -// permissions and limitations under the License. +// 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 System; using System.Collections.Generic; using Microsoft.AspNet.Hosting.Builder; using Microsoft.AspNet.Hosting.Server; diff --git a/src/Microsoft.AspNet.Hosting/HostingUtilities.cs b/src/Microsoft.AspNet.Hosting/HostingUtilities.cs index 946e3c9613..5b90b251a2 100644 --- a/src/Microsoft.AspNet.Hosting/HostingUtilities.cs +++ b/src/Microsoft.AspNet.Hosting/HostingUtilities.cs @@ -1,19 +1,5 @@ -// Copyright (c) Microsoft Open Technologies, Inc. -// All Rights Reserved -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR -// CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING -// WITHOUT LIMITATION ANY IMPLIED WARRANTIES OR CONDITIONS OF -// TITLE, FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABLITY OR -// NON-INFRINGEMENT. -// See the Apache 2 License for the specific language governing -// permissions and limitations under the License. +// 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 System; using System.IO; diff --git a/src/Microsoft.AspNet.Hosting/IHostingEngine.cs b/src/Microsoft.AspNet.Hosting/IHostingEngine.cs index 324e9beba8..ba6c74ecd1 100644 --- a/src/Microsoft.AspNet.Hosting/IHostingEngine.cs +++ b/src/Microsoft.AspNet.Hosting/IHostingEngine.cs @@ -1,19 +1,5 @@ -// Copyright (c) Microsoft Open Technologies, Inc. -// All Rights Reserved -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR -// CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING -// WITHOUT LIMITATION ANY IMPLIED WARRANTIES OR CONDITIONS OF -// TITLE, FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABLITY OR -// NON-INFRINGEMENT. -// See the Apache 2 License for the specific language governing -// permissions and limitations under the License. +// 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 System; diff --git a/src/Microsoft.AspNet.Hosting/PipelineInstance.cs b/src/Microsoft.AspNet.Hosting/PipelineInstance.cs index ec3a8f5284..2efe3d6b24 100644 --- a/src/Microsoft.AspNet.Hosting/PipelineInstance.cs +++ b/src/Microsoft.AspNet.Hosting/PipelineInstance.cs @@ -1,19 +1,5 @@ -// Copyright (c) Microsoft Open Technologies, Inc. -// All Rights Reserved -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR -// CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING -// WITHOUT LIMITATION ANY IMPLIED WARRANTIES OR CONDITIONS OF -// TITLE, FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABLITY OR -// NON-INFRINGEMENT. -// See the Apache 2 License for the specific language governing -// permissions and limitations under the License. +// 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 System; using System.Threading.Tasks; diff --git a/src/Microsoft.AspNet.Hosting/PlatformHelper.cs b/src/Microsoft.AspNet.Hosting/PlatformHelper.cs index 0581162444..1309a18786 100644 --- a/src/Microsoft.AspNet.Hosting/PlatformHelper.cs +++ b/src/Microsoft.AspNet.Hosting/PlatformHelper.cs @@ -1,19 +1,5 @@ -// Copyright (c) Microsoft Open Technologies, Inc. -// All Rights Reserved -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR -// CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING -// WITHOUT LIMITATION ANY IMPLIED WARRANTIES OR CONDITIONS OF -// TITLE, FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABLITY OR -// NON-INFRINGEMENT. -// See the Apache 2 License for the specific language governing -// permissions and limitations under the License. +// 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 System; diff --git a/src/Microsoft.AspNet.Hosting/Program.cs b/src/Microsoft.AspNet.Hosting/Program.cs index 6afeacd0ee..d96fb4f131 100644 --- a/src/Microsoft.AspNet.Hosting/Program.cs +++ b/src/Microsoft.AspNet.Hosting/Program.cs @@ -1,19 +1,5 @@ -// Copyright (c) Microsoft Open Technologies, Inc. -// All Rights Reserved -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR -// CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING -// WITHOUT LIMITATION ANY IMPLIED WARRANTIES OR CONDITIONS OF -// TITLE, FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABLITY OR -// NON-INFRINGEMENT. -// See the Apache 2 License for the specific language governing -// permissions and limitations under the License. +// 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 System; using System.IO; diff --git a/src/Microsoft.AspNet.Hosting/Server/IServerFactory.cs b/src/Microsoft.AspNet.Hosting/Server/IServerFactory.cs index 0b75dbe5e9..94cb26ece7 100644 --- a/src/Microsoft.AspNet.Hosting/Server/IServerFactory.cs +++ b/src/Microsoft.AspNet.Hosting/Server/IServerFactory.cs @@ -1,19 +1,5 @@ -// Copyright (c) Microsoft Open Technologies, Inc. -// All Rights Reserved -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR -// CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING -// WITHOUT LIMITATION ANY IMPLIED WARRANTIES OR CONDITIONS OF -// TITLE, FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABLITY OR -// NON-INFRINGEMENT. -// See the Apache 2 License for the specific language governing -// permissions and limitations under the License. +// 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 System; using System.Threading.Tasks; diff --git a/src/Microsoft.AspNet.Hosting/Server/IServerManager.cs b/src/Microsoft.AspNet.Hosting/Server/IServerManager.cs index 169ce54cf5..92aa79dfd2 100644 --- a/src/Microsoft.AspNet.Hosting/Server/IServerManager.cs +++ b/src/Microsoft.AspNet.Hosting/Server/IServerManager.cs @@ -1,19 +1,5 @@ -// Copyright (c) Microsoft Open Technologies, Inc. -// All Rights Reserved -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR -// CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING -// WITHOUT LIMITATION ANY IMPLIED WARRANTIES OR CONDITIONS OF -// TITLE, FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABLITY OR -// NON-INFRINGEMENT. -// See the Apache 2 License for the specific language governing -// permissions and limitations under the License. +// 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. namespace Microsoft.AspNet.Hosting.Server { diff --git a/src/Microsoft.AspNet.Hosting/Server/ServerManager.cs b/src/Microsoft.AspNet.Hosting/Server/ServerManager.cs index 726e6746cc..d59cb979fc 100644 --- a/src/Microsoft.AspNet.Hosting/Server/ServerManager.cs +++ b/src/Microsoft.AspNet.Hosting/Server/ServerManager.cs @@ -1,19 +1,5 @@ -// Copyright (c) Microsoft Open Technologies, Inc. -// All Rights Reserved -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR -// CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING -// WITHOUT LIMITATION ANY IMPLIED WARRANTIES OR CONDITIONS OF -// TITLE, FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABLITY OR -// NON-INFRINGEMENT. -// See the Apache 2 License for the specific language governing -// permissions and limitations under the License. +// 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 System; using System.Linq; diff --git a/src/Microsoft.AspNet.Hosting/Startup/IStartupLoader.cs b/src/Microsoft.AspNet.Hosting/Startup/IStartupLoader.cs index faba106da5..24667a0c42 100644 --- a/src/Microsoft.AspNet.Hosting/Startup/IStartupLoader.cs +++ b/src/Microsoft.AspNet.Hosting/Startup/IStartupLoader.cs @@ -1,24 +1,9 @@ -// Copyright (c) Microsoft Open Technologies, Inc. -// All Rights Reserved -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR -// CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING -// WITHOUT LIMITATION ANY IMPLIED WARRANTIES OR CONDITIONS OF -// TITLE, FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABLITY OR -// NON-INFRINGEMENT. -// See the Apache 2 License for the specific language governing -// permissions and limitations under the License. +// 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 System; using System.Collections.Generic; using Microsoft.AspNet.Builder; -using Microsoft.AspNet.Http; namespace Microsoft.AspNet.Hosting.Startup { diff --git a/src/Microsoft.AspNet.Hosting/Startup/IStartupLoaderProvider.cs b/src/Microsoft.AspNet.Hosting/Startup/IStartupLoaderProvider.cs index 3a2f9561c2..a134f501e5 100644 --- a/src/Microsoft.AspNet.Hosting/Startup/IStartupLoaderProvider.cs +++ b/src/Microsoft.AspNet.Hosting/Startup/IStartupLoaderProvider.cs @@ -1,19 +1,5 @@ -// Copyright (c) Microsoft Open Technologies, Inc. -// All Rights Reserved -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR -// CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING -// WITHOUT LIMITATION ANY IMPLIED WARRANTIES OR CONDITIONS OF -// TITLE, FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABLITY OR -// NON-INFRINGEMENT. -// See the Apache 2 License for the specific language governing -// permissions and limitations under the License. +// 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. namespace Microsoft.AspNet.Hosting.Startup { diff --git a/src/Microsoft.AspNet.Hosting/Startup/IStartupManager.cs b/src/Microsoft.AspNet.Hosting/Startup/IStartupManager.cs index 8cdd089054..15932fb21b 100644 --- a/src/Microsoft.AspNet.Hosting/Startup/IStartupManager.cs +++ b/src/Microsoft.AspNet.Hosting/Startup/IStartupManager.cs @@ -1,19 +1,5 @@ -// Copyright (c) Microsoft Open Technologies, Inc. -// All Rights Reserved -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR -// CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING -// WITHOUT LIMITATION ANY IMPLIED WARRANTIES OR CONDITIONS OF -// TITLE, FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABLITY OR -// NON-INFRINGEMENT. -// See the Apache 2 License for the specific language governing -// permissions and limitations under the License. +// 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 System; using Microsoft.AspNet.Builder; diff --git a/src/Microsoft.AspNet.Hosting/Startup/NullStartupLoader.cs b/src/Microsoft.AspNet.Hosting/Startup/NullStartupLoader.cs index c40983087a..ae672d4598 100644 --- a/src/Microsoft.AspNet.Hosting/Startup/NullStartupLoader.cs +++ b/src/Microsoft.AspNet.Hosting/Startup/NullStartupLoader.cs @@ -1,19 +1,5 @@ -// Copyright (c) Microsoft Open Technologies, Inc. -// All Rights Reserved -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR -// CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING -// WITHOUT LIMITATION ANY IMPLIED WARRANTIES OR CONDITIONS OF -// TITLE, FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABLITY OR -// NON-INFRINGEMENT. -// See the Apache 2 License for the specific language governing -// permissions and limitations under the License. +// 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 System; using System.Collections.Generic; diff --git a/src/Microsoft.AspNet.Hosting/Startup/StartupLoader.cs b/src/Microsoft.AspNet.Hosting/Startup/StartupLoader.cs index c87a47cafc..fd4756cb54 100644 --- a/src/Microsoft.AspNet.Hosting/Startup/StartupLoader.cs +++ b/src/Microsoft.AspNet.Hosting/Startup/StartupLoader.cs @@ -1,19 +1,5 @@ -// Copyright (c) Microsoft Open Technologies, Inc. -// All Rights Reserved -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR -// CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING -// WITHOUT LIMITATION ANY IMPLIED WARRANTIES OR CONDITIONS OF -// TITLE, FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABLITY OR -// NON-INFRINGEMENT. -// See the Apache 2 License for the specific language governing -// permissions and limitations under the License. +// 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 System; using System.Collections.Generic; diff --git a/src/Microsoft.AspNet.Hosting/Startup/StartupLoaderProvider.cs b/src/Microsoft.AspNet.Hosting/Startup/StartupLoaderProvider.cs index a5e962786e..22cfe0872a 100644 --- a/src/Microsoft.AspNet.Hosting/Startup/StartupLoaderProvider.cs +++ b/src/Microsoft.AspNet.Hosting/Startup/StartupLoaderProvider.cs @@ -1,19 +1,5 @@ -// Copyright (c) Microsoft Open Technologies, Inc. -// All Rights Reserved -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR -// CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING -// WITHOUT LIMITATION ANY IMPLIED WARRANTIES OR CONDITIONS OF -// TITLE, FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABLITY OR -// NON-INFRINGEMENT. -// See the Apache 2 License for the specific language governing -// permissions and limitations under the License. +// 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 System; diff --git a/src/Microsoft.AspNet.Hosting/Startup/StartupManager.cs b/src/Microsoft.AspNet.Hosting/Startup/StartupManager.cs index cc722eafb5..8f7249899f 100644 --- a/src/Microsoft.AspNet.Hosting/Startup/StartupManager.cs +++ b/src/Microsoft.AspNet.Hosting/Startup/StartupManager.cs @@ -1,19 +1,5 @@ -// Copyright (c) Microsoft Open Technologies, Inc. -// All Rights Reserved -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR -// CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING -// WITHOUT LIMITATION ANY IMPLIED WARRANTIES OR CONDITIONS OF -// TITLE, FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABLITY OR -// NON-INFRINGEMENT. -// See the Apache 2 License for the specific language governing -// permissions and limitations under the License. +// 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 System; using System.Collections.Generic; diff --git a/src/Microsoft.AspNet.Hosting/WebApplication.cs b/src/Microsoft.AspNet.Hosting/WebApplication.cs index ccd679476d..b891a0b5a7 100644 --- a/src/Microsoft.AspNet.Hosting/WebApplication.cs +++ b/src/Microsoft.AspNet.Hosting/WebApplication.cs @@ -1,19 +1,5 @@ -// Copyright (c) Microsoft Open Technologies, Inc. -// All Rights Reserved -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR -// CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING -// WITHOUT LIMITATION ANY IMPLIED WARRANTIES OR CONDITIONS OF -// TITLE, FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABLITY OR -// NON-INFRINGEMENT. -// See the Apache 2 License for the specific language governing -// permissions and limitations under the License. +// 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 System; using Microsoft.Framework.DependencyInjection; diff --git a/src/Microsoft.AspNet.RequestContainer/ContainerExtensions.cs b/src/Microsoft.AspNet.RequestContainer/ContainerExtensions.cs index 3ae3541481..7a6f2bd54f 100644 --- a/src/Microsoft.AspNet.RequestContainer/ContainerExtensions.cs +++ b/src/Microsoft.AspNet.RequestContainer/ContainerExtensions.cs @@ -1,19 +1,5 @@ -// Copyright (c) Microsoft Open Technologies, Inc. -// All Rights Reserved -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR -// CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING -// WITHOUT LIMITATION ANY IMPLIED WARRANTIES OR CONDITIONS OF -// TITLE, FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABLITY OR -// NON-INFRINGEMENT. -// See the Apache 2 License for the specific language governing -// permissions and limitations under the License. +// 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 System; using System.Collections.Generic; diff --git a/src/Microsoft.AspNet.RequestContainer/ContainerMiddleware.cs b/src/Microsoft.AspNet.RequestContainer/ContainerMiddleware.cs index 518eac189c..706b14294a 100644 --- a/src/Microsoft.AspNet.RequestContainer/ContainerMiddleware.cs +++ b/src/Microsoft.AspNet.RequestContainer/ContainerMiddleware.cs @@ -1,19 +1,5 @@ -// Copyright (c) Microsoft Open Technologies, Inc. -// All Rights Reserved -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR -// CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING -// WITHOUT LIMITATION ANY IMPLIED WARRANTIES OR CONDITIONS OF -// TITLE, FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABLITY OR -// NON-INFRINGEMENT. -// See the Apache 2 License for the specific language governing -// permissions and limitations under the License. +// 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 System; #if ASPNET50 diff --git a/test/Microsoft.AspNet.Hosting.Tests/Fakes/FakeOptions.cs b/test/Microsoft.AspNet.Hosting.Tests/Fakes/FakeOptions.cs index 6d6d2c0982..d3c7ee2b0b 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/Fakes/FakeOptions.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/Fakes/FakeOptions.cs @@ -1,19 +1,5 @@ -// Copyright (c) Microsoft Open Technologies, Inc. -// All Rights Reserved -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR -// CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING -// WITHOUT LIMITATION ANY IMPLIED WARRANTIES OR CONDITIONS OF -// TITLE, FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABLITY OR -// NON-INFRINGEMENT. -// See the Apache 2 License for the specific language governing -// permissions and limitations under the License. +// 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. namespace Microsoft.AspNet.Hosting.Fakes { diff --git a/test/Microsoft.AspNet.Hosting.Tests/Fakes/IFakeStartupCallback.cs b/test/Microsoft.AspNet.Hosting.Tests/Fakes/IFakeStartupCallback.cs index 708dac5281..5a5ca0341b 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/Fakes/IFakeStartupCallback.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/Fakes/IFakeStartupCallback.cs @@ -1,19 +1,5 @@ -// Copyright (c) Microsoft Open Technologies, Inc. -// All Rights Reserved -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR -// CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING -// WITHOUT LIMITATION ANY IMPLIED WARRANTIES OR CONDITIONS OF -// TITLE, FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABLITY OR -// NON-INFRINGEMENT. -// See the Apache 2 License for the specific language governing -// permissions and limitations under the License. +// 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. namespace Microsoft.AspNet.Hosting.Fakes { diff --git a/test/Microsoft.AspNet.Hosting.Tests/Fakes/Startup.cs b/test/Microsoft.AspNet.Hosting.Tests/Fakes/Startup.cs index 1421544258..2fa43ea158 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/Fakes/Startup.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/Fakes/Startup.cs @@ -1,22 +1,7 @@ -// Copyright (c) Microsoft Open Technologies, Inc. -// All Rights Reserved -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR -// CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING -// WITHOUT LIMITATION ANY IMPLIED WARRANTIES OR CONDITIONS OF -// TITLE, FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABLITY OR -// NON-INFRINGEMENT. -// See the Apache 2 License for the specific language governing -// permissions and limitations under the License. +// 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.Builder; -using Microsoft.AspNet.Http; using Microsoft.Framework.DependencyInjection; namespace Microsoft.AspNet.Hosting.Fakes @@ -59,7 +44,6 @@ namespace Microsoft.AspNet.Hosting.Fakes }); } - public void Configure(IApplicationBuilder builder) { } diff --git a/test/Microsoft.AspNet.Hosting.Tests/Fakes/StartupNoServices.cs b/test/Microsoft.AspNet.Hosting.Tests/Fakes/StartupNoServices.cs index 24a329073a..16e73e3d9c 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/Fakes/StartupNoServices.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/Fakes/StartupNoServices.cs @@ -1,23 +1,7 @@ -// Copyright (c) Microsoft Open Technologies, Inc. -// All Rights Reserved -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR -// CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING -// WITHOUT LIMITATION ANY IMPLIED WARRANTIES OR CONDITIONS OF -// TITLE, FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABLITY OR -// NON-INFRINGEMENT. -// See the Apache 2 License for the specific language governing -// permissions and limitations under the License. +// 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.Builder; -using Microsoft.AspNet.Http; -using Microsoft.Framework.DependencyInjection; namespace Microsoft.AspNet.Hosting.Fakes { diff --git a/test/Microsoft.AspNet.Hosting.Tests/Fakes/StartupWithServices.cs b/test/Microsoft.AspNet.Hosting.Tests/Fakes/StartupWithServices.cs index c13ec7eb7f..c7d4050481 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/Fakes/StartupWithServices.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/Fakes/StartupWithServices.cs @@ -1,22 +1,7 @@ -// Copyright (c) Microsoft Open Technologies, Inc. -// All Rights Reserved -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR -// CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING -// WITHOUT LIMITATION ANY IMPLIED WARRANTIES OR CONDITIONS OF -// TITLE, FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABLITY OR -// NON-INFRINGEMENT. -// See the Apache 2 License for the specific language governing -// permissions and limitations under the License. +// 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.Builder; -using Microsoft.AspNet.Http; namespace Microsoft.AspNet.Hosting.Fakes { diff --git a/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs b/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs index 6091c7ae12..6f79dc1eab 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs @@ -1,19 +1,5 @@ -// Copyright (c) Microsoft Open Technologies, Inc. -// All Rights Reserved -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR -// CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING -// WITHOUT LIMITATION ANY IMPLIED WARRANTIES OR CONDITIONS OF -// TITLE, FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABLITY OR -// NON-INFRINGEMENT. -// See the Apache 2 License for the specific language governing -// permissions and limitations under the License. +// 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 System; using System.Collections.Generic; diff --git a/test/Microsoft.AspNet.Hosting.Tests/StartupManagerTests.cs b/test/Microsoft.AspNet.Hosting.Tests/StartupManagerTests.cs index 97248b78c6..9771926b7a 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/StartupManagerTests.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/StartupManagerTests.cs @@ -1,19 +1,5 @@ -// Copyright (c) Microsoft Open Technologies, Inc. -// All Rights Reserved -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR -// CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING -// WITHOUT LIMITATION ANY IMPLIED WARRANTIES OR CONDITIONS OF -// TITLE, FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABLITY OR -// NON-INFRINGEMENT. -// See the Apache 2 License for the specific language governing -// permissions and limitations under the License. +// 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 System.Collections.Generic; using Microsoft.AspNet.Hosting.Fakes; diff --git a/test/Microsoft.AspNet.Hosting.Tests/UseServicesFacts.cs b/test/Microsoft.AspNet.Hosting.Tests/UseServicesFacts.cs index 3da2beebdb..5e67d5bd4e 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/UseServicesFacts.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/UseServicesFacts.cs @@ -1,4 +1,7 @@ -using System; +// 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 System; using Microsoft.AspNet.Builder; using Microsoft.Framework.DependencyInjection; using Microsoft.Framework.DependencyInjection.Fallback; From babb296f35c3784b0b11dc702c230803e5e1a150 Mon Sep 17 00:00:00 2001 From: Hao Kung Date: Thu, 9 Oct 2014 14:05:59 -0700 Subject: [PATCH 128/987] Rename UseServices -> UsePerRequestServices --- .../ContainerExtensions.cs | 14 +++++++------- .../UseServicesFacts.cs | 4 ++-- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/Microsoft.AspNet.RequestContainer/ContainerExtensions.cs b/src/Microsoft.AspNet.RequestContainer/ContainerExtensions.cs index 7a6f2bd54f..5494e86edc 100644 --- a/src/Microsoft.AspNet.RequestContainer/ContainerExtensions.cs +++ b/src/Microsoft.AspNet.RequestContainer/ContainerExtensions.cs @@ -31,33 +31,33 @@ namespace Microsoft.AspNet.Builder }); } - public static IApplicationBuilder UseServices(this IApplicationBuilder builder) + public static IApplicationBuilder UsePerRequestServices(this IApplicationBuilder builder) { return builder.UseMiddleware(typeof(ContainerMiddleware)); } - public static IApplicationBuilder UseServices(this IApplicationBuilder builder, IServiceProvider applicationServices) + public static IApplicationBuilder UsePerRequestServices(this IApplicationBuilder builder, IServiceProvider applicationServices) { builder.ApplicationServices = applicationServices; return builder.UseMiddleware(typeof(ContainerMiddleware)); } - public static IApplicationBuilder UseServices(this IApplicationBuilder builder, IEnumerable applicationServices) + public static IApplicationBuilder UsePerRequestServices(this IApplicationBuilder builder, IEnumerable applicationServices) { - return builder.UseServices(services => services.Add(applicationServices)); + return builder.UsePerRequestServices(services => services.Add(applicationServices)); } - public static IApplicationBuilder UseServices(this IApplicationBuilder builder, Action configureServices) + public static IApplicationBuilder UsePerRequestServices(this IApplicationBuilder builder, Action configureServices) { - return builder.UseServices(serviceCollection => + return builder.UsePerRequestServices(serviceCollection => { configureServices(serviceCollection); return serviceCollection.BuildServiceProvider(builder.ApplicationServices); }); } - public static IApplicationBuilder UseServices(this IApplicationBuilder builder, Func configureServices) + public static IApplicationBuilder UsePerRequestServices(this IApplicationBuilder builder, Func configureServices) { var serviceCollection = new ServiceCollection(); diff --git a/test/Microsoft.AspNet.Hosting.Tests/UseServicesFacts.cs b/test/Microsoft.AspNet.Hosting.Tests/UseServicesFacts.cs index 5e67d5bd4e..2dae3babea 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/UseServicesFacts.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/UseServicesFacts.cs @@ -18,7 +18,7 @@ namespace Microsoft.AspNet.Hosting.Tests var baseServiceProvider = new ServiceCollection().BuildServiceProvider(); var builder = new ApplicationBuilder(baseServiceProvider); - builder.UseServices(serviceCollection => { }); + builder.UsePerRequestServices(serviceCollection => { }); var optionsAccessor = builder.ApplicationServices.GetService>(); Assert.NotNull(optionsAccessor); @@ -32,7 +32,7 @@ namespace Microsoft.AspNet.Hosting.Tests var builder = new ApplicationBuilder(baseServiceProvider); IServiceProvider serviceProvider = null; - builder.UseServices(serviceCollection => + builder.UsePerRequestServices(serviceCollection => { serviceProvider = serviceCollection.BuildServiceProvider(builder.ApplicationServices); return serviceProvider; From e094c1a71d0e71ca842092e793bd2a8999c1baff Mon Sep 17 00:00:00 2001 From: Pranav K Date: Fri, 10 Oct 2014 10:32:44 -0700 Subject: [PATCH 129/987] Reacting to CLR package versioning changes --- src/Microsoft.AspNet.Hosting/project.json | 22 ++++++++-------- .../project.json | 22 ++++++++-------- src/Microsoft.AspNet.TestHost/project.json | 26 +++++++++---------- 3 files changed, 35 insertions(+), 35 deletions(-) diff --git a/src/Microsoft.AspNet.Hosting/project.json b/src/Microsoft.AspNet.Hosting/project.json index 3bc77a7eb6..562e25d619 100644 --- a/src/Microsoft.AspNet.Hosting/project.json +++ b/src/Microsoft.AspNet.Hosting/project.json @@ -16,17 +16,17 @@ "aspnet50": { }, "aspnetcore50": { "dependencies": { - "System.Collections": "4.0.10.0", - "System.ComponentModel": "4.0.0.0", - "System.Console": "4.0.0.0", - "System.Diagnostics.Debug": "4.0.10.0", - "System.IO": "4.0.10.0", - "System.Linq": "4.0.0.0", - "System.Reflection": "4.0.10.0", - "System.Runtime": "4.0.20.0", - "System.Runtime.Extensions": "4.0.10.0", - "System.Threading": "4.0.0.0", - "System.Threading.Tasks": "4.0.10.0" + "System.Collections": "4.0.10-beta-*", + "System.ComponentModel": "4.0.0-beta-*", + "System.Console": "4.0.0-beta-*", + "System.Diagnostics.Debug": "4.0.10-beta-*", + "System.IO": "4.0.10-beta-*", + "System.Linq": "4.0.0-beta-*", + "System.Reflection": "4.0.10-beta-*", + "System.Runtime": "4.0.20-beta-*", + "System.Runtime.Extensions": "4.0.10-beta-*", + "System.Threading": "4.0.0-beta-*", + "System.Threading.Tasks": "4.0.10-beta-*" } } } diff --git a/src/Microsoft.AspNet.RequestContainer/project.json b/src/Microsoft.AspNet.RequestContainer/project.json index d381b0bb3d..2f81f60c6c 100644 --- a/src/Microsoft.AspNet.RequestContainer/project.json +++ b/src/Microsoft.AspNet.RequestContainer/project.json @@ -9,17 +9,17 @@ "aspnet50": {}, "aspnetcore50": { "dependencies": { - "System.Collections": "4.0.10.0", - "System.ComponentModel": "4.0.0.0", - "System.Diagnostics.Debug": "4.0.10.0", - "System.Linq": "4.0.0.0", - "System.Reflection": "4.0.10.0", - "System.Reflection.Extensions": "4.0.0.0", - "System.Reflection.TypeExtensions": "4.0.0.0", - "System.Runtime": "4.0.20.0", - "System.Runtime.Extensions": "4.0.10.0", - "System.Threading": "4.0.0.0", - "System.Threading.Tasks": "4.0.10.0" + "System.Collections": "4.0.10-beta-*", + "System.ComponentModel": "4.0.0-beta-*", + "System.Diagnostics.Debug": "4.0.10-beta-*", + "System.Linq": "4.0.0-beta-*", + "System.Reflection": "4.0.10-beta-*", + "System.Reflection.Extensions": "4.0.0-beta-*", + "System.Reflection.TypeExtensions": "4.0.0-beta-*", + "System.Runtime": "4.0.20-beta-*", + "System.Runtime.Extensions": "4.0.10-beta-*", + "System.Threading": "4.0.0-beta-*", + "System.Threading.Tasks": "4.0.10-beta-*" } } } diff --git a/src/Microsoft.AspNet.TestHost/project.json b/src/Microsoft.AspNet.TestHost/project.json index 0364f0bf2c..97cfef7de5 100644 --- a/src/Microsoft.AspNet.TestHost/project.json +++ b/src/Microsoft.AspNet.TestHost/project.json @@ -6,23 +6,23 @@ "frameworks": { "aspnet50": { "frameworkAssemblies": { - "System.Net.Http": "4.0.0.0" + "System.Net.Http": "4.0.0-beta-*" } }, "aspnetcore50": { "dependencies": { - "System.Collections": "4.0.10.0", - "System.ComponentModel": "4.0.0.0", - "System.Globalization": "4.0.10.0", - "System.Linq": "4.0.0.0", - "System.Reflection": "4.0.10.0", - "System.Runtime": "4.0.20.0", - "System.Runtime.Extensions": "4.0.10.0", - "System.Runtime.Serialization.Primitives": "4.0.0.0", - "System.Threading": "4.0.0.0", - "System.Threading.Tasks": "4.0.10.0", - "System.Threading.Thread": "4.0.0.0", - "System.Net.Http": "4.0.0.0" + "System.Collections": "4.0.10-beta-*", + "System.ComponentModel": "4.0.0-beta-*", + "System.Globalization": "4.0.10-beta-*", + "System.Linq": "4.0.0-beta-*", + "System.Reflection": "4.0.10-beta-*", + "System.Runtime": "4.0.20-beta-*", + "System.Runtime.Extensions": "4.0.10-beta-*", + "System.Runtime.Serialization.Primitives": "4.0.0-beta-*", + "System.Threading": "4.0.0-beta-*", + "System.Threading.Tasks": "4.0.10-beta-*", + "System.Threading.Thread": "4.0.0-beta-*", + "System.Net.Http": "4.0.0-beta-*" } } } From fafc191d056c8f163e8c01c5638b370d06db720c Mon Sep 17 00:00:00 2001 From: Pranav K Date: Fri, 10 Oct 2014 10:57:58 -0700 Subject: [PATCH 130/987] Removing version from framework assemblies node --- src/Microsoft.AspNet.TestHost/project.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Microsoft.AspNet.TestHost/project.json b/src/Microsoft.AspNet.TestHost/project.json index 97cfef7de5..69ffdf1d4e 100644 --- a/src/Microsoft.AspNet.TestHost/project.json +++ b/src/Microsoft.AspNet.TestHost/project.json @@ -6,7 +6,7 @@ "frameworks": { "aspnet50": { "frameworkAssemblies": { - "System.Net.Http": "4.0.0-beta-*" + "System.Net.Http": "" } }, "aspnetcore50": { From 821e13a1a7526b719a2c680e742781b36cfd4b02 Mon Sep 17 00:00:00 2001 From: Levi B Date: Fri, 10 Oct 2014 12:13:58 -0700 Subject: [PATCH 131/987] Update Hosting to account for DataProtection API changes. --- src/Microsoft.AspNet.Hosting/HostingServices.cs | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/src/Microsoft.AspNet.Hosting/HostingServices.cs b/src/Microsoft.AspNet.Hosting/HostingServices.cs index 6bedf61f50..dbf5c26adc 100644 --- a/src/Microsoft.AspNet.Hosting/HostingServices.cs +++ b/src/Microsoft.AspNet.Hosting/HostingServices.cs @@ -41,19 +41,9 @@ namespace Microsoft.AspNet.Hosting yield return describer.Scoped(typeof(IContextAccessor<>), typeof(ContextAccessor<>)); - if (PlatformHelper.IsMono) + foreach (var service in DataProtectionServices.GetDefaultServices()) { -#if ASPNET50 - yield return describer.Instance(DataProtectionProvider.CreateFromLegacyDpapi()); -#endif - } - else - { - // The default IDataProtectionProvider is a singleton. - // Note: DPAPI isn't usable in IIS where the user profile hasn't been loaded, but loading DPAPI - // is deferred until the first call to Protect / Unprotect. It's up to an IIS-based host to - // replace this service as part of application initialization. - yield return describer.Instance(DataProtectionProvider.CreateFromDpapi()); + yield return service; } } } From c859c3dad51ff751ee07d20c8f148bccc292d36f Mon Sep 17 00:00:00 2001 From: Levi B Date: Fri, 10 Oct 2014 12:27:14 -0700 Subject: [PATCH 132/987] Skip failing test due to DataProtection changes. --- test/Microsoft.AspNet.Hosting.Tests/StartupManagerTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/Microsoft.AspNet.Hosting.Tests/StartupManagerTests.cs b/test/Microsoft.AspNet.Hosting.Tests/StartupManagerTests.cs index 9771926b7a..d84773ad76 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/StartupManagerTests.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/StartupManagerTests.cs @@ -59,7 +59,7 @@ namespace Microsoft.AspNet.Hosting Assert.Equal(environment, options.Environment); } - [Fact] + [Fact(Skip = "DataProtection registers default Options services; need to figure out what to do with this test.")] public void StartupClassDoesNotRegisterOptionsWithNoConfigureServices() { var serviceCollection = new ServiceCollection(); From ebe4948a3eb9106d3a8da0252c1cc9b53203f70d Mon Sep 17 00:00:00 2001 From: Levi B Date: Fri, 10 Oct 2014 15:00:09 -0700 Subject: [PATCH 133/987] Add a discriminator so that DataProtection doesn't use the same subkey across apps by default. --- src/Microsoft.AspNet.Hosting/Program.cs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/Microsoft.AspNet.Hosting/Program.cs b/src/Microsoft.AspNet.Hosting/Program.cs index d96fb4f131..801041bdc0 100644 --- a/src/Microsoft.AspNet.Hosting/Program.cs +++ b/src/Microsoft.AspNet.Hosting/Program.cs @@ -5,6 +5,7 @@ using System; using System.IO; using System.Threading; using System.Threading.Tasks; +using Microsoft.AspNet.Security.DataProtection; using Microsoft.Framework.ConfigurationModel; using Microsoft.Framework.DependencyInjection; using Microsoft.Framework.DependencyInjection.Fallback; @@ -46,6 +47,14 @@ namespace Microsoft.AspNet.Hosting var serviceCollection = new ServiceCollection(); serviceCollection.Add(HostingServices.GetDefaultServices(config)); serviceCollection.AddInstance(hostingEnv); + // The application name is a "good enough" mechanism to identify this application + // on the machine and to prevent subkeys from being shared across multiple applications + // by default. + serviceCollection.ConfigureOptions(options => + { + options.ApplicationDiscriminator = appEnv.ApplicationName; + }); + var services = serviceCollection.BuildServiceProvider(_serviceProvider); var context = new HostingContext() From 6466d1061e6053dcdfc277c1cf59dc02a3a6d8e2 Mon Sep 17 00:00:00 2001 From: Hao Kung Date: Tue, 14 Oct 2014 19:01:01 -0700 Subject: [PATCH 134/987] Use/EnsureRequestServices changes - Split UseServices overloads into UseRequestServices and UseServices - Add RequestServicesContainer class which contains the old ContainerMiddleware logic and exposes a new EnsureRequestServices(HttpContext) method which can be called to populate RequestServices - ConfigureServices now scans for Configure{Env}Services instead of ConfigureServices{Env} - Add OptionsServices as part of default HostingServices --- .../HostingServices.cs | 6 + src/Microsoft.AspNet.Hosting/Program.cs | 2 +- .../Startup/StartupLoader.cs | 12 +- .../ContainerExtensions.cs | 14 +- .../ContainerMiddleware.cs | 28 +--- .../RequestServicesContainer.cs | 142 ++++++++++++++++++ .../Fakes/FakeOptions.cs | 1 + .../Fakes/IFakeService.cs | 8 + .../Fakes/Startup.cs | 16 +- .../Fakes/StartupBoom.cs | 12 ++ .../Fakes/StartupUseServices.cs | 30 ++++ .../Microsoft.AspNet.Hosting.Tests.kproj | 1 + .../StartupManagerTests.cs | 39 +++-- .../UseRequestServicesFacts.cs | 79 ++++++++++ .../UseServicesFacts.cs | 10 +- .../Microsoft.AspNet.TestHost.Tests.kproj | 1 + 16 files changed, 341 insertions(+), 60 deletions(-) create mode 100644 src/Microsoft.AspNet.RequestContainer/RequestServicesContainer.cs create mode 100644 test/Microsoft.AspNet.Hosting.Tests/Fakes/IFakeService.cs create mode 100644 test/Microsoft.AspNet.Hosting.Tests/Fakes/StartupBoom.cs create mode 100644 test/Microsoft.AspNet.Hosting.Tests/Fakes/StartupUseServices.cs create mode 100644 test/Microsoft.AspNet.Hosting.Tests/UseRequestServicesFacts.cs diff --git a/src/Microsoft.AspNet.Hosting/HostingServices.cs b/src/Microsoft.AspNet.Hosting/HostingServices.cs index dbf5c26adc..f1ce9b3cd2 100644 --- a/src/Microsoft.AspNet.Hosting/HostingServices.cs +++ b/src/Microsoft.AspNet.Hosting/HostingServices.cs @@ -9,6 +9,7 @@ using Microsoft.AspNet.Security.DataProtection; using Microsoft.Framework.ConfigurationModel; using Microsoft.Framework.DependencyInjection; using Microsoft.Framework.Logging; +using Microsoft.Framework.OptionsModel; namespace Microsoft.AspNet.Hosting { @@ -41,6 +42,11 @@ namespace Microsoft.AspNet.Hosting yield return describer.Scoped(typeof(IContextAccessor<>), typeof(ContextAccessor<>)); + foreach (var service in OptionsServices.GetDefaultServices()) + { + yield return service; + } + foreach (var service in DataProtectionServices.GetDefaultServices()) { yield return service; diff --git a/src/Microsoft.AspNet.Hosting/Program.cs b/src/Microsoft.AspNet.Hosting/Program.cs index 801041bdc0..5d83450f4d 100644 --- a/src/Microsoft.AspNet.Hosting/Program.cs +++ b/src/Microsoft.AspNet.Hosting/Program.cs @@ -50,7 +50,7 @@ namespace Microsoft.AspNet.Hosting // The application name is a "good enough" mechanism to identify this application // on the machine and to prevent subkeys from being shared across multiple applications // by default. - serviceCollection.ConfigureOptions(options => + serviceCollection.Configure(options => { options.ApplicationDiscriminator = appEnv.ApplicationName; }); diff --git a/src/Microsoft.AspNet.Hosting/Startup/StartupLoader.cs b/src/Microsoft.AspNet.Hosting/Startup/StartupLoader.cs index fd4756cb54..7658009466 100644 --- a/src/Microsoft.AspNet.Hosting/Startup/StartupLoader.cs +++ b/src/Microsoft.AspNet.Hosting/Startup/StartupLoader.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Generic; +using System.Globalization; using System.Linq; using System.Reflection; using Microsoft.AspNet.Builder; @@ -27,16 +28,17 @@ namespace Microsoft.AspNet.Hosting.Startup private MethodInfo FindMethod(Type startupType, string methodName, string environmentName, Type returnType = null, bool required = true) { - var methodNameWithEnv = methodName + environmentName; + var methodNameWithEnv = string.Format(CultureInfo.InvariantCulture, methodName, environmentName); + var methodNameWithNoEnv = string.Format(CultureInfo.InvariantCulture, methodName, ""); var methodInfo = startupType.GetTypeInfo().GetDeclaredMethod(methodNameWithEnv) - ?? startupType.GetTypeInfo().GetDeclaredMethod(methodName); + ?? startupType.GetTypeInfo().GetDeclaredMethod(methodNameWithNoEnv); if (methodInfo == null) { if (required) { throw new Exception(string.Format("TODO: {0} or {1} method not found", methodNameWithEnv, - methodName)); + methodNameWithNoEnv)); } return null; @@ -134,9 +136,9 @@ namespace Microsoft.AspNet.Hosting.Startup applicationName)); } - var configureMethod = FindMethod(type, "Configure", environmentName, typeof(void), required: true); + var configureMethod = FindMethod(type, "Configure{0}", environmentName, typeof(void), required: true); // TODO: accept IServiceProvider method as well? - var servicesMethod = FindMethod(type, "ConfigureServices", environmentName, typeof(void), required: false); + var servicesMethod = FindMethod(type, "Configure{0}Services", environmentName, typeof(void), required: false); object instance = null; if (!configureMethod.IsStatic || (servicesMethod != null && !servicesMethod.IsStatic)) diff --git a/src/Microsoft.AspNet.RequestContainer/ContainerExtensions.cs b/src/Microsoft.AspNet.RequestContainer/ContainerExtensions.cs index 5494e86edc..fbd5f08ea4 100644 --- a/src/Microsoft.AspNet.RequestContainer/ContainerExtensions.cs +++ b/src/Microsoft.AspNet.RequestContainer/ContainerExtensions.cs @@ -31,33 +31,33 @@ namespace Microsoft.AspNet.Builder }); } - public static IApplicationBuilder UsePerRequestServices(this IApplicationBuilder builder) + public static IApplicationBuilder UseRequestServices(this IApplicationBuilder builder) { return builder.UseMiddleware(typeof(ContainerMiddleware)); } - public static IApplicationBuilder UsePerRequestServices(this IApplicationBuilder builder, IServiceProvider applicationServices) + public static IApplicationBuilder UseRequestServices(this IApplicationBuilder builder, IServiceProvider applicationServices) { builder.ApplicationServices = applicationServices; return builder.UseMiddleware(typeof(ContainerMiddleware)); } - public static IApplicationBuilder UsePerRequestServices(this IApplicationBuilder builder, IEnumerable applicationServices) + public static IApplicationBuilder UseServices(this IApplicationBuilder builder, IEnumerable applicationServices) { - return builder.UsePerRequestServices(services => services.Add(applicationServices)); + return builder.UseServices(services => services.Add(applicationServices)); } - public static IApplicationBuilder UsePerRequestServices(this IApplicationBuilder builder, Action configureServices) + public static IApplicationBuilder UseServices(this IApplicationBuilder builder, Action configureServices) { - return builder.UsePerRequestServices(serviceCollection => + return builder.UseServices(serviceCollection => { configureServices(serviceCollection); return serviceCollection.BuildServiceProvider(builder.ApplicationServices); }); } - public static IApplicationBuilder UsePerRequestServices(this IApplicationBuilder builder, Func configureServices) + public static IApplicationBuilder UseServices(this IApplicationBuilder builder, Func configureServices) { var serviceCollection = new ServiceCollection(); diff --git a/src/Microsoft.AspNet.RequestContainer/ContainerMiddleware.cs b/src/Microsoft.AspNet.RequestContainer/ContainerMiddleware.cs index 706b14294a..3c1e5e52c9 100644 --- a/src/Microsoft.AspNet.RequestContainer/ContainerMiddleware.cs +++ b/src/Microsoft.AspNet.RequestContainer/ContainerMiddleware.cs @@ -49,7 +49,7 @@ namespace Microsoft.AspNet.RequestContainer _rootHttpContextAccessor.SetContextSource(AccessRootHttpContext, ExchangeRootHttpContext); } - private HttpContext AccessRootHttpContext() + internal static HttpContext AccessRootHttpContext() { #if ASPNET50 var handle = CallContext.LogicalGetData(LogicalDataKey) as ObjectHandle; @@ -59,7 +59,7 @@ namespace Microsoft.AspNet.RequestContainer #endif } - private HttpContext ExchangeRootHttpContext(HttpContext httpContext) + internal static HttpContext ExchangeRootHttpContext(HttpContext httpContext) { #if ASPNET50 var prior = CallContext.LogicalGetData(LogicalDataKey) as ObjectHandle; @@ -92,29 +92,9 @@ namespace Microsoft.AspNet.RequestContainer appHttpContextAccessor = priorApplicationServices.GetService>(); } - using (var scope = appServiceScopeFactory.CreateScope()) + using (var container = new RequestServicesContainer(httpContext, appServiceScopeFactory, appHttpContextAccessor, appServiceProvider)) { - var scopeServiceProvider = scope.ServiceProvider; - var scopeHttpContextAccessor = scopeServiceProvider.GetService>(); - - httpContext.ApplicationServices = appServiceProvider; - httpContext.RequestServices = scopeServiceProvider; - - var priorAppHttpContext = appHttpContextAccessor.SetValue(httpContext); - var priorScopeHttpContext = scopeHttpContextAccessor.SetValue(httpContext); - - try - { - await _next.Invoke(httpContext); - } - finally - { - scopeHttpContextAccessor.SetValue(priorScopeHttpContext); - appHttpContextAccessor.SetValue(priorAppHttpContext); - - httpContext.RequestServices = priorRequestServices; - httpContext.ApplicationServices = priorApplicationServices; - } + await _next.Invoke(httpContext); } } } diff --git a/src/Microsoft.AspNet.RequestContainer/RequestServicesContainer.cs b/src/Microsoft.AspNet.RequestContainer/RequestServicesContainer.cs new file mode 100644 index 0000000000..c4bbf142c2 --- /dev/null +++ b/src/Microsoft.AspNet.RequestContainer/RequestServicesContainer.cs @@ -0,0 +1,142 @@ +// 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 System; +using Microsoft.AspNet.Http; +using Microsoft.Framework.DependencyInjection; + +namespace Microsoft.AspNet.RequestContainer +{ + public class RequestServicesContainer : IDisposable + { + public RequestServicesContainer( + HttpContext context, + IServiceScopeFactory scopeFactory, + IContextAccessor appContextAccessor, + IServiceProvider appServiceProvider) + { + if (scopeFactory == null) + { + throw new ArgumentNullException(nameof(scopeFactory)); + } + if (context == null) + { + throw new ArgumentNullException(nameof(context)); + } + if (appContextAccessor == null) + { + throw new ArgumentNullException(nameof(appContextAccessor)); + } + + AppContextAccessor = appContextAccessor; + + Context = context; + PriorAppServices = context.ApplicationServices; + PriorRequestServices = context.RequestServices; + + // Begin the scope + Scope = scopeFactory.CreateScope(); + ScopeContextAccessor = Scope.ServiceProvider.GetService>(); + + Context.ApplicationServices = appServiceProvider; + Context.RequestServices = Scope.ServiceProvider; + + PriorAppHttpContext = AppContextAccessor.SetValue(context); + PriorScopeHttpContext = ScopeContextAccessor.SetValue(context); + } + + private HttpContext Context { get; set; } + private IServiceProvider PriorAppServices { get; set; } + private IServiceProvider PriorRequestServices { get; set; } + private HttpContext PriorAppHttpContext { get; set; } + private HttpContext PriorScopeHttpContext { get; set; } + private IServiceScope Scope { get; set; } + private IContextAccessor ScopeContextAccessor { get; set; } + private IContextAccessor AppContextAccessor { get; set; } + + // CONSIDER: this could be an extension method on HttpContext instead + public static RequestServicesContainer EnsureRequestServices(HttpContext httpContext) + { + // All done if we already have a request services + if (httpContext.RequestServices != null) + { + return null; + } + + if (httpContext.ApplicationServices == null) + { + throw new InvalidOperationException("TODO: httpContext.ApplicationServices is null!"); + } + + // Matches constructor of RequestContainer + var rootServiceProvider = httpContext.ApplicationServices.GetService(); + var rootHttpContextAccessor = httpContext.ApplicationServices.GetService>(); + var rootServiceScopeFactory = httpContext.ApplicationServices.GetService(); + + rootHttpContextAccessor.SetContextSource(ContainerMiddleware.AccessRootHttpContext, ContainerMiddleware.ExchangeRootHttpContext); + + // Pre Scope setup + var priorApplicationServices = httpContext.ApplicationServices; + var priorRequestServices = httpContext.RequestServices; + + var appServiceProvider = rootServiceProvider; + var appServiceScopeFactory = rootServiceScopeFactory; + var appHttpContextAccessor = rootHttpContextAccessor; + + if (priorApplicationServices != null && + priorApplicationServices != appServiceProvider) + { + appServiceProvider = priorApplicationServices; + appServiceScopeFactory = priorApplicationServices.GetService(); + appHttpContextAccessor = priorApplicationServices.GetService>(); + } + + // Creates the scope and does the service swaps + return new RequestServicesContainer(httpContext, appServiceScopeFactory, appHttpContextAccessor, appServiceProvider); + } + + #region IDisposable Support + private bool disposedValue = false; // To detect redundant calls + + protected virtual void Dispose(bool disposing) + { + if (!disposedValue) + { + if (disposing) + { + ScopeContextAccessor.SetValue(PriorScopeHttpContext); + AppContextAccessor.SetValue(PriorAppHttpContext); + + Context.RequestServices = PriorRequestServices; + Context.ApplicationServices = PriorAppServices; + } + + if (Scope != null) + { + Scope.Dispose(); + Scope = null; + } + + Context = null; + PriorAppServices = null; + PriorRequestServices = null; + ScopeContextAccessor = null; + AppContextAccessor = null; + PriorAppHttpContext = null; + PriorScopeHttpContext = null; + + disposedValue = true; + } + } + + // This code added to correctly implement the disposable pattern. + public void Dispose() + { + // Do not change this code. Put cleanup code in Dispose(bool disposing) above. + Dispose(true); + } + #endregion + + } + +} \ No newline at end of file diff --git a/test/Microsoft.AspNet.Hosting.Tests/Fakes/FakeOptions.cs b/test/Microsoft.AspNet.Hosting.Tests/Fakes/FakeOptions.cs index d3c7ee2b0b..a955ed377e 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/Fakes/FakeOptions.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/Fakes/FakeOptions.cs @@ -7,5 +7,6 @@ namespace Microsoft.AspNet.Hosting.Fakes { public bool Configured { get; set; } public string Environment { get; set; } + public string Message { get; set; } } } \ No newline at end of file diff --git a/test/Microsoft.AspNet.Hosting.Tests/Fakes/IFakeService.cs b/test/Microsoft.AspNet.Hosting.Tests/Fakes/IFakeService.cs new file mode 100644 index 0000000000..e183e13eb2 --- /dev/null +++ b/test/Microsoft.AspNet.Hosting.Tests/Fakes/IFakeService.cs @@ -0,0 +1,8 @@ +// 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. + +namespace Microsoft.AspNet.Hosting.Fakes +{ + public interface IFakeService { } + public class FakeService : IFakeService { } +} \ No newline at end of file diff --git a/test/Microsoft.AspNet.Hosting.Tests/Fakes/Startup.cs b/test/Microsoft.AspNet.Hosting.Tests/Fakes/Startup.cs index 2fa43ea158..6f97e4ceda 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/Fakes/Startup.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/Fakes/Startup.cs @@ -14,37 +14,37 @@ namespace Microsoft.AspNet.Hosting.Fakes public void ConfigureServices(IServiceCollection services) { - services.ConfigureOptions(o => o.Configured = true); + services.Configure(o => o.Configured = true); } - public void ConfigureServicesDev(IServiceCollection services) + public void ConfigureDevServices(IServiceCollection services) { - services.ConfigureOptions(o => + services.Configure(o => { o.Configured = true; o.Environment = "Dev"; }); } - public void ConfigureServicesRetail(IServiceCollection services) + public void ConfigureRetailServices(IServiceCollection services) { - services.ConfigureOptions(o => + services.Configure(o => { o.Configured = true; o.Environment = "Retail"; }); } - public static void ConfigureServicesStatic(IServiceCollection services) + public static void ConfigureStaticServices(IServiceCollection services) { - services.ConfigureOptions(o => + services.Configure(o => { o.Configured = true; o.Environment = "Static"; }); } - public void Configure(IApplicationBuilder builder) + public virtual void Configure(IApplicationBuilder builder) { } } diff --git a/test/Microsoft.AspNet.Hosting.Tests/Fakes/StartupBoom.cs b/test/Microsoft.AspNet.Hosting.Tests/Fakes/StartupBoom.cs new file mode 100644 index 0000000000..6fb647a489 --- /dev/null +++ b/test/Microsoft.AspNet.Hosting.Tests/Fakes/StartupBoom.cs @@ -0,0 +1,12 @@ +// 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. + +namespace Microsoft.AspNet.Hosting.Fakes +{ + public class StartupBoom + { + public StartupBoom() + { + } + } +} \ No newline at end of file diff --git a/test/Microsoft.AspNet.Hosting.Tests/Fakes/StartupUseServices.cs b/test/Microsoft.AspNet.Hosting.Tests/Fakes/StartupUseServices.cs new file mode 100644 index 0000000000..bfd85da550 --- /dev/null +++ b/test/Microsoft.AspNet.Hosting.Tests/Fakes/StartupUseServices.cs @@ -0,0 +1,30 @@ +// 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.Builder; +using Microsoft.Framework.DependencyInjection; + +namespace Microsoft.AspNet.Hosting.Fakes +{ + public class StartupUseServices + { + public StartupUseServices() + { + } + + public void ConfigureUseServicesServices(IServiceCollection services) + { + services.Configure(o => o.Configured = true); + services.AddTransient(); + } + + public void Configure(IApplicationBuilder builder) + { + builder.UseServices(services => + { + services.AddTransient(); + services.Configure(o => o.Message = "Configured"); + }); + } + } +} \ No newline at end of file diff --git a/test/Microsoft.AspNet.Hosting.Tests/Microsoft.AspNet.Hosting.Tests.kproj b/test/Microsoft.AspNet.Hosting.Tests/Microsoft.AspNet.Hosting.Tests.kproj index d20ea65b15..0b04b9270d 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/Microsoft.AspNet.Hosting.Tests.kproj +++ b/test/Microsoft.AspNet.Hosting.Tests/Microsoft.AspNet.Hosting.Tests.kproj @@ -16,6 +16,7 @@ 2.0 + 29216 \ No newline at end of file diff --git a/test/Microsoft.AspNet.Hosting.Tests/StartupManagerTests.cs b/test/Microsoft.AspNet.Hosting.Tests/StartupManagerTests.cs index d84773ad76..2d73f17c22 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/StartupManagerTests.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/StartupManagerTests.cs @@ -53,14 +53,37 @@ namespace Microsoft.AspNet.Hosting startup.Invoke(app); - var options = app.ApplicationServices.GetService>().Options; + var options = app.ApplicationServices.GetService>().Options; Assert.NotNull(options); Assert.True(options.Configured); Assert.Equal(environment, options.Environment); } - [Fact(Skip = "DataProtection registers default Options services; need to figure out what to do with this test.")] - public void StartupClassDoesNotRegisterOptionsWithNoConfigureServices() + [Fact] + public void StartupClassWithConfigureServicesAndUseServicesAddsBothToServices() + { + var serviceCollection = new ServiceCollection(); + serviceCollection.Add(HostingServices.GetDefaultServices()); + var services = serviceCollection.BuildServiceProvider(); + var manager = services.GetService(); + + var startup = manager.LoadStartup("Microsoft.AspNet.Hosting.Tests", "UseServices"); + + var app = new ApplicationBuilder(services); + + startup.Invoke(app); + + Assert.NotNull(app.ApplicationServices.GetService()); + Assert.NotNull(app.ApplicationServices.GetService()); + + var options = app.ApplicationServices.GetService>().Options; + Assert.NotNull(options); + Assert.Equal("Configured", options.Message); + Assert.False(options.Configured); // REVIEW: why doesn't the ConfigureServices ConfigureOptions get run? + } + + [Fact] + public void StartupWithNoConfigureThrows() { var serviceCollection = new ServiceCollection(); serviceCollection.Add(HostingServices.GetDefaultServices()); @@ -68,14 +91,8 @@ namespace Microsoft.AspNet.Hosting var services = serviceCollection.BuildServiceProvider(); var manager = services.GetService(); - var startup = manager.LoadStartup("Microsoft.AspNet.Hosting.Tests", "NoServices"); - - var app = new ApplicationBuilder(services); - - startup.Invoke(app); - - var ex = Assert.Throws(() => app.ApplicationServices.GetService>()); - Assert.True(ex.Message.Contains("No service for type 'Microsoft.Framework.OptionsModel.IOptionsAccessor")); + var ex = Assert.Throws(() => manager.LoadStartup("Microsoft.AspNet.Hosting.Tests", "Boom")); + Assert.True(ex.Message.Contains("ConfigureBoom or Configure method not found")); } public void ConfigurationMethodCalled(object instance) diff --git a/test/Microsoft.AspNet.Hosting.Tests/UseRequestServicesFacts.cs b/test/Microsoft.AspNet.Hosting.Tests/UseRequestServicesFacts.cs new file mode 100644 index 0000000000..597c286054 --- /dev/null +++ b/test/Microsoft.AspNet.Hosting.Tests/UseRequestServicesFacts.cs @@ -0,0 +1,79 @@ +// 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.Builder; +using Microsoft.Framework.DependencyInjection; +using Microsoft.Framework.DependencyInjection.Fallback; +using Xunit; +using Microsoft.AspNet.PipelineCore; +using Microsoft.AspNet.RequestContainer; + +namespace Microsoft.AspNet.Hosting.Tests +{ + public class RequestServicesContainerFacts + { + [Fact] + public void RequestServicesAvailableOnlyAfterRequestServices() + { + var baseServiceProvider = new ServiceCollection() + .Add(HostingServices.GetDefaultServices()) + .BuildServiceProvider(); + var builder = new ApplicationBuilder(baseServiceProvider); + + bool foundRequestServicesBefore = false; + builder.Use(next => async c => + { + foundRequestServicesBefore = c.RequestServices != null; + await next.Invoke(c); + }); + builder.UseRequestServices(); + bool foundRequestServicesAfter = false; + builder.Use(next => async c => + { + foundRequestServicesAfter = c.RequestServices != null; + await next.Invoke(c); + }); + + var context = new DefaultHttpContext(); + builder.Build().Invoke(context); + Assert.False(foundRequestServicesBefore); + Assert.True(foundRequestServicesAfter); + } + + [Fact] + public void EnsureRequestServicesSetsRequestServices() + { + var baseServiceProvider = new ServiceCollection() + .Add(HostingServices.GetDefaultServices()) + .BuildServiceProvider(); + var builder = new ApplicationBuilder(baseServiceProvider); + + bool foundRequestServicesBefore = false; + builder.Use(next => async c => + { + foundRequestServicesBefore = c.RequestServices != null; + await next.Invoke(c); + }); + builder.Use(next => async c => + { + using (var container = RequestServicesContainer.EnsureRequestServices(c)) + { + await next.Invoke(c); + } + }); + bool foundRequestServicesAfter = false; + builder.Use(next => async c => + { + foundRequestServicesAfter = c.RequestServices != null; + await next.Invoke(c); + }); + + var context = new DefaultHttpContext(); + context.ApplicationServices = baseServiceProvider; + builder.Build().Invoke(context); + Assert.False(foundRequestServicesBefore); + Assert.True(foundRequestServicesAfter); + } + + } +} \ No newline at end of file diff --git a/test/Microsoft.AspNet.Hosting.Tests/UseServicesFacts.cs b/test/Microsoft.AspNet.Hosting.Tests/UseServicesFacts.cs index 2dae3babea..f32a45af49 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/UseServicesFacts.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/UseServicesFacts.cs @@ -7,6 +7,8 @@ using Microsoft.Framework.DependencyInjection; using Microsoft.Framework.DependencyInjection.Fallback; using Microsoft.Framework.OptionsModel; using Xunit; +using Microsoft.AspNet.Http; +using Microsoft.AspNet.PipelineCore; namespace Microsoft.AspNet.Hosting.Tests { @@ -18,9 +20,9 @@ namespace Microsoft.AspNet.Hosting.Tests var baseServiceProvider = new ServiceCollection().BuildServiceProvider(); var builder = new ApplicationBuilder(baseServiceProvider); - builder.UsePerRequestServices(serviceCollection => { }); + builder.UseServices(serviceCollection => { }); - var optionsAccessor = builder.ApplicationServices.GetService>(); + var optionsAccessor = builder.ApplicationServices.GetService>(); Assert.NotNull(optionsAccessor); } @@ -32,14 +34,14 @@ namespace Microsoft.AspNet.Hosting.Tests var builder = new ApplicationBuilder(baseServiceProvider); IServiceProvider serviceProvider = null; - builder.UsePerRequestServices(serviceCollection => + builder.UseServices(serviceCollection => { serviceProvider = serviceCollection.BuildServiceProvider(builder.ApplicationServices); return serviceProvider; }); Assert.Same(serviceProvider, builder.ApplicationServices); - var optionsAccessor = builder.ApplicationServices.GetService>(); + var optionsAccessor = builder.ApplicationServices.GetService>(); Assert.NotNull(optionsAccessor); } } diff --git a/test/Microsoft.AspNet.TestHost.Tests/Microsoft.AspNet.TestHost.Tests.kproj b/test/Microsoft.AspNet.TestHost.Tests/Microsoft.AspNet.TestHost.Tests.kproj index 777a4d4460..53d92fe14b 100644 --- a/test/Microsoft.AspNet.TestHost.Tests/Microsoft.AspNet.TestHost.Tests.kproj +++ b/test/Microsoft.AspNet.TestHost.Tests/Microsoft.AspNet.TestHost.Tests.kproj @@ -16,6 +16,7 @@ 2.0 + 29215 \ No newline at end of file From 16fee38c957c131bf1fcf86c4135c8d0e3179cc0 Mon Sep 17 00:00:00 2001 From: Hao Kung Date: Tue, 14 Oct 2014 21:02:33 -0700 Subject: [PATCH 135/987] Handle null httpContext.ApplicationServices --- .../RequestServicesContainer.cs | 18 ++++++++++-------- .../UseRequestServicesFacts.cs | 13 +++++++++---- 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/src/Microsoft.AspNet.RequestContainer/RequestServicesContainer.cs b/src/Microsoft.AspNet.RequestContainer/RequestServicesContainer.cs index c4bbf142c2..921cfcc425 100644 --- a/src/Microsoft.AspNet.RequestContainer/RequestServicesContainer.cs +++ b/src/Microsoft.AspNet.RequestContainer/RequestServicesContainer.cs @@ -55,7 +55,7 @@ namespace Microsoft.AspNet.RequestContainer private IContextAccessor AppContextAccessor { get; set; } // CONSIDER: this could be an extension method on HttpContext instead - public static RequestServicesContainer EnsureRequestServices(HttpContext httpContext) + public static RequestServicesContainer EnsureRequestServices(HttpContext httpContext, IServiceProvider services) { // All done if we already have a request services if (httpContext.RequestServices != null) @@ -63,21 +63,23 @@ namespace Microsoft.AspNet.RequestContainer return null; } - if (httpContext.ApplicationServices == null) + var serviceProvider = httpContext.ApplicationServices ?? services; + + if (serviceProvider == null) { - throw new InvalidOperationException("TODO: httpContext.ApplicationServices is null!"); + throw new InvalidOperationException("TODO: services and httpContext.ApplicationServices are both null!"); } // Matches constructor of RequestContainer - var rootServiceProvider = httpContext.ApplicationServices.GetService(); - var rootHttpContextAccessor = httpContext.ApplicationServices.GetService>(); - var rootServiceScopeFactory = httpContext.ApplicationServices.GetService(); + var rootServiceProvider = serviceProvider.GetService(); + var rootHttpContextAccessor = serviceProvider.GetService>(); + var rootServiceScopeFactory = serviceProvider.GetService(); rootHttpContextAccessor.SetContextSource(ContainerMiddleware.AccessRootHttpContext, ContainerMiddleware.ExchangeRootHttpContext); // Pre Scope setup - var priorApplicationServices = httpContext.ApplicationServices; - var priorRequestServices = httpContext.RequestServices; + var priorApplicationServices = serviceProvider; + var priorRequestServices = serviceProvider; var appServiceProvider = rootServiceProvider; var appServiceScopeFactory = rootServiceScopeFactory; diff --git a/test/Microsoft.AspNet.Hosting.Tests/UseRequestServicesFacts.cs b/test/Microsoft.AspNet.Hosting.Tests/UseRequestServicesFacts.cs index 597c286054..1229df1bb4 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/UseRequestServicesFacts.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/UseRequestServicesFacts.cs @@ -40,8 +40,10 @@ namespace Microsoft.AspNet.Hosting.Tests Assert.True(foundRequestServicesAfter); } - [Fact] - public void EnsureRequestServicesSetsRequestServices() + [Theory] + [InlineData(true)] + [InlineData(false)] + public void EnsureRequestServicesSetsRequestServices(bool initializeApplicationServices) { var baseServiceProvider = new ServiceCollection() .Add(HostingServices.GetDefaultServices()) @@ -56,7 +58,7 @@ namespace Microsoft.AspNet.Hosting.Tests }); builder.Use(next => async c => { - using (var container = RequestServicesContainer.EnsureRequestServices(c)) + using (var container = RequestServicesContainer.EnsureRequestServices(c, baseServiceProvider)) { await next.Invoke(c); } @@ -69,7 +71,10 @@ namespace Microsoft.AspNet.Hosting.Tests }); var context = new DefaultHttpContext(); - context.ApplicationServices = baseServiceProvider; + if (initializeApplicationServices) + { + context.ApplicationServices = baseServiceProvider; + } builder.Build().Invoke(context); Assert.False(foundRequestServicesBefore); Assert.True(foundRequestServicesAfter); From 33dd087e0ff07ca8f685a82f31ed931e331048ea Mon Sep 17 00:00:00 2001 From: Chris Ross Date: Wed, 15 Oct 2014 15:35:29 -0700 Subject: [PATCH 136/987] Move UseMiddleware from RequestContainer to Http.Extensions. --- .../ContainerExtensions.cs | 25 +++---------------- .../project.json | 5 +--- 2 files changed, 4 insertions(+), 26 deletions(-) diff --git a/src/Microsoft.AspNet.RequestContainer/ContainerExtensions.cs b/src/Microsoft.AspNet.RequestContainer/ContainerExtensions.cs index fbd5f08ea4..fe822f5820 100644 --- a/src/Microsoft.AspNet.RequestContainer/ContainerExtensions.cs +++ b/src/Microsoft.AspNet.RequestContainer/ContainerExtensions.cs @@ -3,8 +3,6 @@ using System; using System.Collections.Generic; -using System.Linq; -using System.Reflection; using Microsoft.AspNet.RequestContainer; using Microsoft.Framework.DependencyInjection; using Microsoft.Framework.DependencyInjection.Fallback; @@ -14,33 +12,16 @@ namespace Microsoft.AspNet.Builder { public static class ContainerExtensions { - public static IApplicationBuilder UseMiddleware(this IApplicationBuilder builder, params object[] args) - { - return builder.UseMiddleware(typeof(T), args); - } - - public static IApplicationBuilder UseMiddleware(this IApplicationBuilder builder, Type middleware, params object[] args) - { - // TODO: move this ext method someplace nice - return builder.Use(next => - { - var typeActivator = builder.ApplicationServices.GetService(); - var instance = typeActivator.CreateInstance(builder.ApplicationServices, middleware, new[] { next }.Concat(args).ToArray()); - var methodinfo = middleware.GetMethod("Invoke", BindingFlags.Instance | BindingFlags.Public); - return (RequestDelegate)methodinfo.CreateDelegate(typeof(RequestDelegate), instance); - }); - } - public static IApplicationBuilder UseRequestServices(this IApplicationBuilder builder) { - return builder.UseMiddleware(typeof(ContainerMiddleware)); + return builder.UseMiddleware(); } public static IApplicationBuilder UseRequestServices(this IApplicationBuilder builder, IServiceProvider applicationServices) { builder.ApplicationServices = applicationServices; - return builder.UseMiddleware(typeof(ContainerMiddleware)); + return builder.UseMiddleware(); } public static IApplicationBuilder UseServices(this IApplicationBuilder builder, IEnumerable applicationServices) @@ -64,7 +45,7 @@ namespace Microsoft.AspNet.Builder serviceCollection.Add(OptionsServices.GetDefaultServices()); builder.ApplicationServices = configureServices(serviceCollection); - return builder.UseMiddleware(typeof(ContainerMiddleware)); + return builder.UseMiddleware(); } } } \ No newline at end of file diff --git a/src/Microsoft.AspNet.RequestContainer/project.json b/src/Microsoft.AspNet.RequestContainer/project.json index 2f81f60c6c..fc73a32d6a 100644 --- a/src/Microsoft.AspNet.RequestContainer/project.json +++ b/src/Microsoft.AspNet.RequestContainer/project.json @@ -2,6 +2,7 @@ "version": "1.0.0-*", "dependencies": { "Microsoft.AspNet.Http": "1.0.0-*", + "Microsoft.AspNet.Http.Extensions": "1.0.0-*", "Microsoft.Framework.DependencyInjection": "1.0.0-*", "Microsoft.Framework.OptionsModel": "1.0.0-*" }, @@ -12,10 +13,6 @@ "System.Collections": "4.0.10-beta-*", "System.ComponentModel": "4.0.0-beta-*", "System.Diagnostics.Debug": "4.0.10-beta-*", - "System.Linq": "4.0.0-beta-*", - "System.Reflection": "4.0.10-beta-*", - "System.Reflection.Extensions": "4.0.0-beta-*", - "System.Reflection.TypeExtensions": "4.0.0-beta-*", "System.Runtime": "4.0.20-beta-*", "System.Runtime.Extensions": "4.0.10-beta-*", "System.Threading": "4.0.0-beta-*", From 4efa6a428b0872820e70e086813cf891212f1469 Mon Sep 17 00:00:00 2001 From: Hao Kung Date: Thu, 16 Oct 2014 11:44:52 -0700 Subject: [PATCH 137/987] Support IServiceProvider ConfigureServices() --- .../Startup/StartupLoader.cs | 38 +++++++++----- .../Fakes/Startup.cs | 49 +++++++++++++++++++ .../StartupManagerTests.cs | 22 +++++++++ 3 files changed, 96 insertions(+), 13 deletions(-) diff --git a/src/Microsoft.AspNet.Hosting/Startup/StartupLoader.cs b/src/Microsoft.AspNet.Hosting/Startup/StartupLoader.cs index 7658009466..6e9591949b 100644 --- a/src/Microsoft.AspNet.Hosting/Startup/StartupLoader.cs +++ b/src/Microsoft.AspNet.Hosting/Startup/StartupLoader.cs @@ -43,17 +43,19 @@ namespace Microsoft.AspNet.Hosting.Startup } return null; } - if (returnType != null && methodInfo.ReturnType != returnType) { - throw new Exception(string.Format("TODO: {0} method does not return " + returnType.Name, - methodInfo.Name)); + if (required) + { + throw new Exception(string.Format("TODO: {0} method does not return " + returnType.Name, + methodInfo.Name)); + } + return null; } - return methodInfo; } - private void Invoke(MethodInfo methodInfo, object instance, IApplicationBuilder builder, IServiceCollection services = null) + private object Invoke(MethodInfo methodInfo, object instance, IApplicationBuilder builder, IServiceCollection services = null) { var parameterInfos = methodInfo.GetParameters(); var parameters = new object[parameterInfos.Length]; @@ -84,7 +86,7 @@ namespace Microsoft.AspNet.Hosting.Startup } } } - methodInfo.Invoke(instance, parameters); + return methodInfo.Invoke(instance, parameters); } public Action LoadStartup( @@ -137,8 +139,8 @@ namespace Microsoft.AspNet.Hosting.Startup } var configureMethod = FindMethod(type, "Configure{0}", environmentName, typeof(void), required: true); - // TODO: accept IServiceProvider method as well? - var servicesMethod = FindMethod(type, "Configure{0}Services", environmentName, typeof(void), required: false); + var servicesMethod = FindMethod(type, "Configure{0}Services", environmentName, typeof(IServiceProvider), required: false) + ?? FindMethod(type, "Configure{0}Services", environmentName, typeof(void), required: false); object instance = null; if (!configureMethod.IsStatic || (servicesMethod != null && !servicesMethod.IsStatic)) @@ -149,12 +151,22 @@ namespace Microsoft.AspNet.Hosting.Startup { if (servicesMethod != null) { - var services = new ServiceCollection(); - services.Add(OptionsServices.GetDefaultServices()); - Invoke(servicesMethod, instance, builder, services); - if (builder != null) + if (servicesMethod.ReturnType == typeof(IServiceProvider)) { - builder.ApplicationServices = services.BuildServiceProvider(builder.ApplicationServices); + // IServiceProvider ConfigureServices() + builder.ApplicationServices = (Invoke(servicesMethod, instance, builder) as IServiceProvider) + ?? builder.ApplicationServices; + } + else + { + // void ConfigureServices(IServiceCollection) + var services = new ServiceCollection(); + services.Add(OptionsServices.GetDefaultServices()); + Invoke(servicesMethod, instance, builder, services); + if (builder != null) + { + builder.ApplicationServices = services.BuildServiceProvider(builder.ApplicationServices); + } } } Invoke(configureMethod, instance, builder); diff --git a/test/Microsoft.AspNet.Hosting.Tests/Fakes/Startup.cs b/test/Microsoft.AspNet.Hosting.Tests/Fakes/Startup.cs index 6f97e4ceda..dab52127bd 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/Fakes/Startup.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/Fakes/Startup.cs @@ -3,6 +3,9 @@ using Microsoft.AspNet.Builder; using Microsoft.Framework.DependencyInjection; +using Microsoft.Framework.DependencyInjection.Fallback; +using Microsoft.Framework.OptionsModel; +using System; namespace Microsoft.AspNet.Hosting.Fakes { @@ -44,6 +47,52 @@ namespace Microsoft.AspNet.Hosting.Fakes }); } + public static IServiceProvider ConfigureStaticProviderServices() + { + var services = new ServiceCollection(); + services.Add(OptionsServices.GetDefaultServices()); + services.Configure(o => + { + o.Configured = true; + o.Environment = "StaticProvider"; + }); + return services.BuildServiceProvider(); + } + + public static IServiceProvider ConfigureFallbackProviderServices(IServiceProvider fallback) + { + return fallback; + } + + public static IServiceProvider ConfigureNullServices() + { + return null; + } + + public IServiceProvider ConfigureProviderServices() + { + var services = new ServiceCollection(); + services.Add(OptionsServices.GetDefaultServices()); + services.Configure(o => + { + o.Configured = true; + o.Environment = "Provider"; + }); + return services.BuildServiceProvider(); + } + + public IServiceProvider ConfigureProviderArgsServices(IApplicationBuilder me) + { + var services = new ServiceCollection(); + services.Add(OptionsServices.GetDefaultServices()); + services.Configure(o => + { + o.Configured = true; + o.Environment = "ProviderArgs"; + }); + return services.BuildServiceProvider(); + } + public virtual void Configure(IApplicationBuilder builder) { } diff --git a/test/Microsoft.AspNet.Hosting.Tests/StartupManagerTests.cs b/test/Microsoft.AspNet.Hosting.Tests/StartupManagerTests.cs index 2d73f17c22..6a7527e749 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/StartupManagerTests.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/StartupManagerTests.cs @@ -40,6 +40,9 @@ namespace Microsoft.AspNet.Hosting [InlineData("Dev")] [InlineData("Retail")] [InlineData("Static")] + [InlineData("StaticProvider")] + [InlineData("Provider")] + [InlineData("ProviderArgs")] public void StartupClassAddsConfigureServicesToApplicationServices(string environment) { var serviceCollection = new ServiceCollection(); @@ -59,6 +62,25 @@ namespace Microsoft.AspNet.Hosting Assert.Equal(environment, options.Environment); } + [Theory] + [InlineData("Null")] + [InlineData("FallbackProvider")] + public void StartupClassConfigureServicesThatFallsbackToApplicationServices(string env) + { + var serviceCollection = new ServiceCollection(); + serviceCollection.Add(HostingServices.GetDefaultServices()); + var services = serviceCollection.BuildServiceProvider(); + var manager = services.GetService(); + + var startup = manager.LoadStartup("Microsoft.AspNet.Hosting.Tests", env); + + var app = new ApplicationBuilder(services); + + startup.Invoke(app); + + Assert.Equal(services, app.ApplicationServices); + } + [Fact] public void StartupClassWithConfigureServicesAndUseServicesAddsBothToServices() { From cd90a337eeda518ab47d709c506ba42757746bab Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Thu, 16 Oct 2014 16:20:52 -0700 Subject: [PATCH 138/987] Change GetService calls to GetRequiredService GetRequiredService throws for missing services like GetService used to. --- src/Microsoft.AspNet.Hosting/HostingEngine.cs | 2 +- src/Microsoft.AspNet.Hosting/Program.cs | 6 +++--- .../Startup/StartupLoader.cs | 2 +- src/Microsoft.AspNet.Hosting/WebApplication.cs | 2 +- .../ContainerMiddleware.cs | 4 ++-- .../RequestServicesContainer.cs | 12 ++++++------ src/Microsoft.AspNet.TestHost/TestServer.cs | 6 +++--- .../HostingEngineTests.cs | 4 ++-- .../StartupManagerTests.cs | 18 +++++++++--------- .../UseServicesFacts.cs | 4 ++-- .../TestServerTests.cs | 2 +- 11 files changed, 31 insertions(+), 31 deletions(-) diff --git a/src/Microsoft.AspNet.Hosting/HostingEngine.cs b/src/Microsoft.AspNet.Hosting/HostingEngine.cs index f7642f14f8..4eb09ab00d 100644 --- a/src/Microsoft.AspNet.Hosting/HostingEngine.cs +++ b/src/Microsoft.AspNet.Hosting/HostingEngine.cs @@ -37,7 +37,7 @@ namespace Microsoft.AspNet.Hosting InitalizeServerFactory(context); EnsureApplicationDelegate(context); - var applicationLifetime = (ApplicationLifetime)context.Services.GetService(); + var applicationLifetime = (ApplicationLifetime)context.Services.GetRequiredService(); var pipeline = new PipelineInstance(_httpContextFactory, context.ApplicationDelegate); var server = context.ServerFactory.Start(context.Server, pipeline.Invoke); diff --git a/src/Microsoft.AspNet.Hosting/Program.cs b/src/Microsoft.AspNet.Hosting/Program.cs index 5d83450f4d..a339fa9de9 100644 --- a/src/Microsoft.AspNet.Hosting/Program.cs +++ b/src/Microsoft.AspNet.Hosting/Program.cs @@ -36,7 +36,7 @@ namespace Microsoft.AspNet.Hosting config.AddEnvironmentVariables(); config.AddCommandLine(args); - var appEnv = _serviceProvider.GetService(); + var appEnv = _serviceProvider.GetRequiredService(); var hostingEnv = new HostingEnvironment() { @@ -67,8 +67,8 @@ namespace Microsoft.AspNet.Hosting EnvironmentName = hostingEnv.EnvironmentName, }; - var engine = services.GetService(); - var appShutdownService = _serviceProvider.GetService(); + var engine = services.GetRequiredService(); + var appShutdownService = _serviceProvider.GetRequiredService(); var shutdownHandle = new ManualResetEvent(false); var serverShutdown = engine.Start(context); diff --git a/src/Microsoft.AspNet.Hosting/Startup/StartupLoader.cs b/src/Microsoft.AspNet.Hosting/Startup/StartupLoader.cs index 6e9591949b..376ba3a07f 100644 --- a/src/Microsoft.AspNet.Hosting/Startup/StartupLoader.cs +++ b/src/Microsoft.AspNet.Hosting/Startup/StartupLoader.cs @@ -74,7 +74,7 @@ namespace Microsoft.AspNet.Hosting.Startup { try { - parameters[index] = _services.GetService(parameterInfo.ParameterType); + parameters[index] = _services.GetRequiredService(parameterInfo.ParameterType); } catch (Exception) { diff --git a/src/Microsoft.AspNet.Hosting/WebApplication.cs b/src/Microsoft.AspNet.Hosting/WebApplication.cs index b891a0b5a7..054f90d6d4 100644 --- a/src/Microsoft.AspNet.Hosting/WebApplication.cs +++ b/src/Microsoft.AspNet.Hosting/WebApplication.cs @@ -19,7 +19,7 @@ namespace Microsoft.AspNet.Hosting Services = serviceCollection.BuildServiceProvider() }; - var engine = context.Services.GetService(); + var engine = context.Services.GetRequiredService(); if (engine == null) { throw new Exception("TODO: IHostingEngine service not available exception"); diff --git a/src/Microsoft.AspNet.RequestContainer/ContainerMiddleware.cs b/src/Microsoft.AspNet.RequestContainer/ContainerMiddleware.cs index 3c1e5e52c9..4145525ab8 100644 --- a/src/Microsoft.AspNet.RequestContainer/ContainerMiddleware.cs +++ b/src/Microsoft.AspNet.RequestContainer/ContainerMiddleware.cs @@ -88,8 +88,8 @@ namespace Microsoft.AspNet.RequestContainer priorApplicationServices != appServiceProvider) { appServiceProvider = priorApplicationServices; - appServiceScopeFactory = priorApplicationServices.GetService(); - appHttpContextAccessor = priorApplicationServices.GetService>(); + appServiceScopeFactory = priorApplicationServices.GetRequiredService(); + appHttpContextAccessor = priorApplicationServices.GetRequiredService>(); } using (var container = new RequestServicesContainer(httpContext, appServiceScopeFactory, appHttpContextAccessor, appServiceProvider)) diff --git a/src/Microsoft.AspNet.RequestContainer/RequestServicesContainer.cs b/src/Microsoft.AspNet.RequestContainer/RequestServicesContainer.cs index 921cfcc425..a7c646321e 100644 --- a/src/Microsoft.AspNet.RequestContainer/RequestServicesContainer.cs +++ b/src/Microsoft.AspNet.RequestContainer/RequestServicesContainer.cs @@ -36,7 +36,7 @@ namespace Microsoft.AspNet.RequestContainer // Begin the scope Scope = scopeFactory.CreateScope(); - ScopeContextAccessor = Scope.ServiceProvider.GetService>(); + ScopeContextAccessor = Scope.ServiceProvider.GetRequiredService>(); Context.ApplicationServices = appServiceProvider; Context.RequestServices = Scope.ServiceProvider; @@ -71,9 +71,9 @@ namespace Microsoft.AspNet.RequestContainer } // Matches constructor of RequestContainer - var rootServiceProvider = serviceProvider.GetService(); - var rootHttpContextAccessor = serviceProvider.GetService>(); - var rootServiceScopeFactory = serviceProvider.GetService(); + var rootServiceProvider = serviceProvider.GetRequiredService(); + var rootHttpContextAccessor = serviceProvider.GetRequiredService>(); + var rootServiceScopeFactory = serviceProvider.GetRequiredService(); rootHttpContextAccessor.SetContextSource(ContainerMiddleware.AccessRootHttpContext, ContainerMiddleware.ExchangeRootHttpContext); @@ -89,8 +89,8 @@ namespace Microsoft.AspNet.RequestContainer priorApplicationServices != appServiceProvider) { appServiceProvider = priorApplicationServices; - appServiceScopeFactory = priorApplicationServices.GetService(); - appHttpContextAccessor = priorApplicationServices.GetService>(); + appServiceScopeFactory = priorApplicationServices.GetRequiredService(); + appHttpContextAccessor = priorApplicationServices.GetRequiredService>(); } // Creates the scope and does the service swaps diff --git a/src/Microsoft.AspNet.TestHost/TestServer.cs b/src/Microsoft.AspNet.TestHost/TestServer.cs index dee516dd2d..977623c3d0 100644 --- a/src/Microsoft.AspNet.TestHost/TestServer.cs +++ b/src/Microsoft.AspNet.TestHost/TestServer.cs @@ -26,7 +26,7 @@ namespace Microsoft.AspNet.TestHost public TestServer(IConfiguration config, IServiceProvider serviceProvider, Action appStartup) { - var appEnv = serviceProvider.GetService(); + var appEnv = serviceProvider.GetRequiredService(); HostingContext hostContext = new HostingContext() { @@ -37,7 +37,7 @@ namespace Microsoft.AspNet.TestHost ApplicationStartup = appStartup }; - var engine = serviceProvider.GetService(); + var engine = serviceProvider.GetRequiredService(); _appInstance = engine.Start(hostContext); } @@ -48,7 +48,7 @@ namespace Microsoft.AspNet.TestHost public static TestServer Create(IServiceProvider provider, Action app) { - var appEnv = provider.GetService(); + var appEnv = provider.GetRequiredService(); var hostingEnv = new HostingEnvironment() { diff --git a/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs b/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs index 6f79dc1eab..01ec585067 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs @@ -24,7 +24,7 @@ namespace Microsoft.AspNet.Hosting serviceCollection.Add(HostingServices.GetDefaultServices()); var services = serviceCollection.BuildServiceProvider(); - var engine = services.GetService(); + var engine = services.GetRequiredService(); Assert.NotNull(engine); } @@ -36,7 +36,7 @@ namespace Microsoft.AspNet.Hosting serviceCollection.Add(HostingServices.GetDefaultServices()); var services = serviceCollection.BuildServiceProvider(); - var engine = services.GetService(); + var engine = services.GetRequiredService(); var context = new HostingContext { diff --git a/test/Microsoft.AspNet.Hosting.Tests/StartupManagerTests.cs b/test/Microsoft.AspNet.Hosting.Tests/StartupManagerTests.cs index 6a7527e749..764d0f9ff9 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/StartupManagerTests.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/StartupManagerTests.cs @@ -26,7 +26,7 @@ namespace Microsoft.AspNet.Hosting serviceCollection.AddInstance(this); var services = serviceCollection.BuildServiceProvider(); - var manager = services.GetService(); + var manager = services.GetRequiredService(); var startup = manager.LoadStartup("Microsoft.AspNet.Hosting.Tests", "WithServices"); @@ -48,7 +48,7 @@ namespace Microsoft.AspNet.Hosting var serviceCollection = new ServiceCollection(); serviceCollection.Add(HostingServices.GetDefaultServices()); var services = serviceCollection.BuildServiceProvider(); - var manager = services.GetService(); + var manager = services.GetRequiredService(); var startup = manager.LoadStartup("Microsoft.AspNet.Hosting.Tests", environment ?? ""); @@ -56,7 +56,7 @@ namespace Microsoft.AspNet.Hosting startup.Invoke(app); - var options = app.ApplicationServices.GetService>().Options; + var options = app.ApplicationServices.GetRequiredService>().Options; Assert.NotNull(options); Assert.True(options.Configured); Assert.Equal(environment, options.Environment); @@ -70,7 +70,7 @@ namespace Microsoft.AspNet.Hosting var serviceCollection = new ServiceCollection(); serviceCollection.Add(HostingServices.GetDefaultServices()); var services = serviceCollection.BuildServiceProvider(); - var manager = services.GetService(); + var manager = services.GetRequiredService(); var startup = manager.LoadStartup("Microsoft.AspNet.Hosting.Tests", env); @@ -87,7 +87,7 @@ namespace Microsoft.AspNet.Hosting var serviceCollection = new ServiceCollection(); serviceCollection.Add(HostingServices.GetDefaultServices()); var services = serviceCollection.BuildServiceProvider(); - var manager = services.GetService(); + var manager = services.GetRequiredService(); var startup = manager.LoadStartup("Microsoft.AspNet.Hosting.Tests", "UseServices"); @@ -95,10 +95,10 @@ namespace Microsoft.AspNet.Hosting startup.Invoke(app); - Assert.NotNull(app.ApplicationServices.GetService()); - Assert.NotNull(app.ApplicationServices.GetService()); + Assert.NotNull(app.ApplicationServices.GetRequiredService()); + Assert.NotNull(app.ApplicationServices.GetRequiredService()); - var options = app.ApplicationServices.GetService>().Options; + var options = app.ApplicationServices.GetRequiredService>().Options; Assert.NotNull(options); Assert.Equal("Configured", options.Message); Assert.False(options.Configured); // REVIEW: why doesn't the ConfigureServices ConfigureOptions get run? @@ -111,7 +111,7 @@ namespace Microsoft.AspNet.Hosting serviceCollection.Add(HostingServices.GetDefaultServices()); serviceCollection.AddInstance(this); var services = serviceCollection.BuildServiceProvider(); - var manager = services.GetService(); + var manager = services.GetRequiredService(); var ex = Assert.Throws(() => manager.LoadStartup("Microsoft.AspNet.Hosting.Tests", "Boom")); Assert.True(ex.Message.Contains("ConfigureBoom or Configure method not found")); diff --git a/test/Microsoft.AspNet.Hosting.Tests/UseServicesFacts.cs b/test/Microsoft.AspNet.Hosting.Tests/UseServicesFacts.cs index f32a45af49..d556e2b4fe 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/UseServicesFacts.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/UseServicesFacts.cs @@ -22,7 +22,7 @@ namespace Microsoft.AspNet.Hosting.Tests builder.UseServices(serviceCollection => { }); - var optionsAccessor = builder.ApplicationServices.GetService>(); + var optionsAccessor = builder.ApplicationServices.GetRequiredService>(); Assert.NotNull(optionsAccessor); } @@ -41,7 +41,7 @@ namespace Microsoft.AspNet.Hosting.Tests }); Assert.Same(serviceProvider, builder.ApplicationServices); - var optionsAccessor = builder.ApplicationServices.GetService>(); + var optionsAccessor = builder.ApplicationServices.GetRequiredService>(); Assert.NotNull(optionsAccessor); } } diff --git a/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs b/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs index 025d3a7a21..8a9bacf97b 100644 --- a/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs +++ b/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs @@ -61,7 +61,7 @@ namespace Microsoft.AspNet.TestHost { TestServer server = TestServer.Create(app => { - var env = app.ApplicationServices.GetService(); + var env = app.ApplicationServices.GetRequiredService(); Assert.Equal(Path.GetFullPath("testroot"), env.WebRoot); }); } From d4778e1ad1026a4ee8cbcc1efb53a29694932a34 Mon Sep 17 00:00:00 2001 From: Chris Ross Date: Fri, 17 Oct 2014 10:01:13 -0700 Subject: [PATCH 139/987] Add missing Contracts dependency. --- src/Microsoft.AspNet.Hosting/project.json | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Microsoft.AspNet.Hosting/project.json b/src/Microsoft.AspNet.Hosting/project.json index 562e25d619..0165011fdb 100644 --- a/src/Microsoft.AspNet.Hosting/project.json +++ b/src/Microsoft.AspNet.Hosting/project.json @@ -19,6 +19,7 @@ "System.Collections": "4.0.10-beta-*", "System.ComponentModel": "4.0.0-beta-*", "System.Console": "4.0.0-beta-*", + "System.Diagnostics.Contracts": "4.0.0-beta-*", "System.Diagnostics.Debug": "4.0.10-beta-*", "System.IO": "4.0.10-beta-*", "System.Linq": "4.0.0-beta-*", From 941344bdc39dde9d6599693cdde1edbec673700e Mon Sep 17 00:00:00 2001 From: Pranav K Date: Tue, 21 Oct 2014 12:43:13 -0700 Subject: [PATCH 140/987] Updating build.sh to work on Mono --- build.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build.sh b/build.sh index 4323aefc48..c7873ef58e 100755 --- a/build.sh +++ b/build.sh @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash if test `uname` = Darwin; then cachedir=~/Library/Caches/KBuild @@ -28,7 +28,7 @@ if test ! -d packages/KoreBuild; then fi if ! type k > /dev/null 2>&1; then - source setup/kvm.sh + source packages/KoreBuild/build/kvm.sh fi if ! type k > /dev/null 2>&1; then From c9fbaccde1f67d4ec976d16d6c0c93574ba1b03d Mon Sep 17 00:00:00 2001 From: Pranav K Date: Fri, 24 Oct 2014 00:45:27 -0700 Subject: [PATCH 141/987] Cleaning up project.json Updating Newtonsoft.Json version to 6.0.6 --- src/Microsoft.AspNet.Hosting/project.json | 19 ++----------------- .../project.json | 14 +------------- src/Microsoft.AspNet.TestHost/project.json | 12 +----------- .../project.json | 2 -- 4 files changed, 4 insertions(+), 43 deletions(-) diff --git a/src/Microsoft.AspNet.Hosting/project.json b/src/Microsoft.AspNet.Hosting/project.json index 0165011fdb..5346ba2067 100644 --- a/src/Microsoft.AspNet.Hosting/project.json +++ b/src/Microsoft.AspNet.Hosting/project.json @@ -1,33 +1,18 @@ { "version": "1.0.0-*", "dependencies": { - "Microsoft.AspNet.FeatureModel": "1.0.0-*", - "Microsoft.AspNet.Http": "1.0.0-*", "Microsoft.AspNet.PipelineCore": "1.0.0-*", "Microsoft.AspNet.Security.DataProtection": "1.0.0-*", - "Microsoft.Framework.ConfigurationModel": "1.0.0-*", - "Microsoft.Framework.DependencyInjection": "1.0.0-*", "Microsoft.Framework.Logging": "1.0.0-*", "Microsoft.Framework.OptionsModel": "1.0.0-*", "Microsoft.Framework.Runtime.Interfaces": { "version": "1.0.0-*", "type": "build" }, - "Newtonsoft.Json": "6.0.4" + "Newtonsoft.Json": "6.0.6" }, "frameworks": { "aspnet50": { }, "aspnetcore50": { "dependencies": { - "System.Collections": "4.0.10-beta-*", - "System.ComponentModel": "4.0.0-beta-*", - "System.Console": "4.0.0-beta-*", - "System.Diagnostics.Contracts": "4.0.0-beta-*", - "System.Diagnostics.Debug": "4.0.10-beta-*", - "System.IO": "4.0.10-beta-*", - "System.Linq": "4.0.0-beta-*", - "System.Reflection": "4.0.10-beta-*", - "System.Runtime": "4.0.20-beta-*", - "System.Runtime.Extensions": "4.0.10-beta-*", - "System.Threading": "4.0.0-beta-*", - "System.Threading.Tasks": "4.0.10-beta-*" + "System.Console": "4.0.0-beta-*" } } } diff --git a/src/Microsoft.AspNet.RequestContainer/project.json b/src/Microsoft.AspNet.RequestContainer/project.json index fc73a32d6a..e9d11e207f 100644 --- a/src/Microsoft.AspNet.RequestContainer/project.json +++ b/src/Microsoft.AspNet.RequestContainer/project.json @@ -1,23 +1,11 @@ { "version": "1.0.0-*", "dependencies": { - "Microsoft.AspNet.Http": "1.0.0-*", "Microsoft.AspNet.Http.Extensions": "1.0.0-*", - "Microsoft.Framework.DependencyInjection": "1.0.0-*", "Microsoft.Framework.OptionsModel": "1.0.0-*" }, "frameworks": { "aspnet50": {}, - "aspnetcore50": { - "dependencies": { - "System.Collections": "4.0.10-beta-*", - "System.ComponentModel": "4.0.0-beta-*", - "System.Diagnostics.Debug": "4.0.10-beta-*", - "System.Runtime": "4.0.20-beta-*", - "System.Runtime.Extensions": "4.0.10-beta-*", - "System.Threading": "4.0.0-beta-*", - "System.Threading.Tasks": "4.0.10-beta-*" - } - } + "aspnetcore50": {} } } diff --git a/src/Microsoft.AspNet.TestHost/project.json b/src/Microsoft.AspNet.TestHost/project.json index 69ffdf1d4e..ee0ffcfd3f 100644 --- a/src/Microsoft.AspNet.TestHost/project.json +++ b/src/Microsoft.AspNet.TestHost/project.json @@ -11,17 +11,7 @@ }, "aspnetcore50": { "dependencies": { - "System.Collections": "4.0.10-beta-*", - "System.ComponentModel": "4.0.0-beta-*", - "System.Globalization": "4.0.10-beta-*", - "System.Linq": "4.0.0-beta-*", - "System.Reflection": "4.0.10-beta-*", - "System.Runtime": "4.0.20-beta-*", - "System.Runtime.Extensions": "4.0.10-beta-*", - "System.Runtime.Serialization.Primitives": "4.0.0-beta-*", - "System.Threading": "4.0.0-beta-*", - "System.Threading.Tasks": "4.0.10-beta-*", - "System.Threading.Thread": "4.0.0-beta-*", + "System.Diagnostics.Contracts": "4.0.0-beta", "System.Net.Http": "4.0.0-beta-*" } } diff --git a/test/Microsoft.AspNet.TestHost.Tests/project.json b/test/Microsoft.AspNet.TestHost.Tests/project.json index b9d539b2fa..ef0573cbe7 100644 --- a/test/Microsoft.AspNet.TestHost.Tests/project.json +++ b/test/Microsoft.AspNet.TestHost.Tests/project.json @@ -1,8 +1,6 @@ { "dependencies": { - "Microsoft.AspNet.Hosting": "1.0.0-*", "Microsoft.AspNet.TestHost": "1.0.0-*", - "Microsoft.Framework.Runtime.Interfaces": "1.0.0-*", "Xunit.KRunner": "1.0.0-*" }, "commands": { From 9309765ffa6cdef562616d354212346d22868c37 Mon Sep 17 00:00:00 2001 From: Pranav K Date: Fri, 24 Oct 2014 08:01:10 -0700 Subject: [PATCH 142/987] Fixing System.Diagnostics.Contracts reference --- src/Microsoft.AspNet.TestHost/project.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Microsoft.AspNet.TestHost/project.json b/src/Microsoft.AspNet.TestHost/project.json index ee0ffcfd3f..86f2d33e78 100644 --- a/src/Microsoft.AspNet.TestHost/project.json +++ b/src/Microsoft.AspNet.TestHost/project.json @@ -11,7 +11,7 @@ }, "aspnetcore50": { "dependencies": { - "System.Diagnostics.Contracts": "4.0.0-beta", + "System.Diagnostics.Contracts": "4.0.0-beta-*", "System.Net.Http": "4.0.0-beta-*" } } From 5b515fd13241801d547f497f8da66d6d8010953f Mon Sep 17 00:00:00 2001 From: David Fowler Date: Wed, 29 Oct 2014 10:22:19 -0700 Subject: [PATCH 143/987] Updated JSON.NET to 6.0.6 --- src/Microsoft.AspNet.Hosting/project.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Microsoft.AspNet.Hosting/project.json b/src/Microsoft.AspNet.Hosting/project.json index 0165011fdb..29c8cb1083 100644 --- a/src/Microsoft.AspNet.Hosting/project.json +++ b/src/Microsoft.AspNet.Hosting/project.json @@ -10,7 +10,7 @@ "Microsoft.Framework.Logging": "1.0.0-*", "Microsoft.Framework.OptionsModel": "1.0.0-*", "Microsoft.Framework.Runtime.Interfaces": { "version": "1.0.0-*", "type": "build" }, - "Newtonsoft.Json": "6.0.4" + "Newtonsoft.Json": "6.0.6" }, "frameworks": { "aspnet50": { }, From c9e0f9beb16b489e34586d38ccfcdd01ee4c33a1 Mon Sep 17 00:00:00 2001 From: David Fowler Date: Fri, 31 Oct 2014 01:06:50 -0700 Subject: [PATCH 144/987] Added package descriptions --- src/Microsoft.AspNet.Hosting/project.json | 1 + src/Microsoft.AspNet.RequestContainer/project.json | 1 + src/Microsoft.AspNet.TestHost/project.json | 1 + 3 files changed, 3 insertions(+) diff --git a/src/Microsoft.AspNet.Hosting/project.json b/src/Microsoft.AspNet.Hosting/project.json index 29c8cb1083..0ce52748d1 100644 --- a/src/Microsoft.AspNet.Hosting/project.json +++ b/src/Microsoft.AspNet.Hosting/project.json @@ -1,5 +1,6 @@ { "version": "1.0.0-*", + "description": "ASP.NET 5 core hosting infrastructure and startup logic for web applications.", "dependencies": { "Microsoft.AspNet.FeatureModel": "1.0.0-*", "Microsoft.AspNet.Http": "1.0.0-*", diff --git a/src/Microsoft.AspNet.RequestContainer/project.json b/src/Microsoft.AspNet.RequestContainer/project.json index fc73a32d6a..fe61e42058 100644 --- a/src/Microsoft.AspNet.RequestContainer/project.json +++ b/src/Microsoft.AspNet.RequestContainer/project.json @@ -1,5 +1,6 @@ { "version": "1.0.0-*", + "description": "ASP.NET 5 enables per-request scoping of services.", "dependencies": { "Microsoft.AspNet.Http": "1.0.0-*", "Microsoft.AspNet.Http.Extensions": "1.0.0-*", diff --git a/src/Microsoft.AspNet.TestHost/project.json b/src/Microsoft.AspNet.TestHost/project.json index 69ffdf1d4e..74e19b6e44 100644 --- a/src/Microsoft.AspNet.TestHost/project.json +++ b/src/Microsoft.AspNet.TestHost/project.json @@ -1,5 +1,6 @@ { "version": "1.0.0-*", + "description": "ASP.NET 5 web server for writing and running tests.", "dependencies": { "Microsoft.AspNet.Hosting": "1.0.0-*" }, From 7f1024aac0174e353b50624b5ece845805d1e115 Mon Sep 17 00:00:00 2001 From: Hao Kung Date: Tue, 4 Nov 2014 12:32:24 -0800 Subject: [PATCH 145/987] Unify ConfigureServices to take IServiceCollection with Options --- src/Microsoft.AspNet.Hosting/Startup/StartupLoader.cs | 8 ++++---- test/Microsoft.AspNet.Hosting.Tests/Fakes/Startup.cs | 4 +--- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/src/Microsoft.AspNet.Hosting/Startup/StartupLoader.cs b/src/Microsoft.AspNet.Hosting/Startup/StartupLoader.cs index 376ba3a07f..1c6b2eb98a 100644 --- a/src/Microsoft.AspNet.Hosting/Startup/StartupLoader.cs +++ b/src/Microsoft.AspNet.Hosting/Startup/StartupLoader.cs @@ -151,17 +151,17 @@ namespace Microsoft.AspNet.Hosting.Startup { if (servicesMethod != null) { + var services = new ServiceCollection(); + services.Add(OptionsServices.GetDefaultServices()); if (servicesMethod.ReturnType == typeof(IServiceProvider)) { - // IServiceProvider ConfigureServices() - builder.ApplicationServices = (Invoke(servicesMethod, instance, builder) as IServiceProvider) + // IServiceProvider ConfigureServices(IServiceCollection) + builder.ApplicationServices = (Invoke(servicesMethod, instance, builder, services) as IServiceProvider) ?? builder.ApplicationServices; } else { // void ConfigureServices(IServiceCollection) - var services = new ServiceCollection(); - services.Add(OptionsServices.GetDefaultServices()); Invoke(servicesMethod, instance, builder, services); if (builder != null) { diff --git a/test/Microsoft.AspNet.Hosting.Tests/Fakes/Startup.cs b/test/Microsoft.AspNet.Hosting.Tests/Fakes/Startup.cs index dab52127bd..5a85b82357 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/Fakes/Startup.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/Fakes/Startup.cs @@ -69,10 +69,8 @@ namespace Microsoft.AspNet.Hosting.Fakes return null; } - public IServiceProvider ConfigureProviderServices() + public IServiceProvider ConfigureProviderServices(IServiceCollection services) { - var services = new ServiceCollection(); - services.Add(OptionsServices.GetDefaultServices()); services.Configure(o => { o.Configured = true; From 5a55767162f6ff67fa84d05da72262f1e54946a1 Mon Sep 17 00:00:00 2001 From: Pranav K Date: Thu, 6 Nov 2014 10:48:08 -0800 Subject: [PATCH 146/987] Updating to release NuGet.config --- NuGet.Config | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NuGet.Config b/NuGet.Config index f41e9c631d..2d3b0cb857 100644 --- a/NuGet.Config +++ b/NuGet.Config @@ -1,7 +1,7 @@  - + From 65f595ca02744a10e95e7738c39502ac93bee654 Mon Sep 17 00:00:00 2001 From: Chris Ross Date: Thu, 30 Oct 2014 14:39:43 -0700 Subject: [PATCH 147/987] Add new HeadersSent API. --- src/Microsoft.AspNet.TestHost/ResponseFeature.cs | 3 +++ test/Microsoft.AspNet.TestHost.Tests/ResponseFeatureTests.cs | 5 +++++ 2 files changed, 8 insertions(+) diff --git a/src/Microsoft.AspNet.TestHost/ResponseFeature.cs b/src/Microsoft.AspNet.TestHost/ResponseFeature.cs index 5b7d230a13..9f2ebfd081 100644 --- a/src/Microsoft.AspNet.TestHost/ResponseFeature.cs +++ b/src/Microsoft.AspNet.TestHost/ResponseFeature.cs @@ -30,6 +30,8 @@ namespace Microsoft.AspNet.TestHost public Stream Body { get; set; } + public bool HeadersSent { get; set; } + public void OnSendingHeaders(Action callback, object state) { var prior = _sendingHeaders; @@ -43,6 +45,7 @@ namespace Microsoft.AspNet.TestHost public void FireOnSendingHeaders() { _sendingHeaders(); + HeadersSent = true; } } } diff --git a/test/Microsoft.AspNet.TestHost.Tests/ResponseFeatureTests.cs b/test/Microsoft.AspNet.TestHost.Tests/ResponseFeatureTests.cs index ebf601cb82..2564ee7112 100644 --- a/test/Microsoft.AspNet.TestHost.Tests/ResponseFeatureTests.cs +++ b/test/Microsoft.AspNet.TestHost.Tests/ResponseFeatureTests.cs @@ -15,6 +15,11 @@ namespace Microsoft.AspNet.TestHost // Assert Assert.Equal(200, responseInformation.StatusCode); + Assert.False(responseInformation.HeadersSent); + + responseInformation.FireOnSendingHeaders(); + + Assert.True(responseInformation.HeadersSent); } } } \ No newline at end of file From cd184e3e33e3f3138deb7476af223e0bec8c037f Mon Sep 17 00:00:00 2001 From: Pranav K Date: Thu, 6 Nov 2014 10:48:08 -0800 Subject: [PATCH 148/987] Updating to release NuGet.config --- NuGet.Config | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NuGet.Config b/NuGet.Config index f41e9c631d..2d3b0cb857 100644 --- a/NuGet.Config +++ b/NuGet.Config @@ -1,7 +1,7 @@  - + From 8f16060f941b71551be09015d76efb86770d84d7 Mon Sep 17 00:00:00 2001 From: Pranav K Date: Thu, 6 Nov 2014 22:17:09 -0800 Subject: [PATCH 149/987] Fixing dev NuGet.config --- NuGet.Config | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NuGet.Config b/NuGet.Config index 2d3b0cb857..f41e9c631d 100644 --- a/NuGet.Config +++ b/NuGet.Config @@ -1,7 +1,7 @@  - + From d25ffec65582695eeb3a17dd59e207565885f914 Mon Sep 17 00:00:00 2001 From: Victor Hurdugaci Date: Wed, 12 Nov 2014 15:06:43 -0800 Subject: [PATCH 150/987] Update KProj to latest version --- .../Microsoft.AspNet.Hosting.kproj | 18 ++++++----------- .../Microsoft.AspNet.RequestContainer.kproj | 18 ++++++----------- .../Microsoft.AspNet.TestHost.kproj | 18 ++++++----------- .../Microsoft.AspNet.Hosting.Tests.kproj | 20 ++++++------------- .../Microsoft.AspNet.TestHost.Tests.kproj | 20 ++++++------------- 5 files changed, 30 insertions(+), 64 deletions(-) diff --git a/src/Microsoft.AspNet.Hosting/Microsoft.AspNet.Hosting.kproj b/src/Microsoft.AspNet.Hosting/Microsoft.AspNet.Hosting.kproj index c677b192d6..28467979c0 100644 --- a/src/Microsoft.AspNet.Hosting/Microsoft.AspNet.Hosting.kproj +++ b/src/Microsoft.AspNet.Hosting/Microsoft.AspNet.Hosting.kproj @@ -1,20 +1,14 @@ - - + + - 12.0 + 14.0 $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) 3944f036-7e75-47e8-aa52-c4b89a64ec3a - Library - - - - - - - 2.0 + ..\..\artifacts\obj\$(MSBuildProjectName) + ..\..\artifacts\bin\$(MSBuildProjectName)\ - \ No newline at end of file + diff --git a/src/Microsoft.AspNet.RequestContainer/Microsoft.AspNet.RequestContainer.kproj b/src/Microsoft.AspNet.RequestContainer/Microsoft.AspNet.RequestContainer.kproj index e3e12065f7..43376819b1 100644 --- a/src/Microsoft.AspNet.RequestContainer/Microsoft.AspNet.RequestContainer.kproj +++ b/src/Microsoft.AspNet.RequestContainer/Microsoft.AspNet.RequestContainer.kproj @@ -1,20 +1,14 @@ - - + + - 12.0 + 14.0 $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) 374a5b0c-3e93-4a23-a4a0-ee2ab6df7814 - Library - - - - - - - 2.0 + ..\..\artifacts\obj\$(MSBuildProjectName) + ..\..\artifacts\bin\$(MSBuildProjectName)\ - \ No newline at end of file + diff --git a/src/Microsoft.AspNet.TestHost/Microsoft.AspNet.TestHost.kproj b/src/Microsoft.AspNet.TestHost/Microsoft.AspNet.TestHost.kproj index f68105749b..0ec30b643d 100644 --- a/src/Microsoft.AspNet.TestHost/Microsoft.AspNet.TestHost.kproj +++ b/src/Microsoft.AspNet.TestHost/Microsoft.AspNet.TestHost.kproj @@ -1,20 +1,14 @@ - - + + - 12.0 + 14.0 $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) 1a415a3f-1081-45db-809b-ee19cea02dc0 - Library - - - - - - - 2.0 + ..\..\artifacts\obj\$(MSBuildProjectName) + ..\..\artifacts\bin\$(MSBuildProjectName)\ - \ No newline at end of file + diff --git a/test/Microsoft.AspNet.Hosting.Tests/Microsoft.AspNet.Hosting.Tests.kproj b/test/Microsoft.AspNet.Hosting.Tests/Microsoft.AspNet.Hosting.Tests.kproj index 0b04b9270d..95b1cc35f3 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/Microsoft.AspNet.Hosting.Tests.kproj +++ b/test/Microsoft.AspNet.Hosting.Tests/Microsoft.AspNet.Hosting.Tests.kproj @@ -1,22 +1,14 @@ - - + + - 12.0 + 14.0 $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) d4f18d58-52b1-435d-a012-10f2cdf158c4 - Library - net45 - - - - - - - 2.0 - 29216 + ..\..\artifacts\obj\$(MSBuildProjectName) + ..\..\artifacts\bin\$(MSBuildProjectName)\ - \ No newline at end of file + diff --git a/test/Microsoft.AspNet.TestHost.Tests/Microsoft.AspNet.TestHost.Tests.kproj b/test/Microsoft.AspNet.TestHost.Tests/Microsoft.AspNet.TestHost.Tests.kproj index 53d92fe14b..259cc5243d 100644 --- a/test/Microsoft.AspNet.TestHost.Tests/Microsoft.AspNet.TestHost.Tests.kproj +++ b/test/Microsoft.AspNet.TestHost.Tests/Microsoft.AspNet.TestHost.Tests.kproj @@ -1,22 +1,14 @@ - - + + - 12.0 + 14.0 $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) 0acb2719-9484-49b5-b8e3-117091192511 - Library - net45 - - - - - - - 2.0 - 29215 + ..\..\artifacts\obj\$(MSBuildProjectName) + ..\..\artifacts\bin\$(MSBuildProjectName)\ - \ No newline at end of file + From bf5d14f4770353ad63797afde0099a6eb38063c6 Mon Sep 17 00:00:00 2001 From: Chris Ross Date: Wed, 5 Nov 2014 09:39:03 -0800 Subject: [PATCH 151/987] #78 - Enable TestServer to populate the PathBase. --- .../ClientHandler.cs | 24 +++++++++++++++---- src/Microsoft.AspNet.TestHost/TestServer.cs | 8 +++++-- .../ClientHandlerTests.cs | 24 +++++++++---------- 3 files changed, 37 insertions(+), 19 deletions(-) diff --git a/src/Microsoft.AspNet.TestHost/ClientHandler.cs b/src/Microsoft.AspNet.TestHost/ClientHandler.cs index 29400083e8..b23dffbe70 100644 --- a/src/Microsoft.AspNet.TestHost/ClientHandler.cs +++ b/src/Microsoft.AspNet.TestHost/ClientHandler.cs @@ -24,12 +24,13 @@ namespace Microsoft.AspNet.TestHost public class ClientHandler : HttpMessageHandler { private readonly Func _next; + private readonly PathString _pathBase; /// /// Create a new handler. /// /// The pipeline entry point. - public ClientHandler(Func next) + public ClientHandler(Func next, PathString pathBase) { if (next == null) { @@ -37,6 +38,7 @@ namespace Microsoft.AspNet.TestHost } _next = next; + _pathBase = pathBase; } /// @@ -55,7 +57,7 @@ namespace Microsoft.AspNet.TestHost throw new ArgumentNullException("request"); } - var state = new RequestState(request, cancellationToken); + var state = new RequestState(request, _pathBase, cancellationToken); var requestContent = request.Content ?? new StreamContent(Stream.Null); var body = await requestContent.ReadAsStreamAsync(); if (body.CanSeek) @@ -95,7 +97,7 @@ namespace Microsoft.AspNet.TestHost private ResponseStream _responseStream; private ResponseFeature _responseFeature; - internal RequestState(HttpRequestMessage request, CancellationToken cancellationToken) + internal RequestState(HttpRequestMessage request, PathString pathBase, CancellationToken cancellationToken) { _request = request; _responseTcs = new TaskCompletionSource(); @@ -118,8 +120,20 @@ namespace Microsoft.AspNet.TestHost serverRequest.Protocol = "HTTP/" + request.Version.ToString(2); serverRequest.Scheme = request.RequestUri.Scheme; serverRequest.Method = request.Method.ToString(); - serverRequest.Path = PathString.FromUriComponent(request.RequestUri); - serverRequest.PathBase = PathString.Empty; + + var fullPath = PathString.FromUriComponent(request.RequestUri); + PathString remainder; + if (fullPath.StartsWithSegments(pathBase, out remainder)) + { + serverRequest.PathBase = pathBase; + serverRequest.Path = remainder; + } + else + { + serverRequest.PathBase = PathString.Empty; + serverRequest.Path = fullPath; + } + serverRequest.QueryString = QueryString.FromUriComponent(request.RequestUri); // TODO: serverRequest.CallCancelled = cancellationToken; diff --git a/src/Microsoft.AspNet.TestHost/TestServer.cs b/src/Microsoft.AspNet.TestHost/TestServer.cs index 977623c3d0..8a98adb5ad 100644 --- a/src/Microsoft.AspNet.TestHost/TestServer.cs +++ b/src/Microsoft.AspNet.TestHost/TestServer.cs @@ -7,6 +7,7 @@ using System.Threading.Tasks; using Microsoft.AspNet.Builder; using Microsoft.AspNet.Hosting; using Microsoft.AspNet.Hosting.Server; +using Microsoft.AspNet.Http; using Microsoft.Framework.ConfigurationModel; using Microsoft.Framework.DependencyInjection; using Microsoft.Framework.DependencyInjection.Fallback; @@ -41,6 +42,8 @@ namespace Microsoft.AspNet.TestHost _appInstance = engine.Start(hostContext); } + public Uri BaseAddress { get; set; } = new Uri("http://localhost/"); + public static TestServer Create(Action app) { return Create(provider: CallContextServiceLocator.Locator.ServiceProvider, app: app); @@ -68,12 +71,13 @@ namespace Microsoft.AspNet.TestHost public HttpMessageHandler CreateHandler() { - return new ClientHandler(Invoke); + var pathBase = BaseAddress == null ? PathString.Empty : PathString.FromUriComponent(BaseAddress); + return new ClientHandler(Invoke, pathBase); } public HttpClient CreateClient() { - return new HttpClient(CreateHandler()) { BaseAddress = new Uri("http://localhost/") }; + return new HttpClient(CreateHandler()) { BaseAddress = BaseAddress }; } /// diff --git a/test/Microsoft.AspNet.TestHost.Tests/ClientHandlerTests.cs b/test/Microsoft.AspNet.TestHost.Tests/ClientHandlerTests.cs index 623a0bc395..13b6f085c7 100644 --- a/test/Microsoft.AspNet.TestHost.Tests/ClientHandlerTests.cs +++ b/test/Microsoft.AspNet.TestHost.Tests/ClientHandlerTests.cs @@ -28,8 +28,8 @@ namespace Microsoft.AspNet.TestHost Assert.Equal("HTTP/1.1", context.Request.Protocol); Assert.Equal("GET", context.Request.Method); Assert.Equal("https", context.Request.Scheme); - Assert.Equal(string.Empty, context.Request.PathBase.Value); - Assert.Equal("/A/Path/and/file.txt", context.Request.Path.Value); + Assert.Equal("/A/Path", context.Request.PathBase.Value); + Assert.Equal("/and/file.txt", context.Request.Path.Value); Assert.Equal("?and=query", context.Request.QueryString.Value); Assert.NotNull(context.Request.Body); Assert.NotNull(context.Request.Headers); @@ -40,7 +40,7 @@ namespace Microsoft.AspNet.TestHost Assert.Equal("example.com", context.Request.Host.Value); return Task.FromResult(0); - }); + }, new PathString("/A/Path")); var httpClient = new HttpClient(handler); return httpClient.GetAsync("https://example.com/A/Path/and/file.txt?and=query"); } @@ -57,7 +57,7 @@ namespace Microsoft.AspNet.TestHost context.Response.Headers["TestHeader"] = "TestValue:" + requestCount++; return Task.FromResult(0); - }); + }, PathString.Empty); HttpMessageInvoker invoker = new HttpMessageInvoker(handler); HttpRequestMessage message = new HttpRequestMessage(HttpMethod.Post, "https://example.com/"); @@ -79,7 +79,7 @@ namespace Microsoft.AspNet.TestHost context.Response.Headers["TestHeader"] = "TestValue"; return Task.FromResult(0); - }); + }, PathString.Empty); var httpClient = new HttpClient(handler); HttpResponseMessage response = await httpClient.GetAsync("https://example.com/"); Assert.Equal("TestValue", response.Headers.GetValues("TestHeader").First()); @@ -93,7 +93,7 @@ namespace Microsoft.AspNet.TestHost { block.WaitOne(); return Task.FromResult(0); - }); + }, PathString.Empty); var httpClient = new HttpClient(handler); Task task = httpClient.GetAsync("https://example.com/"); Assert.False(task.IsCompleted); @@ -113,7 +113,7 @@ namespace Microsoft.AspNet.TestHost await context.Response.WriteAsync("BodyStarted,"); block.WaitOne(); await context.Response.WriteAsync("BodyFinished"); - }); + }, PathString.Empty); var httpClient = new HttpClient(handler); HttpResponseMessage response = await httpClient.GetAsync("https://example.com/", HttpCompletionOption.ResponseHeadersRead); @@ -133,7 +133,7 @@ namespace Microsoft.AspNet.TestHost context.Response.Body.Flush(); block.WaitOne(); await context.Response.WriteAsync("BodyFinished"); - }); + }, PathString.Empty); var httpClient = new HttpClient(handler); HttpResponseMessage response = await httpClient.GetAsync("https://example.com/", HttpCompletionOption.ResponseHeadersRead); @@ -153,7 +153,7 @@ namespace Microsoft.AspNet.TestHost context.Response.Body.Flush(); block.WaitOne(); return Task.FromResult(0); - }); + }, PathString.Empty); var httpClient = new HttpClient(handler); HttpResponseMessage response = await httpClient.GetAsync("https://example.com/", HttpCompletionOption.ResponseHeadersRead); @@ -179,7 +179,7 @@ namespace Microsoft.AspNet.TestHost context.Response.Body.Flush(); block.WaitOne(); return Task.FromResult(0); - }); + }, PathString.Empty); var httpClient = new HttpClient(handler); HttpResponseMessage response = await httpClient.GetAsync("https://example.com/", HttpCompletionOption.ResponseHeadersRead); @@ -201,7 +201,7 @@ namespace Microsoft.AspNet.TestHost var handler = new ClientHandler(env => { throw new InvalidOperationException("Test Exception"); - }); + }, PathString.Empty); var httpClient = new HttpClient(handler); return Assert.ThrowsAsync(() => httpClient.GetAsync("https://example.com/", HttpCompletionOption.ResponseHeadersRead)); @@ -218,7 +218,7 @@ namespace Microsoft.AspNet.TestHost await context.Response.WriteAsync("BodyStarted"); block.WaitOne(); throw new InvalidOperationException("Test Exception"); - }); + }, PathString.Empty); var httpClient = new HttpClient(handler); HttpResponseMessage response = await httpClient.GetAsync("https://example.com/", HttpCompletionOption.ResponseHeadersRead); From b7bb7f8fcfb62418d1e124c3197dfb7939bdf905 Mon Sep 17 00:00:00 2001 From: Chris Ross Date: Fri, 14 Nov 2014 09:43:33 -0800 Subject: [PATCH 152/987] Fix issue with empty path. --- src/Microsoft.AspNet.TestHost/TestServer.cs | 5 +++ .../ClientHandlerTests.cs | 15 +++++++ .../TestClientTests.cs | 42 +++++++++++++++++++ 3 files changed, 62 insertions(+) diff --git a/src/Microsoft.AspNet.TestHost/TestServer.cs b/src/Microsoft.AspNet.TestHost/TestServer.cs index 8a98adb5ad..496fc9da94 100644 --- a/src/Microsoft.AspNet.TestHost/TestServer.cs +++ b/src/Microsoft.AspNet.TestHost/TestServer.cs @@ -72,6 +72,11 @@ namespace Microsoft.AspNet.TestHost public HttpMessageHandler CreateHandler() { var pathBase = BaseAddress == null ? PathString.Empty : PathString.FromUriComponent(BaseAddress); + if (pathBase.Equals(new PathString("/"))) + { + // When we just have http://host/ the trailing slash is really part of the Path, not the PathBase. + pathBase = PathString.Empty; + } return new ClientHandler(Invoke, pathBase); } diff --git a/test/Microsoft.AspNet.TestHost.Tests/ClientHandlerTests.cs b/test/Microsoft.AspNet.TestHost.Tests/ClientHandlerTests.cs index 13b6f085c7..23f65bce8b 100644 --- a/test/Microsoft.AspNet.TestHost.Tests/ClientHandlerTests.cs +++ b/test/Microsoft.AspNet.TestHost.Tests/ClientHandlerTests.cs @@ -45,6 +45,21 @@ namespace Microsoft.AspNet.TestHost return httpClient.GetAsync("https://example.com/A/Path/and/file.txt?and=query"); } + [Fact] + public Task SingleSlashNotMovedToPathBase() + { + var handler = new ClientHandler(env => + { + var context = new DefaultHttpContext((IFeatureCollection)env); + Assert.Equal("", context.Request.PathBase.Value); + Assert.Equal("/", context.Request.Path.Value); + + return Task.FromResult(0); + }, new PathString("")); + var httpClient = new HttpClient(handler); + return httpClient.GetAsync("https://example.com/"); + } + [Fact] public async Task ResubmitRequestWorks() { diff --git a/test/Microsoft.AspNet.TestHost.Tests/TestClientTests.cs b/test/Microsoft.AspNet.TestHost.Tests/TestClientTests.cs index d9843657dd..c1ba2d9f59 100644 --- a/test/Microsoft.AspNet.TestHost.Tests/TestClientTests.cs +++ b/test/Microsoft.AspNet.TestHost.Tests/TestClientTests.cs @@ -45,6 +45,48 @@ namespace Microsoft.AspNet.TestHost Assert.Equal(expected, actual); } + [Fact] + public async Task NoTrailingSlash_NoPathBase() + { + // Arrange + var expected = "GET Response"; + RequestDelegate appDelegate = ctx => + { + Assert.Equal("", ctx.Request.PathBase.Value); + Assert.Equal("/", ctx.Request.Path.Value); + return ctx.Response.WriteAsync(expected); + }; + var server = TestServer.Create(_services, app => app.Run(appDelegate)); + var client = server.CreateClient(); + + // Act + var actual = await client.GetStringAsync("http://localhost:12345"); + + // Assert + Assert.Equal(expected, actual); + } + + [Fact] + public async Task SingleTrailingSlash_NoPathBase() + { + // Arrange + var expected = "GET Response"; + RequestDelegate appDelegate = ctx => + { + Assert.Equal("", ctx.Request.PathBase.Value); + Assert.Equal("/", ctx.Request.Path.Value); + return ctx.Response.WriteAsync(expected); + }; + var server = TestServer.Create(_services, app => app.Run(appDelegate)); + var client = server.CreateClient(); + + // Act + var actual = await client.GetStringAsync("http://localhost:12345/"); + + // Assert + Assert.Equal(expected, actual); + } + [Fact] public async Task PutAsyncWorks() { From b44ffdb745aa227b311a6f0ec3d178db33fd8c70 Mon Sep 17 00:00:00 2001 From: Chris Ross Date: Wed, 12 Nov 2014 15:54:28 -0800 Subject: [PATCH 153/987] #111 - Remove DataProtectionOptions from the service collection. --- src/Microsoft.AspNet.Hosting/HostingServices.cs | 6 ------ src/Microsoft.AspNet.Hosting/Program.cs | 8 -------- src/Microsoft.AspNet.Hosting/project.json | 1 - 3 files changed, 15 deletions(-) diff --git a/src/Microsoft.AspNet.Hosting/HostingServices.cs b/src/Microsoft.AspNet.Hosting/HostingServices.cs index f1ce9b3cd2..52d5e978ca 100644 --- a/src/Microsoft.AspNet.Hosting/HostingServices.cs +++ b/src/Microsoft.AspNet.Hosting/HostingServices.cs @@ -5,7 +5,6 @@ using System.Collections.Generic; using Microsoft.AspNet.Hosting.Builder; using Microsoft.AspNet.Hosting.Server; using Microsoft.AspNet.Hosting.Startup; -using Microsoft.AspNet.Security.DataProtection; using Microsoft.Framework.ConfigurationModel; using Microsoft.Framework.DependencyInjection; using Microsoft.Framework.Logging; @@ -46,11 +45,6 @@ namespace Microsoft.AspNet.Hosting { yield return service; } - - foreach (var service in DataProtectionServices.GetDefaultServices()) - { - yield return service; - } } } } diff --git a/src/Microsoft.AspNet.Hosting/Program.cs b/src/Microsoft.AspNet.Hosting/Program.cs index a339fa9de9..03e470620c 100644 --- a/src/Microsoft.AspNet.Hosting/Program.cs +++ b/src/Microsoft.AspNet.Hosting/Program.cs @@ -5,7 +5,6 @@ using System; using System.IO; using System.Threading; using System.Threading.Tasks; -using Microsoft.AspNet.Security.DataProtection; using Microsoft.Framework.ConfigurationModel; using Microsoft.Framework.DependencyInjection; using Microsoft.Framework.DependencyInjection.Fallback; @@ -47,13 +46,6 @@ namespace Microsoft.AspNet.Hosting var serviceCollection = new ServiceCollection(); serviceCollection.Add(HostingServices.GetDefaultServices(config)); serviceCollection.AddInstance(hostingEnv); - // The application name is a "good enough" mechanism to identify this application - // on the machine and to prevent subkeys from being shared across multiple applications - // by default. - serviceCollection.Configure(options => - { - options.ApplicationDiscriminator = appEnv.ApplicationName; - }); var services = serviceCollection.BuildServiceProvider(_serviceProvider); diff --git a/src/Microsoft.AspNet.Hosting/project.json b/src/Microsoft.AspNet.Hosting/project.json index 7bd0c8398b..e39c50689a 100644 --- a/src/Microsoft.AspNet.Hosting/project.json +++ b/src/Microsoft.AspNet.Hosting/project.json @@ -3,7 +3,6 @@ "description": "ASP.NET 5 core hosting infrastructure and startup logic for web applications.", "dependencies": { "Microsoft.AspNet.PipelineCore": "1.0.0-*", - "Microsoft.AspNet.Security.DataProtection": "1.0.0-*", "Microsoft.Framework.Logging": "1.0.0-*", "Microsoft.Framework.OptionsModel": "1.0.0-*", "Microsoft.Framework.Runtime.Interfaces": { "version": "1.0.0-*", "type": "build" }, From ac6f1223df1ee4564ec799bd70365d6d9976aa8c Mon Sep 17 00:00:00 2001 From: Hao Kung Date: Thu, 20 Nov 2014 17:23:31 -0800 Subject: [PATCH 154/987] Hosting changes reacting to fallback being removed - HostingServices.Create() is the supported way to create a service collection with kre services imported - IHostingEnvironment is now a normal service - IConfigureHostingEnvironment is how you configure it --- .../ConfigureHostingEnvironment.cs | 22 ++++ src/Microsoft.AspNet.Hosting/HostingEngine.cs | 1 - .../HostingEnvironment.cs | 12 ++ .../HostingServices.cs | 51 +++++++- .../IConfigureHostingEnvironment.cs | 13 ++ .../IHostingEnvironment.cs | 2 +- src/Microsoft.AspNet.Hosting/Program.cs | 18 +-- .../Startup/StartupLoader.cs | 7 +- .../WebApplication.cs | 31 ----- .../ContainerExtensions.cs | 19 ++- .../project.json | 1 + src/Microsoft.AspNet.TestHost/TestServer.cs | 29 +++-- .../Fakes/FakeService.cs | 7 ++ .../Fakes/IFactoryService.cs | 12 ++ .../Fakes/IFakeEveryService.cs | 12 ++ .../Fakes/IFakeScopedService.cs | 9 ++ .../Fakes/IFakeService.cs | 1 - .../Fakes/IFakeServiceInstance.cs | 9 ++ .../Fakes/IFakeSingletonService.cs | 9 ++ .../Fakes/INonexistentService.cs | 9 ++ .../HostingEngineTests.cs | 8 +- .../HostingServicesFacts.cs | 116 ++++++++++++++++++ .../StartupManagerTests.cs | 33 +++-- .../UseRequestServicesFacts.cs | 39 ++++-- .../UseServicesFacts.cs | 11 +- .../TestClientTests.cs | 7 +- .../TestServerTests.cs | 8 +- 27 files changed, 372 insertions(+), 124 deletions(-) create mode 100644 src/Microsoft.AspNet.Hosting/ConfigureHostingEnvironment.cs create mode 100644 src/Microsoft.AspNet.Hosting/IConfigureHostingEnvironment.cs delete mode 100644 src/Microsoft.AspNet.Hosting/WebApplication.cs create mode 100644 test/Microsoft.AspNet.Hosting.Tests/Fakes/FakeService.cs create mode 100644 test/Microsoft.AspNet.Hosting.Tests/Fakes/IFactoryService.cs create mode 100644 test/Microsoft.AspNet.Hosting.Tests/Fakes/IFakeEveryService.cs create mode 100644 test/Microsoft.AspNet.Hosting.Tests/Fakes/IFakeScopedService.cs create mode 100644 test/Microsoft.AspNet.Hosting.Tests/Fakes/IFakeServiceInstance.cs create mode 100644 test/Microsoft.AspNet.Hosting.Tests/Fakes/IFakeSingletonService.cs create mode 100644 test/Microsoft.AspNet.Hosting.Tests/Fakes/INonexistentService.cs create mode 100644 test/Microsoft.AspNet.Hosting.Tests/HostingServicesFacts.cs diff --git a/src/Microsoft.AspNet.Hosting/ConfigureHostingEnvironment.cs b/src/Microsoft.AspNet.Hosting/ConfigureHostingEnvironment.cs new file mode 100644 index 0000000000..399054f2cd --- /dev/null +++ b/src/Microsoft.AspNet.Hosting/ConfigureHostingEnvironment.cs @@ -0,0 +1,22 @@ +// 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 System; + +namespace Microsoft.AspNet.Hosting +{ + public class ConfigureHostingEnvironment : IConfigureHostingEnvironment + { + private readonly Action _action; + + public ConfigureHostingEnvironment(Action configure) + { + _action = configure; + } + + public void Configure(IHostingEnvironment hostingEnv) + { + _action.Invoke(hostingEnv); + } + } +} \ No newline at end of file diff --git a/src/Microsoft.AspNet.Hosting/HostingEngine.cs b/src/Microsoft.AspNet.Hosting/HostingEngine.cs index 4eb09ab00d..0dc426b1a4 100644 --- a/src/Microsoft.AspNet.Hosting/HostingEngine.cs +++ b/src/Microsoft.AspNet.Hosting/HostingEngine.cs @@ -7,7 +7,6 @@ using Microsoft.AspNet.Hosting.Builder; using Microsoft.AspNet.Hosting.Server; using Microsoft.AspNet.Hosting.Startup; using Microsoft.Framework.DependencyInjection; -using Microsoft.Framework.DependencyInjection.Fallback; namespace Microsoft.AspNet.Hosting { diff --git a/src/Microsoft.AspNet.Hosting/HostingEnvironment.cs b/src/Microsoft.AspNet.Hosting/HostingEnvironment.cs index 3881faa333..0b0550d888 100644 --- a/src/Microsoft.AspNet.Hosting/HostingEnvironment.cs +++ b/src/Microsoft.AspNet.Hosting/HostingEnvironment.cs @@ -1,10 +1,22 @@ // 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 System.Collections.Generic; +using Microsoft.Framework.Runtime; + namespace Microsoft.AspNet.Hosting { public class HostingEnvironment : IHostingEnvironment { + public HostingEnvironment(IApplicationEnvironment appEnv, IEnumerable configures) + { + WebRoot = HostingUtilities.GetWebRoot(appEnv.ApplicationBasePath); + foreach (var configure in configures) + { + configure.Configure(this); + } + } + public string EnvironmentName { get; set; } public string WebRoot { get; set; } diff --git a/src/Microsoft.AspNet.Hosting/HostingServices.cs b/src/Microsoft.AspNet.Hosting/HostingServices.cs index 52d5e978ca..9ec27a1f83 100644 --- a/src/Microsoft.AspNet.Hosting/HostingServices.cs +++ b/src/Microsoft.AspNet.Hosting/HostingServices.cs @@ -1,26 +1,52 @@ // 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 System; using System.Collections.Generic; +using System.Linq; using Microsoft.AspNet.Hosting.Builder; using Microsoft.AspNet.Hosting.Server; using Microsoft.AspNet.Hosting.Startup; using Microsoft.Framework.ConfigurationModel; using Microsoft.Framework.DependencyInjection; +using Microsoft.Framework.DependencyInjection.ServiceLookup; using Microsoft.Framework.Logging; using Microsoft.Framework.OptionsModel; +using Microsoft.Framework.Runtime.Infrastructure; namespace Microsoft.AspNet.Hosting { public static class HostingServices { - public static IEnumerable GetDefaultServices() + private static IServiceCollection Import(IServiceProvider fallbackProvider) { - return GetDefaultServices(new Configuration()); + var services = new ServiceCollection(); + var manifest = fallbackProvider.GetRequiredService(); + foreach (var service in manifest.Services) + { + // REVIEW: should this be Singleton instead? + services.AddTransient(service, sp => fallbackProvider.GetService(service)); + } + return services; } - public static IEnumerable GetDefaultServices(IConfiguration configuration) + public static IServiceCollection Create(IConfiguration configuration = null) { + return Create(CallContextServiceLocator.Locator.ServiceProvider); + } + + public static IServiceCollection Create(IServiceProvider fallbackServices, IConfiguration configuration = null) + { + var services = Import(fallbackServices); + services.Add(GetDefaultServices(configuration)); + services.AddSingleton(sp => new HostingManifest(fallbackServices)); + return services; + } + + // REVIEW: make this private? + public static IEnumerable GetDefaultServices(IConfiguration configuration = null) + { + configuration = configuration ?? new Configuration(); var describer = new ServiceDescriber(configuration); yield return describer.Transient(); @@ -32,13 +58,16 @@ namespace Microsoft.AspNet.Hosting yield return describer.Transient(); yield return describer.Transient(); - yield return describer.Singleton(); - yield return describer.Instance(new ApplicationLifetime()); + // These three services as exported in the manifest + yield return describer.Singleton(); + yield return describer.Singleton(); // TODO: Do we expect this to be provide by the runtime eventually? yield return describer.Singleton(); + // TODO: Remove the below services and push the responsibility to frameworks to add + yield return describer.Scoped(typeof(IContextAccessor<>), typeof(ContextAccessor<>)); foreach (var service in OptionsServices.GetDefaultServices()) @@ -46,5 +75,17 @@ namespace Microsoft.AspNet.Hosting yield return service; } } + + private class HostingManifest : IServiceManifest + { + public HostingManifest(IServiceProvider fallback) + { + var manifest = fallback.GetRequiredService(); + Services = new Type[] { typeof(ITypeActivator), typeof(IHostingEnvironment), typeof(ILoggerFactory) } + .Concat(manifest.Services).Distinct(); + } + + public IEnumerable Services { get; private set; } + } } } diff --git a/src/Microsoft.AspNet.Hosting/IConfigureHostingEnvironment.cs b/src/Microsoft.AspNet.Hosting/IConfigureHostingEnvironment.cs new file mode 100644 index 0000000000..715d55b687 --- /dev/null +++ b/src/Microsoft.AspNet.Hosting/IConfigureHostingEnvironment.cs @@ -0,0 +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.Framework.Runtime; + +namespace Microsoft.AspNet.Hosting +{ + [AssemblyNeutral] + public interface IConfigureHostingEnvironment + { + void Configure(IHostingEnvironment hostingEnv); + } +} \ No newline at end of file diff --git a/src/Microsoft.AspNet.Hosting/IHostingEnvironment.cs b/src/Microsoft.AspNet.Hosting/IHostingEnvironment.cs index d510d0ba23..3760c17799 100644 --- a/src/Microsoft.AspNet.Hosting/IHostingEnvironment.cs +++ b/src/Microsoft.AspNet.Hosting/IHostingEnvironment.cs @@ -8,7 +8,7 @@ namespace Microsoft.AspNet.Hosting [AssemblyNeutral] public interface IHostingEnvironment { - string EnvironmentName { get; } + string EnvironmentName { get; set; } string WebRoot { get; } } diff --git a/src/Microsoft.AspNet.Hosting/Program.cs b/src/Microsoft.AspNet.Hosting/Program.cs index 03e470620c..b8bd4a2d7f 100644 --- a/src/Microsoft.AspNet.Hosting/Program.cs +++ b/src/Microsoft.AspNet.Hosting/Program.cs @@ -25,6 +25,8 @@ namespace Microsoft.AspNet.Hosting _serviceProvider = serviceProvider; } + + public void Main(string[] args) { var config = new Configuration(); @@ -35,19 +37,11 @@ namespace Microsoft.AspNet.Hosting config.AddEnvironmentVariables(); config.AddCommandLine(args); - var appEnv = _serviceProvider.GetRequiredService(); + var serviceCollection = HostingServices.Create(_serviceProvider, config); + var services = serviceCollection.BuildServiceProvider(); - var hostingEnv = new HostingEnvironment() - { - EnvironmentName = config.Get(EnvironmentKey) ?? DefaultEnvironmentName, - WebRoot = HostingUtilities.GetWebRoot(appEnv.ApplicationBasePath), - }; - - var serviceCollection = new ServiceCollection(); - serviceCollection.Add(HostingServices.GetDefaultServices(config)); - serviceCollection.AddInstance(hostingEnv); - - var services = serviceCollection.BuildServiceProvider(_serviceProvider); + var appEnv = services.GetRequiredService(); + var hostingEnv = services.GetRequiredService(); var context = new HostingContext() { diff --git a/src/Microsoft.AspNet.Hosting/Startup/StartupLoader.cs b/src/Microsoft.AspNet.Hosting/Startup/StartupLoader.cs index 1c6b2eb98a..cf41930701 100644 --- a/src/Microsoft.AspNet.Hosting/Startup/StartupLoader.cs +++ b/src/Microsoft.AspNet.Hosting/Startup/StartupLoader.cs @@ -151,8 +151,11 @@ namespace Microsoft.AspNet.Hosting.Startup { if (servicesMethod != null) { - var services = new ServiceCollection(); + var services = HostingServices.Create(builder.ApplicationServices); + // TODO: remove adding options services.Add(OptionsServices.GetDefaultServices()); + services.AddScoped(typeof(IContextAccessor<>), typeof(ContextAccessor<>)); + if (servicesMethod.ReturnType == typeof(IServiceProvider)) { // IServiceProvider ConfigureServices(IServiceCollection) @@ -165,7 +168,7 @@ namespace Microsoft.AspNet.Hosting.Startup Invoke(servicesMethod, instance, builder, services); if (builder != null) { - builder.ApplicationServices = services.BuildServiceProvider(builder.ApplicationServices); + builder.ApplicationServices = services.BuildServiceProvider(); } } } diff --git a/src/Microsoft.AspNet.Hosting/WebApplication.cs b/src/Microsoft.AspNet.Hosting/WebApplication.cs deleted file mode 100644 index 054f90d6d4..0000000000 --- a/src/Microsoft.AspNet.Hosting/WebApplication.cs +++ /dev/null @@ -1,31 +0,0 @@ -// 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 System; -using Microsoft.Framework.DependencyInjection; -using Microsoft.Framework.DependencyInjection.Fallback; - -namespace Microsoft.AspNet.Hosting -{ - public static class WebApplication - { - public static IDisposable Start() - { - var serviceCollection = new ServiceCollection(); - serviceCollection.Add(HostingServices.GetDefaultServices()); - - var context = new HostingContext - { - Services = serviceCollection.BuildServiceProvider() - }; - - var engine = context.Services.GetRequiredService(); - if (engine == null) - { - throw new Exception("TODO: IHostingEngine service not available exception"); - } - - return engine.Start(context); - } - } -} \ No newline at end of file diff --git a/src/Microsoft.AspNet.RequestContainer/ContainerExtensions.cs b/src/Microsoft.AspNet.RequestContainer/ContainerExtensions.cs index fe822f5820..31c6f51b09 100644 --- a/src/Microsoft.AspNet.RequestContainer/ContainerExtensions.cs +++ b/src/Microsoft.AspNet.RequestContainer/ContainerExtensions.cs @@ -4,6 +4,7 @@ using System; using System.Collections.Generic; using Microsoft.AspNet.RequestContainer; +using Microsoft.AspNet.Hosting; using Microsoft.Framework.DependencyInjection; using Microsoft.Framework.DependencyInjection.Fallback; using Microsoft.Framework.OptionsModel; @@ -17,32 +18,42 @@ namespace Microsoft.AspNet.Builder return builder.UseMiddleware(); } + // Review: what do we use these for? + public static IApplicationBuilder UseRequestServices(this IApplicationBuilder builder, IServiceProvider applicationServices) { + // REVIEW: should this be doing fallback? builder.ApplicationServices = applicationServices; return builder.UseMiddleware(); } + // Note: Manifests are lost after UseServices, services are flattened into ApplicationServices + public static IApplicationBuilder UseServices(this IApplicationBuilder builder, IEnumerable applicationServices) { return builder.UseServices(services => services.Add(applicationServices)); } - public static IApplicationBuilder UseServices(this IApplicationBuilder builder, Action configureServices) + public static IApplicationBuilder UseServices(this IApplicationBuilder builder, Action configureServices) { return builder.UseServices(serviceCollection => { configureServices(serviceCollection); - return serviceCollection.BuildServiceProvider(builder.ApplicationServices); + return serviceCollection.BuildServiceProvider(); }); } - public static IApplicationBuilder UseServices(this IApplicationBuilder builder, Func configureServices) + public static IApplicationBuilder UseServices(this IApplicationBuilder builder, Func configureServices) { - var serviceCollection = new ServiceCollection(); + // Import services from hosting/KRE as fallback + var serviceCollection = HostingServices.Create(builder.ApplicationServices); + // TODO: should remove OptionServices here soon... serviceCollection.Add(OptionsServices.GetDefaultServices()); + serviceCollection.AddScoped(typeof(IContextAccessor<>), typeof(ContextAccessor<>)); + + // REVIEW: serviceCollection has the merged services, manifests are lost after this builder.ApplicationServices = configureServices(serviceCollection); return builder.UseMiddleware(); diff --git a/src/Microsoft.AspNet.RequestContainer/project.json b/src/Microsoft.AspNet.RequestContainer/project.json index 31d710c78c..d8f3cef5a9 100644 --- a/src/Microsoft.AspNet.RequestContainer/project.json +++ b/src/Microsoft.AspNet.RequestContainer/project.json @@ -3,6 +3,7 @@ "description": "ASP.NET 5 enables per-request scoping of services.", "dependencies": { "Microsoft.AspNet.Http.Extensions": "1.0.0-*", + "Microsoft.AspNet.Hosting": "1.0.0-*", "Microsoft.Framework.OptionsModel": "1.0.0-*" }, "frameworks": { diff --git a/src/Microsoft.AspNet.TestHost/TestServer.cs b/src/Microsoft.AspNet.TestHost/TestServer.cs index 496fc9da94..17a8dde680 100644 --- a/src/Microsoft.AspNet.TestHost/TestServer.cs +++ b/src/Microsoft.AspNet.TestHost/TestServer.cs @@ -2,7 +2,10 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.Collections.Generic; +using System.Linq; using System.Net.Http; +using System.Reflection; using System.Threading.Tasks; using Microsoft.AspNet.Builder; using Microsoft.AspNet.Hosting; @@ -46,25 +49,16 @@ namespace Microsoft.AspNet.TestHost public static TestServer Create(Action app) { - return Create(provider: CallContextServiceLocator.Locator.ServiceProvider, app: app); + return Create(CallContextServiceLocator.Locator.ServiceProvider, app); } - public static TestServer Create(IServiceProvider provider, Action app) + public static TestServer Create(IServiceProvider serviceProvider, Action app) { - var appEnv = provider.GetRequiredService(); - - var hostingEnv = new HostingEnvironment() - { - EnvironmentName = DefaultEnvironmentName, - WebRoot = HostingUtilities.GetWebRoot(appEnv.ApplicationBasePath), - }; - - var collection = new ServiceCollection(); - collection.Add(HostingServices.GetDefaultServices()); - collection.AddInstance(hostingEnv); - - var appServices = collection.BuildServiceProvider(provider); + var services = HostingServices.Create(serviceProvider); + services.AddSingleton(); + //var appServices = BuildFallbackServiceProvider(services, serviceProvider); + var appServices = services.BuildServiceProvider(); var config = new Configuration(); return new TestServer(config, appServices, app); } @@ -134,5 +128,10 @@ namespace Microsoft.AspNet.TestHost get { return TestServer.ServerName; } } } + + private class ConfigureTestHostingEnvironment : ConfigureHostingEnvironment + { + public ConfigureTestHostingEnvironment() : base(env => env.EnvironmentName = DefaultEnvironmentName) { } + } } } diff --git a/test/Microsoft.AspNet.Hosting.Tests/Fakes/FakeService.cs b/test/Microsoft.AspNet.Hosting.Tests/Fakes/FakeService.cs new file mode 100644 index 0000000000..75e8b53216 --- /dev/null +++ b/test/Microsoft.AspNet.Hosting.Tests/Fakes/FakeService.cs @@ -0,0 +1,7 @@ +// 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. + +namespace Microsoft.AspNet.Hosting.Fakes +{ + public class FakeService : IFakeEveryService { } +} \ No newline at end of file diff --git a/test/Microsoft.AspNet.Hosting.Tests/Fakes/IFactoryService.cs b/test/Microsoft.AspNet.Hosting.Tests/Fakes/IFactoryService.cs new file mode 100644 index 0000000000..e67809bb83 --- /dev/null +++ b/test/Microsoft.AspNet.Hosting.Tests/Fakes/IFactoryService.cs @@ -0,0 +1,12 @@ +// 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. + +namespace Microsoft.AspNet.Hosting.Fakes +{ + public interface IFactoryService + { + IFakeService FakeService { get; } + + int Value { get; } + } +} \ No newline at end of file diff --git a/test/Microsoft.AspNet.Hosting.Tests/Fakes/IFakeEveryService.cs b/test/Microsoft.AspNet.Hosting.Tests/Fakes/IFakeEveryService.cs new file mode 100644 index 0000000000..9fadf70efa --- /dev/null +++ b/test/Microsoft.AspNet.Hosting.Tests/Fakes/IFakeEveryService.cs @@ -0,0 +1,12 @@ +// 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. + +namespace Microsoft.AspNet.Hosting.Fakes +{ + interface IFakeEveryService : + IFakeService, + IFakeServiceInstance, + IFakeSingletonService + { + } +} diff --git a/test/Microsoft.AspNet.Hosting.Tests/Fakes/IFakeScopedService.cs b/test/Microsoft.AspNet.Hosting.Tests/Fakes/IFakeScopedService.cs new file mode 100644 index 0000000000..0e5ca63193 --- /dev/null +++ b/test/Microsoft.AspNet.Hosting.Tests/Fakes/IFakeScopedService.cs @@ -0,0 +1,9 @@ +// 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. + +namespace Microsoft.AspNet.Hosting.Fakes +{ + public interface IFakeScopedService : IFakeService + { + } +} diff --git a/test/Microsoft.AspNet.Hosting.Tests/Fakes/IFakeService.cs b/test/Microsoft.AspNet.Hosting.Tests/Fakes/IFakeService.cs index e183e13eb2..22e1837513 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/Fakes/IFakeService.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/Fakes/IFakeService.cs @@ -4,5 +4,4 @@ namespace Microsoft.AspNet.Hosting.Fakes { public interface IFakeService { } - public class FakeService : IFakeService { } } \ No newline at end of file diff --git a/test/Microsoft.AspNet.Hosting.Tests/Fakes/IFakeServiceInstance.cs b/test/Microsoft.AspNet.Hosting.Tests/Fakes/IFakeServiceInstance.cs new file mode 100644 index 0000000000..e9d8bc0f47 --- /dev/null +++ b/test/Microsoft.AspNet.Hosting.Tests/Fakes/IFakeServiceInstance.cs @@ -0,0 +1,9 @@ +// 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. + +namespace Microsoft.AspNet.Hosting.Fakes +{ + interface IFakeServiceInstance : IFakeService + { + } +} diff --git a/test/Microsoft.AspNet.Hosting.Tests/Fakes/IFakeSingletonService.cs b/test/Microsoft.AspNet.Hosting.Tests/Fakes/IFakeSingletonService.cs new file mode 100644 index 0000000000..844ad72395 --- /dev/null +++ b/test/Microsoft.AspNet.Hosting.Tests/Fakes/IFakeSingletonService.cs @@ -0,0 +1,9 @@ +// 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. + +namespace Microsoft.AspNet.Hosting.Fakes +{ + interface IFakeSingletonService : IFakeService + { + } +} diff --git a/test/Microsoft.AspNet.Hosting.Tests/Fakes/INonexistentService.cs b/test/Microsoft.AspNet.Hosting.Tests/Fakes/INonexistentService.cs new file mode 100644 index 0000000000..0e64d75641 --- /dev/null +++ b/test/Microsoft.AspNet.Hosting.Tests/Fakes/INonexistentService.cs @@ -0,0 +1,9 @@ +// 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. + +namespace Microsoft.AspNet.Hosting.Fakes +{ + public interface INonexistentService + { + } +} \ No newline at end of file diff --git a/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs b/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs index 01ec585067..7fa4a9a289 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs @@ -20,9 +20,7 @@ namespace Microsoft.AspNet.Hosting [Fact] public void HostingEngineCanBeResolvedWithDefaultServices() { - var serviceCollection = new ServiceCollection(); - serviceCollection.Add(HostingServices.GetDefaultServices()); - var services = serviceCollection.BuildServiceProvider(); + var services = HostingServices.Create().BuildServiceProvider(); var engine = services.GetRequiredService(); @@ -32,9 +30,7 @@ namespace Microsoft.AspNet.Hosting [Fact] public void HostingEngineCanBeStarted() { - var serviceCollection = new ServiceCollection(); - serviceCollection.Add(HostingServices.GetDefaultServices()); - var services = serviceCollection.BuildServiceProvider(); + var services = HostingServices.Create().BuildServiceProvider(); var engine = services.GetRequiredService(); diff --git a/test/Microsoft.AspNet.Hosting.Tests/HostingServicesFacts.cs b/test/Microsoft.AspNet.Hosting.Tests/HostingServicesFacts.cs new file mode 100644 index 0000000000..4b2e7ae14e --- /dev/null +++ b/test/Microsoft.AspNet.Hosting.Tests/HostingServicesFacts.cs @@ -0,0 +1,116 @@ +// 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 System; +using System.Collections.Generic; +using Microsoft.AspNet.Hosting.Fakes; +using Microsoft.Framework.DependencyInjection; +using Microsoft.Framework.DependencyInjection.Fallback; +using Microsoft.Framework.DependencyInjection.ServiceLookup; +using Xunit; + +namespace Microsoft.AspNet.Hosting.Tests +{ + public class HostingServicesFacts + { + [Fact] + public void CreateImportsServices() + { + // Arrange + var fallbackServices = new ServiceCollection(); + fallbackServices.AddSingleton(); + var instance = new FakeService(); + var factoryInstance = new FakeFactoryService(instance); + fallbackServices.AddInstance(instance); + fallbackServices.AddTransient(); + fallbackServices.AddSingleton(serviceProvider => factoryInstance); + fallbackServices.AddTransient(); // Don't register in manifest + + fallbackServices.AddInstance(new ServiceManifest( + new Type[] { + typeof(IFakeServiceInstance), + typeof(IFakeService), + typeof(IFakeSingletonService), + typeof(IFactoryService), + typeof(INonexistentService) + })); + + var services = HostingServices.Create(fallbackServices.BuildServiceProvider()); + + // Act + var provider = services.BuildServiceProvider(); + var singleton = provider.GetRequiredService(); + var transient = provider.GetRequiredService(); + var factory = provider.GetRequiredService(); + + // Assert + Assert.Same(singleton, provider.GetRequiredService()); + Assert.NotSame(transient, provider.GetRequiredService()); + Assert.Same(instance, provider.GetRequiredService()); + Assert.Same(factoryInstance, factory); + Assert.Same(factory.FakeService, instance); + Assert.Null(provider.GetService()); + Assert.Null(provider.GetService()); // Make sure we don't leak non manifest services + } + + [Fact] + public void CanHideImportedServices() + { + // Arrange + var fallbackServices = new ServiceCollection(); + var fallbackInstance = new FakeService(); + fallbackServices.AddInstance(fallbackInstance); + fallbackServices.AddInstance(new ServiceManifest(new Type[] { typeof(IFakeService) })); + + var services = HostingServices.Create(fallbackServices.BuildServiceProvider()); + var realInstance = new FakeService(); + services.AddInstance(realInstance); + + // Act + var provider = services.BuildServiceProvider(); + + // Assert + Assert.Equal(realInstance, provider.GetRequiredService()); + } + + [Fact] + public void CreateThrowsWithNoManifest() + { + // Arrange + var fallbackServices = new ServiceCollection(); + fallbackServices.AddSingleton(); + var instance = new FakeService(); + fallbackServices.AddInstance(instance); + fallbackServices.AddTransient(); + + // Act + var exp = Assert.Throws(() => HostingServices.Create(fallbackServices.BuildServiceProvider())); + + + // Assert + Assert.True(exp.Message.Contains("No service for type 'Microsoft.Framework.DependencyInjection.ServiceLookup.IServiceManifest'")); + } + + private class ServiceManifest : IServiceManifest + { + public ServiceManifest(IEnumerable services) + { + Services = services; + } + + public IEnumerable Services { get; private set; } + } + + private class FakeFactoryService : IFactoryService + { + public FakeFactoryService(FakeService service) + { + FakeService = service; + } + + public IFakeService FakeService { get; private set; } + + public int Value { get; private set; } + } + } +} \ No newline at end of file diff --git a/test/Microsoft.AspNet.Hosting.Tests/StartupManagerTests.cs b/test/Microsoft.AspNet.Hosting.Tests/StartupManagerTests.cs index 764d0f9ff9..a1e083864c 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/StartupManagerTests.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/StartupManagerTests.cs @@ -1,17 +1,17 @@ // 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 System; using System.Collections.Generic; +using Microsoft.AspNet.Builder; using Microsoft.AspNet.Hosting.Fakes; using Microsoft.AspNet.Hosting.Startup; using Microsoft.Framework.DependencyInjection; using Microsoft.Framework.DependencyInjection.Fallback; -using Xunit; using Microsoft.Framework.OptionsModel; -using Microsoft.AspNet.Builder; -using System; +using Xunit; -namespace Microsoft.AspNet.Hosting +namespace Microsoft.AspNet.Hosting.Tests { public class StartupManagerTests : IFakeStartupCallback @@ -45,9 +45,7 @@ namespace Microsoft.AspNet.Hosting [InlineData("ProviderArgs")] public void StartupClassAddsConfigureServicesToApplicationServices(string environment) { - var serviceCollection = new ServiceCollection(); - serviceCollection.Add(HostingServices.GetDefaultServices()); - var services = serviceCollection.BuildServiceProvider(); + var services = HostingServices.Create().BuildServiceProvider(); var manager = services.GetRequiredService(); var startup = manager.LoadStartup("Microsoft.AspNet.Hosting.Tests", environment ?? ""); @@ -67,9 +65,7 @@ namespace Microsoft.AspNet.Hosting [InlineData("FallbackProvider")] public void StartupClassConfigureServicesThatFallsbackToApplicationServices(string env) { - var serviceCollection = new ServiceCollection(); - serviceCollection.Add(HostingServices.GetDefaultServices()); - var services = serviceCollection.BuildServiceProvider(); + var services = HostingServices.Create().BuildServiceProvider(); var manager = services.GetRequiredService(); var startup = manager.LoadStartup("Microsoft.AspNet.Hosting.Tests", env); @@ -81,12 +77,12 @@ namespace Microsoft.AspNet.Hosting Assert.Equal(services, app.ApplicationServices); } - [Fact] - public void StartupClassWithConfigureServicesAndUseServicesAddsBothToServices() + // REVIEW: With the manifest change, Since the ConfigureServices are not imported, UseServices will mask what's in ConfigureServices + // This will throw since ConfigureServices consumes manifest and then UseServices will blow up + [Fact(Skip = "Review Failure")] + public void StartupClassWithConfigureServicesAndUseServicesHidesConfigureServices() { - var serviceCollection = new ServiceCollection(); - serviceCollection.Add(HostingServices.GetDefaultServices()); - var services = serviceCollection.BuildServiceProvider(); + var services = HostingServices.Create().BuildServiceProvider(); var manager = services.GetRequiredService(); var startup = manager.LoadStartup("Microsoft.AspNet.Hosting.Tests", "UseServices"); @@ -96,19 +92,18 @@ namespace Microsoft.AspNet.Hosting startup.Invoke(app); Assert.NotNull(app.ApplicationServices.GetRequiredService()); - Assert.NotNull(app.ApplicationServices.GetRequiredService()); + Assert.Null(app.ApplicationServices.GetService()); var options = app.ApplicationServices.GetRequiredService>().Options; Assert.NotNull(options); Assert.Equal("Configured", options.Message); - Assert.False(options.Configured); // REVIEW: why doesn't the ConfigureServices ConfigureOptions get run? + Assert.False(options.Configured); // Options never resolved from inner containers } [Fact] public void StartupWithNoConfigureThrows() { - var serviceCollection = new ServiceCollection(); - serviceCollection.Add(HostingServices.GetDefaultServices()); + var serviceCollection = HostingServices.Create(); serviceCollection.AddInstance(this); var services = serviceCollection.BuildServiceProvider(); var manager = services.GetRequiredService(); diff --git a/test/Microsoft.AspNet.Hosting.Tests/UseRequestServicesFacts.cs b/test/Microsoft.AspNet.Hosting.Tests/UseRequestServicesFacts.cs index 1229df1bb4..7b01e54c6f 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/UseRequestServicesFacts.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/UseRequestServicesFacts.cs @@ -1,12 +1,17 @@ // 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 System; using Microsoft.AspNet.Builder; -using Microsoft.Framework.DependencyInjection; -using Microsoft.Framework.DependencyInjection.Fallback; -using Xunit; +using Microsoft.AspNet.Hosting.Builder; +using Microsoft.AspNet.Hosting.Server; +using Microsoft.AspNet.Hosting.Startup; using Microsoft.AspNet.PipelineCore; using Microsoft.AspNet.RequestContainer; +using Microsoft.Framework.DependencyInjection; +using Microsoft.Framework.DependencyInjection.Fallback; +using Microsoft.Framework.Logging; +using Xunit; namespace Microsoft.AspNet.Hosting.Tests { @@ -15,9 +20,7 @@ namespace Microsoft.AspNet.Hosting.Tests [Fact] public void RequestServicesAvailableOnlyAfterRequestServices() { - var baseServiceProvider = new ServiceCollection() - .Add(HostingServices.GetDefaultServices()) - .BuildServiceProvider(); + var baseServiceProvider = HostingServices.Create().BuildServiceProvider(); var builder = new ApplicationBuilder(baseServiceProvider); bool foundRequestServicesBefore = false; @@ -45,9 +48,7 @@ namespace Microsoft.AspNet.Hosting.Tests [InlineData(false)] public void EnsureRequestServicesSetsRequestServices(bool initializeApplicationServices) { - var baseServiceProvider = new ServiceCollection() - .Add(HostingServices.GetDefaultServices()) - .BuildServiceProvider(); + var baseServiceProvider = HostingServices.Create().BuildServiceProvider(); var builder = new ApplicationBuilder(baseServiceProvider); bool foundRequestServicesBefore = false; @@ -80,5 +81,25 @@ namespace Microsoft.AspNet.Hosting.Tests Assert.True(foundRequestServicesAfter); } + [Theory] + [InlineData(typeof(IHostingEngine))] + [InlineData(typeof(IServerManager))] + [InlineData(typeof(IStartupManager))] + [InlineData(typeof(IStartupLoaderProvider))] + [InlineData(typeof(IApplicationBuilderFactory))] + [InlineData(typeof(IStartupLoaderProvider))] + [InlineData(typeof(IHttpContextFactory))] + [InlineData(typeof(ITypeActivator))] + [InlineData(typeof(IApplicationLifetime))] + [InlineData(typeof(ILoggerFactory))] + public void UseRequestServicesHostingImportedServicesAreDefined(Type service) + { + var baseServiceProvider = HostingServices.Create().BuildServiceProvider(); + var builder = new ApplicationBuilder(baseServiceProvider); + + builder.UseRequestServices(); + + Assert.NotNull(builder.ApplicationServices.GetRequiredService(service)); + } } } \ No newline at end of file diff --git a/test/Microsoft.AspNet.Hosting.Tests/UseServicesFacts.cs b/test/Microsoft.AspNet.Hosting.Tests/UseServicesFacts.cs index d556e2b4fe..54b9b50eeb 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/UseServicesFacts.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/UseServicesFacts.cs @@ -6,9 +6,8 @@ using Microsoft.AspNet.Builder; using Microsoft.Framework.DependencyInjection; using Microsoft.Framework.DependencyInjection.Fallback; using Microsoft.Framework.OptionsModel; +using Microsoft.Framework.Runtime.Infrastructure; using Xunit; -using Microsoft.AspNet.Http; -using Microsoft.AspNet.PipelineCore; namespace Microsoft.AspNet.Hosting.Tests { @@ -17,8 +16,7 @@ namespace Microsoft.AspNet.Hosting.Tests [Fact] public void OptionsAccessorCanBeResolvedAfterCallingUseServicesWithAction() { - var baseServiceProvider = new ServiceCollection().BuildServiceProvider(); - var builder = new ApplicationBuilder(baseServiceProvider); + var builder = new ApplicationBuilder(CallContextServiceLocator.Locator.ServiceProvider); builder.UseServices(serviceCollection => { }); @@ -30,13 +28,12 @@ namespace Microsoft.AspNet.Hosting.Tests [Fact] public void OptionsAccessorCanBeResolvedAfterCallingUseServicesWithFunc() { - var baseServiceProvider = new ServiceCollection().BuildServiceProvider(); - var builder = new ApplicationBuilder(baseServiceProvider); + var builder = new ApplicationBuilder(CallContextServiceLocator.Locator.ServiceProvider); IServiceProvider serviceProvider = null; builder.UseServices(serviceCollection => { - serviceProvider = serviceCollection.BuildServiceProvider(builder.ApplicationServices); + serviceProvider = serviceCollection.BuildServiceProvider(); return serviceProvider; }); diff --git a/test/Microsoft.AspNet.TestHost.Tests/TestClientTests.cs b/test/Microsoft.AspNet.TestHost.Tests/TestClientTests.cs index c1ba2d9f59..467aca2005 100644 --- a/test/Microsoft.AspNet.TestHost.Tests/TestClientTests.cs +++ b/test/Microsoft.AspNet.TestHost.Tests/TestClientTests.cs @@ -6,10 +6,9 @@ using System.IO; using System.Net.Http; using System.Threading.Tasks; using Microsoft.AspNet.Builder; +using Microsoft.AspNet.Hosting; using Microsoft.AspNet.Http; -using Microsoft.Framework.DependencyInjection; using Microsoft.Framework.DependencyInjection.Fallback; -using Microsoft.Framework.Runtime; using Xunit; namespace Microsoft.AspNet.TestHost @@ -21,9 +20,7 @@ namespace Microsoft.AspNet.TestHost public TestClientTests() { - _services = new ServiceCollection() - .AddSingleton() - .BuildServiceProvider(); + _services = HostingServices.Create().BuildServiceProvider(); _server = TestServer.Create(_services, app => app.Run(ctx => Task.FromResult(0))); } diff --git a/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs b/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs index 8a9bacf97b..52267bba35 100644 --- a/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs +++ b/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs @@ -11,7 +11,6 @@ using Microsoft.AspNet.Hosting; using Microsoft.AspNet.Http; using Microsoft.Framework.DependencyInjection; using Microsoft.Framework.DependencyInjection.Fallback; -using Microsoft.Framework.Runtime; using Xunit; namespace Microsoft.AspNet.TestHost @@ -22,9 +21,7 @@ namespace Microsoft.AspNet.TestHost public void CreateWithDelegate() { // Arrange - var services = new ServiceCollection() - .AddSingleton() - .BuildServiceProvider(); + var services = HostingServices.Create().BuildServiceProvider(); // Act & Assert Assert.DoesNotThrow(() => TestServer.Create(services, app => { })); @@ -34,8 +31,7 @@ namespace Microsoft.AspNet.TestHost public void ThrowsIfNoApplicationEnvironmentIsRegisteredWithTheProvider() { // Arrange - var services = new ServiceCollection() - .BuildServiceProvider(); + var services = new ServiceCollection().BuildServiceProvider(); // Act & Assert Assert.Throws(() => TestServer.Create(services, new Startup().Configuration)); From 63c8e1889bafcb709f11b49a97a8170137d431eb Mon Sep 17 00:00:00 2001 From: Hao Kung Date: Thu, 20 Nov 2014 17:37:35 -0800 Subject: [PATCH 155/987] Add IServiceManifest --- src/Microsoft.AspNet.Hosting/HostingServices.cs | 2 +- src/Microsoft.AspNet.Hosting/IServiceManifest.cs | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 src/Microsoft.AspNet.Hosting/IServiceManifest.cs diff --git a/src/Microsoft.AspNet.Hosting/HostingServices.cs b/src/Microsoft.AspNet.Hosting/HostingServices.cs index 9ec27a1f83..8d2d015ea5 100644 --- a/src/Microsoft.AspNet.Hosting/HostingServices.cs +++ b/src/Microsoft.AspNet.Hosting/HostingServices.cs @@ -88,4 +88,4 @@ namespace Microsoft.AspNet.Hosting public IEnumerable Services { get; private set; } } } -} +} \ No newline at end of file diff --git a/src/Microsoft.AspNet.Hosting/IServiceManifest.cs b/src/Microsoft.AspNet.Hosting/IServiceManifest.cs new file mode 100644 index 0000000000..3810fdc06c --- /dev/null +++ b/src/Microsoft.AspNet.Hosting/IServiceManifest.cs @@ -0,0 +1,16 @@ +// 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 System; +using System.Collections.Generic; + +namespace Microsoft.Framework.DependencyInjection.ServiceLookup +{ +#if ASPNET50 || ASPNETCORE50 + [Microsoft.Framework.Runtime.AssemblyNeutral] +#endif + public interface IServiceManifest + { + IEnumerable Services { get; } + } +} From 2f02fc6091fcac25ffe0f2bc4f50cdc25f72ffd8 Mon Sep 17 00:00:00 2001 From: Hao Kung Date: Fri, 21 Nov 2014 15:01:52 -0800 Subject: [PATCH 156/987] Fix SelfHost to default to config environment Fixes MusicStore --- src/Microsoft.AspNet.Hosting/Program.cs | 4 ++++ src/Microsoft.AspNet.TestHost/TestServer.cs | 1 - 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Microsoft.AspNet.Hosting/Program.cs b/src/Microsoft.AspNet.Hosting/Program.cs index b8bd4a2d7f..ba69bab638 100644 --- a/src/Microsoft.AspNet.Hosting/Program.cs +++ b/src/Microsoft.AspNet.Hosting/Program.cs @@ -38,6 +38,10 @@ namespace Microsoft.AspNet.Hosting config.AddCommandLine(args); var serviceCollection = HostingServices.Create(_serviceProvider, config); + serviceCollection.AddInstance(new ConfigureHostingEnvironment(env => + { + env.EnvironmentName = config.Get(EnvironmentKey) ?? DefaultEnvironmentName; + })); var services = serviceCollection.BuildServiceProvider(); var appEnv = services.GetRequiredService(); diff --git a/src/Microsoft.AspNet.TestHost/TestServer.cs b/src/Microsoft.AspNet.TestHost/TestServer.cs index 17a8dde680..9e88b16b58 100644 --- a/src/Microsoft.AspNet.TestHost/TestServer.cs +++ b/src/Microsoft.AspNet.TestHost/TestServer.cs @@ -57,7 +57,6 @@ namespace Microsoft.AspNet.TestHost var services = HostingServices.Create(serviceProvider); services.AddSingleton(); - //var appServices = BuildFallbackServiceProvider(services, serviceProvider); var appServices = services.BuildServiceProvider(); var config = new Configuration(); return new TestServer(config, appServices, app); From bd5c07d66a48770efe0499d4356c8217af94858d Mon Sep 17 00:00:00 2001 From: Glenn Condron Date: Fri, 21 Nov 2014 17:04:04 -0800 Subject: [PATCH 157/987] Move default hosting environment code --- .../ConfigureHostingEnvironment.cs | 13 +++++---- .../HostingEnvironment.cs | 3 ++ .../HostingServices.cs | 1 + src/Microsoft.AspNet.Hosting/Program.cs | 10 ++----- src/Microsoft.AspNet.TestHost/TestServer.cs | 10 +------ .../Microsoft.AspNet.Hosting.Tests.kproj | 29 ++++++++++--------- .../Microsoft.AspNet.TestHost.Tests.kproj | 29 ++++++++++--------- 7 files changed, 44 insertions(+), 51 deletions(-) diff --git a/src/Microsoft.AspNet.Hosting/ConfigureHostingEnvironment.cs b/src/Microsoft.AspNet.Hosting/ConfigureHostingEnvironment.cs index 399054f2cd..420b731122 100644 --- a/src/Microsoft.AspNet.Hosting/ConfigureHostingEnvironment.cs +++ b/src/Microsoft.AspNet.Hosting/ConfigureHostingEnvironment.cs @@ -1,22 +1,23 @@ // 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 System; +using Microsoft.Framework.ConfigurationModel; namespace Microsoft.AspNet.Hosting { - public class ConfigureHostingEnvironment : IConfigureHostingEnvironment + internal class ConfigureHostingEnvironment : IConfigureHostingEnvironment { - private readonly Action _action; + private IConfiguration _config; + private const string EnvironmentKey = "KRE_ENV"; - public ConfigureHostingEnvironment(Action configure) + public ConfigureHostingEnvironment(IConfiguration config) { - _action = configure; + _config = config; } public void Configure(IHostingEnvironment hostingEnv) { - _action.Invoke(hostingEnv); + hostingEnv.EnvironmentName = _config.Get(EnvironmentKey) ?? hostingEnv.EnvironmentName; } } } \ No newline at end of file diff --git a/src/Microsoft.AspNet.Hosting/HostingEnvironment.cs b/src/Microsoft.AspNet.Hosting/HostingEnvironment.cs index 0b0550d888..f137f2ae5b 100644 --- a/src/Microsoft.AspNet.Hosting/HostingEnvironment.cs +++ b/src/Microsoft.AspNet.Hosting/HostingEnvironment.cs @@ -8,9 +8,12 @@ namespace Microsoft.AspNet.Hosting { public class HostingEnvironment : IHostingEnvironment { + private const string DefaultEnvironmentName = "Development"; + public HostingEnvironment(IApplicationEnvironment appEnv, IEnumerable configures) { WebRoot = HostingUtilities.GetWebRoot(appEnv.ApplicationBasePath); + EnvironmentName = DefaultEnvironmentName; foreach (var configure in configures) { configure.Configure(this); diff --git a/src/Microsoft.AspNet.Hosting/HostingServices.cs b/src/Microsoft.AspNet.Hosting/HostingServices.cs index 8d2d015ea5..605453f2e9 100644 --- a/src/Microsoft.AspNet.Hosting/HostingServices.cs +++ b/src/Microsoft.AspNet.Hosting/HostingServices.cs @@ -40,6 +40,7 @@ namespace Microsoft.AspNet.Hosting var services = Import(fallbackServices); services.Add(GetDefaultServices(configuration)); services.AddSingleton(sp => new HostingManifest(fallbackServices)); + services.AddInstance(new ConfigureHostingEnvironment(configuration)); return services; } diff --git a/src/Microsoft.AspNet.Hosting/Program.cs b/src/Microsoft.AspNet.Hosting/Program.cs index ba69bab638..4776c41223 100644 --- a/src/Microsoft.AspNet.Hosting/Program.cs +++ b/src/Microsoft.AspNet.Hosting/Program.cs @@ -15,8 +15,6 @@ namespace Microsoft.AspNet.Hosting public class Program { private const string HostingIniFile = "Microsoft.AspNet.Hosting.ini"; - private const string DefaultEnvironmentName = "Development"; - private const string EnvironmentKey = "KRE_ENV"; private readonly IServiceProvider _serviceProvider; @@ -37,12 +35,8 @@ namespace Microsoft.AspNet.Hosting config.AddEnvironmentVariables(); config.AddCommandLine(args); - var serviceCollection = HostingServices.Create(_serviceProvider, config); - serviceCollection.AddInstance(new ConfigureHostingEnvironment(env => - { - env.EnvironmentName = config.Get(EnvironmentKey) ?? DefaultEnvironmentName; - })); - var services = serviceCollection.BuildServiceProvider(); + var services = HostingServices.Create(_serviceProvider, config) + .BuildServiceProvider(); var appEnv = services.GetRequiredService(); var hostingEnv = services.GetRequiredService(); diff --git a/src/Microsoft.AspNet.TestHost/TestServer.cs b/src/Microsoft.AspNet.TestHost/TestServer.cs index 9e88b16b58..97e848033a 100644 --- a/src/Microsoft.AspNet.TestHost/TestServer.cs +++ b/src/Microsoft.AspNet.TestHost/TestServer.cs @@ -54,10 +54,7 @@ namespace Microsoft.AspNet.TestHost public static TestServer Create(IServiceProvider serviceProvider, Action app) { - var services = HostingServices.Create(serviceProvider); - services.AddSingleton(); - - var appServices = services.BuildServiceProvider(); + var appServices = HostingServices.Create(serviceProvider).BuildServiceProvider(); var config = new Configuration(); return new TestServer(config, appServices, app); } @@ -127,10 +124,5 @@ namespace Microsoft.AspNet.TestHost get { return TestServer.ServerName; } } } - - private class ConfigureTestHostingEnvironment : ConfigureHostingEnvironment - { - public ConfigureTestHostingEnvironment() : base(env => env.EnvironmentName = DefaultEnvironmentName) { } - } } } diff --git a/test/Microsoft.AspNet.Hosting.Tests/Microsoft.AspNet.Hosting.Tests.kproj b/test/Microsoft.AspNet.Hosting.Tests/Microsoft.AspNet.Hosting.Tests.kproj index 95b1cc35f3..247779b53f 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/Microsoft.AspNet.Hosting.Tests.kproj +++ b/test/Microsoft.AspNet.Hosting.Tests/Microsoft.AspNet.Hosting.Tests.kproj @@ -1,14 +1,15 @@ - - - - 14.0 - $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) - - - - d4f18d58-52b1-435d-a012-10f2cdf158c4 - ..\..\artifacts\obj\$(MSBuildProjectName) - ..\..\artifacts\bin\$(MSBuildProjectName)\ - - - + + + + 14.0 + $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) + 50390 + + + + d4f18d58-52b1-435d-a012-10f2cdf158c4 + ..\..\artifacts\obj\$(MSBuildProjectName) + ..\..\artifacts\bin\$(MSBuildProjectName)\ + + + \ No newline at end of file diff --git a/test/Microsoft.AspNet.TestHost.Tests/Microsoft.AspNet.TestHost.Tests.kproj b/test/Microsoft.AspNet.TestHost.Tests/Microsoft.AspNet.TestHost.Tests.kproj index 259cc5243d..be290d126c 100644 --- a/test/Microsoft.AspNet.TestHost.Tests/Microsoft.AspNet.TestHost.Tests.kproj +++ b/test/Microsoft.AspNet.TestHost.Tests/Microsoft.AspNet.TestHost.Tests.kproj @@ -1,14 +1,15 @@ - - - - 14.0 - $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) - - - - 0acb2719-9484-49b5-b8e3-117091192511 - ..\..\artifacts\obj\$(MSBuildProjectName) - ..\..\artifacts\bin\$(MSBuildProjectName)\ - - - + + + + 14.0 + $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) + 50389 + + + + 0acb2719-9484-49b5-b8e3-117091192511 + ..\..\artifacts\obj\$(MSBuildProjectName) + ..\..\artifacts\bin\$(MSBuildProjectName)\ + + + \ No newline at end of file From 075edc516c5b65432f605ae9fbb5080289863127 Mon Sep 17 00:00:00 2001 From: David Fowler Date: Sun, 23 Nov 2014 22:48:28 -0800 Subject: [PATCH 158/987] Handle null configuration in HostingServices.Create --- src/Microsoft.AspNet.Hosting/HostingServices.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Microsoft.AspNet.Hosting/HostingServices.cs b/src/Microsoft.AspNet.Hosting/HostingServices.cs index 605453f2e9..e2372db87d 100644 --- a/src/Microsoft.AspNet.Hosting/HostingServices.cs +++ b/src/Microsoft.AspNet.Hosting/HostingServices.cs @@ -32,11 +32,12 @@ namespace Microsoft.AspNet.Hosting public static IServiceCollection Create(IConfiguration configuration = null) { - return Create(CallContextServiceLocator.Locator.ServiceProvider); + return Create(CallContextServiceLocator.Locator.ServiceProvider, configuration); } public static IServiceCollection Create(IServiceProvider fallbackServices, IConfiguration configuration = null) { + configuration = configuration ?? new Configuration(); var services = Import(fallbackServices); services.Add(GetDefaultServices(configuration)); services.AddSingleton(sp => new HostingManifest(fallbackServices)); From aebfecdf87023dd1d39fe74b9bc9e3e6755884d1 Mon Sep 17 00:00:00 2001 From: Pranav K Date: Mon, 24 Nov 2014 10:10:51 -0800 Subject: [PATCH 159/987] Reacting to DI changes --- test/Microsoft.AspNet.Hosting.Tests/Fakes/IFakeEveryService.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/Microsoft.AspNet.Hosting.Tests/Fakes/IFakeEveryService.cs b/test/Microsoft.AspNet.Hosting.Tests/Fakes/IFakeEveryService.cs index 9fadf70efa..6e279051e2 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/Fakes/IFakeEveryService.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/Fakes/IFakeEveryService.cs @@ -4,7 +4,7 @@ namespace Microsoft.AspNet.Hosting.Fakes { interface IFakeEveryService : - IFakeService, + IFakeScopedService, IFakeServiceInstance, IFakeSingletonService { From a9827a43105f97ec8ff6e1c4aa6f3f1f59d59b1e Mon Sep 17 00:00:00 2001 From: Hao Kung Date: Mon, 24 Nov 2014 17:33:11 -0800 Subject: [PATCH 160/987] GetDefaultServices -> AddHosting Also stop adding options --- .../HostingServices.cs | 42 +-------------- .../HostingServicesCollectionExtensions.cs | 53 +++++++++++++++++++ .../Startup/StartupLoader.cs | 6 +-- .../ContainerExtensions.cs | 6 +-- .../Fakes/Startup.cs | 11 ++-- .../StartupManagerTests.cs | 3 +- .../UseServicesFacts.cs | 45 ---------------- 7 files changed, 67 insertions(+), 99 deletions(-) create mode 100644 src/Microsoft.AspNet.Hosting/HostingServicesCollectionExtensions.cs delete mode 100644 test/Microsoft.AspNet.Hosting.Tests/UseServicesFacts.cs diff --git a/src/Microsoft.AspNet.Hosting/HostingServices.cs b/src/Microsoft.AspNet.Hosting/HostingServices.cs index e2372db87d..3ff28e403f 100644 --- a/src/Microsoft.AspNet.Hosting/HostingServices.cs +++ b/src/Microsoft.AspNet.Hosting/HostingServices.cs @@ -4,14 +4,10 @@ using System; using System.Collections.Generic; using System.Linq; -using Microsoft.AspNet.Hosting.Builder; -using Microsoft.AspNet.Hosting.Server; -using Microsoft.AspNet.Hosting.Startup; using Microsoft.Framework.ConfigurationModel; using Microsoft.Framework.DependencyInjection; using Microsoft.Framework.DependencyInjection.ServiceLookup; using Microsoft.Framework.Logging; -using Microsoft.Framework.OptionsModel; using Microsoft.Framework.Runtime.Infrastructure; namespace Microsoft.AspNet.Hosting @@ -24,7 +20,6 @@ namespace Microsoft.AspNet.Hosting var manifest = fallbackProvider.GetRequiredService(); foreach (var service in manifest.Services) { - // REVIEW: should this be Singleton instead? services.AddTransient(service, sp => fallbackProvider.GetService(service)); } return services; @@ -39,45 +34,12 @@ namespace Microsoft.AspNet.Hosting { configuration = configuration ?? new Configuration(); var services = Import(fallbackServices); - services.Add(GetDefaultServices(configuration)); + services.AddHosting(configuration); services.AddSingleton(sp => new HostingManifest(fallbackServices)); - services.AddInstance(new ConfigureHostingEnvironment(configuration)); return services; } - // REVIEW: make this private? - public static IEnumerable GetDefaultServices(IConfiguration configuration = null) - { - configuration = configuration ?? new Configuration(); - var describer = new ServiceDescriber(configuration); - - yield return describer.Transient(); - yield return describer.Transient(); - - yield return describer.Transient(); - yield return describer.Transient(); - - yield return describer.Transient(); - yield return describer.Transient(); - - yield return describer.Instance(new ApplicationLifetime()); - - // These three services as exported in the manifest - yield return describer.Singleton(); - yield return describer.Singleton(); - // TODO: Do we expect this to be provide by the runtime eventually? - yield return describer.Singleton(); - - // TODO: Remove the below services and push the responsibility to frameworks to add - - yield return describer.Scoped(typeof(IContextAccessor<>), typeof(ContextAccessor<>)); - - foreach (var service in OptionsServices.GetDefaultServices()) - { - yield return service; - } - } - + // Manifest exposes the fallback manifest in addition to ITypeActivator, IHostingEnvironment, and ILoggerFactory private class HostingManifest : IServiceManifest { public HostingManifest(IServiceProvider fallback) diff --git a/src/Microsoft.AspNet.Hosting/HostingServicesCollectionExtensions.cs b/src/Microsoft.AspNet.Hosting/HostingServicesCollectionExtensions.cs new file mode 100644 index 0000000000..ac661999b2 --- /dev/null +++ b/src/Microsoft.AspNet.Hosting/HostingServicesCollectionExtensions.cs @@ -0,0 +1,53 @@ +// 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.Hosting; +using Microsoft.AspNet.Hosting.Builder; +using Microsoft.AspNet.Hosting.Server; +using Microsoft.AspNet.Hosting.Startup; +using Microsoft.Framework.ConfigurationModel; +using Microsoft.Framework.Logging; + +namespace Microsoft.Framework.DependencyInjection +{ + public static class HostingServicesExtensions + { + // REVIEW: Logging doesn't depend on DI, where should this live? + public static IServiceCollection AddLogging(this IServiceCollection services, IConfiguration config = null) + { + var describe = new ServiceDescriber(config); + services.TryAdd(describe.Singleton()); + return services; + } + + public static IServiceCollection AddHosting(this IServiceCollection services, IConfiguration configuration = null) + { + var describer = new ServiceDescriber(configuration); + + services.TryAdd(describer.Transient()); + services.TryAdd(describer.Transient()); + + services.TryAdd(describer.Transient()); + services.TryAdd(describer.Transient()); + + services.TryAdd(describer.Transient()); + services.TryAdd(describer.Transient()); + + services.TryAdd(describer.Instance(new ApplicationLifetime())); + + services.AddTypeActivator(configuration); + // TODO: Do we expect this to be provide by the runtime eventually? + services.AddLogging(configuration); + // REVIEW: okay to use existing hosting environment/httpcontext if specified? + services.TryAdd(describer.Singleton()); + + // TODO: Remove this once we have IHttpContextAccessor + services.AddContextAccessor(configuration); + + // REVIEW: don't try add because we pull out IEnumerable? + services.AddInstance(new ConfigureHostingEnvironment(configuration)); + + return services; + } + } +} \ No newline at end of file diff --git a/src/Microsoft.AspNet.Hosting/Startup/StartupLoader.cs b/src/Microsoft.AspNet.Hosting/Startup/StartupLoader.cs index cf41930701..c76153e9d0 100644 --- a/src/Microsoft.AspNet.Hosting/Startup/StartupLoader.cs +++ b/src/Microsoft.AspNet.Hosting/Startup/StartupLoader.cs @@ -152,10 +152,8 @@ namespace Microsoft.AspNet.Hosting.Startup if (servicesMethod != null) { var services = HostingServices.Create(builder.ApplicationServices); - // TODO: remove adding options - services.Add(OptionsServices.GetDefaultServices()); - services.AddScoped(typeof(IContextAccessor<>), typeof(ContextAccessor<>)); - + // TODO: remove this once IHttpContextAccessor service is added + services.AddContextAccessor(); if (servicesMethod.ReturnType == typeof(IServiceProvider)) { // IServiceProvider ConfigureServices(IServiceCollection) diff --git a/src/Microsoft.AspNet.RequestContainer/ContainerExtensions.cs b/src/Microsoft.AspNet.RequestContainer/ContainerExtensions.cs index 31c6f51b09..9813e9164f 100644 --- a/src/Microsoft.AspNet.RequestContainer/ContainerExtensions.cs +++ b/src/Microsoft.AspNet.RequestContainer/ContainerExtensions.cs @@ -7,7 +7,6 @@ using Microsoft.AspNet.RequestContainer; using Microsoft.AspNet.Hosting; using Microsoft.Framework.DependencyInjection; using Microsoft.Framework.DependencyInjection.Fallback; -using Microsoft.Framework.OptionsModel; namespace Microsoft.AspNet.Builder { @@ -49,9 +48,8 @@ namespace Microsoft.AspNet.Builder // Import services from hosting/KRE as fallback var serviceCollection = HostingServices.Create(builder.ApplicationServices); - // TODO: should remove OptionServices here soon... - serviceCollection.Add(OptionsServices.GetDefaultServices()); - serviceCollection.AddScoped(typeof(IContextAccessor<>), typeof(ContextAccessor<>)); + // TODO: remove this once IHttpContextAccessor service is added + serviceCollection.AddContextAccessor(); // REVIEW: serviceCollection has the merged services, manifests are lost after this builder.ApplicationServices = configureServices(serviceCollection); diff --git a/test/Microsoft.AspNet.Hosting.Tests/Fakes/Startup.cs b/test/Microsoft.AspNet.Hosting.Tests/Fakes/Startup.cs index 5a85b82357..e657841566 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/Fakes/Startup.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/Fakes/Startup.cs @@ -17,11 +17,13 @@ namespace Microsoft.AspNet.Hosting.Fakes public void ConfigureServices(IServiceCollection services) { + services.AddOptions(); services.Configure(o => o.Configured = true); } public void ConfigureDevServices(IServiceCollection services) { + services.AddOptions(); services.Configure(o => { o.Configured = true; @@ -31,6 +33,7 @@ namespace Microsoft.AspNet.Hosting.Fakes public void ConfigureRetailServices(IServiceCollection services) { + services.AddOptions(); services.Configure(o => { o.Configured = true; @@ -40,6 +43,7 @@ namespace Microsoft.AspNet.Hosting.Fakes public static void ConfigureStaticServices(IServiceCollection services) { + services.AddOptions(); services.Configure(o => { o.Configured = true; @@ -49,8 +53,7 @@ namespace Microsoft.AspNet.Hosting.Fakes public static IServiceProvider ConfigureStaticProviderServices() { - var services = new ServiceCollection(); - services.Add(OptionsServices.GetDefaultServices()); + var services = new ServiceCollection().AddOptions(); services.Configure(o => { o.Configured = true; @@ -71,6 +74,7 @@ namespace Microsoft.AspNet.Hosting.Fakes public IServiceProvider ConfigureProviderServices(IServiceCollection services) { + services.AddOptions(); services.Configure(o => { o.Configured = true; @@ -81,8 +85,7 @@ namespace Microsoft.AspNet.Hosting.Fakes public IServiceProvider ConfigureProviderArgsServices(IApplicationBuilder me) { - var services = new ServiceCollection(); - services.Add(OptionsServices.GetDefaultServices()); + var services = new ServiceCollection().AddOptions(); services.Configure(o => { o.Configured = true; diff --git a/test/Microsoft.AspNet.Hosting.Tests/StartupManagerTests.cs b/test/Microsoft.AspNet.Hosting.Tests/StartupManagerTests.cs index a1e083864c..10016cdd1b 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/StartupManagerTests.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/StartupManagerTests.cs @@ -21,8 +21,7 @@ namespace Microsoft.AspNet.Hosting.Tests [Fact] public void StartupClassMayHaveHostingServicesInjected() { - var serviceCollection = new ServiceCollection(); - serviceCollection.Add(HostingServices.GetDefaultServices()); + var serviceCollection = new ServiceCollection().AddHosting(); serviceCollection.AddInstance(this); var services = serviceCollection.BuildServiceProvider(); diff --git a/test/Microsoft.AspNet.Hosting.Tests/UseServicesFacts.cs b/test/Microsoft.AspNet.Hosting.Tests/UseServicesFacts.cs deleted file mode 100644 index 54b9b50eeb..0000000000 --- a/test/Microsoft.AspNet.Hosting.Tests/UseServicesFacts.cs +++ /dev/null @@ -1,45 +0,0 @@ -// 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 System; -using Microsoft.AspNet.Builder; -using Microsoft.Framework.DependencyInjection; -using Microsoft.Framework.DependencyInjection.Fallback; -using Microsoft.Framework.OptionsModel; -using Microsoft.Framework.Runtime.Infrastructure; -using Xunit; - -namespace Microsoft.AspNet.Hosting.Tests -{ - public class UseServicesFacts - { - [Fact] - public void OptionsAccessorCanBeResolvedAfterCallingUseServicesWithAction() - { - var builder = new ApplicationBuilder(CallContextServiceLocator.Locator.ServiceProvider); - - builder.UseServices(serviceCollection => { }); - - var optionsAccessor = builder.ApplicationServices.GetRequiredService>(); - Assert.NotNull(optionsAccessor); - } - - - [Fact] - public void OptionsAccessorCanBeResolvedAfterCallingUseServicesWithFunc() - { - var builder = new ApplicationBuilder(CallContextServiceLocator.Locator.ServiceProvider); - IServiceProvider serviceProvider = null; - - builder.UseServices(serviceCollection => - { - serviceProvider = serviceCollection.BuildServiceProvider(); - return serviceProvider; - }); - - Assert.Same(serviceProvider, builder.ApplicationServices); - var optionsAccessor = builder.ApplicationServices.GetRequiredService>(); - Assert.NotNull(optionsAccessor); - } - } -} \ No newline at end of file From bf0c8c95b0b2517708079ea783235a19b7108c4a Mon Sep 17 00:00:00 2001 From: Victor Hurdugaci Date: Tue, 25 Nov 2014 10:47:58 -0800 Subject: [PATCH 161/987] Add schema version to kproj files --- .../Microsoft.AspNet.Hosting.kproj | 3 +++ .../Microsoft.AspNet.RequestContainer.kproj | 3 +++ .../Microsoft.AspNet.TestHost.kproj | 3 +++ .../Microsoft.AspNet.Hosting.Tests.kproj | 8 +++++--- .../Microsoft.AspNet.TestHost.Tests.kproj | 8 +++++--- 5 files changed, 19 insertions(+), 6 deletions(-) diff --git a/src/Microsoft.AspNet.Hosting/Microsoft.AspNet.Hosting.kproj b/src/Microsoft.AspNet.Hosting/Microsoft.AspNet.Hosting.kproj index 28467979c0..e98519ce8c 100644 --- a/src/Microsoft.AspNet.Hosting/Microsoft.AspNet.Hosting.kproj +++ b/src/Microsoft.AspNet.Hosting/Microsoft.AspNet.Hosting.kproj @@ -10,5 +10,8 @@ ..\..\artifacts\obj\$(MSBuildProjectName) ..\..\artifacts\bin\$(MSBuildProjectName)\ + + 2.0 + diff --git a/src/Microsoft.AspNet.RequestContainer/Microsoft.AspNet.RequestContainer.kproj b/src/Microsoft.AspNet.RequestContainer/Microsoft.AspNet.RequestContainer.kproj index 43376819b1..9740be9106 100644 --- a/src/Microsoft.AspNet.RequestContainer/Microsoft.AspNet.RequestContainer.kproj +++ b/src/Microsoft.AspNet.RequestContainer/Microsoft.AspNet.RequestContainer.kproj @@ -10,5 +10,8 @@ ..\..\artifacts\obj\$(MSBuildProjectName) ..\..\artifacts\bin\$(MSBuildProjectName)\ + + 2.0 + diff --git a/src/Microsoft.AspNet.TestHost/Microsoft.AspNet.TestHost.kproj b/src/Microsoft.AspNet.TestHost/Microsoft.AspNet.TestHost.kproj index 0ec30b643d..67078fd3b5 100644 --- a/src/Microsoft.AspNet.TestHost/Microsoft.AspNet.TestHost.kproj +++ b/src/Microsoft.AspNet.TestHost/Microsoft.AspNet.TestHost.kproj @@ -10,5 +10,8 @@ ..\..\artifacts\obj\$(MSBuildProjectName) ..\..\artifacts\bin\$(MSBuildProjectName)\ + + 2.0 + diff --git a/test/Microsoft.AspNet.Hosting.Tests/Microsoft.AspNet.Hosting.Tests.kproj b/test/Microsoft.AspNet.Hosting.Tests/Microsoft.AspNet.Hosting.Tests.kproj index 247779b53f..e82e9b32a2 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/Microsoft.AspNet.Hosting.Tests.kproj +++ b/test/Microsoft.AspNet.Hosting.Tests/Microsoft.AspNet.Hosting.Tests.kproj @@ -1,9 +1,8 @@ - + 14.0 $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) - 50390 @@ -11,5 +10,8 @@ ..\..\artifacts\obj\$(MSBuildProjectName) ..\..\artifacts\bin\$(MSBuildProjectName)\ + + 2.0 + - \ No newline at end of file + diff --git a/test/Microsoft.AspNet.TestHost.Tests/Microsoft.AspNet.TestHost.Tests.kproj b/test/Microsoft.AspNet.TestHost.Tests/Microsoft.AspNet.TestHost.Tests.kproj index be290d126c..04d1606ca3 100644 --- a/test/Microsoft.AspNet.TestHost.Tests/Microsoft.AspNet.TestHost.Tests.kproj +++ b/test/Microsoft.AspNet.TestHost.Tests/Microsoft.AspNet.TestHost.Tests.kproj @@ -1,9 +1,8 @@ - + 14.0 $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) - 50389 @@ -11,5 +10,8 @@ ..\..\artifacts\obj\$(MSBuildProjectName) ..\..\artifacts\bin\$(MSBuildProjectName)\ + + 2.0 + - \ No newline at end of file + From d85580649f4b6ef870168f1baec14a88810c403a Mon Sep 17 00:00:00 2001 From: Victor Hurdugaci Date: Wed, 3 Dec 2014 11:38:31 -0800 Subject: [PATCH 162/987] Update the expected exception from DI --- test/Microsoft.AspNet.Hosting.Tests/HostingServicesFacts.cs | 2 +- test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/test/Microsoft.AspNet.Hosting.Tests/HostingServicesFacts.cs b/test/Microsoft.AspNet.Hosting.Tests/HostingServicesFacts.cs index 4b2e7ae14e..65aa6faecd 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/HostingServicesFacts.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/HostingServicesFacts.cs @@ -84,7 +84,7 @@ namespace Microsoft.AspNet.Hosting.Tests fallbackServices.AddTransient(); // Act - var exp = Assert.Throws(() => HostingServices.Create(fallbackServices.BuildServiceProvider())); + var exp = Assert.Throws(() => HostingServices.Create(fallbackServices.BuildServiceProvider())); // Assert diff --git a/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs b/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs index 52267bba35..4f8b619dd7 100644 --- a/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs +++ b/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs @@ -34,7 +34,7 @@ namespace Microsoft.AspNet.TestHost var services = new ServiceCollection().BuildServiceProvider(); // Act & Assert - Assert.Throws(() => TestServer.Create(services, new Startup().Configuration)); + Assert.Throws(() => TestServer.Create(services, new Startup().Configuration)); } [Fact] From 99c566cac1cd6ea1ea6c3613602d980fb04925ba Mon Sep 17 00:00:00 2001 From: aidan casey Date: Fri, 5 Dec 2014 04:54:58 +1100 Subject: [PATCH 163/987] NDC London bug fix! , changing environment variable name --- src/Microsoft.AspNet.Hosting/ConfigureHostingEnvironment.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Microsoft.AspNet.Hosting/ConfigureHostingEnvironment.cs b/src/Microsoft.AspNet.Hosting/ConfigureHostingEnvironment.cs index 420b731122..a714c2cfef 100644 --- a/src/Microsoft.AspNet.Hosting/ConfigureHostingEnvironment.cs +++ b/src/Microsoft.AspNet.Hosting/ConfigureHostingEnvironment.cs @@ -8,7 +8,7 @@ namespace Microsoft.AspNet.Hosting internal class ConfigureHostingEnvironment : IConfigureHostingEnvironment { private IConfiguration _config; - private const string EnvironmentKey = "KRE_ENV"; + private const string EnvironmentKey = "ASPNET_ENV"; public ConfigureHostingEnvironment(IConfiguration config) { From b883968eefa73f7b546c681e5135f515ff666a13 Mon Sep 17 00:00:00 2001 From: Chris Ross Date: Thu, 4 Dec 2014 14:44:16 -0800 Subject: [PATCH 164/987] #86 - Implement IWebRootFileSystemProvider --- .../HostingEnvironment.cs | 5 +- .../HostingServicesCollectionExtensions.cs | 2 + .../IHostingEnvironment.cs | 2 - .../IWebRootFileSystemProvider.cs | 18 +++++++ .../WebRootFileSystemProvider.cs | 50 +++++++++++++++++++ src/Microsoft.AspNet.Hosting/project.json | 1 + .../HostingEngineTests.cs | 10 ++++ .../testroot/TextFile.txt | 1 + .../TestServerTests.cs | 6 +-- .../project.json | 3 +- 10 files changed, 87 insertions(+), 11 deletions(-) create mode 100644 src/Microsoft.AspNet.Hosting/IWebRootFileSystemProvider.cs create mode 100644 src/Microsoft.AspNet.Hosting/WebRootFileSystemProvider.cs create mode 100644 test/Microsoft.AspNet.Hosting.Tests/testroot/TextFile.txt diff --git a/src/Microsoft.AspNet.Hosting/HostingEnvironment.cs b/src/Microsoft.AspNet.Hosting/HostingEnvironment.cs index f137f2ae5b..acafebc789 100644 --- a/src/Microsoft.AspNet.Hosting/HostingEnvironment.cs +++ b/src/Microsoft.AspNet.Hosting/HostingEnvironment.cs @@ -10,9 +10,8 @@ namespace Microsoft.AspNet.Hosting { private const string DefaultEnvironmentName = "Development"; - public HostingEnvironment(IApplicationEnvironment appEnv, IEnumerable configures) + public HostingEnvironment(IEnumerable configures) { - WebRoot = HostingUtilities.GetWebRoot(appEnv.ApplicationBasePath); EnvironmentName = DefaultEnvironmentName; foreach (var configure in configures) { @@ -21,7 +20,5 @@ namespace Microsoft.AspNet.Hosting } public string EnvironmentName { get; set; } - - public string WebRoot { get; set; } } } \ No newline at end of file diff --git a/src/Microsoft.AspNet.Hosting/HostingServicesCollectionExtensions.cs b/src/Microsoft.AspNet.Hosting/HostingServicesCollectionExtensions.cs index ac661999b2..ee9fea15aa 100644 --- a/src/Microsoft.AspNet.Hosting/HostingServicesCollectionExtensions.cs +++ b/src/Microsoft.AspNet.Hosting/HostingServicesCollectionExtensions.cs @@ -35,6 +35,8 @@ namespace Microsoft.Framework.DependencyInjection services.TryAdd(describer.Instance(new ApplicationLifetime())); + services.TryAdd(describer.Singleton()); + services.AddTypeActivator(configuration); // TODO: Do we expect this to be provide by the runtime eventually? services.AddLogging(configuration); diff --git a/src/Microsoft.AspNet.Hosting/IHostingEnvironment.cs b/src/Microsoft.AspNet.Hosting/IHostingEnvironment.cs index 3760c17799..380c72550e 100644 --- a/src/Microsoft.AspNet.Hosting/IHostingEnvironment.cs +++ b/src/Microsoft.AspNet.Hosting/IHostingEnvironment.cs @@ -9,7 +9,5 @@ namespace Microsoft.AspNet.Hosting public interface IHostingEnvironment { string EnvironmentName { get; set; } - - string WebRoot { get; } } } \ No newline at end of file diff --git a/src/Microsoft.AspNet.Hosting/IWebRootFileSystemProvider.cs b/src/Microsoft.AspNet.Hosting/IWebRootFileSystemProvider.cs new file mode 100644 index 0000000000..8f65cff6e4 --- /dev/null +++ b/src/Microsoft.AspNet.Hosting/IWebRootFileSystemProvider.cs @@ -0,0 +1,18 @@ +// 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.FileSystems; +using Microsoft.Framework.Runtime; + +namespace Microsoft.AspNet.Hosting +{ + [AssemblyNeutral] + public interface IWebRootFileSystemProvider + { + string WebRoot { get; } + + IFileSystem GetFileSystem(); + + string MapPath(string path); + } +} \ No newline at end of file diff --git a/src/Microsoft.AspNet.Hosting/WebRootFileSystemProvider.cs b/src/Microsoft.AspNet.Hosting/WebRootFileSystemProvider.cs new file mode 100644 index 0000000000..79fefaab5e --- /dev/null +++ b/src/Microsoft.AspNet.Hosting/WebRootFileSystemProvider.cs @@ -0,0 +1,50 @@ +// 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 System; +using System.IO; +using Microsoft.AspNet.FileSystems; +using Microsoft.Framework.Runtime; + +namespace Microsoft.AspNet.Hosting +{ + public class WebRootFileSystemProvider : IWebRootFileSystemProvider + { + private readonly IFileSystem _fileSystem; + + public WebRootFileSystemProvider(IApplicationEnvironment appEnvironment) + { + var root = HostingUtilities.GetWebRoot(appEnvironment.ApplicationBasePath); + + if (!string.IsNullOrEmpty(root) && + root[root.Length - 1] != Path.DirectorySeparatorChar) + { + root += Path.DirectorySeparatorChar; + } + + WebRoot = root; + + _fileSystem = new PhysicalFileSystem(WebRoot); + } + + public string WebRoot { get; private set; } + + public IFileSystem GetFileSystem() + { + return _fileSystem; + } + + public string MapPath(string path) + { + var fullPath = Path.GetFullPath(Path.Combine(WebRoot, path)); + + // Don't allow MapPath to escape the base root directory + if (!fullPath.StartsWith(WebRoot, StringComparison.OrdinalIgnoreCase)) + { + throw new ArgumentException("Invalid path: " + path, nameof(path)); + } + + return fullPath; + } + } +} \ No newline at end of file diff --git a/src/Microsoft.AspNet.Hosting/project.json b/src/Microsoft.AspNet.Hosting/project.json index e39c50689a..63dd7c6c7d 100644 --- a/src/Microsoft.AspNet.Hosting/project.json +++ b/src/Microsoft.AspNet.Hosting/project.json @@ -2,6 +2,7 @@ "version": "1.0.0-*", "description": "ASP.NET 5 core hosting infrastructure and startup logic for web applications.", "dependencies": { + "Microsoft.AspNet.FileSystems": "1.0.0-*", "Microsoft.AspNet.PipelineCore": "1.0.0-*", "Microsoft.Framework.Logging": "1.0.0-*", "Microsoft.Framework.OptionsModel": "1.0.0-*", diff --git a/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs b/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs index 7fa4a9a289..3677b8041d 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Generic; +using System.IO; using System.Threading.Tasks; using Microsoft.AspNet.Builder; using Microsoft.AspNet.Hosting.Server; @@ -52,6 +53,15 @@ namespace Microsoft.AspNet.Hosting Assert.Equal(1, _startInstances[0].DisposeCalls); } + [Fact] + public void WebRootCanBeResolvedFromTheProjectJson() + { + var services = HostingServices.Create().BuildServiceProvider(); + var provider = services.GetRequiredService(); + Assert.Equal(Path.GetFullPath("testroot") + Path.DirectorySeparatorChar, provider.WebRoot); + Assert.True(provider.GetFileSystem().GetFileInfo("TextFile.txt").Exists); + } + public void Initialize(IApplicationBuilder builder) { diff --git a/test/Microsoft.AspNet.Hosting.Tests/testroot/TextFile.txt b/test/Microsoft.AspNet.Hosting.Tests/testroot/TextFile.txt new file mode 100644 index 0000000000..d5669ad838 --- /dev/null +++ b/test/Microsoft.AspNet.Hosting.Tests/testroot/TextFile.txt @@ -0,0 +1 @@ +A text file. \ No newline at end of file diff --git a/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs b/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs index 4f8b619dd7..c64c0af3fc 100644 --- a/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs +++ b/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs @@ -53,12 +53,12 @@ namespace Microsoft.AspNet.TestHost } [Fact] - public void WebRootCanBeResolvedFromProjectJson() + public void WebRootCanBeResolvedWhenNotInTheProjectJson() { TestServer server = TestServer.Create(app => { - var env = app.ApplicationServices.GetRequiredService(); - Assert.Equal(Path.GetFullPath("testroot"), env.WebRoot); + var provider = app.ApplicationServices.GetRequiredService(); + Assert.Equal(Directory.GetCurrentDirectory() + Path.DirectorySeparatorChar, provider.WebRoot); }); } diff --git a/test/Microsoft.AspNet.TestHost.Tests/project.json b/test/Microsoft.AspNet.TestHost.Tests/project.json index ef0573cbe7..996af770f3 100644 --- a/test/Microsoft.AspNet.TestHost.Tests/project.json +++ b/test/Microsoft.AspNet.TestHost.Tests/project.json @@ -8,6 +8,5 @@ }, "frameworks": { "aspnet50": { } - }, - "webroot": "testroot" + } } From 03e4739a3f608822ed3202634eb3412c291dd82d Mon Sep 17 00:00:00 2001 From: Chris Ross Date: Thu, 4 Dec 2014 17:23:21 -0800 Subject: [PATCH 165/987] Re-merge IWebRoot & IHostingEnv. --- .../HostingEnvironment.cs | 9 +++- .../HostingServicesCollectionExtensions.cs | 2 - .../IHostingEnvironment.cs | 5 ++ .../IWebRootFileSystemProvider.cs | 18 ------- .../WebRootFileSystemProvider.cs | 50 ------------------- .../HostingEngineTests.cs | 6 +-- .../TestServerTests.cs | 4 +- 7 files changed, 18 insertions(+), 76 deletions(-) delete mode 100644 src/Microsoft.AspNet.Hosting/IWebRootFileSystemProvider.cs delete mode 100644 src/Microsoft.AspNet.Hosting/WebRootFileSystemProvider.cs diff --git a/src/Microsoft.AspNet.Hosting/HostingEnvironment.cs b/src/Microsoft.AspNet.Hosting/HostingEnvironment.cs index acafebc789..7644d5f38b 100644 --- a/src/Microsoft.AspNet.Hosting/HostingEnvironment.cs +++ b/src/Microsoft.AspNet.Hosting/HostingEnvironment.cs @@ -2,6 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Collections.Generic; +using Microsoft.AspNet.FileSystems; using Microsoft.Framework.Runtime; namespace Microsoft.AspNet.Hosting @@ -10,9 +11,11 @@ namespace Microsoft.AspNet.Hosting { private const string DefaultEnvironmentName = "Development"; - public HostingEnvironment(IEnumerable configures) + public HostingEnvironment(IApplicationEnvironment appEnvironment, IEnumerable configures) { EnvironmentName = DefaultEnvironmentName; + WebRoot = HostingUtilities.GetWebRoot(appEnvironment.ApplicationBasePath); + WebRootFileSystem = new PhysicalFileSystem(WebRoot); foreach (var configure in configures) { configure.Configure(this); @@ -20,5 +23,9 @@ namespace Microsoft.AspNet.Hosting } public string EnvironmentName { get; set; } + + public string WebRoot { get; private set; } + + public IFileSystem WebRootFileSystem { get; private set; } } } \ No newline at end of file diff --git a/src/Microsoft.AspNet.Hosting/HostingServicesCollectionExtensions.cs b/src/Microsoft.AspNet.Hosting/HostingServicesCollectionExtensions.cs index ee9fea15aa..ac661999b2 100644 --- a/src/Microsoft.AspNet.Hosting/HostingServicesCollectionExtensions.cs +++ b/src/Microsoft.AspNet.Hosting/HostingServicesCollectionExtensions.cs @@ -35,8 +35,6 @@ namespace Microsoft.Framework.DependencyInjection services.TryAdd(describer.Instance(new ApplicationLifetime())); - services.TryAdd(describer.Singleton()); - services.AddTypeActivator(configuration); // TODO: Do we expect this to be provide by the runtime eventually? services.AddLogging(configuration); diff --git a/src/Microsoft.AspNet.Hosting/IHostingEnvironment.cs b/src/Microsoft.AspNet.Hosting/IHostingEnvironment.cs index 380c72550e..6505f1cf57 100644 --- a/src/Microsoft.AspNet.Hosting/IHostingEnvironment.cs +++ b/src/Microsoft.AspNet.Hosting/IHostingEnvironment.cs @@ -1,6 +1,7 @@ // 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.FileSystems; using Microsoft.Framework.Runtime; namespace Microsoft.AspNet.Hosting @@ -9,5 +10,9 @@ namespace Microsoft.AspNet.Hosting public interface IHostingEnvironment { string EnvironmentName { get; set; } + + string WebRoot { get; } + + IFileSystem WebRootFileSystem { get; } } } \ No newline at end of file diff --git a/src/Microsoft.AspNet.Hosting/IWebRootFileSystemProvider.cs b/src/Microsoft.AspNet.Hosting/IWebRootFileSystemProvider.cs deleted file mode 100644 index 8f65cff6e4..0000000000 --- a/src/Microsoft.AspNet.Hosting/IWebRootFileSystemProvider.cs +++ /dev/null @@ -1,18 +0,0 @@ -// 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.FileSystems; -using Microsoft.Framework.Runtime; - -namespace Microsoft.AspNet.Hosting -{ - [AssemblyNeutral] - public interface IWebRootFileSystemProvider - { - string WebRoot { get; } - - IFileSystem GetFileSystem(); - - string MapPath(string path); - } -} \ No newline at end of file diff --git a/src/Microsoft.AspNet.Hosting/WebRootFileSystemProvider.cs b/src/Microsoft.AspNet.Hosting/WebRootFileSystemProvider.cs deleted file mode 100644 index 79fefaab5e..0000000000 --- a/src/Microsoft.AspNet.Hosting/WebRootFileSystemProvider.cs +++ /dev/null @@ -1,50 +0,0 @@ -// 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 System; -using System.IO; -using Microsoft.AspNet.FileSystems; -using Microsoft.Framework.Runtime; - -namespace Microsoft.AspNet.Hosting -{ - public class WebRootFileSystemProvider : IWebRootFileSystemProvider - { - private readonly IFileSystem _fileSystem; - - public WebRootFileSystemProvider(IApplicationEnvironment appEnvironment) - { - var root = HostingUtilities.GetWebRoot(appEnvironment.ApplicationBasePath); - - if (!string.IsNullOrEmpty(root) && - root[root.Length - 1] != Path.DirectorySeparatorChar) - { - root += Path.DirectorySeparatorChar; - } - - WebRoot = root; - - _fileSystem = new PhysicalFileSystem(WebRoot); - } - - public string WebRoot { get; private set; } - - public IFileSystem GetFileSystem() - { - return _fileSystem; - } - - public string MapPath(string path) - { - var fullPath = Path.GetFullPath(Path.Combine(WebRoot, path)); - - // Don't allow MapPath to escape the base root directory - if (!fullPath.StartsWith(WebRoot, StringComparison.OrdinalIgnoreCase)) - { - throw new ArgumentException("Invalid path: " + path, nameof(path)); - } - - return fullPath; - } - } -} \ No newline at end of file diff --git a/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs b/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs index 3677b8041d..e2e0ba6852 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs @@ -57,9 +57,9 @@ namespace Microsoft.AspNet.Hosting public void WebRootCanBeResolvedFromTheProjectJson() { var services = HostingServices.Create().BuildServiceProvider(); - var provider = services.GetRequiredService(); - Assert.Equal(Path.GetFullPath("testroot") + Path.DirectorySeparatorChar, provider.WebRoot); - Assert.True(provider.GetFileSystem().GetFileInfo("TextFile.txt").Exists); + var env = services.GetRequiredService(); + Assert.Equal(Path.GetFullPath("testroot"), env.WebRoot); + Assert.True(env.WebRootFileSystem.GetFileInfo("TextFile.txt").Exists); } public void Initialize(IApplicationBuilder builder) diff --git a/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs b/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs index c64c0af3fc..9a1a2c7b19 100644 --- a/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs +++ b/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs @@ -57,8 +57,8 @@ namespace Microsoft.AspNet.TestHost { TestServer server = TestServer.Create(app => { - var provider = app.ApplicationServices.GetRequiredService(); - Assert.Equal(Directory.GetCurrentDirectory() + Path.DirectorySeparatorChar, provider.WebRoot); + var env = app.ApplicationServices.GetRequiredService(); + Assert.Equal(Directory.GetCurrentDirectory(), env.WebRoot); }); } From 2155c08e7684dc2dd3f4872ba1ac2b59670fcb00 Mon Sep 17 00:00:00 2001 From: Chris Ross Date: Fri, 5 Dec 2014 09:24:06 -0800 Subject: [PATCH 166/987] Make WebRootFileSystem settable. --- src/Microsoft.AspNet.Hosting/HostingEnvironment.cs | 2 +- src/Microsoft.AspNet.Hosting/IHostingEnvironment.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Microsoft.AspNet.Hosting/HostingEnvironment.cs b/src/Microsoft.AspNet.Hosting/HostingEnvironment.cs index 7644d5f38b..181aa6aac8 100644 --- a/src/Microsoft.AspNet.Hosting/HostingEnvironment.cs +++ b/src/Microsoft.AspNet.Hosting/HostingEnvironment.cs @@ -26,6 +26,6 @@ namespace Microsoft.AspNet.Hosting public string WebRoot { get; private set; } - public IFileSystem WebRootFileSystem { get; private set; } + public IFileSystem WebRootFileSystem { get; set; } } } \ No newline at end of file diff --git a/src/Microsoft.AspNet.Hosting/IHostingEnvironment.cs b/src/Microsoft.AspNet.Hosting/IHostingEnvironment.cs index 6505f1cf57..bcf0e6b812 100644 --- a/src/Microsoft.AspNet.Hosting/IHostingEnvironment.cs +++ b/src/Microsoft.AspNet.Hosting/IHostingEnvironment.cs @@ -13,6 +13,6 @@ namespace Microsoft.AspNet.Hosting string WebRoot { get; } - IFileSystem WebRootFileSystem { get; } + IFileSystem WebRootFileSystem { get; set; } } } \ No newline at end of file From 559f5491d41b257608e5cd79633498cdf6b9335e Mon Sep 17 00:00:00 2001 From: David Fowler Date: Fri, 5 Dec 2014 06:20:23 -0800 Subject: [PATCH 167/987] Make services registered in ConfigureServices work in Configure - Added a test #114 --- .../Startup/StartupLoader.cs | 3 +- .../Fakes/StartupWithConfigureServices.cs | 35 +++++++++++++++++++ .../StartupManagerTests.cs | 17 +++++++++ 3 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 test/Microsoft.AspNet.Hosting.Tests/Fakes/StartupWithConfigureServices.cs diff --git a/src/Microsoft.AspNet.Hosting/Startup/StartupLoader.cs b/src/Microsoft.AspNet.Hosting/Startup/StartupLoader.cs index c76153e9d0..8063d48c44 100644 --- a/src/Microsoft.AspNet.Hosting/Startup/StartupLoader.cs +++ b/src/Microsoft.AspNet.Hosting/Startup/StartupLoader.cs @@ -57,6 +57,7 @@ namespace Microsoft.AspNet.Hosting.Startup private object Invoke(MethodInfo methodInfo, object instance, IApplicationBuilder builder, IServiceCollection services = null) { + var serviceProvider = builder?.ApplicationServices ?? _services; var parameterInfos = methodInfo.GetParameters(); var parameters = new object[parameterInfos.Length]; for (var index = 0; index != parameterInfos.Length; ++index) @@ -74,7 +75,7 @@ namespace Microsoft.AspNet.Hosting.Startup { try { - parameters[index] = _services.GetRequiredService(parameterInfo.ParameterType); + parameters[index] = serviceProvider.GetRequiredService(parameterInfo.ParameterType); } catch (Exception) { diff --git a/test/Microsoft.AspNet.Hosting.Tests/Fakes/StartupWithConfigureServices.cs b/test/Microsoft.AspNet.Hosting.Tests/Fakes/StartupWithConfigureServices.cs new file mode 100644 index 0000000000..8c580bb13b --- /dev/null +++ b/test/Microsoft.AspNet.Hosting.Tests/Fakes/StartupWithConfigureServices.cs @@ -0,0 +1,35 @@ +using System; +using Microsoft.AspNet.Builder; +using Microsoft.Framework.DependencyInjection; + +namespace Microsoft.AspNet.Hosting.Fakes +{ + public class StartupWithConfigureServices + { + public void ConfigureServices(IServiceCollection services) + { + services.AddSingleton(); + } + + public void Configure(IApplicationBuilder app, IFoo foo) + { + foo.Bar(); + } + + public interface IFoo + { + bool Invoked { get; } + void Bar(); + } + + public class Foo : IFoo + { + public bool Invoked { get; private set; } + + public void Bar() + { + Invoked = true; + } + } + } +} \ No newline at end of file diff --git a/test/Microsoft.AspNet.Hosting.Tests/StartupManagerTests.cs b/test/Microsoft.AspNet.Hosting.Tests/StartupManagerTests.cs index 10016cdd1b..d9789bfccf 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/StartupManagerTests.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/StartupManagerTests.cs @@ -111,6 +111,23 @@ namespace Microsoft.AspNet.Hosting.Tests Assert.True(ex.Message.Contains("ConfigureBoom or Configure method not found")); } + [Fact] + public void StartupClassWithConfigureServicesShouldMakeServiceAvailableInConfigure() + { + var serviceCollection = HostingServices.Create(); + var services = serviceCollection.BuildServiceProvider(); + var manager = services.GetRequiredService(); + + var app = new ApplicationBuilder(services); + + var startup = manager.LoadStartup("Microsoft.AspNet.Hosting.Tests", "WithConfigureServices"); + + startup.Invoke(app); + + var foo = app.ApplicationServices.GetRequiredService(); + Assert.True(foo.Invoked); + } + public void ConfigurationMethodCalled(object instance) { _configurationMethodCalledList.Add(instance); From a5ab6149379d360dce679a88cd4ee334dcea580e Mon Sep 17 00:00:00 2001 From: David Fowler Date: Sat, 6 Dec 2014 10:35:37 -0800 Subject: [PATCH 168/987] Removed the null check for IApplicationBuilder --- src/Microsoft.AspNet.Hosting/Startup/StartupLoader.cs | 2 +- test/Microsoft.AspNet.Hosting.Tests/StartupManagerTests.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Microsoft.AspNet.Hosting/Startup/StartupLoader.cs b/src/Microsoft.AspNet.Hosting/Startup/StartupLoader.cs index 8063d48c44..3b300a1eca 100644 --- a/src/Microsoft.AspNet.Hosting/Startup/StartupLoader.cs +++ b/src/Microsoft.AspNet.Hosting/Startup/StartupLoader.cs @@ -57,7 +57,7 @@ namespace Microsoft.AspNet.Hosting.Startup private object Invoke(MethodInfo methodInfo, object instance, IApplicationBuilder builder, IServiceCollection services = null) { - var serviceProvider = builder?.ApplicationServices ?? _services; + var serviceProvider = builder.ApplicationServices ?? _services; var parameterInfos = methodInfo.GetParameters(); var parameters = new object[parameterInfos.Length]; for (var index = 0; index != parameterInfos.Length; ++index) diff --git a/test/Microsoft.AspNet.Hosting.Tests/StartupManagerTests.cs b/test/Microsoft.AspNet.Hosting.Tests/StartupManagerTests.cs index d9789bfccf..f3323b978a 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/StartupManagerTests.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/StartupManagerTests.cs @@ -29,7 +29,7 @@ namespace Microsoft.AspNet.Hosting.Tests var startup = manager.LoadStartup("Microsoft.AspNet.Hosting.Tests", "WithServices"); - startup.Invoke(null); + startup.Invoke(new ApplicationBuilder(services)); Assert.Equal(2, _configurationMethodCalledList.Count); } From 9c28fc93c3b1e85ed227599491875d6fb207b03c Mon Sep 17 00:00:00 2001 From: Suhas Joshi Date: Mon, 8 Dec 2014 15:14:17 -0800 Subject: [PATCH 169/987] Updating to release NuGet.config --- NuGet.Config | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NuGet.Config b/NuGet.Config index f41e9c631d..2d3b0cb857 100644 --- a/NuGet.Config +++ b/NuGet.Config @@ -1,7 +1,7 @@  - + From f958bbf7744452478eb8dce17c3d52d8e2e699ba Mon Sep 17 00:00:00 2001 From: Suhas Joshi Date: Mon, 8 Dec 2014 15:24:40 -0800 Subject: [PATCH 170/987] Updating to dev NuGet.config --- NuGet.Config | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NuGet.Config b/NuGet.Config index 2d3b0cb857..f41e9c631d 100644 --- a/NuGet.Config +++ b/NuGet.Config @@ -1,7 +1,7 @@  - + From 4ad0f41eeab3131ff17feb2d619722c0fb81bf5c Mon Sep 17 00:00:00 2001 From: Brennan Date: Mon, 15 Dec 2014 15:17:07 -0800 Subject: [PATCH 171/987] Update tests to use official xunit --- test/Microsoft.AspNet.Hosting.Tests/project.json | 4 ++-- test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs | 4 ++-- test/Microsoft.AspNet.TestHost.Tests/project.json | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/test/Microsoft.AspNet.Hosting.Tests/project.json b/test/Microsoft.AspNet.Hosting.Tests/project.json index 5c8c65cacf..8adf1a1d0e 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/project.json +++ b/test/Microsoft.AspNet.Hosting.Tests/project.json @@ -2,13 +2,13 @@ "dependencies": { "Microsoft.AspNet.Hosting": "1.0.0-*", "Microsoft.AspNet.RequestContainer": "1.0.0-*", - "Xunit.KRunner": "1.0.0-*" + "xunit.runner.kre": "1.0.0-*" }, "frameworks": { "aspnet50": { } }, "commands": { - "test": "Xunit.KRunner" + "test": "xunit.runner.kre" }, "webroot": "testroot" } diff --git a/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs b/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs index 9a1a2c7b19..47cd1d1403 100644 --- a/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs +++ b/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs @@ -23,8 +23,8 @@ namespace Microsoft.AspNet.TestHost // Arrange var services = HostingServices.Create().BuildServiceProvider(); - // Act & Assert - Assert.DoesNotThrow(() => TestServer.Create(services, app => { })); + // Act & Assert (Does not throw) + TestServer.Create(services, app => { }); } [Fact] diff --git a/test/Microsoft.AspNet.TestHost.Tests/project.json b/test/Microsoft.AspNet.TestHost.Tests/project.json index 996af770f3..cf98630c3f 100644 --- a/test/Microsoft.AspNet.TestHost.Tests/project.json +++ b/test/Microsoft.AspNet.TestHost.Tests/project.json @@ -1,10 +1,10 @@ { "dependencies": { "Microsoft.AspNet.TestHost": "1.0.0-*", - "Xunit.KRunner": "1.0.0-*" + "xunit.runner.kre": "1.0.0-*" }, "commands": { - "test": "Xunit.KRunner" + "test": "xunit.runner.kre" }, "frameworks": { "aspnet50": { } From 4333003df0c5f2ad0a1dc3047fd2a5ae862a6c16 Mon Sep 17 00:00:00 2001 From: Chris Ross Date: Thu, 18 Dec 2014 15:30:43 -0800 Subject: [PATCH 172/987] Generalize BasePath logic. --- src/Microsoft.AspNet.TestHost/ClientHandler.cs | 6 ++++++ src/Microsoft.AspNet.TestHost/TestServer.cs | 5 ----- test/Microsoft.AspNet.TestHost.Tests/ClientHandlerTests.cs | 2 +- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/Microsoft.AspNet.TestHost/ClientHandler.cs b/src/Microsoft.AspNet.TestHost/ClientHandler.cs index b23dffbe70..d108874bdd 100644 --- a/src/Microsoft.AspNet.TestHost/ClientHandler.cs +++ b/src/Microsoft.AspNet.TestHost/ClientHandler.cs @@ -38,6 +38,12 @@ namespace Microsoft.AspNet.TestHost } _next = next; + + // PathString.StartsWithSegments that we use below requires the base path to not end in a slash. + if (pathBase.HasValue && pathBase.Value.EndsWith("/")) + { + pathBase = new PathString(pathBase.Value.Substring(0, pathBase.Value.Length - 1)); + } _pathBase = pathBase; } diff --git a/src/Microsoft.AspNet.TestHost/TestServer.cs b/src/Microsoft.AspNet.TestHost/TestServer.cs index 97e848033a..54b908133e 100644 --- a/src/Microsoft.AspNet.TestHost/TestServer.cs +++ b/src/Microsoft.AspNet.TestHost/TestServer.cs @@ -62,11 +62,6 @@ namespace Microsoft.AspNet.TestHost public HttpMessageHandler CreateHandler() { var pathBase = BaseAddress == null ? PathString.Empty : PathString.FromUriComponent(BaseAddress); - if (pathBase.Equals(new PathString("/"))) - { - // When we just have http://host/ the trailing slash is really part of the Path, not the PathBase. - pathBase = PathString.Empty; - } return new ClientHandler(Invoke, pathBase); } diff --git a/test/Microsoft.AspNet.TestHost.Tests/ClientHandlerTests.cs b/test/Microsoft.AspNet.TestHost.Tests/ClientHandlerTests.cs index 23f65bce8b..a536114e57 100644 --- a/test/Microsoft.AspNet.TestHost.Tests/ClientHandlerTests.cs +++ b/test/Microsoft.AspNet.TestHost.Tests/ClientHandlerTests.cs @@ -40,7 +40,7 @@ namespace Microsoft.AspNet.TestHost Assert.Equal("example.com", context.Request.Host.Value); return Task.FromResult(0); - }, new PathString("/A/Path")); + }, new PathString("/A/Path/")); var httpClient = new HttpClient(handler); return httpClient.GetAsync("https://example.com/A/Path/and/file.txt?and=query"); } From 6cd5744383f0793ae45bec90e1943848ff16c637 Mon Sep 17 00:00:00 2001 From: Kai Ruhnau Date: Sat, 27 Dec 2014 12:13:26 +0100 Subject: [PATCH 173/987] Catch exceptions while disposing --- src/Microsoft.AspNet.Hosting/Program.cs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/Microsoft.AspNet.Hosting/Program.cs b/src/Microsoft.AspNet.Hosting/Program.cs index 4776c41223..8376913626 100644 --- a/src/Microsoft.AspNet.Hosting/Program.cs +++ b/src/Microsoft.AspNet.Hosting/Program.cs @@ -8,6 +8,7 @@ using System.Threading.Tasks; using Microsoft.Framework.ConfigurationModel; using Microsoft.Framework.DependencyInjection; using Microsoft.Framework.DependencyInjection.Fallback; +using Microsoft.Framework.Logging; using Microsoft.Framework.Runtime; namespace Microsoft.AspNet.Hosting @@ -52,6 +53,7 @@ namespace Microsoft.AspNet.Hosting }; var engine = services.GetRequiredService(); + var loggerFactory = services.GetRequiredService(); var appShutdownService = _serviceProvider.GetRequiredService(); var shutdownHandle = new ManualResetEvent(false); @@ -59,7 +61,15 @@ namespace Microsoft.AspNet.Hosting appShutdownService.ShutdownRequested.Register(() => { - serverShutdown.Dispose(); + try + { + serverShutdown.Dispose(); + } + catch (Exception ex) + { + var logger = loggerFactory.Create(); + logger.WriteError("TODO: Dispose threw an exception", ex); + } shutdownHandle.Set(); }); From f786fb7bd0b60c1551774235a4954830760e6c2e Mon Sep 17 00:00:00 2001 From: Hao Kung Date: Mon, 12 Jan 2015 10:22:15 -0800 Subject: [PATCH 174/987] Add HttpContextAccessor --- .../HostingServices.cs | 2 +- .../HostingServicesCollectionExtensions.cs | 5 +- .../HttpContextAccessor.cs | 73 ++++++++++++++++++ .../IHttpContextAccessor.cs | 15 ++++ .../Startup/StartupLoader.cs | 3 - .../ContainerExtensions.cs | 4 - .../ContainerMiddleware.cs | 76 ++----------------- .../RequestServicesContainer.cs | 23 +++--- .../project.json | 6 +- .../UseRequestServicesFacts.cs | 1 + 10 files changed, 112 insertions(+), 96 deletions(-) create mode 100644 src/Microsoft.AspNet.Hosting/HttpContextAccessor.cs create mode 100644 src/Microsoft.AspNet.Hosting/IHttpContextAccessor.cs diff --git a/src/Microsoft.AspNet.Hosting/HostingServices.cs b/src/Microsoft.AspNet.Hosting/HostingServices.cs index 3ff28e403f..b717bb7050 100644 --- a/src/Microsoft.AspNet.Hosting/HostingServices.cs +++ b/src/Microsoft.AspNet.Hosting/HostingServices.cs @@ -45,7 +45,7 @@ namespace Microsoft.AspNet.Hosting public HostingManifest(IServiceProvider fallback) { var manifest = fallback.GetRequiredService(); - Services = new Type[] { typeof(ITypeActivator), typeof(IHostingEnvironment), typeof(ILoggerFactory) } + Services = new Type[] { typeof(ITypeActivator), typeof(IHostingEnvironment), typeof(ILoggerFactory), typeof(IHttpContextAccessor) } .Concat(manifest.Services).Distinct(); } diff --git a/src/Microsoft.AspNet.Hosting/HostingServicesCollectionExtensions.cs b/src/Microsoft.AspNet.Hosting/HostingServicesCollectionExtensions.cs index ac661999b2..5122ca73da 100644 --- a/src/Microsoft.AspNet.Hosting/HostingServicesCollectionExtensions.cs +++ b/src/Microsoft.AspNet.Hosting/HostingServicesCollectionExtensions.cs @@ -38,11 +38,8 @@ namespace Microsoft.Framework.DependencyInjection services.AddTypeActivator(configuration); // TODO: Do we expect this to be provide by the runtime eventually? services.AddLogging(configuration); - // REVIEW: okay to use existing hosting environment/httpcontext if specified? services.TryAdd(describer.Singleton()); - - // TODO: Remove this once we have IHttpContextAccessor - services.AddContextAccessor(configuration); + services.TryAdd(describer.Scoped()); // REVIEW: don't try add because we pull out IEnumerable? services.AddInstance(new ConfigureHostingEnvironment(configuration)); diff --git a/src/Microsoft.AspNet.Hosting/HttpContextAccessor.cs b/src/Microsoft.AspNet.Hosting/HttpContextAccessor.cs new file mode 100644 index 0000000000..c811d4bfef --- /dev/null +++ b/src/Microsoft.AspNet.Hosting/HttpContextAccessor.cs @@ -0,0 +1,73 @@ +// 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 System; +#if ASPNET50 +using System.Runtime.Remoting.Messaging; +using System.Runtime.Remoting; +#elif ASPNETCORE50 +using System.Threading; +#endif +using Microsoft.AspNet.Http; + +namespace Microsoft.AspNet.Hosting +{ + public class HttpContextAccessor : IHttpContextAccessor + { + private HttpContext _value; + + public bool IsRootContext { get; set; } + + public HttpContext Value + { + get + { + return IsRootContext ? AccessRootHttpContext() : _value; + } + } + + public HttpContext SetValue(HttpContext value) + { + if (IsRootContext) + { + return ExchangeRootHttpContext(value); + } + var prior = _value; + _value = value; + return prior; + } + +#if ASPNET50 + private const string LogicalDataKey = "__HttpContext_Current__"; +#elif ASPNETCORE50 + private static AsyncLocal _httpContextCurrent = new AsyncLocal(); +#endif + + private static HttpContext AccessRootHttpContext() + { +#if ASPNET50 + var handle = CallContext.LogicalGetData(LogicalDataKey) as ObjectHandle; + return handle != null ? handle.Unwrap() as HttpContext : null; +#elif ASPNETCORE50 + return _httpContextCurrent.Value; +#else + throw new Exception("TODO: CallContext not available"); +#endif + } + + private static HttpContext ExchangeRootHttpContext(HttpContext httpContext) + { +#if ASPNET50 + var prior = CallContext.LogicalGetData(LogicalDataKey) as ObjectHandle; + CallContext.LogicalSetData(LogicalDataKey, new ObjectHandle(httpContext)); + return prior != null ? prior.Unwrap() as HttpContext : null; +#elif ASPNETCORE50 + var prior = _httpContextCurrent.Value; + _httpContextCurrent.Value = httpContext; + return prior; +#else + return null; +#endif + } + } +} \ No newline at end of file diff --git a/src/Microsoft.AspNet.Hosting/IHttpContextAccessor.cs b/src/Microsoft.AspNet.Hosting/IHttpContextAccessor.cs new file mode 100644 index 0000000000..01656f4cd7 --- /dev/null +++ b/src/Microsoft.AspNet.Hosting/IHttpContextAccessor.cs @@ -0,0 +1,15 @@ +// 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.Http; + +namespace Microsoft.AspNet.Hosting +{ + public interface IHttpContextAccessor + { + bool IsRootContext { get; set; } + HttpContext Value { get; } + + HttpContext SetValue(HttpContext value); + } +} \ No newline at end of file diff --git a/src/Microsoft.AspNet.Hosting/Startup/StartupLoader.cs b/src/Microsoft.AspNet.Hosting/Startup/StartupLoader.cs index 3b300a1eca..a7e85283bf 100644 --- a/src/Microsoft.AspNet.Hosting/Startup/StartupLoader.cs +++ b/src/Microsoft.AspNet.Hosting/Startup/StartupLoader.cs @@ -9,7 +9,6 @@ using System.Reflection; using Microsoft.AspNet.Builder; using Microsoft.Framework.DependencyInjection; using Microsoft.Framework.DependencyInjection.Fallback; -using Microsoft.Framework.OptionsModel; namespace Microsoft.AspNet.Hosting.Startup { @@ -153,8 +152,6 @@ namespace Microsoft.AspNet.Hosting.Startup if (servicesMethod != null) { var services = HostingServices.Create(builder.ApplicationServices); - // TODO: remove this once IHttpContextAccessor service is added - services.AddContextAccessor(); if (servicesMethod.ReturnType == typeof(IServiceProvider)) { // IServiceProvider ConfigureServices(IServiceCollection) diff --git a/src/Microsoft.AspNet.RequestContainer/ContainerExtensions.cs b/src/Microsoft.AspNet.RequestContainer/ContainerExtensions.cs index 9813e9164f..06d89995f2 100644 --- a/src/Microsoft.AspNet.RequestContainer/ContainerExtensions.cs +++ b/src/Microsoft.AspNet.RequestContainer/ContainerExtensions.cs @@ -48,10 +48,6 @@ namespace Microsoft.AspNet.Builder // Import services from hosting/KRE as fallback var serviceCollection = HostingServices.Create(builder.ApplicationServices); - // TODO: remove this once IHttpContextAccessor service is added - serviceCollection.AddContextAccessor(); - - // REVIEW: serviceCollection has the merged services, manifests are lost after this builder.ApplicationServices = configureServices(serviceCollection); return builder.UseMiddleware(); diff --git a/src/Microsoft.AspNet.RequestContainer/ContainerMiddleware.cs b/src/Microsoft.AspNet.RequestContainer/ContainerMiddleware.cs index 4145525ab8..097acf6d1b 100644 --- a/src/Microsoft.AspNet.RequestContainer/ContainerMiddleware.cs +++ b/src/Microsoft.AspNet.RequestContainer/ContainerMiddleware.cs @@ -2,72 +2,21 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -#if ASPNET50 -using System.Runtime.Remoting.Messaging; -#endif using System.Threading.Tasks; using Microsoft.AspNet.Builder; using Microsoft.AspNet.Http; -using Microsoft.Framework.DependencyInjection; -#if ASPNET50 -using System.Runtime.Remoting; -#endif + namespace Microsoft.AspNet.RequestContainer { public class ContainerMiddleware { - private const string LogicalDataKey = "__HttpContext_Current__"; private readonly RequestDelegate _next; - private readonly IServiceProvider _rootServiceProvider; - private readonly IContextAccessor _rootHttpContextAccessor; - private readonly IServiceScopeFactory _rootServiceScopeFactory; + private readonly IServiceProvider _services; - public ContainerMiddleware( - RequestDelegate next, - IServiceProvider rootServiceProvider, - IContextAccessor rootHttpContextAccessor, - IServiceScopeFactory rootServiceScopeFactory) + public ContainerMiddleware(RequestDelegate next, IServiceProvider services) { - if (rootServiceProvider == null) - { - throw new ArgumentNullException("rootServiceProvider"); - } - if (rootHttpContextAccessor == null) - { - throw new ArgumentNullException("rootHttpContextAccessor"); - } - if (rootServiceScopeFactory == null) - { - throw new ArgumentNullException("rootServiceScopeFactory"); - } - + _services = services; _next = next; - _rootServiceProvider = rootServiceProvider; - _rootServiceScopeFactory = rootServiceScopeFactory; - _rootHttpContextAccessor = rootHttpContextAccessor; - - _rootHttpContextAccessor.SetContextSource(AccessRootHttpContext, ExchangeRootHttpContext); - } - - internal static HttpContext AccessRootHttpContext() - { -#if ASPNET50 - var handle = CallContext.LogicalGetData(LogicalDataKey) as ObjectHandle; - return handle != null ? handle.Unwrap() as HttpContext : null; -#else - throw new Exception("TODO: CallContext not available"); -#endif - } - - internal static HttpContext ExchangeRootHttpContext(HttpContext httpContext) - { -#if ASPNET50 - var prior = CallContext.LogicalGetData(LogicalDataKey) as ObjectHandle; - CallContext.LogicalSetData(LogicalDataKey, new ObjectHandle(httpContext)); - return prior != null ? prior.Unwrap() as HttpContext : null; -#else - return null; -#endif } public async Task Invoke(HttpContext httpContext) @@ -77,22 +26,7 @@ namespace Microsoft.AspNet.RequestContainer throw new Exception("TODO: nested request container scope? this is probably a mistake on your part?"); } - var priorApplicationServices = httpContext.ApplicationServices; - var priorRequestServices = httpContext.RequestServices; - - var appServiceProvider = _rootServiceProvider; - var appServiceScopeFactory = _rootServiceScopeFactory; - var appHttpContextAccessor = _rootHttpContextAccessor; - - if (priorApplicationServices != null && - priorApplicationServices != appServiceProvider) - { - appServiceProvider = priorApplicationServices; - appServiceScopeFactory = priorApplicationServices.GetRequiredService(); - appHttpContextAccessor = priorApplicationServices.GetRequiredService>(); - } - - using (var container = new RequestServicesContainer(httpContext, appServiceScopeFactory, appHttpContextAccessor, appServiceProvider)) + using (var container = RequestServicesContainer.EnsureRequestServices(httpContext, _services)) { await _next.Invoke(httpContext); } diff --git a/src/Microsoft.AspNet.RequestContainer/RequestServicesContainer.cs b/src/Microsoft.AspNet.RequestContainer/RequestServicesContainer.cs index a7c646321e..8b3d32316d 100644 --- a/src/Microsoft.AspNet.RequestContainer/RequestServicesContainer.cs +++ b/src/Microsoft.AspNet.RequestContainer/RequestServicesContainer.cs @@ -2,6 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using Microsoft.AspNet.Hosting; using Microsoft.AspNet.Http; using Microsoft.Framework.DependencyInjection; @@ -12,7 +13,7 @@ namespace Microsoft.AspNet.RequestContainer public RequestServicesContainer( HttpContext context, IServiceScopeFactory scopeFactory, - IContextAccessor appContextAccessor, + IHttpContextAccessor appContextAccessor, IServiceProvider appServiceProvider) { if (scopeFactory == null) @@ -36,7 +37,7 @@ namespace Microsoft.AspNet.RequestContainer // Begin the scope Scope = scopeFactory.CreateScope(); - ScopeContextAccessor = Scope.ServiceProvider.GetRequiredService>(); + ScopeContextAccessor = Scope.ServiceProvider.GetRequiredService(); Context.ApplicationServices = appServiceProvider; Context.RequestServices = Scope.ServiceProvider; @@ -51,8 +52,9 @@ namespace Microsoft.AspNet.RequestContainer private HttpContext PriorAppHttpContext { get; set; } private HttpContext PriorScopeHttpContext { get; set; } private IServiceScope Scope { get; set; } - private IContextAccessor ScopeContextAccessor { get; set; } - private IContextAccessor AppContextAccessor { get; set; } + private IHttpContextAccessor ScopeContextAccessor { get; set; } + private IHttpContextAccessor AppContextAccessor { get; set; } + // CONSIDER: this could be an extension method on HttpContext instead public static RequestServicesContainer EnsureRequestServices(HttpContext httpContext, IServiceProvider services) @@ -64,7 +66,6 @@ namespace Microsoft.AspNet.RequestContainer } var serviceProvider = httpContext.ApplicationServices ?? services; - if (serviceProvider == null) { throw new InvalidOperationException("TODO: services and httpContext.ApplicationServices are both null!"); @@ -72,10 +73,10 @@ namespace Microsoft.AspNet.RequestContainer // Matches constructor of RequestContainer var rootServiceProvider = serviceProvider.GetRequiredService(); - var rootHttpContextAccessor = serviceProvider.GetRequiredService>(); + var rootHttpContextAccessor = serviceProvider.GetRequiredService(); var rootServiceScopeFactory = serviceProvider.GetRequiredService(); - rootHttpContextAccessor.SetContextSource(ContainerMiddleware.AccessRootHttpContext, ContainerMiddleware.ExchangeRootHttpContext); + rootHttpContextAccessor.IsRootContext = true; // Pre Scope setup var priorApplicationServices = serviceProvider; @@ -90,14 +91,14 @@ namespace Microsoft.AspNet.RequestContainer { appServiceProvider = priorApplicationServices; appServiceScopeFactory = priorApplicationServices.GetRequiredService(); - appHttpContextAccessor = priorApplicationServices.GetRequiredService>(); + appHttpContextAccessor = priorApplicationServices.GetRequiredService(); } // Creates the scope and does the service swaps return new RequestServicesContainer(httpContext, appServiceScopeFactory, appHttpContextAccessor, appServiceProvider); } - #region IDisposable Support +#region IDisposable Support private bool disposedValue = false; // To detect redundant calls protected virtual void Dispose(bool disposing) @@ -137,8 +138,6 @@ namespace Microsoft.AspNet.RequestContainer // Do not change this code. Put cleanup code in Dispose(bool disposing) above. Dispose(true); } - #endregion - +#endregion } - } \ No newline at end of file diff --git a/src/Microsoft.AspNet.RequestContainer/project.json b/src/Microsoft.AspNet.RequestContainer/project.json index d8f3cef5a9..076064ad98 100644 --- a/src/Microsoft.AspNet.RequestContainer/project.json +++ b/src/Microsoft.AspNet.RequestContainer/project.json @@ -8,6 +8,10 @@ }, "frameworks": { "aspnet50": {}, - "aspnetcore50": {} + "aspnetcore50": { + "dependencies": { + "System.Threading": "4.0.10-beta-*" + } + }, } } diff --git a/test/Microsoft.AspNet.Hosting.Tests/UseRequestServicesFacts.cs b/test/Microsoft.AspNet.Hosting.Tests/UseRequestServicesFacts.cs index 7b01e54c6f..0e00d492ef 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/UseRequestServicesFacts.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/UseRequestServicesFacts.cs @@ -92,6 +92,7 @@ namespace Microsoft.AspNet.Hosting.Tests [InlineData(typeof(ITypeActivator))] [InlineData(typeof(IApplicationLifetime))] [InlineData(typeof(ILoggerFactory))] + [InlineData(typeof(IHttpContextAccessor))] public void UseRequestServicesHostingImportedServicesAreDefined(Type service) { var baseServiceProvider = HostingServices.Create().BuildServiceProvider(); From 16a811479eb4f098387b0bcd6702e25003ae6c59 Mon Sep 17 00:00:00 2001 From: Hao Kung Date: Wed, 14 Jan 2015 17:24:33 -0800 Subject: [PATCH 175/987] Simplify HttpContextAccessor (now singleton) --- src/Microsoft.AspNet.Hosting/HostingEngine.cs | 7 ++- .../HostingServicesCollectionExtensions.cs | 2 +- .../HttpContextAccessor.cs | 59 ++++++------------- .../IHttpContextAccessor.cs | 5 +- .../PipelineInstance.cs | 7 ++- .../RequestServicesContainer.cs | 30 +--------- .../TestServerTests.cs | 17 ++++++ 7 files changed, 46 insertions(+), 81 deletions(-) diff --git a/src/Microsoft.AspNet.Hosting/HostingEngine.cs b/src/Microsoft.AspNet.Hosting/HostingEngine.cs index 0dc426b1a4..83ef3a8d8e 100644 --- a/src/Microsoft.AspNet.Hosting/HostingEngine.cs +++ b/src/Microsoft.AspNet.Hosting/HostingEngine.cs @@ -16,17 +16,20 @@ namespace Microsoft.AspNet.Hosting private readonly IStartupManager _startupManager; private readonly IApplicationBuilderFactory _builderFactory; private readonly IHttpContextFactory _httpContextFactory; + private readonly IHttpContextAccessor _contextAccessor; public HostingEngine( IServerManager serverManager, IStartupManager startupManager, IApplicationBuilderFactory builderFactory, - IHttpContextFactory httpContextFactory) + IHttpContextFactory httpContextFactory, + IHttpContextAccessor contextAccessor) { _serverManager = serverManager; _startupManager = startupManager; _builderFactory = builderFactory; _httpContextFactory = httpContextFactory; + _contextAccessor = contextAccessor; } public IDisposable Start(HostingContext context) @@ -37,7 +40,7 @@ namespace Microsoft.AspNet.Hosting EnsureApplicationDelegate(context); var applicationLifetime = (ApplicationLifetime)context.Services.GetRequiredService(); - var pipeline = new PipelineInstance(_httpContextFactory, context.ApplicationDelegate); + var pipeline = new PipelineInstance(_httpContextFactory, context.ApplicationDelegate, _contextAccessor); var server = context.ServerFactory.Start(context.Server, pipeline.Invoke); return new Disposable(() => diff --git a/src/Microsoft.AspNet.Hosting/HostingServicesCollectionExtensions.cs b/src/Microsoft.AspNet.Hosting/HostingServicesCollectionExtensions.cs index 5122ca73da..82c134ffb2 100644 --- a/src/Microsoft.AspNet.Hosting/HostingServicesCollectionExtensions.cs +++ b/src/Microsoft.AspNet.Hosting/HostingServicesCollectionExtensions.cs @@ -39,7 +39,7 @@ namespace Microsoft.Framework.DependencyInjection // TODO: Do we expect this to be provide by the runtime eventually? services.AddLogging(configuration); services.TryAdd(describer.Singleton()); - services.TryAdd(describer.Scoped()); + services.TryAdd(describer.Singleton()); // REVIEW: don't try add because we pull out IEnumerable? services.AddInstance(new ConfigureHostingEnvironment(configuration)); diff --git a/src/Microsoft.AspNet.Hosting/HttpContextAccessor.cs b/src/Microsoft.AspNet.Hosting/HttpContextAccessor.cs index c811d4bfef..4507d384cf 100644 --- a/src/Microsoft.AspNet.Hosting/HttpContextAccessor.cs +++ b/src/Microsoft.AspNet.Hosting/HttpContextAccessor.cs @@ -14,60 +14,35 @@ namespace Microsoft.AspNet.Hosting { public class HttpContextAccessor : IHttpContextAccessor { - private HttpContext _value; - - public bool IsRootContext { get; set; } +#if ASPNET50 + private const string LogicalDataKey = "__HttpContext_Current__"; public HttpContext Value { get { - return IsRootContext ? AccessRootHttpContext() : _value; + var handle = CallContext.LogicalGetData(LogicalDataKey) as ObjectHandle; + return handle != null ? handle.Unwrap() as HttpContext : null; } - } - - public HttpContext SetValue(HttpContext value) - { - if (IsRootContext) + set { - return ExchangeRootHttpContext(value); + CallContext.LogicalSetData(LogicalDataKey, new ObjectHandle(value)); } - var prior = _value; - _value = value; - return prior; } -#if ASPNET50 - private const string LogicalDataKey = "__HttpContext_Current__"; #elif ASPNETCORE50 - private static AsyncLocal _httpContextCurrent = new AsyncLocal(); -#endif - - private static HttpContext AccessRootHttpContext() + private AsyncLocal _httpContextCurrent = new AsyncLocal(); + public HttpContext Value { -#if ASPNET50 - var handle = CallContext.LogicalGetData(LogicalDataKey) as ObjectHandle; - return handle != null ? handle.Unwrap() as HttpContext : null; -#elif ASPNETCORE50 - return _httpContextCurrent.Value; -#else - throw new Exception("TODO: CallContext not available"); -#endif + get + { + return _httpContextCurrent.Value; + } + set + { + _httpContextCurrent.Value = value; + } } - - private static HttpContext ExchangeRootHttpContext(HttpContext httpContext) - { -#if ASPNET50 - var prior = CallContext.LogicalGetData(LogicalDataKey) as ObjectHandle; - CallContext.LogicalSetData(LogicalDataKey, new ObjectHandle(httpContext)); - return prior != null ? prior.Unwrap() as HttpContext : null; -#elif ASPNETCORE50 - var prior = _httpContextCurrent.Value; - _httpContextCurrent.Value = httpContext; - return prior; -#else - return null; #endif - } } -} \ No newline at end of file +} diff --git a/src/Microsoft.AspNet.Hosting/IHttpContextAccessor.cs b/src/Microsoft.AspNet.Hosting/IHttpContextAccessor.cs index 01656f4cd7..563808d7f8 100644 --- a/src/Microsoft.AspNet.Hosting/IHttpContextAccessor.cs +++ b/src/Microsoft.AspNet.Hosting/IHttpContextAccessor.cs @@ -7,9 +7,6 @@ namespace Microsoft.AspNet.Hosting { public interface IHttpContextAccessor { - bool IsRootContext { get; set; } - HttpContext Value { get; } - - HttpContext SetValue(HttpContext value); + HttpContext Value { get; set; } } } \ No newline at end of file diff --git a/src/Microsoft.AspNet.Hosting/PipelineInstance.cs b/src/Microsoft.AspNet.Hosting/PipelineInstance.cs index 2efe3d6b24..d69a700c94 100644 --- a/src/Microsoft.AspNet.Hosting/PipelineInstance.cs +++ b/src/Microsoft.AspNet.Hosting/PipelineInstance.cs @@ -4,9 +4,7 @@ using System; using System.Threading.Tasks; using Microsoft.AspNet.Builder; -using Microsoft.AspNet.Http; using Microsoft.AspNet.Hosting.Builder; -using Microsoft.AspNet.Hosting.Server; namespace Microsoft.AspNet.Hosting { @@ -14,16 +12,19 @@ namespace Microsoft.AspNet.Hosting { private readonly IHttpContextFactory _httpContextFactory; private readonly RequestDelegate _requestDelegate; + private readonly IHttpContextAccessor _contextAccessor; - public PipelineInstance(IHttpContextFactory httpContextFactory, RequestDelegate requestDelegate) + public PipelineInstance(IHttpContextFactory httpContextFactory, RequestDelegate requestDelegate, IHttpContextAccessor contextAccessor) { _httpContextFactory = httpContextFactory; _requestDelegate = requestDelegate; + _contextAccessor = contextAccessor; } public Task Invoke(object serverEnvironment) { var httpContext = _httpContextFactory.CreateHttpContext(serverEnvironment); + _contextAccessor.Value = httpContext; return _requestDelegate(httpContext); } diff --git a/src/Microsoft.AspNet.RequestContainer/RequestServicesContainer.cs b/src/Microsoft.AspNet.RequestContainer/RequestServicesContainer.cs index 8b3d32316d..747aae5012 100644 --- a/src/Microsoft.AspNet.RequestContainer/RequestServicesContainer.cs +++ b/src/Microsoft.AspNet.RequestContainer/RequestServicesContainer.cs @@ -2,7 +2,6 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using Microsoft.AspNet.Hosting; using Microsoft.AspNet.Http; using Microsoft.Framework.DependencyInjection; @@ -13,7 +12,6 @@ namespace Microsoft.AspNet.RequestContainer public RequestServicesContainer( HttpContext context, IServiceScopeFactory scopeFactory, - IHttpContextAccessor appContextAccessor, IServiceProvider appServiceProvider) { if (scopeFactory == null) @@ -24,12 +22,6 @@ namespace Microsoft.AspNet.RequestContainer { throw new ArgumentNullException(nameof(context)); } - if (appContextAccessor == null) - { - throw new ArgumentNullException(nameof(appContextAccessor)); - } - - AppContextAccessor = appContextAccessor; Context = context; PriorAppServices = context.ApplicationServices; @@ -37,23 +29,15 @@ namespace Microsoft.AspNet.RequestContainer // Begin the scope Scope = scopeFactory.CreateScope(); - ScopeContextAccessor = Scope.ServiceProvider.GetRequiredService(); Context.ApplicationServices = appServiceProvider; Context.RequestServices = Scope.ServiceProvider; - - PriorAppHttpContext = AppContextAccessor.SetValue(context); - PriorScopeHttpContext = ScopeContextAccessor.SetValue(context); } private HttpContext Context { get; set; } private IServiceProvider PriorAppServices { get; set; } private IServiceProvider PriorRequestServices { get; set; } - private HttpContext PriorAppHttpContext { get; set; } - private HttpContext PriorScopeHttpContext { get; set; } private IServiceScope Scope { get; set; } - private IHttpContextAccessor ScopeContextAccessor { get; set; } - private IHttpContextAccessor AppContextAccessor { get; set; } // CONSIDER: this could be an extension method on HttpContext instead @@ -73,29 +57,24 @@ namespace Microsoft.AspNet.RequestContainer // Matches constructor of RequestContainer var rootServiceProvider = serviceProvider.GetRequiredService(); - var rootHttpContextAccessor = serviceProvider.GetRequiredService(); var rootServiceScopeFactory = serviceProvider.GetRequiredService(); - rootHttpContextAccessor.IsRootContext = true; - // Pre Scope setup var priorApplicationServices = serviceProvider; var priorRequestServices = serviceProvider; var appServiceProvider = rootServiceProvider; var appServiceScopeFactory = rootServiceScopeFactory; - var appHttpContextAccessor = rootHttpContextAccessor; if (priorApplicationServices != null && priorApplicationServices != appServiceProvider) { appServiceProvider = priorApplicationServices; appServiceScopeFactory = priorApplicationServices.GetRequiredService(); - appHttpContextAccessor = priorApplicationServices.GetRequiredService(); } // Creates the scope and does the service swaps - return new RequestServicesContainer(httpContext, appServiceScopeFactory, appHttpContextAccessor, appServiceProvider); + return new RequestServicesContainer(httpContext, appServiceScopeFactory, appServiceProvider); } #region IDisposable Support @@ -107,9 +86,6 @@ namespace Microsoft.AspNet.RequestContainer { if (disposing) { - ScopeContextAccessor.SetValue(PriorScopeHttpContext); - AppContextAccessor.SetValue(PriorAppHttpContext); - Context.RequestServices = PriorRequestServices; Context.ApplicationServices = PriorAppServices; } @@ -123,10 +99,6 @@ namespace Microsoft.AspNet.RequestContainer Context = null; PriorAppServices = null; PriorRequestServices = null; - ScopeContextAccessor = null; - AppContextAccessor = null; - PriorAppHttpContext = null; - PriorScopeHttpContext = null; disposedValue = true; } diff --git a/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs b/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs index 47cd1d1403..0a31db1b21 100644 --- a/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs +++ b/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs @@ -37,6 +37,23 @@ namespace Microsoft.AspNet.TestHost Assert.Throws(() => TestServer.Create(services, new Startup().Configuration)); } + [Fact] + public async Task CanAccessHttpContext() + { + var services = new ServiceCollection().BuildServiceProvider(); + TestServer server = TestServer.Create(app => + { + app.Run(context => + { + var accessor = app.ApplicationServices.GetRequiredService(); + return context.Response.WriteAsync("HasContext:"+(accessor.Value != null)); + }); + }); + + string result = await server.CreateClient().GetStringAsync("/path"); + Assert.Equal("HasContext:True", result); + } + [Fact] public async Task CreateInvokesApp() { From 9746a67990a640ed2078fc53a400d9a251f8bbbf Mon Sep 17 00:00:00 2001 From: Chris Ross Date: Thu, 15 Jan 2015 12:45:07 -0800 Subject: [PATCH 176/987] Handle PipelineCore rename. --- src/Microsoft.AspNet.Hosting/Builder/HttpContextFactory.cs | 4 ++-- src/Microsoft.AspNet.Hosting/project.json | 2 +- src/Microsoft.AspNet.TestHost/ClientHandler.cs | 2 +- .../Microsoft.AspNet.Hosting.Tests/UseRequestServicesFacts.cs | 2 +- test/Microsoft.AspNet.TestHost.Tests/ClientHandlerTests.cs | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Microsoft.AspNet.Hosting/Builder/HttpContextFactory.cs b/src/Microsoft.AspNet.Hosting/Builder/HttpContextFactory.cs index 1b01ed6b17..227d7bd2f4 100644 --- a/src/Microsoft.AspNet.Hosting/Builder/HttpContextFactory.cs +++ b/src/Microsoft.AspNet.Hosting/Builder/HttpContextFactory.cs @@ -1,9 +1,9 @@ // 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.Http; using Microsoft.AspNet.FeatureModel; -using Microsoft.AspNet.PipelineCore; +using Microsoft.AspNet.Http; +using Microsoft.AspNet.Http.Core; namespace Microsoft.AspNet.Hosting.Builder { diff --git a/src/Microsoft.AspNet.Hosting/project.json b/src/Microsoft.AspNet.Hosting/project.json index 63dd7c6c7d..ebd3beb943 100644 --- a/src/Microsoft.AspNet.Hosting/project.json +++ b/src/Microsoft.AspNet.Hosting/project.json @@ -3,7 +3,7 @@ "description": "ASP.NET 5 core hosting infrastructure and startup logic for web applications.", "dependencies": { "Microsoft.AspNet.FileSystems": "1.0.0-*", - "Microsoft.AspNet.PipelineCore": "1.0.0-*", + "Microsoft.AspNet.Http.Core": "1.0.0-*", "Microsoft.Framework.Logging": "1.0.0-*", "Microsoft.Framework.OptionsModel": "1.0.0-*", "Microsoft.Framework.Runtime.Interfaces": { "version": "1.0.0-*", "type": "build" }, diff --git a/src/Microsoft.AspNet.TestHost/ClientHandler.cs b/src/Microsoft.AspNet.TestHost/ClientHandler.cs index d108874bdd..c24922d5b3 100644 --- a/src/Microsoft.AspNet.TestHost/ClientHandler.cs +++ b/src/Microsoft.AspNet.TestHost/ClientHandler.cs @@ -12,8 +12,8 @@ using System.Threading; using System.Threading.Tasks; using Microsoft.AspNet.FeatureModel; using Microsoft.AspNet.Http; +using Microsoft.AspNet.Http.Core; using Microsoft.AspNet.HttpFeature; -using Microsoft.AspNet.PipelineCore; namespace Microsoft.AspNet.TestHost { diff --git a/test/Microsoft.AspNet.Hosting.Tests/UseRequestServicesFacts.cs b/test/Microsoft.AspNet.Hosting.Tests/UseRequestServicesFacts.cs index 0e00d492ef..e247d4ec64 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/UseRequestServicesFacts.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/UseRequestServicesFacts.cs @@ -6,7 +6,7 @@ using Microsoft.AspNet.Builder; using Microsoft.AspNet.Hosting.Builder; using Microsoft.AspNet.Hosting.Server; using Microsoft.AspNet.Hosting.Startup; -using Microsoft.AspNet.PipelineCore; +using Microsoft.AspNet.Http.Core; using Microsoft.AspNet.RequestContainer; using Microsoft.Framework.DependencyInjection; using Microsoft.Framework.DependencyInjection.Fallback; diff --git a/test/Microsoft.AspNet.TestHost.Tests/ClientHandlerTests.cs b/test/Microsoft.AspNet.TestHost.Tests/ClientHandlerTests.cs index a536114e57..435f7a3224 100644 --- a/test/Microsoft.AspNet.TestHost.Tests/ClientHandlerTests.cs +++ b/test/Microsoft.AspNet.TestHost.Tests/ClientHandlerTests.cs @@ -9,8 +9,8 @@ using System.Threading; using System.Threading.Tasks; using Microsoft.AspNet.FeatureModel; using Microsoft.AspNet.Http; +using Microsoft.AspNet.Http.Core; using Microsoft.AspNet.HttpFeature; -using Microsoft.AspNet.PipelineCore; using Xunit; namespace Microsoft.AspNet.TestHost From bf9d22bb895a748d272860690647e9b5a4d017c3 Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Sun, 18 Jan 2015 20:50:01 -0800 Subject: [PATCH 177/987] Handle HttpFeature rename --- src/Microsoft.AspNet.TestHost/ClientHandler.cs | 2 +- src/Microsoft.AspNet.TestHost/RequestFeature.cs | 2 +- src/Microsoft.AspNet.TestHost/ResponseFeature.cs | 2 +- test/Microsoft.AspNet.TestHost.Tests/ClientHandlerTests.cs | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Microsoft.AspNet.TestHost/ClientHandler.cs b/src/Microsoft.AspNet.TestHost/ClientHandler.cs index c24922d5b3..1549565532 100644 --- a/src/Microsoft.AspNet.TestHost/ClientHandler.cs +++ b/src/Microsoft.AspNet.TestHost/ClientHandler.cs @@ -13,7 +13,7 @@ using System.Threading.Tasks; using Microsoft.AspNet.FeatureModel; using Microsoft.AspNet.Http; using Microsoft.AspNet.Http.Core; -using Microsoft.AspNet.HttpFeature; +using Microsoft.AspNet.Http.Interfaces; namespace Microsoft.AspNet.TestHost { diff --git a/src/Microsoft.AspNet.TestHost/RequestFeature.cs b/src/Microsoft.AspNet.TestHost/RequestFeature.cs index 2ea5ae5127..f23df6716a 100644 --- a/src/Microsoft.AspNet.TestHost/RequestFeature.cs +++ b/src/Microsoft.AspNet.TestHost/RequestFeature.cs @@ -4,7 +4,7 @@ using System; using System.Collections.Generic; using System.IO; -using Microsoft.AspNet.HttpFeature; +using Microsoft.AspNet.Http.Interfaces; namespace Microsoft.AspNet.TestHost { diff --git a/src/Microsoft.AspNet.TestHost/ResponseFeature.cs b/src/Microsoft.AspNet.TestHost/ResponseFeature.cs index 9f2ebfd081..8c8aa08e60 100644 --- a/src/Microsoft.AspNet.TestHost/ResponseFeature.cs +++ b/src/Microsoft.AspNet.TestHost/ResponseFeature.cs @@ -4,7 +4,7 @@ using System; using System.Collections.Generic; using System.IO; -using Microsoft.AspNet.HttpFeature; +using Microsoft.AspNet.Http.Interfaces; namespace Microsoft.AspNet.TestHost { diff --git a/test/Microsoft.AspNet.TestHost.Tests/ClientHandlerTests.cs b/test/Microsoft.AspNet.TestHost.Tests/ClientHandlerTests.cs index 435f7a3224..9956339096 100644 --- a/test/Microsoft.AspNet.TestHost.Tests/ClientHandlerTests.cs +++ b/test/Microsoft.AspNet.TestHost.Tests/ClientHandlerTests.cs @@ -10,7 +10,7 @@ using System.Threading.Tasks; using Microsoft.AspNet.FeatureModel; using Microsoft.AspNet.Http; using Microsoft.AspNet.Http.Core; -using Microsoft.AspNet.HttpFeature; +using Microsoft.AspNet.Http.Interfaces; using Xunit; namespace Microsoft.AspNet.TestHost From cb17819552fe6d38a536ccc035d655bbfa300f89 Mon Sep 17 00:00:00 2001 From: Pranav K Date: Tue, 20 Jan 2015 01:31:43 -0800 Subject: [PATCH 178/987] Updating build.cmd and build.sh to use dotnetsdk --- build.cmd | 6 +++--- build.sh | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/build.cmd b/build.cmd index 86ca5bbbf1..c8041fdd9d 100644 --- a/build.cmd +++ b/build.cmd @@ -20,9 +20,9 @@ IF EXIST packages\KoreBuild goto run .nuget\NuGet.exe install Sake -version 0.2 -o packages -ExcludeVersion IF "%SKIP_KRE_INSTALL%"=="1" goto run -CALL packages\KoreBuild\build\kvm upgrade -runtime CLR -x86 -CALL packages\KoreBuild\build\kvm install default -runtime CoreCLR -x86 +CALL packages\KoreBuild\build\dotnetsdk upgrade -runtime CLR -x86 +CALL packages\KoreBuild\build\dotnetsdk install default -runtime CoreCLR -x86 :run -CALL packages\KoreBuild\build\kvm use default -runtime CLR -x86 +CALL packages\KoreBuild\build\dotnetsdk use default -runtime CLR -x86 packages\Sake\tools\Sake.exe -I packages\KoreBuild\build -f makefile.shade %* diff --git a/build.sh b/build.sh index c7873ef58e..3f3c731c04 100755 --- a/build.sh +++ b/build.sh @@ -28,11 +28,11 @@ if test ! -d packages/KoreBuild; then fi if ! type k > /dev/null 2>&1; then - source packages/KoreBuild/build/kvm.sh + source setup/dotnetsdk.sh fi if ! type k > /dev/null 2>&1; then - kvm upgrade + dotnetsdk upgrade fi mono packages/Sake/tools/Sake.exe -I packages/KoreBuild/build -f makefile.shade "$@" From a93537e3be3710272e906c7273e7c2994fe3ebd2 Mon Sep 17 00:00:00 2001 From: Pranav K Date: Tue, 20 Jan 2015 01:36:04 -0800 Subject: [PATCH 179/987] Updating build.cmd and build.sh to use dotnetsdk --- build.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.sh b/build.sh index 3f3c731c04..350d7e389a 100755 --- a/build.sh +++ b/build.sh @@ -28,7 +28,7 @@ if test ! -d packages/KoreBuild; then fi if ! type k > /dev/null 2>&1; then - source setup/dotnetsdk.sh + source packages/KoreBuild/build/dotnetsdk.sh fi if ! type k > /dev/null 2>&1; then From 36c2a44b915d8553864dcfdc378c718498327266 Mon Sep 17 00:00:00 2001 From: Chris Ross Date: Tue, 20 Jan 2015 08:37:10 -0800 Subject: [PATCH 180/987] Handle IFileSystem rename. --- src/Microsoft.AspNet.Hosting/HostingEnvironment.cs | 6 +++--- src/Microsoft.AspNet.Hosting/IHostingEnvironment.cs | 4 ++-- src/Microsoft.AspNet.Hosting/project.json | 2 +- test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/Microsoft.AspNet.Hosting/HostingEnvironment.cs b/src/Microsoft.AspNet.Hosting/HostingEnvironment.cs index 181aa6aac8..47d805f99b 100644 --- a/src/Microsoft.AspNet.Hosting/HostingEnvironment.cs +++ b/src/Microsoft.AspNet.Hosting/HostingEnvironment.cs @@ -2,7 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Collections.Generic; -using Microsoft.AspNet.FileSystems; +using Microsoft.AspNet.FileProviders; using Microsoft.Framework.Runtime; namespace Microsoft.AspNet.Hosting @@ -15,7 +15,7 @@ namespace Microsoft.AspNet.Hosting { EnvironmentName = DefaultEnvironmentName; WebRoot = HostingUtilities.GetWebRoot(appEnvironment.ApplicationBasePath); - WebRootFileSystem = new PhysicalFileSystem(WebRoot); + WebRootFileProvider = new PhysicalFileProvider(WebRoot); foreach (var configure in configures) { configure.Configure(this); @@ -26,6 +26,6 @@ namespace Microsoft.AspNet.Hosting public string WebRoot { get; private set; } - public IFileSystem WebRootFileSystem { get; set; } + public IFileProvider WebRootFileProvider { get; set; } } } \ No newline at end of file diff --git a/src/Microsoft.AspNet.Hosting/IHostingEnvironment.cs b/src/Microsoft.AspNet.Hosting/IHostingEnvironment.cs index bcf0e6b812..8f5966e332 100644 --- a/src/Microsoft.AspNet.Hosting/IHostingEnvironment.cs +++ b/src/Microsoft.AspNet.Hosting/IHostingEnvironment.cs @@ -1,7 +1,7 @@ // 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.FileSystems; +using Microsoft.AspNet.FileProviders; using Microsoft.Framework.Runtime; namespace Microsoft.AspNet.Hosting @@ -13,6 +13,6 @@ namespace Microsoft.AspNet.Hosting string WebRoot { get; } - IFileSystem WebRootFileSystem { get; set; } + IFileProvider WebRootFileProvider { get; set; } } } \ No newline at end of file diff --git a/src/Microsoft.AspNet.Hosting/project.json b/src/Microsoft.AspNet.Hosting/project.json index ebd3beb943..5c740ce152 100644 --- a/src/Microsoft.AspNet.Hosting/project.json +++ b/src/Microsoft.AspNet.Hosting/project.json @@ -2,7 +2,7 @@ "version": "1.0.0-*", "description": "ASP.NET 5 core hosting infrastructure and startup logic for web applications.", "dependencies": { - "Microsoft.AspNet.FileSystems": "1.0.0-*", + "Microsoft.AspNet.FileProviders": "1.0.0-*", "Microsoft.AspNet.Http.Core": "1.0.0-*", "Microsoft.Framework.Logging": "1.0.0-*", "Microsoft.Framework.OptionsModel": "1.0.0-*", diff --git a/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs b/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs index e2e0ba6852..3c6d5c13b6 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs @@ -59,7 +59,7 @@ namespace Microsoft.AspNet.Hosting var services = HostingServices.Create().BuildServiceProvider(); var env = services.GetRequiredService(); Assert.Equal(Path.GetFullPath("testroot"), env.WebRoot); - Assert.True(env.WebRootFileSystem.GetFileInfo("TextFile.txt").Exists); + Assert.True(env.WebRootFileProvider.GetFileInfo("TextFile.txt").Exists); } public void Initialize(IApplicationBuilder builder) From 2c6411e95d83604c021a650dd8d288f3049bbf77 Mon Sep 17 00:00:00 2001 From: Suhas Joshi Date: Tue, 20 Jan 2015 17:22:57 -0800 Subject: [PATCH 181/987] Updating NuGet.config --- NuGet.Config | 1 - 1 file changed, 1 deletion(-) diff --git a/NuGet.Config b/NuGet.Config index 2d3b0cb857..53454b2000 100644 --- a/NuGet.Config +++ b/NuGet.Config @@ -1,7 +1,6 @@  - From e9c79612aa3748e90256a4657da8ae71a8191ce6 Mon Sep 17 00:00:00 2001 From: Wei Wang Date: Tue, 20 Jan 2015 18:17:58 -0800 Subject: [PATCH 182/987] Rename SKIP_KRE_INSTALL to SKIP_DOTNET_INSTALL --- build.cmd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.cmd b/build.cmd index c8041fdd9d..220a1ff561 100644 --- a/build.cmd +++ b/build.cmd @@ -19,7 +19,7 @@ IF EXIST packages\KoreBuild goto run .nuget\NuGet.exe install KoreBuild -ExcludeVersion -o packages -nocache -pre .nuget\NuGet.exe install Sake -version 0.2 -o packages -ExcludeVersion -IF "%SKIP_KRE_INSTALL%"=="1" goto run +IF "%SKIP_DOTNET_INSTALL%"=="1" goto run CALL packages\KoreBuild\build\dotnetsdk upgrade -runtime CLR -x86 CALL packages\KoreBuild\build\dotnetsdk install default -runtime CoreCLR -x86 From dd8dee2979abda792a4eb3be45c5fa6d224c9021 Mon Sep 17 00:00:00 2001 From: Aligned Date: Wed, 21 Jan 2015 13:18:51 -0600 Subject: [PATCH 183/987] Change ASP.NET vNext to ASP.Net 5 in the Readme.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 1dbf89ce85..8bf71cfc4d 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ Hosting ======= -The Hosting repo contains code required to host an ASP.NET vNext application, it is the entry point used when self-hosting an application. +The Hosting repo contains code required to host an ASP.NET 5 application, it is the entry point used when self-hosting an application. -This project is part of ASP.NET vNext. You can find samples, documentation and getting started instructions for ASP.NET vNext at the [Home](https://github.com/aspnet/home) repo. +This project is part of ASP.NET 5. You can find samples, documentation and getting started instructions for ASP.NET 5 at the [Home](https://github.com/aspnet/home) repo. From f733c18075e837acc7117f73a35d00858b3e0b92 Mon Sep 17 00:00:00 2001 From: Suhas Joshi Date: Wed, 21 Jan 2015 15:49:23 -0800 Subject: [PATCH 184/987] Updating to release NuGet.config --- NuGet.Config | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NuGet.Config b/NuGet.Config index f41e9c631d..2d3b0cb857 100644 --- a/NuGet.Config +++ b/NuGet.Config @@ -1,7 +1,7 @@  - + From 2535e30b125dd5c5c99ea6215a5926d312a0e010 Mon Sep 17 00:00:00 2001 From: Wei Wang Date: Wed, 28 Jan 2015 18:10:06 -0800 Subject: [PATCH 185/987] Update build.cmd and build.sh to use kvm --- build.cmd | 6 +++--- build.sh | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/build.cmd b/build.cmd index 220a1ff561..5885abe388 100644 --- a/build.cmd +++ b/build.cmd @@ -20,9 +20,9 @@ IF EXIST packages\KoreBuild goto run .nuget\NuGet.exe install Sake -version 0.2 -o packages -ExcludeVersion IF "%SKIP_DOTNET_INSTALL%"=="1" goto run -CALL packages\KoreBuild\build\dotnetsdk upgrade -runtime CLR -x86 -CALL packages\KoreBuild\build\dotnetsdk install default -runtime CoreCLR -x86 +CALL packages\KoreBuild\build\kvm upgrade -runtime CLR -x86 +CALL packages\KoreBuild\build\kvm install default -runtime CoreCLR -x86 :run -CALL packages\KoreBuild\build\dotnetsdk use default -runtime CLR -x86 +CALL packages\KoreBuild\build\kvm use default -runtime CLR -x86 packages\Sake\tools\Sake.exe -I packages\KoreBuild\build -f makefile.shade %* diff --git a/build.sh b/build.sh index 350d7e389a..c7873ef58e 100755 --- a/build.sh +++ b/build.sh @@ -28,11 +28,11 @@ if test ! -d packages/KoreBuild; then fi if ! type k > /dev/null 2>&1; then - source packages/KoreBuild/build/dotnetsdk.sh + source packages/KoreBuild/build/kvm.sh fi if ! type k > /dev/null 2>&1; then - dotnetsdk upgrade + kvm upgrade fi mono packages/Sake/tools/Sake.exe -I packages/KoreBuild/build -f makefile.shade "$@" From 89484cdffb9f0f7ce84cf4a8ea00db1ea6969912 Mon Sep 17 00:00:00 2001 From: Wei Wang Date: Wed, 28 Jan 2015 18:10:20 -0800 Subject: [PATCH 186/987] Change SKIP_DOTNET_INSTALL to SKIP_KRE_INSTALL --- build.cmd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.cmd b/build.cmd index 5885abe388..86ca5bbbf1 100644 --- a/build.cmd +++ b/build.cmd @@ -19,7 +19,7 @@ IF EXIST packages\KoreBuild goto run .nuget\NuGet.exe install KoreBuild -ExcludeVersion -o packages -nocache -pre .nuget\NuGet.exe install Sake -version 0.2 -o packages -ExcludeVersion -IF "%SKIP_DOTNET_INSTALL%"=="1" goto run +IF "%SKIP_KRE_INSTALL%"=="1" goto run CALL packages\KoreBuild\build\kvm upgrade -runtime CLR -x86 CALL packages\KoreBuild\build\kvm install default -runtime CoreCLR -x86 From ba58c767e8c34f1a27935c0deca7c48836294ba5 Mon Sep 17 00:00:00 2001 From: Pranav K Date: Wed, 28 Jan 2015 22:34:18 -0800 Subject: [PATCH 187/987] Fixing NuGet.config --- NuGet.Config | 1 + 1 file changed, 1 insertion(+) diff --git a/NuGet.Config b/NuGet.Config index 53454b2000..2d3b0cb857 100644 --- a/NuGet.Config +++ b/NuGet.Config @@ -1,6 +1,7 @@  + From eba2808109f86b034466051d0abccf2d01cf81fa Mon Sep 17 00:00:00 2001 From: damianedwards Date: Tue, 27 Jan 2015 17:50:42 -0800 Subject: [PATCH 188/987] Register ILogger -> Logger in default services --- .../HostingServicesCollectionExtensions.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Microsoft.AspNet.Hosting/HostingServicesCollectionExtensions.cs b/src/Microsoft.AspNet.Hosting/HostingServicesCollectionExtensions.cs index 82c134ffb2..8c52a6910d 100644 --- a/src/Microsoft.AspNet.Hosting/HostingServicesCollectionExtensions.cs +++ b/src/Microsoft.AspNet.Hosting/HostingServicesCollectionExtensions.cs @@ -17,6 +17,7 @@ namespace Microsoft.Framework.DependencyInjection { var describe = new ServiceDescriber(config); services.TryAdd(describe.Singleton()); + services.TryAdd(describe.Singleton(typeof(ILogger<>), typeof(Logger<>))); return services; } From 6208698a5c3e65f2b531f5c5aa87a231d9f69a40 Mon Sep 17 00:00:00 2001 From: David Fowler Date: Mon, 9 Feb 2015 22:10:29 -0800 Subject: [PATCH 189/987] Added Microsoft.AspNet.Hosting.Interfaces package --- Hosting.sln | 17 +++++++++++++++- .../IApplicationLifetime.cs | 0 .../IHostingEnvironment.cs | 0 .../IServerFactory.cs | 0 .../Microsoft.AspNet.Hosting.Interfaces.kproj | 20 +++++++++++++++++++ .../project.json | 14 +++++++++++++ src/Microsoft.AspNet.Hosting/project.json | 6 +++--- .../Microsoft.AspNet.Hosting.Tests.kproj | 5 +++-- 8 files changed, 56 insertions(+), 6 deletions(-) rename src/{Microsoft.AspNet.Hosting => Microsoft.AspNet.Hosting.Interfaces}/IApplicationLifetime.cs (100%) rename src/{Microsoft.AspNet.Hosting => Microsoft.AspNet.Hosting.Interfaces}/IHostingEnvironment.cs (100%) rename src/{Microsoft.AspNet.Hosting/Server => Microsoft.AspNet.Hosting.Interfaces}/IServerFactory.cs (100%) create mode 100644 src/Microsoft.AspNet.Hosting.Interfaces/Microsoft.AspNet.Hosting.Interfaces.kproj create mode 100644 src/Microsoft.AspNet.Hosting.Interfaces/project.json diff --git a/Hosting.sln b/Hosting.sln index 52888aa65a..33c4336fb9 100644 --- a/Hosting.sln +++ b/Hosting.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 14 -VisualStudioVersion = 14.0.21916.0 +VisualStudioVersion = 14.0.22530.0 MinimumVisualStudioVersion = 10.0.40219.1 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{E0497F39-AFFB-4819-A116-E39E361915AB}" EndProject @@ -22,6 +22,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution global.json = global.json EndProjectSection EndProject +Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNet.Hosting.Interfaces", "src\Microsoft.AspNet.Hosting.Interfaces\Microsoft.AspNet.Hosting.Interfaces.kproj", "{BB780FBB-7842-4759-8DE7-96FA2E5571C1}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -82,6 +84,18 @@ Global {374A5B0C-3E93-4A23-A4A0-EE2AB6DF7814}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU {374A5B0C-3E93-4A23-A4A0-EE2AB6DF7814}.Release|Mixed Platforms.Build.0 = Release|Any CPU {374A5B0C-3E93-4A23-A4A0-EE2AB6DF7814}.Release|x86.ActiveCfg = Release|Any CPU + {BB780FBB-7842-4759-8DE7-96FA2E5571C1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {BB780FBB-7842-4759-8DE7-96FA2E5571C1}.Debug|Any CPU.Build.0 = Debug|Any CPU + {BB780FBB-7842-4759-8DE7-96FA2E5571C1}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU + {BB780FBB-7842-4759-8DE7-96FA2E5571C1}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU + {BB780FBB-7842-4759-8DE7-96FA2E5571C1}.Debug|x86.ActiveCfg = Debug|Any CPU + {BB780FBB-7842-4759-8DE7-96FA2E5571C1}.Debug|x86.Build.0 = Debug|Any CPU + {BB780FBB-7842-4759-8DE7-96FA2E5571C1}.Release|Any CPU.ActiveCfg = Release|Any CPU + {BB780FBB-7842-4759-8DE7-96FA2E5571C1}.Release|Any CPU.Build.0 = Release|Any CPU + {BB780FBB-7842-4759-8DE7-96FA2E5571C1}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU + {BB780FBB-7842-4759-8DE7-96FA2E5571C1}.Release|Mixed Platforms.Build.0 = Release|Any CPU + {BB780FBB-7842-4759-8DE7-96FA2E5571C1}.Release|x86.ActiveCfg = Release|Any CPU + {BB780FBB-7842-4759-8DE7-96FA2E5571C1}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -92,5 +106,6 @@ Global {3944F036-7E75-47E8-AA52-C4B89A64EC3A} = {E0497F39-AFFB-4819-A116-E39E361915AB} {D4F18D58-52B1-435D-A012-10F2CDF158C4} = {FEB39027-9158-4DE2-997F-7ADAEF8188D0} {374A5B0C-3E93-4A23-A4A0-EE2AB6DF7814} = {E0497F39-AFFB-4819-A116-E39E361915AB} + {BB780FBB-7842-4759-8DE7-96FA2E5571C1} = {E0497F39-AFFB-4819-A116-E39E361915AB} EndGlobalSection EndGlobal diff --git a/src/Microsoft.AspNet.Hosting/IApplicationLifetime.cs b/src/Microsoft.AspNet.Hosting.Interfaces/IApplicationLifetime.cs similarity index 100% rename from src/Microsoft.AspNet.Hosting/IApplicationLifetime.cs rename to src/Microsoft.AspNet.Hosting.Interfaces/IApplicationLifetime.cs diff --git a/src/Microsoft.AspNet.Hosting/IHostingEnvironment.cs b/src/Microsoft.AspNet.Hosting.Interfaces/IHostingEnvironment.cs similarity index 100% rename from src/Microsoft.AspNet.Hosting/IHostingEnvironment.cs rename to src/Microsoft.AspNet.Hosting.Interfaces/IHostingEnvironment.cs diff --git a/src/Microsoft.AspNet.Hosting/Server/IServerFactory.cs b/src/Microsoft.AspNet.Hosting.Interfaces/IServerFactory.cs similarity index 100% rename from src/Microsoft.AspNet.Hosting/Server/IServerFactory.cs rename to src/Microsoft.AspNet.Hosting.Interfaces/IServerFactory.cs diff --git a/src/Microsoft.AspNet.Hosting.Interfaces/Microsoft.AspNet.Hosting.Interfaces.kproj b/src/Microsoft.AspNet.Hosting.Interfaces/Microsoft.AspNet.Hosting.Interfaces.kproj new file mode 100644 index 0000000000..b50140bec2 --- /dev/null +++ b/src/Microsoft.AspNet.Hosting.Interfaces/Microsoft.AspNet.Hosting.Interfaces.kproj @@ -0,0 +1,20 @@ + + + + 14.0 + $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) + + + + + bb780fbb-7842-4759-8de7-96fa2e5571c1 + Microsoft.AspNet.Hosting.Interfaces + ..\..\artifacts\obj\$(MSBuildProjectName) + ..\..\artifacts\bin\$(MSBuildProjectName)\ + + + + 2.0 + + + \ No newline at end of file diff --git a/src/Microsoft.AspNet.Hosting.Interfaces/project.json b/src/Microsoft.AspNet.Hosting.Interfaces/project.json new file mode 100644 index 0000000000..21b82874ae --- /dev/null +++ b/src/Microsoft.AspNet.Hosting.Interfaces/project.json @@ -0,0 +1,14 @@ +{ + "version": "1.0.0-*", + "dependencies": { + "Microsoft.AspNet.Http": "1.0.0-*", + "Microsoft.AspNet.FileProviders.Interfaces": "1.0.0-*", + "Microsoft.Framework.Runtime.Interfaces": "1.0.0-*", + "Microsoft.Framework.ConfigurationModel": "1.0.0-*" + }, + + "frameworks": { + "aspnet50": { }, + "aspnetcore50": { } + } +} diff --git a/src/Microsoft.AspNet.Hosting/project.json b/src/Microsoft.AspNet.Hosting/project.json index 5c740ce152..2696a48923 100644 --- a/src/Microsoft.AspNet.Hosting/project.json +++ b/src/Microsoft.AspNet.Hosting/project.json @@ -2,11 +2,11 @@ "version": "1.0.0-*", "description": "ASP.NET 5 core hosting infrastructure and startup logic for web applications.", "dependencies": { - "Microsoft.AspNet.FileProviders": "1.0.0-*", + "Microsoft.AspNet.Hosting.Interfaces": "1.0.0-*", + "Microsoft.AspNet.FileProviders": "1.0.0-*", "Microsoft.AspNet.Http.Core": "1.0.0-*", "Microsoft.Framework.Logging": "1.0.0-*", - "Microsoft.Framework.OptionsModel": "1.0.0-*", - "Microsoft.Framework.Runtime.Interfaces": { "version": "1.0.0-*", "type": "build" }, + "Microsoft.Framework.DependencyInjection": "1.0.0-*", "Newtonsoft.Json": "6.0.6" }, "frameworks": { diff --git a/test/Microsoft.AspNet.Hosting.Tests/Microsoft.AspNet.Hosting.Tests.kproj b/test/Microsoft.AspNet.Hosting.Tests/Microsoft.AspNet.Hosting.Tests.kproj index e82e9b32a2..766519fb73 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/Microsoft.AspNet.Hosting.Tests.kproj +++ b/test/Microsoft.AspNet.Hosting.Tests/Microsoft.AspNet.Hosting.Tests.kproj @@ -1,4 +1,4 @@ - + 14.0 @@ -12,6 +12,7 @@ 2.0 + 23533 - + \ No newline at end of file From 5038c369db16a23312612073ce7b36ab4b1931aa Mon Sep 17 00:00:00 2001 From: Pranav K Date: Thu, 12 Feb 2015 14:44:38 -0800 Subject: [PATCH 190/987] Using IServiceManifest from Microsoft.Framework.Runtime.Interfaces --- .../IApplicationLifetime.cs | 2 -- .../IConfigureHostingEnvironment.cs | 1 - .../IHostingEnvironment.cs | 2 -- .../IServerFactory.cs | 2 -- .../project.json | 1 - src/Microsoft.AspNet.Hosting/IServiceManifest.cs | 16 ---------------- src/Microsoft.AspNet.Hosting/project.json | 1 + 7 files changed, 1 insertion(+), 24 deletions(-) rename src/{Microsoft.AspNet.Hosting => Microsoft.AspNet.Hosting.Interfaces}/IConfigureHostingEnvironment.cs (94%) delete mode 100644 src/Microsoft.AspNet.Hosting/IServiceManifest.cs diff --git a/src/Microsoft.AspNet.Hosting.Interfaces/IApplicationLifetime.cs b/src/Microsoft.AspNet.Hosting.Interfaces/IApplicationLifetime.cs index df20556da1..755a415103 100644 --- a/src/Microsoft.AspNet.Hosting.Interfaces/IApplicationLifetime.cs +++ b/src/Microsoft.AspNet.Hosting.Interfaces/IApplicationLifetime.cs @@ -2,14 +2,12 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Threading; -using Microsoft.Framework.Runtime; namespace Microsoft.AspNet.Hosting { /// /// Allows consumers to perform cleanup during a graceful shutdown. /// - [AssemblyNeutral] public interface IApplicationLifetime { /// diff --git a/src/Microsoft.AspNet.Hosting/IConfigureHostingEnvironment.cs b/src/Microsoft.AspNet.Hosting.Interfaces/IConfigureHostingEnvironment.cs similarity index 94% rename from src/Microsoft.AspNet.Hosting/IConfigureHostingEnvironment.cs rename to src/Microsoft.AspNet.Hosting.Interfaces/IConfigureHostingEnvironment.cs index 715d55b687..6ea92fde03 100644 --- a/src/Microsoft.AspNet.Hosting/IConfigureHostingEnvironment.cs +++ b/src/Microsoft.AspNet.Hosting.Interfaces/IConfigureHostingEnvironment.cs @@ -5,7 +5,6 @@ using Microsoft.Framework.Runtime; namespace Microsoft.AspNet.Hosting { - [AssemblyNeutral] public interface IConfigureHostingEnvironment { void Configure(IHostingEnvironment hostingEnv); diff --git a/src/Microsoft.AspNet.Hosting.Interfaces/IHostingEnvironment.cs b/src/Microsoft.AspNet.Hosting.Interfaces/IHostingEnvironment.cs index 8f5966e332..c946e5d3ff 100644 --- a/src/Microsoft.AspNet.Hosting.Interfaces/IHostingEnvironment.cs +++ b/src/Microsoft.AspNet.Hosting.Interfaces/IHostingEnvironment.cs @@ -2,11 +2,9 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using Microsoft.AspNet.FileProviders; -using Microsoft.Framework.Runtime; namespace Microsoft.AspNet.Hosting { - [AssemblyNeutral] public interface IHostingEnvironment { string EnvironmentName { get; set; } diff --git a/src/Microsoft.AspNet.Hosting.Interfaces/IServerFactory.cs b/src/Microsoft.AspNet.Hosting.Interfaces/IServerFactory.cs index 94cb26ece7..979730e5de 100644 --- a/src/Microsoft.AspNet.Hosting.Interfaces/IServerFactory.cs +++ b/src/Microsoft.AspNet.Hosting.Interfaces/IServerFactory.cs @@ -5,11 +5,9 @@ using System; using System.Threading.Tasks; using Microsoft.AspNet.Builder; using Microsoft.Framework.ConfigurationModel; -using Microsoft.Framework.Runtime; namespace Microsoft.AspNet.Hosting.Server { - [AssemblyNeutral] public interface IServerFactory { IServerInformation Initialize(IConfiguration configuration); diff --git a/src/Microsoft.AspNet.Hosting.Interfaces/project.json b/src/Microsoft.AspNet.Hosting.Interfaces/project.json index 21b82874ae..9e5b132ac8 100644 --- a/src/Microsoft.AspNet.Hosting.Interfaces/project.json +++ b/src/Microsoft.AspNet.Hosting.Interfaces/project.json @@ -3,7 +3,6 @@ "dependencies": { "Microsoft.AspNet.Http": "1.0.0-*", "Microsoft.AspNet.FileProviders.Interfaces": "1.0.0-*", - "Microsoft.Framework.Runtime.Interfaces": "1.0.0-*", "Microsoft.Framework.ConfigurationModel": "1.0.0-*" }, diff --git a/src/Microsoft.AspNet.Hosting/IServiceManifest.cs b/src/Microsoft.AspNet.Hosting/IServiceManifest.cs deleted file mode 100644 index 3810fdc06c..0000000000 --- a/src/Microsoft.AspNet.Hosting/IServiceManifest.cs +++ /dev/null @@ -1,16 +0,0 @@ -// 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 System; -using System.Collections.Generic; - -namespace Microsoft.Framework.DependencyInjection.ServiceLookup -{ -#if ASPNET50 || ASPNETCORE50 - [Microsoft.Framework.Runtime.AssemblyNeutral] -#endif - public interface IServiceManifest - { - IEnumerable Services { get; } - } -} diff --git a/src/Microsoft.AspNet.Hosting/project.json b/src/Microsoft.AspNet.Hosting/project.json index 2696a48923..f4deb14aca 100644 --- a/src/Microsoft.AspNet.Hosting/project.json +++ b/src/Microsoft.AspNet.Hosting/project.json @@ -3,6 +3,7 @@ "description": "ASP.NET 5 core hosting infrastructure and startup logic for web applications.", "dependencies": { "Microsoft.AspNet.Hosting.Interfaces": "1.0.0-*", + "Microsoft.Framework.Runtime.Interfaces": "1.0.0-*", "Microsoft.AspNet.FileProviders": "1.0.0-*", "Microsoft.AspNet.Http.Core": "1.0.0-*", "Microsoft.Framework.Logging": "1.0.0-*", From fe3675a9e06f5a3ff1eed9c8aeb8108f88e90d10 Mon Sep 17 00:00:00 2001 From: dtkujawski Date: Thu, 12 Feb 2015 17:40:14 -0600 Subject: [PATCH 191/987] Ability to derive Startup from a base class and have "Configure" and "ConfigureServices" be invoked from the base class when present. --- .../Startup/StartupLoader.cs | 20 ++++++------- .../Fakes/Startup.cs | 12 ++++---- .../Fakes/StartupBase.cs | 29 +++++++++++++++++++ .../StartupManagerTests.cs | 3 +- 4 files changed, 47 insertions(+), 17 deletions(-) create mode 100644 test/Microsoft.AspNet.Hosting.Tests/Fakes/StartupBase.cs diff --git a/src/Microsoft.AspNet.Hosting/Startup/StartupLoader.cs b/src/Microsoft.AspNet.Hosting/Startup/StartupLoader.cs index a7e85283bf..24770cd502 100644 --- a/src/Microsoft.AspNet.Hosting/Startup/StartupLoader.cs +++ b/src/Microsoft.AspNet.Hosting/Startup/StartupLoader.cs @@ -29,18 +29,18 @@ namespace Microsoft.AspNet.Hosting.Startup { var methodNameWithEnv = string.Format(CultureInfo.InvariantCulture, methodName, environmentName); var methodNameWithNoEnv = string.Format(CultureInfo.InvariantCulture, methodName, ""); - var methodInfo = startupType.GetTypeInfo().GetDeclaredMethod(methodNameWithEnv) - ?? startupType.GetTypeInfo().GetDeclaredMethod(methodNameWithNoEnv); - if (methodInfo == null) + var methodInfo = startupType.GetMethod(methodNameWithEnv, BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static) + ?? startupType.GetMethod(methodNameWithNoEnv, BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static); + if (methodInfo == null) { if (required) - { - throw new Exception(string.Format("TODO: {0} or {1} method not found", - methodNameWithEnv, - methodNameWithNoEnv)); + { + throw new Exception(string.Format("TODO: {0} or {1} method not found", + methodNameWithEnv, + methodNameWithNoEnv)); - } - return null; + } + return null; } if (returnType != null && methodInfo.ReturnType != returnType) { @@ -160,7 +160,7 @@ namespace Microsoft.AspNet.Hosting.Startup } else { - // void ConfigureServices(IServiceCollection) + // void ConfigureServices(IServiceCollection) Invoke(servicesMethod, instance, builder, services); if (builder != null) { diff --git a/test/Microsoft.AspNet.Hosting.Tests/Fakes/Startup.cs b/test/Microsoft.AspNet.Hosting.Tests/Fakes/Startup.cs index e657841566..54ef6de669 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/Fakes/Startup.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/Fakes/Startup.cs @@ -9,7 +9,7 @@ using System; namespace Microsoft.AspNet.Hosting.Fakes { - public class Startup + public class Startup : StartupBase { public Startup() { @@ -31,7 +31,7 @@ namespace Microsoft.AspNet.Hosting.Fakes }); } - public void ConfigureRetailServices(IServiceCollection services) + public void ConfigureRetailServices(IServiceCollection services) { services.AddOptions(); services.Configure(o => @@ -94,8 +94,8 @@ namespace Microsoft.AspNet.Hosting.Fakes return services.BuildServiceProvider(); } - public virtual void Configure(IApplicationBuilder builder) - { - } - } + public virtual void Configure(IApplicationBuilder builder) + { + } + } } \ No newline at end of file diff --git a/test/Microsoft.AspNet.Hosting.Tests/Fakes/StartupBase.cs b/test/Microsoft.AspNet.Hosting.Tests/Fakes/StartupBase.cs new file mode 100644 index 0000000000..f1ee427a87 --- /dev/null +++ b/test/Microsoft.AspNet.Hosting.Tests/Fakes/StartupBase.cs @@ -0,0 +1,29 @@ +// 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.Builder; +using Microsoft.Framework.DependencyInjection; +using Microsoft.Framework.DependencyInjection.Fallback; +using Microsoft.Framework.OptionsModel; +using System; + +namespace Microsoft.AspNet.Hosting.Fakes +{ + public class StartupBase + { + public StartupBase() + { + } + + public void ConfigureBaseClassServices(IServiceCollection services) + { + services.AddOptions(); + services.Configure(o => + { + o.Configured = true; + o.Environment = "BaseClass"; + }); + } + + } +} \ No newline at end of file diff --git a/test/Microsoft.AspNet.Hosting.Tests/StartupManagerTests.cs b/test/Microsoft.AspNet.Hosting.Tests/StartupManagerTests.cs index f3323b978a..46758b92bc 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/StartupManagerTests.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/StartupManagerTests.cs @@ -42,7 +42,8 @@ namespace Microsoft.AspNet.Hosting.Tests [InlineData("StaticProvider")] [InlineData("Provider")] [InlineData("ProviderArgs")] - public void StartupClassAddsConfigureServicesToApplicationServices(string environment) + [InlineData("BaseClass")] + public void StartupClassAddsConfigureServicesToApplicationServices(string environment) { var services = HostingServices.Create().BuildServiceProvider(); var manager = services.GetRequiredService(); From a48f76da7c4687e3372b02ef945ad70fad55f7fc Mon Sep 17 00:00:00 2001 From: Brice Lambson Date: Thu, 12 Feb 2015 15:48:49 -0800 Subject: [PATCH 192/987] Update IServiceProvider references --- src/Microsoft.AspNet.Hosting/HostingServices.cs | 2 +- test/Microsoft.AspNet.Hosting.Tests/HostingServicesFacts.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Microsoft.AspNet.Hosting/HostingServices.cs b/src/Microsoft.AspNet.Hosting/HostingServices.cs index b717bb7050..46b0f94703 100644 --- a/src/Microsoft.AspNet.Hosting/HostingServices.cs +++ b/src/Microsoft.AspNet.Hosting/HostingServices.cs @@ -6,8 +6,8 @@ using System.Collections.Generic; using System.Linq; using Microsoft.Framework.ConfigurationModel; using Microsoft.Framework.DependencyInjection; -using Microsoft.Framework.DependencyInjection.ServiceLookup; using Microsoft.Framework.Logging; +using Microsoft.Framework.Runtime; using Microsoft.Framework.Runtime.Infrastructure; namespace Microsoft.AspNet.Hosting diff --git a/test/Microsoft.AspNet.Hosting.Tests/HostingServicesFacts.cs b/test/Microsoft.AspNet.Hosting.Tests/HostingServicesFacts.cs index 65aa6faecd..4fe3e36006 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/HostingServicesFacts.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/HostingServicesFacts.cs @@ -6,7 +6,7 @@ using System.Collections.Generic; using Microsoft.AspNet.Hosting.Fakes; using Microsoft.Framework.DependencyInjection; using Microsoft.Framework.DependencyInjection.Fallback; -using Microsoft.Framework.DependencyInjection.ServiceLookup; +using Microsoft.Framework.Runtime; using Xunit; namespace Microsoft.AspNet.Hosting.Tests From 66b98e2ff3bfdc2ec3fb47cac69a166d556dd2aa Mon Sep 17 00:00:00 2001 From: Pranav K Date: Thu, 12 Feb 2015 16:05:09 -0800 Subject: [PATCH 193/987] Reacting to IServiceManifest namespace rename --- test/Microsoft.AspNet.Hosting.Tests/HostingServicesFacts.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/test/Microsoft.AspNet.Hosting.Tests/HostingServicesFacts.cs b/test/Microsoft.AspNet.Hosting.Tests/HostingServicesFacts.cs index 4fe3e36006..5e6e733da8 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/HostingServicesFacts.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/HostingServicesFacts.cs @@ -84,11 +84,12 @@ namespace Microsoft.AspNet.Hosting.Tests fallbackServices.AddTransient(); // Act - var exp = Assert.Throws(() => HostingServices.Create(fallbackServices.BuildServiceProvider())); + var exception = Assert.Throws(() => HostingServices.Create(fallbackServices.BuildServiceProvider())); // Assert - Assert.True(exp.Message.Contains("No service for type 'Microsoft.Framework.DependencyInjection.ServiceLookup.IServiceManifest'")); + Assert.Equal($"No service for type '{typeof(IServiceManifest).FullName}' has been registered.", + exception.Message); } private class ServiceManifest : IServiceManifest From e95472e953b2bf09a31b9b3ac2f20453f38e7b7c Mon Sep 17 00:00:00 2001 From: dtkujawski Date: Thu, 12 Feb 2015 23:45:26 -0600 Subject: [PATCH 194/987] Switch from tabs to spaces --- .../Startup/StartupLoader.cs | 20 +++++++++---------- .../Fakes/Startup.cs | 10 +++++----- .../Fakes/StartupBase.cs | 20 +++++++++---------- .../StartupManagerTests.cs | 4 ++-- 4 files changed, 27 insertions(+), 27 deletions(-) diff --git a/src/Microsoft.AspNet.Hosting/Startup/StartupLoader.cs b/src/Microsoft.AspNet.Hosting/Startup/StartupLoader.cs index 24770cd502..ba48bd211c 100644 --- a/src/Microsoft.AspNet.Hosting/Startup/StartupLoader.cs +++ b/src/Microsoft.AspNet.Hosting/Startup/StartupLoader.cs @@ -29,18 +29,18 @@ namespace Microsoft.AspNet.Hosting.Startup { var methodNameWithEnv = string.Format(CultureInfo.InvariantCulture, methodName, environmentName); var methodNameWithNoEnv = string.Format(CultureInfo.InvariantCulture, methodName, ""); - var methodInfo = startupType.GetMethod(methodNameWithEnv, BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static) - ?? startupType.GetMethod(methodNameWithNoEnv, BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static); - if (methodInfo == null) + var methodInfo = startupType.GetMethod(methodNameWithEnv, BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static) + ?? startupType.GetMethod(methodNameWithNoEnv, BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static); + if (methodInfo == null) { if (required) - { - throw new Exception(string.Format("TODO: {0} or {1} method not found", - methodNameWithEnv, - methodNameWithNoEnv)); + { + throw new Exception(string.Format("TODO: {0} or {1} method not found", + methodNameWithEnv, + methodNameWithNoEnv)); - } - return null; + } + return null; } if (returnType != null && methodInfo.ReturnType != returnType) { @@ -160,7 +160,7 @@ namespace Microsoft.AspNet.Hosting.Startup } else { - // void ConfigureServices(IServiceCollection) + // void ConfigureServices(IServiceCollection) Invoke(servicesMethod, instance, builder, services); if (builder != null) { diff --git a/test/Microsoft.AspNet.Hosting.Tests/Fakes/Startup.cs b/test/Microsoft.AspNet.Hosting.Tests/Fakes/Startup.cs index 54ef6de669..efcb11537a 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/Fakes/Startup.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/Fakes/Startup.cs @@ -31,7 +31,7 @@ namespace Microsoft.AspNet.Hosting.Fakes }); } - public void ConfigureRetailServices(IServiceCollection services) + public void ConfigureRetailServices(IServiceCollection services) { services.AddOptions(); services.Configure(o => @@ -94,8 +94,8 @@ namespace Microsoft.AspNet.Hosting.Fakes return services.BuildServiceProvider(); } - public virtual void Configure(IApplicationBuilder builder) - { - } - } + public virtual void Configure(IApplicationBuilder builder) + { + } + } } \ No newline at end of file diff --git a/test/Microsoft.AspNet.Hosting.Tests/Fakes/StartupBase.cs b/test/Microsoft.AspNet.Hosting.Tests/Fakes/StartupBase.cs index f1ee427a87..7fbe35cffb 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/Fakes/StartupBase.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/Fakes/StartupBase.cs @@ -15,15 +15,15 @@ namespace Microsoft.AspNet.Hosting.Fakes { } - public void ConfigureBaseClassServices(IServiceCollection services) - { - services.AddOptions(); - services.Configure(o => - { - o.Configured = true; - o.Environment = "BaseClass"; - }); - } + public void ConfigureBaseClassServices(IServiceCollection services) + { + services.AddOptions(); + services.Configure(o => + { + o.Configured = true; + o.Environment = "BaseClass"; + }); + } - } + } } \ No newline at end of file diff --git a/test/Microsoft.AspNet.Hosting.Tests/StartupManagerTests.cs b/test/Microsoft.AspNet.Hosting.Tests/StartupManagerTests.cs index 46758b92bc..29aa84173c 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/StartupManagerTests.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/StartupManagerTests.cs @@ -42,8 +42,8 @@ namespace Microsoft.AspNet.Hosting.Tests [InlineData("StaticProvider")] [InlineData("Provider")] [InlineData("ProviderArgs")] - [InlineData("BaseClass")] - public void StartupClassAddsConfigureServicesToApplicationServices(string environment) + [InlineData("BaseClass")] + public void StartupClassAddsConfigureServicesToApplicationServices(string environment) { var services = HostingServices.Create().BuildServiceProvider(); var manager = services.GetRequiredService(); From 5a5975e348d0b17541ca8fcdb424ddb8285b058f Mon Sep 17 00:00:00 2001 From: dtkujawski Date: Fri, 13 Feb 2015 11:47:42 -0600 Subject: [PATCH 195/987] Removed Ctor, Cleaned up namespace and removed extra vertical spacing as per comments. --- test/Microsoft.AspNet.Hosting.Tests/Fakes/StartupBase.cs | 9 --------- 1 file changed, 9 deletions(-) diff --git a/test/Microsoft.AspNet.Hosting.Tests/Fakes/StartupBase.cs b/test/Microsoft.AspNet.Hosting.Tests/Fakes/StartupBase.cs index 7fbe35cffb..e9daa9584d 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/Fakes/StartupBase.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/Fakes/StartupBase.cs @@ -1,20 +1,12 @@ // 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.Builder; using Microsoft.Framework.DependencyInjection; -using Microsoft.Framework.DependencyInjection.Fallback; -using Microsoft.Framework.OptionsModel; -using System; namespace Microsoft.AspNet.Hosting.Fakes { public class StartupBase { - public StartupBase() - { - } - public void ConfigureBaseClassServices(IServiceCollection services) { services.AddOptions(); @@ -24,6 +16,5 @@ namespace Microsoft.AspNet.Hosting.Fakes o.Environment = "BaseClass"; }); } - } } \ No newline at end of file From 34acb16e2038f5e00855b6df89f937402f15c558 Mon Sep 17 00:00:00 2001 From: Wei Wang Date: Mon, 16 Feb 2015 13:29:03 -0800 Subject: [PATCH 196/987] Add project.lock.json to .gitignore --- .gitignore | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 08e21e25bf..ac82da7568 100644 --- a/.gitignore +++ b/.gitignore @@ -23,4 +23,5 @@ nuget.exe *.ncrunchsolution *.*sdf *.ipch -*.sln.ide \ No newline at end of file +*.sln.ide +project.lock.json From 2ee12735b3cfd2198ac33d423f158dba0eaba8c2 Mon Sep 17 00:00:00 2001 From: Hao Kung Date: Thu, 19 Feb 2015 13:22:58 -0800 Subject: [PATCH 197/987] Make it easier to add hosting services Fixes https://github.com/aspnet/Hosting/pull/146 --- .../ConfigureHostingEnvironment.cs | 2 +- .../HostingServices.cs | 42 +++++++++--- .../HostingServicesCollectionExtensions.cs | 14 +++- src/Microsoft.AspNet.TestHost/TestServer.cs | 17 +++-- .../HostingServicesFacts.cs | 67 +++++++++++++++++++ .../TestServerTests.cs | 30 ++++++++- 6 files changed, 153 insertions(+), 19 deletions(-) diff --git a/src/Microsoft.AspNet.Hosting/ConfigureHostingEnvironment.cs b/src/Microsoft.AspNet.Hosting/ConfigureHostingEnvironment.cs index a714c2cfef..892eaab372 100644 --- a/src/Microsoft.AspNet.Hosting/ConfigureHostingEnvironment.cs +++ b/src/Microsoft.AspNet.Hosting/ConfigureHostingEnvironment.cs @@ -17,7 +17,7 @@ namespace Microsoft.AspNet.Hosting public void Configure(IHostingEnvironment hostingEnv) { - hostingEnv.EnvironmentName = _config.Get(EnvironmentKey) ?? hostingEnv.EnvironmentName; + hostingEnv.EnvironmentName = _config?.Get(EnvironmentKey) ?? hostingEnv.EnvironmentName; } } } \ No newline at end of file diff --git a/src/Microsoft.AspNet.Hosting/HostingServices.cs b/src/Microsoft.AspNet.Hosting/HostingServices.cs index 46b0f94703..f102226ff8 100644 --- a/src/Microsoft.AspNet.Hosting/HostingServices.cs +++ b/src/Microsoft.AspNet.Hosting/HostingServices.cs @@ -14,39 +14,61 @@ namespace Microsoft.AspNet.Hosting { public static class HostingServices { - private static IServiceCollection Import(IServiceProvider fallbackProvider) + private static IServiceCollection Import(IServiceProvider fallbackProvider, Action configureHostServices) { var services = new ServiceCollection(); + if (configureHostServices != null) + { + configureHostServices(services); + } var manifest = fallbackProvider.GetRequiredService(); foreach (var service in manifest.Services) { services.AddTransient(service, sp => fallbackProvider.GetService(service)); } + services.AddSingleton(sp => new HostingManifest(services)); return services; } - public static IServiceCollection Create(IConfiguration configuration = null) + public static IServiceCollection Create() { - return Create(CallContextServiceLocator.Locator.ServiceProvider, configuration); + return Create(CallContextServiceLocator.Locator.ServiceProvider, configureHostServices: null, configuration: null); } - public static IServiceCollection Create(IServiceProvider fallbackServices, IConfiguration configuration = null) + public static IServiceCollection Create(IServiceProvider fallbackServices) { - configuration = configuration ?? new Configuration(); - var services = Import(fallbackServices); + return Create(fallbackServices, configureHostServices: null, configuration: null); + } + + public static IServiceCollection Create(IServiceProvider fallbackServices, Action configureHostServices) + { + return Create(fallbackServices, configureHostServices, configuration: null); + } + + public static IServiceCollection Create(Action configureHostServices, IConfiguration configuration) + { + return Create(CallContextServiceLocator.Locator.ServiceProvider, configureHostServices, configuration); + } + + public static IServiceCollection Create(IServiceProvider fallbackServices, IConfiguration configuration) + { + return Create(CallContextServiceLocator.Locator.ServiceProvider, configureHostServices: null, configuration: configuration); + } + + public static IServiceCollection Create(IServiceProvider fallbackServices, Action configureHostServices, IConfiguration configuration) + { + var services = Import(fallbackServices, configureHostServices); services.AddHosting(configuration); - services.AddSingleton(sp => new HostingManifest(fallbackServices)); return services; } // Manifest exposes the fallback manifest in addition to ITypeActivator, IHostingEnvironment, and ILoggerFactory private class HostingManifest : IServiceManifest { - public HostingManifest(IServiceProvider fallback) + public HostingManifest(IServiceCollection hostServices) { - var manifest = fallback.GetRequiredService(); Services = new Type[] { typeof(ITypeActivator), typeof(IHostingEnvironment), typeof(ILoggerFactory), typeof(IHttpContextAccessor) } - .Concat(manifest.Services).Distinct(); + .Concat(hostServices.Select(s => s.ServiceType)).Distinct(); } public IEnumerable Services { get; private set; } diff --git a/src/Microsoft.AspNet.Hosting/HostingServicesCollectionExtensions.cs b/src/Microsoft.AspNet.Hosting/HostingServicesCollectionExtensions.cs index 8c52a6910d..f6a73158a7 100644 --- a/src/Microsoft.AspNet.Hosting/HostingServicesCollectionExtensions.cs +++ b/src/Microsoft.AspNet.Hosting/HostingServicesCollectionExtensions.cs @@ -12,8 +12,13 @@ namespace Microsoft.Framework.DependencyInjection { public static class HostingServicesExtensions { + public static IServiceCollection AddLogging(this IServiceCollection services) + { + return services.AddLogging(config: null); + } + // REVIEW: Logging doesn't depend on DI, where should this live? - public static IServiceCollection AddLogging(this IServiceCollection services, IConfiguration config = null) + public static IServiceCollection AddLogging(this IServiceCollection services, IConfiguration config) { var describe = new ServiceDescriber(config); services.TryAdd(describe.Singleton()); @@ -21,7 +26,12 @@ namespace Microsoft.Framework.DependencyInjection return services; } - public static IServiceCollection AddHosting(this IServiceCollection services, IConfiguration configuration = null) + public static IServiceCollection AddHosting(this IServiceCollection services) + { + return services.AddHosting(configuration: null); + } + + public static IServiceCollection AddHosting(this IServiceCollection services, IConfiguration configuration) { var describer = new ServiceDescriber(configuration); diff --git a/src/Microsoft.AspNet.TestHost/TestServer.cs b/src/Microsoft.AspNet.TestHost/TestServer.cs index 54b908133e..a5496170d1 100644 --- a/src/Microsoft.AspNet.TestHost/TestServer.cs +++ b/src/Microsoft.AspNet.TestHost/TestServer.cs @@ -2,10 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using System.Collections.Generic; -using System.Linq; using System.Net.Http; -using System.Reflection; using System.Threading.Tasks; using Microsoft.AspNet.Builder; using Microsoft.AspNet.Hosting; @@ -49,12 +46,22 @@ namespace Microsoft.AspNet.TestHost public static TestServer Create(Action app) { - return Create(CallContextServiceLocator.Locator.ServiceProvider, app); + return Create(CallContextServiceLocator.Locator.ServiceProvider, app, configureHostServices: null); + } + + public static TestServer Create(Action app, Action configureHostServices) + { + return Create(CallContextServiceLocator.Locator.ServiceProvider, app, configureHostServices); } public static TestServer Create(IServiceProvider serviceProvider, Action app) { - var appServices = HostingServices.Create(serviceProvider).BuildServiceProvider(); + return Create(serviceProvider, app, configureHostServices: null); + } + + public static TestServer Create(IServiceProvider serviceProvider, Action app, Action configureHostServices) + { + var appServices = HostingServices.Create(serviceProvider, configureHostServices).BuildServiceProvider(); var config = new Configuration(); return new TestServer(config, appServices, app); } diff --git a/test/Microsoft.AspNet.Hosting.Tests/HostingServicesFacts.cs b/test/Microsoft.AspNet.Hosting.Tests/HostingServicesFacts.cs index 5e6e733da8..8cafaa90c6 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/HostingServicesFacts.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/HostingServicesFacts.cs @@ -53,6 +53,73 @@ namespace Microsoft.AspNet.Hosting.Tests Assert.Null(provider.GetService()); // Make sure we don't leak non manifest services } + [Fact] + public void CreateCanAddAdditionalServices() + { + // Arrange + var fallbackServices = new ServiceCollection(); + fallbackServices.AddTransient(); + fallbackServices.AddTransient(); // Don't register in manifest + + fallbackServices.AddInstance(new ServiceManifest( + new Type[] { + typeof(IFakeService), + })); + + var instance = new FakeService(); + var factoryInstance = new FakeFactoryService(instance); + + var services = HostingServices.Create(fallbackServices.BuildServiceProvider(), + additionalHostServices => + { + additionalHostServices.AddSingleton(); + additionalHostServices.AddInstance(instance); + additionalHostServices.AddSingleton(serviceProvider => factoryInstance); + }); + + // Act + var provider = services.BuildServiceProvider(); + var singleton = provider.GetRequiredService(); + var transient = provider.GetRequiredService(); + var factory = provider.GetRequiredService(); + var manifest = provider.GetRequiredService(); + + // Assert + Assert.Same(singleton, provider.GetRequiredService()); + Assert.NotSame(transient, provider.GetRequiredService()); + Assert.Same(instance, provider.GetRequiredService()); + Assert.Same(factoryInstance, factory); + Assert.Same(factory.FakeService, instance); + Assert.Null(provider.GetService()); + Assert.Null(provider.GetService()); // Make sure we don't leak non manifest services + Assert.Contains(typeof(IFakeSingletonService), manifest.Services); + Assert.Contains(typeof(IFakeServiceInstance), manifest.Services); + Assert.Contains(typeof(IFactoryService), manifest.Services); + } + + [Fact] + public void CreateAdditionalServicesDoNotOverrideFallback() + { + // Arrange + var fallbackServices = new ServiceCollection(); + fallbackServices.AddTransient(); + + fallbackServices.AddInstance(new ServiceManifest( + new Type[] { + typeof(IFakeService), + })); + + var services = HostingServices.Create(fallbackServices.BuildServiceProvider(), + additionalHostServices => additionalHostServices.AddSingleton()); + + // Act + var provider = services.BuildServiceProvider(); + var stillTransient = provider.GetRequiredService(); + + // Assert + Assert.NotSame(stillTransient, provider.GetRequiredService()); + } + [Fact] public void CanHideImportedServices() { diff --git a/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs b/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs index 0a31db1b21..57d4ed290e 100644 --- a/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs +++ b/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs @@ -40,7 +40,6 @@ namespace Microsoft.AspNet.TestHost [Fact] public async Task CanAccessHttpContext() { - var services = new ServiceCollection().BuildServiceProvider(); TestServer server = TestServer.Create(app => { app.Run(context => @@ -54,6 +53,35 @@ namespace Microsoft.AspNet.TestHost Assert.Equal("HasContext:True", result); } + public class ContextHolder + { + public ContextHolder(IHttpContextAccessor accessor) + { + Accessor = accessor; + } + + public IHttpContextAccessor Accessor { get; set; } + } + + [Fact] + public async Task CanAddNewHostServices() + { + TestServer server = TestServer.Create(app => + { + var a = app.ApplicationServices.GetRequiredService(); + + app.Run(context => + { + var b = app.ApplicationServices.GetRequiredService(); + var accessor = app.ApplicationServices.GetRequiredService(); + return context.Response.WriteAsync("HasContext:" + (accessor.Accessor.Value != null)); + }); + }, newHostServices => newHostServices.AddSingleton()); + + string result = await server.CreateClient().GetStringAsync("/path"); + Assert.Equal("HasContext:True", result); + } + [Fact] public async Task CreateInvokesApp() { From 21d5ae540ee7c53d38ea3e634db151254f23e0b7 Mon Sep 17 00:00:00 2001 From: Hao Kung Date: Thu, 19 Feb 2015 15:17:18 -0800 Subject: [PATCH 198/987] Fix for MVC functional failures --- src/Microsoft.AspNet.Hosting/HostingServices.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Microsoft.AspNet.Hosting/HostingServices.cs b/src/Microsoft.AspNet.Hosting/HostingServices.cs index f102226ff8..7ebc153c12 100644 --- a/src/Microsoft.AspNet.Hosting/HostingServices.cs +++ b/src/Microsoft.AspNet.Hosting/HostingServices.cs @@ -52,7 +52,7 @@ namespace Microsoft.AspNet.Hosting public static IServiceCollection Create(IServiceProvider fallbackServices, IConfiguration configuration) { - return Create(CallContextServiceLocator.Locator.ServiceProvider, configureHostServices: null, configuration: configuration); + return Create(fallbackServices, configureHostServices: null, configuration: configuration); } public static IServiceCollection Create(IServiceProvider fallbackServices, Action configureHostServices, IConfiguration configuration) From b510370c9b31b6f1f922d90735fb210f52ca0fe4 Mon Sep 17 00:00:00 2001 From: Hao Kung Date: Thu, 19 Feb 2015 16:58:04 -0800 Subject: [PATCH 199/987] Add ILogger to manifest --- src/Microsoft.AspNet.Hosting/HostingServices.cs | 2 +- test/Microsoft.AspNet.Hosting.Tests/UseRequestServicesFacts.cs | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Microsoft.AspNet.Hosting/HostingServices.cs b/src/Microsoft.AspNet.Hosting/HostingServices.cs index 7ebc153c12..926812c408 100644 --- a/src/Microsoft.AspNet.Hosting/HostingServices.cs +++ b/src/Microsoft.AspNet.Hosting/HostingServices.cs @@ -67,7 +67,7 @@ namespace Microsoft.AspNet.Hosting { public HostingManifest(IServiceCollection hostServices) { - Services = new Type[] { typeof(ITypeActivator), typeof(IHostingEnvironment), typeof(ILoggerFactory), typeof(IHttpContextAccessor) } + Services = new Type[] { typeof(ITypeActivator), typeof(IHostingEnvironment), typeof(ILoggerFactory), typeof(ILogger<>), typeof(IHttpContextAccessor) } .Concat(hostServices.Select(s => s.ServiceType)).Distinct(); } diff --git a/test/Microsoft.AspNet.Hosting.Tests/UseRequestServicesFacts.cs b/test/Microsoft.AspNet.Hosting.Tests/UseRequestServicesFacts.cs index e247d4ec64..74027b51fc 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/UseRequestServicesFacts.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/UseRequestServicesFacts.cs @@ -93,6 +93,7 @@ namespace Microsoft.AspNet.Hosting.Tests [InlineData(typeof(IApplicationLifetime))] [InlineData(typeof(ILoggerFactory))] [InlineData(typeof(IHttpContextAccessor))] + [InlineData(typeof(ILogger))] public void UseRequestServicesHostingImportedServicesAreDefined(Type service) { var baseServiceProvider = HostingServices.Create().BuildServiceProvider(); From d687ec2c26a1ad34d7ee7db21f17be916c45d07c Mon Sep 17 00:00:00 2001 From: Hao Kung Date: Thu, 19 Feb 2015 17:57:27 -0800 Subject: [PATCH 200/987] Revert HostingServices.Create changes Need to understand MVC failures --- .../ConfigureHostingEnvironment.cs | 2 +- .../HostingServices.cs | 44 +++--------- .../HostingServicesCollectionExtensions.cs | 14 +--- src/Microsoft.AspNet.TestHost/TestServer.cs | 17 ++--- .../HostingServicesFacts.cs | 67 ------------------- .../UseRequestServicesFacts.cs | 1 - .../TestServerTests.cs | 30 +-------- 7 files changed, 20 insertions(+), 155 deletions(-) diff --git a/src/Microsoft.AspNet.Hosting/ConfigureHostingEnvironment.cs b/src/Microsoft.AspNet.Hosting/ConfigureHostingEnvironment.cs index 892eaab372..a714c2cfef 100644 --- a/src/Microsoft.AspNet.Hosting/ConfigureHostingEnvironment.cs +++ b/src/Microsoft.AspNet.Hosting/ConfigureHostingEnvironment.cs @@ -17,7 +17,7 @@ namespace Microsoft.AspNet.Hosting public void Configure(IHostingEnvironment hostingEnv) { - hostingEnv.EnvironmentName = _config?.Get(EnvironmentKey) ?? hostingEnv.EnvironmentName; + hostingEnv.EnvironmentName = _config.Get(EnvironmentKey) ?? hostingEnv.EnvironmentName; } } } \ No newline at end of file diff --git a/src/Microsoft.AspNet.Hosting/HostingServices.cs b/src/Microsoft.AspNet.Hosting/HostingServices.cs index 926812c408..46b0f94703 100644 --- a/src/Microsoft.AspNet.Hosting/HostingServices.cs +++ b/src/Microsoft.AspNet.Hosting/HostingServices.cs @@ -14,61 +14,39 @@ namespace Microsoft.AspNet.Hosting { public static class HostingServices { - private static IServiceCollection Import(IServiceProvider fallbackProvider, Action configureHostServices) + private static IServiceCollection Import(IServiceProvider fallbackProvider) { var services = new ServiceCollection(); - if (configureHostServices != null) - { - configureHostServices(services); - } var manifest = fallbackProvider.GetRequiredService(); foreach (var service in manifest.Services) { services.AddTransient(service, sp => fallbackProvider.GetService(service)); } - services.AddSingleton(sp => new HostingManifest(services)); return services; } - public static IServiceCollection Create() + public static IServiceCollection Create(IConfiguration configuration = null) { - return Create(CallContextServiceLocator.Locator.ServiceProvider, configureHostServices: null, configuration: null); + return Create(CallContextServiceLocator.Locator.ServiceProvider, configuration); } - public static IServiceCollection Create(IServiceProvider fallbackServices) + public static IServiceCollection Create(IServiceProvider fallbackServices, IConfiguration configuration = null) { - return Create(fallbackServices, configureHostServices: null, configuration: null); - } - - public static IServiceCollection Create(IServiceProvider fallbackServices, Action configureHostServices) - { - return Create(fallbackServices, configureHostServices, configuration: null); - } - - public static IServiceCollection Create(Action configureHostServices, IConfiguration configuration) - { - return Create(CallContextServiceLocator.Locator.ServiceProvider, configureHostServices, configuration); - } - - public static IServiceCollection Create(IServiceProvider fallbackServices, IConfiguration configuration) - { - return Create(fallbackServices, configureHostServices: null, configuration: configuration); - } - - public static IServiceCollection Create(IServiceProvider fallbackServices, Action configureHostServices, IConfiguration configuration) - { - var services = Import(fallbackServices, configureHostServices); + configuration = configuration ?? new Configuration(); + var services = Import(fallbackServices); services.AddHosting(configuration); + services.AddSingleton(sp => new HostingManifest(fallbackServices)); return services; } // Manifest exposes the fallback manifest in addition to ITypeActivator, IHostingEnvironment, and ILoggerFactory private class HostingManifest : IServiceManifest { - public HostingManifest(IServiceCollection hostServices) + public HostingManifest(IServiceProvider fallback) { - Services = new Type[] { typeof(ITypeActivator), typeof(IHostingEnvironment), typeof(ILoggerFactory), typeof(ILogger<>), typeof(IHttpContextAccessor) } - .Concat(hostServices.Select(s => s.ServiceType)).Distinct(); + var manifest = fallback.GetRequiredService(); + Services = new Type[] { typeof(ITypeActivator), typeof(IHostingEnvironment), typeof(ILoggerFactory), typeof(IHttpContextAccessor) } + .Concat(manifest.Services).Distinct(); } public IEnumerable Services { get; private set; } diff --git a/src/Microsoft.AspNet.Hosting/HostingServicesCollectionExtensions.cs b/src/Microsoft.AspNet.Hosting/HostingServicesCollectionExtensions.cs index f6a73158a7..8c52a6910d 100644 --- a/src/Microsoft.AspNet.Hosting/HostingServicesCollectionExtensions.cs +++ b/src/Microsoft.AspNet.Hosting/HostingServicesCollectionExtensions.cs @@ -12,13 +12,8 @@ namespace Microsoft.Framework.DependencyInjection { public static class HostingServicesExtensions { - public static IServiceCollection AddLogging(this IServiceCollection services) - { - return services.AddLogging(config: null); - } - // REVIEW: Logging doesn't depend on DI, where should this live? - public static IServiceCollection AddLogging(this IServiceCollection services, IConfiguration config) + public static IServiceCollection AddLogging(this IServiceCollection services, IConfiguration config = null) { var describe = new ServiceDescriber(config); services.TryAdd(describe.Singleton()); @@ -26,12 +21,7 @@ namespace Microsoft.Framework.DependencyInjection return services; } - public static IServiceCollection AddHosting(this IServiceCollection services) - { - return services.AddHosting(configuration: null); - } - - public static IServiceCollection AddHosting(this IServiceCollection services, IConfiguration configuration) + public static IServiceCollection AddHosting(this IServiceCollection services, IConfiguration configuration = null) { var describer = new ServiceDescriber(configuration); diff --git a/src/Microsoft.AspNet.TestHost/TestServer.cs b/src/Microsoft.AspNet.TestHost/TestServer.cs index a5496170d1..54b908133e 100644 --- a/src/Microsoft.AspNet.TestHost/TestServer.cs +++ b/src/Microsoft.AspNet.TestHost/TestServer.cs @@ -2,7 +2,10 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.Collections.Generic; +using System.Linq; using System.Net.Http; +using System.Reflection; using System.Threading.Tasks; using Microsoft.AspNet.Builder; using Microsoft.AspNet.Hosting; @@ -46,22 +49,12 @@ namespace Microsoft.AspNet.TestHost public static TestServer Create(Action app) { - return Create(CallContextServiceLocator.Locator.ServiceProvider, app, configureHostServices: null); - } - - public static TestServer Create(Action app, Action configureHostServices) - { - return Create(CallContextServiceLocator.Locator.ServiceProvider, app, configureHostServices); + return Create(CallContextServiceLocator.Locator.ServiceProvider, app); } public static TestServer Create(IServiceProvider serviceProvider, Action app) { - return Create(serviceProvider, app, configureHostServices: null); - } - - public static TestServer Create(IServiceProvider serviceProvider, Action app, Action configureHostServices) - { - var appServices = HostingServices.Create(serviceProvider, configureHostServices).BuildServiceProvider(); + var appServices = HostingServices.Create(serviceProvider).BuildServiceProvider(); var config = new Configuration(); return new TestServer(config, appServices, app); } diff --git a/test/Microsoft.AspNet.Hosting.Tests/HostingServicesFacts.cs b/test/Microsoft.AspNet.Hosting.Tests/HostingServicesFacts.cs index 8cafaa90c6..5e6e733da8 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/HostingServicesFacts.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/HostingServicesFacts.cs @@ -53,73 +53,6 @@ namespace Microsoft.AspNet.Hosting.Tests Assert.Null(provider.GetService()); // Make sure we don't leak non manifest services } - [Fact] - public void CreateCanAddAdditionalServices() - { - // Arrange - var fallbackServices = new ServiceCollection(); - fallbackServices.AddTransient(); - fallbackServices.AddTransient(); // Don't register in manifest - - fallbackServices.AddInstance(new ServiceManifest( - new Type[] { - typeof(IFakeService), - })); - - var instance = new FakeService(); - var factoryInstance = new FakeFactoryService(instance); - - var services = HostingServices.Create(fallbackServices.BuildServiceProvider(), - additionalHostServices => - { - additionalHostServices.AddSingleton(); - additionalHostServices.AddInstance(instance); - additionalHostServices.AddSingleton(serviceProvider => factoryInstance); - }); - - // Act - var provider = services.BuildServiceProvider(); - var singleton = provider.GetRequiredService(); - var transient = provider.GetRequiredService(); - var factory = provider.GetRequiredService(); - var manifest = provider.GetRequiredService(); - - // Assert - Assert.Same(singleton, provider.GetRequiredService()); - Assert.NotSame(transient, provider.GetRequiredService()); - Assert.Same(instance, provider.GetRequiredService()); - Assert.Same(factoryInstance, factory); - Assert.Same(factory.FakeService, instance); - Assert.Null(provider.GetService()); - Assert.Null(provider.GetService()); // Make sure we don't leak non manifest services - Assert.Contains(typeof(IFakeSingletonService), manifest.Services); - Assert.Contains(typeof(IFakeServiceInstance), manifest.Services); - Assert.Contains(typeof(IFactoryService), manifest.Services); - } - - [Fact] - public void CreateAdditionalServicesDoNotOverrideFallback() - { - // Arrange - var fallbackServices = new ServiceCollection(); - fallbackServices.AddTransient(); - - fallbackServices.AddInstance(new ServiceManifest( - new Type[] { - typeof(IFakeService), - })); - - var services = HostingServices.Create(fallbackServices.BuildServiceProvider(), - additionalHostServices => additionalHostServices.AddSingleton()); - - // Act - var provider = services.BuildServiceProvider(); - var stillTransient = provider.GetRequiredService(); - - // Assert - Assert.NotSame(stillTransient, provider.GetRequiredService()); - } - [Fact] public void CanHideImportedServices() { diff --git a/test/Microsoft.AspNet.Hosting.Tests/UseRequestServicesFacts.cs b/test/Microsoft.AspNet.Hosting.Tests/UseRequestServicesFacts.cs index 74027b51fc..e247d4ec64 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/UseRequestServicesFacts.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/UseRequestServicesFacts.cs @@ -93,7 +93,6 @@ namespace Microsoft.AspNet.Hosting.Tests [InlineData(typeof(IApplicationLifetime))] [InlineData(typeof(ILoggerFactory))] [InlineData(typeof(IHttpContextAccessor))] - [InlineData(typeof(ILogger))] public void UseRequestServicesHostingImportedServicesAreDefined(Type service) { var baseServiceProvider = HostingServices.Create().BuildServiceProvider(); diff --git a/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs b/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs index 57d4ed290e..0a31db1b21 100644 --- a/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs +++ b/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs @@ -40,6 +40,7 @@ namespace Microsoft.AspNet.TestHost [Fact] public async Task CanAccessHttpContext() { + var services = new ServiceCollection().BuildServiceProvider(); TestServer server = TestServer.Create(app => { app.Run(context => @@ -53,35 +54,6 @@ namespace Microsoft.AspNet.TestHost Assert.Equal("HasContext:True", result); } - public class ContextHolder - { - public ContextHolder(IHttpContextAccessor accessor) - { - Accessor = accessor; - } - - public IHttpContextAccessor Accessor { get; set; } - } - - [Fact] - public async Task CanAddNewHostServices() - { - TestServer server = TestServer.Create(app => - { - var a = app.ApplicationServices.GetRequiredService(); - - app.Run(context => - { - var b = app.ApplicationServices.GetRequiredService(); - var accessor = app.ApplicationServices.GetRequiredService(); - return context.Response.WriteAsync("HasContext:" + (accessor.Accessor.Value != null)); - }); - }, newHostServices => newHostServices.AddSingleton()); - - string result = await server.CreateClient().GetStringAsync("/path"); - Assert.Equal("HasContext:True", result); - } - [Fact] public async Task CreateInvokesApp() { From 00864c1af4b854ef396794ea306e77c2a5ec9986 Mon Sep 17 00:00:00 2001 From: Praburaj Date: Wed, 25 Feb 2015 16:05:22 -0800 Subject: [PATCH 201/987] Hosting API review feedback # 1 Addresses: https://github.com/aspnet/Hosting/issues/164 https://github.com/aspnet/Hosting/issues/163 https://github.com/aspnet/Hosting/issues/155 https://github.com/aspnet/Hosting/issues/156 https://github.com/aspnet/Hosting/issues/154 --- .../ApplicationLifetime.cs | 4 +- .../HostingContext.cs | 5 +-- src/Microsoft.AspNet.Hosting/HostingEngine.cs | 34 +++++++++------ .../HostingServicesCollectionExtensions.cs | 5 +-- src/Microsoft.AspNet.Hosting/Program.cs | 7 ++-- .../{IServerManager.cs => IServerLoader.cs} | 4 +- .../{ServerManager.cs => ServerLoader.cs} | 6 +-- .../Startup/IStartupLoaderProvider.cs | 12 ------ .../Startup/IStartupManager.cs | 16 ------- .../Startup/NullStartupLoader.cs | 28 ------------- .../Startup/StartupLoader.cs | 12 ++---- .../Startup/StartupLoaderProvider.cs | 24 ----------- .../Startup/StartupManager.cs | 42 ------------------- src/Microsoft.AspNet.TestHost/TestServer.cs | 6 +-- .../HostingEngineTests.cs | 3 +- .../StartupManagerTests.cs | 30 +++++++------ .../UseRequestServicesFacts.cs | 6 +-- 17 files changed, 62 insertions(+), 182 deletions(-) rename src/Microsoft.AspNet.Hosting/Server/{IServerManager.cs => IServerLoader.cs} (71%) rename src/Microsoft.AspNet.Hosting/Server/{ServerManager.cs => ServerLoader.cs} (93%) delete mode 100644 src/Microsoft.AspNet.Hosting/Startup/IStartupLoaderProvider.cs delete mode 100644 src/Microsoft.AspNet.Hosting/Startup/IStartupManager.cs delete mode 100644 src/Microsoft.AspNet.Hosting/Startup/NullStartupLoader.cs delete mode 100644 src/Microsoft.AspNet.Hosting/Startup/StartupLoaderProvider.cs delete mode 100644 src/Microsoft.AspNet.Hosting/Startup/StartupManager.cs diff --git a/src/Microsoft.AspNet.Hosting/ApplicationLifetime.cs b/src/Microsoft.AspNet.Hosting/ApplicationLifetime.cs index d1db40def4..3d9fa53b8b 100644 --- a/src/Microsoft.AspNet.Hosting/ApplicationLifetime.cs +++ b/src/Microsoft.AspNet.Hosting/ApplicationLifetime.cs @@ -42,7 +42,7 @@ namespace Microsoft.AspNet.Hosting /// /// Signals the ApplicationStopping event and blocks until it completes. /// - public void SignalStopping() + public void NotifyStopping() { try { @@ -57,7 +57,7 @@ namespace Microsoft.AspNet.Hosting /// /// Signals the ApplicationStopped event and blocks until it completes. /// - public void SignalStopped() + public void NotifyStopped() { try { diff --git a/src/Microsoft.AspNet.Hosting/HostingContext.cs b/src/Microsoft.AspNet.Hosting/HostingContext.cs index e7ddd9b863..c3bcba3d26 100644 --- a/src/Microsoft.AspNet.Hosting/HostingContext.cs +++ b/src/Microsoft.AspNet.Hosting/HostingContext.cs @@ -3,7 +3,6 @@ using System; using Microsoft.AspNet.Builder; -using Microsoft.AspNet.Http; using Microsoft.AspNet.Hosting.Server; using Microsoft.Framework.ConfigurationModel; @@ -11,7 +10,7 @@ namespace Microsoft.AspNet.Hosting { public class HostingContext { - public IServiceProvider Services { get; set; } + public IApplicationLifetime ApplicationLifeTime { get; set; } public IConfiguration Configuration { get; set; } public IApplicationBuilder Builder { get; set; } @@ -21,7 +20,7 @@ namespace Microsoft.AspNet.Hosting public Action ApplicationStartup { get; set; } public RequestDelegate ApplicationDelegate { get; set; } - public string ServerName { get; set; } + public string ServerFactoryAssembly { get; set; } public IServerFactory ServerFactory { get; set; } public IServerInformation Server { get; set; } } diff --git a/src/Microsoft.AspNet.Hosting/HostingEngine.cs b/src/Microsoft.AspNet.Hosting/HostingEngine.cs index 83ef3a8d8e..7b86e8ce42 100644 --- a/src/Microsoft.AspNet.Hosting/HostingEngine.cs +++ b/src/Microsoft.AspNet.Hosting/HostingEngine.cs @@ -2,31 +2,32 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.Collections.Generic; +using System.Linq; using System.Threading; using Microsoft.AspNet.Hosting.Builder; using Microsoft.AspNet.Hosting.Server; using Microsoft.AspNet.Hosting.Startup; -using Microsoft.Framework.DependencyInjection; namespace Microsoft.AspNet.Hosting { public class HostingEngine : IHostingEngine { - private readonly IServerManager _serverManager; - private readonly IStartupManager _startupManager; + private readonly IServerLoader _serverManager; + private readonly IStartupLoader _startupLoader; private readonly IApplicationBuilderFactory _builderFactory; private readonly IHttpContextFactory _httpContextFactory; private readonly IHttpContextAccessor _contextAccessor; public HostingEngine( - IServerManager serverManager, - IStartupManager startupManager, + IServerLoader serverManager, + IStartupLoader startupLoader, IApplicationBuilderFactory builderFactory, IHttpContextFactory httpContextFactory, IHttpContextAccessor contextAccessor) { _serverManager = serverManager; - _startupManager = startupManager; + _startupLoader = startupLoader; _builderFactory = builderFactory; _httpContextFactory = httpContextFactory; _contextAccessor = contextAccessor; @@ -39,16 +40,16 @@ namespace Microsoft.AspNet.Hosting InitalizeServerFactory(context); EnsureApplicationDelegate(context); - var applicationLifetime = (ApplicationLifetime)context.Services.GetRequiredService(); + var applicationLifetime = (ApplicationLifetime)context.ApplicationLifeTime; var pipeline = new PipelineInstance(_httpContextFactory, context.ApplicationDelegate, _contextAccessor); var server = context.ServerFactory.Start(context.Server, pipeline.Invoke); - + return new Disposable(() => { - applicationLifetime.SignalStopping(); + applicationLifetime.NotifyStopping(); server.Dispose(); pipeline.Dispose(); - applicationLifetime.SignalStopped(); + applicationLifetime.NotifyStopped(); }); } @@ -69,7 +70,7 @@ namespace Microsoft.AspNet.Hosting return; } - context.ServerFactory = _serverManager.GetServerFactory(context.ServerName); + context.ServerFactory = _serverManager.LoadServerFactory(context.ServerFactoryAssembly); } private void InitalizeServerFactory(HostingContext context) @@ -105,9 +106,16 @@ namespace Microsoft.AspNet.Hosting return; } - context.ApplicationStartup = _startupManager.LoadStartup( + var diagnosticMessages = new List(); + context.ApplicationStartup = _startupLoader.LoadStartup( context.ApplicationName, - context.EnvironmentName); + context.EnvironmentName, + diagnosticMessages); + + if (context.ApplicationStartup == null) + { + throw new Exception(diagnosticMessages.Aggregate("TODO: web application entrypoint not found message", (a, b) => a + "\r\n" + b)); + } } private class Disposable : IDisposable diff --git a/src/Microsoft.AspNet.Hosting/HostingServicesCollectionExtensions.cs b/src/Microsoft.AspNet.Hosting/HostingServicesCollectionExtensions.cs index 8c52a6910d..1c698d3f49 100644 --- a/src/Microsoft.AspNet.Hosting/HostingServicesCollectionExtensions.cs +++ b/src/Microsoft.AspNet.Hosting/HostingServicesCollectionExtensions.cs @@ -26,10 +26,9 @@ namespace Microsoft.Framework.DependencyInjection var describer = new ServiceDescriber(configuration); services.TryAdd(describer.Transient()); - services.TryAdd(describer.Transient()); + services.TryAdd(describer.Transient()); - services.TryAdd(describer.Transient()); - services.TryAdd(describer.Transient()); + services.TryAdd(describer.Transient()); services.TryAdd(describer.Transient()); services.TryAdd(describer.Transient()); diff --git a/src/Microsoft.AspNet.Hosting/Program.cs b/src/Microsoft.AspNet.Hosting/Program.cs index 8376913626..96b1478529 100644 --- a/src/Microsoft.AspNet.Hosting/Program.cs +++ b/src/Microsoft.AspNet.Hosting/Program.cs @@ -24,8 +24,6 @@ namespace Microsoft.AspNet.Hosting _serviceProvider = serviceProvider; } - - public void Main(string[] args) { var config = new Configuration(); @@ -41,12 +39,13 @@ namespace Microsoft.AspNet.Hosting var appEnv = services.GetRequiredService(); var hostingEnv = services.GetRequiredService(); + var applicationLifeTime = services.GetRequiredService(); var context = new HostingContext() { - Services = services, + ApplicationLifeTime = applicationLifeTime, Configuration = config, - ServerName = config.Get("server"), // TODO: Key names + ServerFactoryAssembly = config.Get("server"), // TODO: Key names ApplicationName = config.Get("app") // TODO: Key names ?? appEnv.ApplicationName, EnvironmentName = hostingEnv.EnvironmentName, diff --git a/src/Microsoft.AspNet.Hosting/Server/IServerManager.cs b/src/Microsoft.AspNet.Hosting/Server/IServerLoader.cs similarity index 71% rename from src/Microsoft.AspNet.Hosting/Server/IServerManager.cs rename to src/Microsoft.AspNet.Hosting/Server/IServerLoader.cs index 92aa79dfd2..f0b91fcf8f 100644 --- a/src/Microsoft.AspNet.Hosting/Server/IServerManager.cs +++ b/src/Microsoft.AspNet.Hosting/Server/IServerLoader.cs @@ -3,8 +3,8 @@ namespace Microsoft.AspNet.Hosting.Server { - public interface IServerManager + public interface IServerLoader { - IServerFactory GetServerFactory(string serverName); + IServerFactory LoadServerFactory(string serverName); } } \ No newline at end of file diff --git a/src/Microsoft.AspNet.Hosting/Server/ServerManager.cs b/src/Microsoft.AspNet.Hosting/Server/ServerLoader.cs similarity index 93% rename from src/Microsoft.AspNet.Hosting/Server/ServerManager.cs rename to src/Microsoft.AspNet.Hosting/Server/ServerLoader.cs index d59cb979fc..9354eff0a8 100644 --- a/src/Microsoft.AspNet.Hosting/Server/ServerManager.cs +++ b/src/Microsoft.AspNet.Hosting/Server/ServerLoader.cs @@ -8,16 +8,16 @@ using Microsoft.Framework.DependencyInjection; namespace Microsoft.AspNet.Hosting.Server { - public class ServerManager : IServerManager + public class ServerLoader : IServerLoader { private readonly IServiceProvider _services; - public ServerManager(IServiceProvider services) + public ServerLoader(IServiceProvider services) { _services = services; } - public IServerFactory GetServerFactory(string serverFactoryIdentifier) + public IServerFactory LoadServerFactory(string serverFactoryIdentifier) { if (string.IsNullOrEmpty(serverFactoryIdentifier)) { diff --git a/src/Microsoft.AspNet.Hosting/Startup/IStartupLoaderProvider.cs b/src/Microsoft.AspNet.Hosting/Startup/IStartupLoaderProvider.cs deleted file mode 100644 index a134f501e5..0000000000 --- a/src/Microsoft.AspNet.Hosting/Startup/IStartupLoaderProvider.cs +++ /dev/null @@ -1,12 +0,0 @@ -// 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. - -namespace Microsoft.AspNet.Hosting.Startup -{ - public interface IStartupLoaderProvider - { - int Order { get; } - - IStartupLoader CreateStartupLoader(IStartupLoader next); - } -} \ No newline at end of file diff --git a/src/Microsoft.AspNet.Hosting/Startup/IStartupManager.cs b/src/Microsoft.AspNet.Hosting/Startup/IStartupManager.cs deleted file mode 100644 index 15932fb21b..0000000000 --- a/src/Microsoft.AspNet.Hosting/Startup/IStartupManager.cs +++ /dev/null @@ -1,16 +0,0 @@ -// 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 System; -using Microsoft.AspNet.Builder; -using Microsoft.AspNet.Http; - -namespace Microsoft.AspNet.Hosting.Startup -{ - public interface IStartupManager - { - Action LoadStartup( - string applicationName, - string environmentName); - } -} \ No newline at end of file diff --git a/src/Microsoft.AspNet.Hosting/Startup/NullStartupLoader.cs b/src/Microsoft.AspNet.Hosting/Startup/NullStartupLoader.cs deleted file mode 100644 index ae672d4598..0000000000 --- a/src/Microsoft.AspNet.Hosting/Startup/NullStartupLoader.cs +++ /dev/null @@ -1,28 +0,0 @@ -// 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 System; -using System.Collections.Generic; -using Microsoft.AspNet.Builder; -using Microsoft.AspNet.Http; - -namespace Microsoft.AspNet.Hosting.Startup -{ - public class NullStartupLoader : IStartupLoader - { - static NullStartupLoader() - { - Instance = new NullStartupLoader(); - } - - public static IStartupLoader Instance { get; private set; } - - public Action LoadStartup( - string applicationName, - string environmentName, - IList diagnosticMessages) - { - return null; - } - } -} \ No newline at end of file diff --git a/src/Microsoft.AspNet.Hosting/Startup/StartupLoader.cs b/src/Microsoft.AspNet.Hosting/Startup/StartupLoader.cs index a7e85283bf..2fb227d5f1 100644 --- a/src/Microsoft.AspNet.Hosting/Startup/StartupLoader.cs +++ b/src/Microsoft.AspNet.Hosting/Startup/StartupLoader.cs @@ -15,14 +15,10 @@ namespace Microsoft.AspNet.Hosting.Startup public class StartupLoader : IStartupLoader { private readonly IServiceProvider _services; - private readonly IStartupLoader _next; - public StartupLoader( - IServiceProvider services, - IStartupLoader next) + public StartupLoader(IServiceProvider services) { _services = services; - _next = next; } private MethodInfo FindMethod(Type startupType, string methodName, string environmentName, Type returnType = null, bool required = true) @@ -94,9 +90,9 @@ namespace Microsoft.AspNet.Hosting.Startup string environmentName, IList diagnosticMessages) { - if (String.IsNullOrEmpty(applicationName)) + if (string.IsNullOrEmpty(applicationName)) { - return _next.LoadStartup(applicationName, environmentName, diagnosticMessages); + throw new ArgumentNullException("applicationName"); } var assembly = Assembly.Load(new AssemblyName(applicationName)); @@ -156,7 +152,7 @@ namespace Microsoft.AspNet.Hosting.Startup { // IServiceProvider ConfigureServices(IServiceCollection) builder.ApplicationServices = (Invoke(servicesMethod, instance, builder, services) as IServiceProvider) - ?? builder.ApplicationServices; + ?? builder.ApplicationServices; } else { diff --git a/src/Microsoft.AspNet.Hosting/Startup/StartupLoaderProvider.cs b/src/Microsoft.AspNet.Hosting/Startup/StartupLoaderProvider.cs deleted file mode 100644 index 22cfe0872a..0000000000 --- a/src/Microsoft.AspNet.Hosting/Startup/StartupLoaderProvider.cs +++ /dev/null @@ -1,24 +0,0 @@ -// 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 System; - -namespace Microsoft.AspNet.Hosting.Startup -{ - public class StartupLoaderProvider : IStartupLoaderProvider - { - private readonly IServiceProvider _services; - - public StartupLoaderProvider(IServiceProvider services) - { - _services = services; - } - - public int Order { get { return -100; } } - - public IStartupLoader CreateStartupLoader(IStartupLoader next) - { - return new StartupLoader(_services, next); - } - } -} diff --git a/src/Microsoft.AspNet.Hosting/Startup/StartupManager.cs b/src/Microsoft.AspNet.Hosting/Startup/StartupManager.cs deleted file mode 100644 index 8f7249899f..0000000000 --- a/src/Microsoft.AspNet.Hosting/Startup/StartupManager.cs +++ /dev/null @@ -1,42 +0,0 @@ -// 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 System; -using System.Collections.Generic; -using System.Linq; -using Microsoft.AspNet.Builder; -using Microsoft.AspNet.Http; - -namespace Microsoft.AspNet.Hosting.Startup -{ - public class StartupManager : IStartupManager - { - private readonly IEnumerable _providers; - - public StartupManager(IEnumerable providers) - { - _providers = providers; - } - - public Action LoadStartup( - string applicationName, - string environmentName) - { - // build ordered chain of application loaders - var chain = _providers - .OrderBy(provider => provider.Order) - .Aggregate(NullStartupLoader.Instance, (next, provider) => provider.CreateStartupLoader(next)); - - // invoke chain to acquire application entrypoint and diagnostic messages - var diagnosticMessages = new List(); - var application = chain.LoadStartup(applicationName, environmentName, diagnosticMessages); - - if (application == null) - { - throw new Exception(diagnosticMessages.Aggregate("TODO: web application entrypoint not found message", (a, b) => a + "\r\n" + b)); - } - - return application; - } - } -} \ No newline at end of file diff --git a/src/Microsoft.AspNet.TestHost/TestServer.cs b/src/Microsoft.AspNet.TestHost/TestServer.cs index 54b908133e..6505344c2e 100644 --- a/src/Microsoft.AspNet.TestHost/TestServer.cs +++ b/src/Microsoft.AspNet.TestHost/TestServer.cs @@ -2,10 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using System.Collections.Generic; -using System.Linq; using System.Net.Http; -using System.Reflection; using System.Threading.Tasks; using Microsoft.AspNet.Builder; using Microsoft.AspNet.Hosting; @@ -31,13 +28,14 @@ namespace Microsoft.AspNet.TestHost public TestServer(IConfiguration config, IServiceProvider serviceProvider, Action appStartup) { var appEnv = serviceProvider.GetRequiredService(); + var applicationLifeTime = serviceProvider.GetRequiredService(); HostingContext hostContext = new HostingContext() { ApplicationName = appEnv.ApplicationName, + ApplicationLifeTime = applicationLifeTime, Configuration = config, ServerFactory = this, - Services = serviceProvider, ApplicationStartup = appStartup }; diff --git a/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs b/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs index 3c6d5c13b6..3784c49be0 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs @@ -34,11 +34,12 @@ namespace Microsoft.AspNet.Hosting var services = HostingServices.Create().BuildServiceProvider(); var engine = services.GetRequiredService(); + var applicationLifeTime = services.GetRequiredService(); var context = new HostingContext { + ApplicationLifeTime = applicationLifeTime, ServerFactory = this, - Services = services, ApplicationName = "Microsoft.AspNet.Hosting.Tests" }; diff --git a/test/Microsoft.AspNet.Hosting.Tests/StartupManagerTests.cs b/test/Microsoft.AspNet.Hosting.Tests/StartupManagerTests.cs index f3323b978a..43e9c13eee 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/StartupManagerTests.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/StartupManagerTests.cs @@ -25,9 +25,10 @@ namespace Microsoft.AspNet.Hosting.Tests serviceCollection.AddInstance(this); var services = serviceCollection.BuildServiceProvider(); - var manager = services.GetRequiredService(); + var loader = services.GetRequiredService(); - var startup = manager.LoadStartup("Microsoft.AspNet.Hosting.Tests", "WithServices"); + var diagnosticMessages = new List(); + var startup = loader.LoadStartup("Microsoft.AspNet.Hosting.Tests", "WithServices", diagnosticMessages); startup.Invoke(new ApplicationBuilder(services)); @@ -45,9 +46,10 @@ namespace Microsoft.AspNet.Hosting.Tests public void StartupClassAddsConfigureServicesToApplicationServices(string environment) { var services = HostingServices.Create().BuildServiceProvider(); - var manager = services.GetRequiredService(); + var loader = services.GetRequiredService(); + var diagnosticMesssages = new List(); - var startup = manager.LoadStartup("Microsoft.AspNet.Hosting.Tests", environment ?? ""); + var startup = loader.LoadStartup("Microsoft.AspNet.Hosting.Tests", environment ?? "", diagnosticMesssages); var app = new ApplicationBuilder(services); @@ -65,9 +67,10 @@ namespace Microsoft.AspNet.Hosting.Tests public void StartupClassConfigureServicesThatFallsbackToApplicationServices(string env) { var services = HostingServices.Create().BuildServiceProvider(); - var manager = services.GetRequiredService(); + var loader = services.GetRequiredService(); + var diagnosticMessages = new List(); - var startup = manager.LoadStartup("Microsoft.AspNet.Hosting.Tests", env); + var startup = loader.LoadStartup("Microsoft.AspNet.Hosting.Tests", env, diagnosticMessages); var app = new ApplicationBuilder(services); @@ -82,9 +85,10 @@ namespace Microsoft.AspNet.Hosting.Tests public void StartupClassWithConfigureServicesAndUseServicesHidesConfigureServices() { var services = HostingServices.Create().BuildServiceProvider(); - var manager = services.GetRequiredService(); + var loader = services.GetRequiredService(); + var diagnosticMessages = new List(); - var startup = manager.LoadStartup("Microsoft.AspNet.Hosting.Tests", "UseServices"); + var startup = loader.LoadStartup("Microsoft.AspNet.Hosting.Tests", "UseServices", diagnosticMessages); var app = new ApplicationBuilder(services); @@ -105,9 +109,10 @@ namespace Microsoft.AspNet.Hosting.Tests var serviceCollection = HostingServices.Create(); serviceCollection.AddInstance(this); var services = serviceCollection.BuildServiceProvider(); - var manager = services.GetRequiredService(); + var loader = services.GetRequiredService(); + var diagnosticMessages = new List(); - var ex = Assert.Throws(() => manager.LoadStartup("Microsoft.AspNet.Hosting.Tests", "Boom")); + var ex = Assert.Throws(() => loader.LoadStartup("Microsoft.AspNet.Hosting.Tests", "Boom", diagnosticMessages)); Assert.True(ex.Message.Contains("ConfigureBoom or Configure method not found")); } @@ -116,11 +121,12 @@ namespace Microsoft.AspNet.Hosting.Tests { var serviceCollection = HostingServices.Create(); var services = serviceCollection.BuildServiceProvider(); - var manager = services.GetRequiredService(); + var loader = services.GetRequiredService(); var app = new ApplicationBuilder(services); - var startup = manager.LoadStartup("Microsoft.AspNet.Hosting.Tests", "WithConfigureServices"); + var diagnosticMessages = new List(); + var startup = loader.LoadStartup("Microsoft.AspNet.Hosting.Tests", "WithConfigureServices", diagnosticMessages); startup.Invoke(app); diff --git a/test/Microsoft.AspNet.Hosting.Tests/UseRequestServicesFacts.cs b/test/Microsoft.AspNet.Hosting.Tests/UseRequestServicesFacts.cs index e247d4ec64..44cd34f8f9 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/UseRequestServicesFacts.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/UseRequestServicesFacts.cs @@ -5,7 +5,6 @@ using System; using Microsoft.AspNet.Builder; using Microsoft.AspNet.Hosting.Builder; using Microsoft.AspNet.Hosting.Server; -using Microsoft.AspNet.Hosting.Startup; using Microsoft.AspNet.Http.Core; using Microsoft.AspNet.RequestContainer; using Microsoft.Framework.DependencyInjection; @@ -83,11 +82,8 @@ namespace Microsoft.AspNet.Hosting.Tests [Theory] [InlineData(typeof(IHostingEngine))] - [InlineData(typeof(IServerManager))] - [InlineData(typeof(IStartupManager))] - [InlineData(typeof(IStartupLoaderProvider))] + [InlineData(typeof(IServerLoader))] [InlineData(typeof(IApplicationBuilderFactory))] - [InlineData(typeof(IStartupLoaderProvider))] [InlineData(typeof(IHttpContextFactory))] [InlineData(typeof(ITypeActivator))] [InlineData(typeof(IApplicationLifetime))] From a2eec4f863bc6d5c3bad43a483ac0041b2b98cb5 Mon Sep 17 00:00:00 2001 From: Praburaj Date: Wed, 25 Feb 2015 17:48:46 -0800 Subject: [PATCH 202/987] 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; } From 435215b542586f2ab2f2a34df8e89b5bc7e52873 Mon Sep 17 00:00:00 2001 From: Praburaj Date: Thu, 26 Feb 2015 10:38:39 -0800 Subject: [PATCH 203/987] PR comments --- .../Builder/HttpContextFactory.cs | 4 +--- src/Microsoft.AspNet.Hosting/HostingContext.cs | 4 ++-- src/Microsoft.AspNet.Hosting/HostingEngine.cs | 8 +++++--- src/Microsoft.AspNet.Hosting/Program.cs | 6 +++--- src/Microsoft.AspNet.Hosting/Startup/StartupLoader.cs | 2 +- src/Microsoft.AspNet.TestHost/TestServer.cs | 4 ++-- test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs | 4 ++-- 7 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/Microsoft.AspNet.Hosting/Builder/HttpContextFactory.cs b/src/Microsoft.AspNet.Hosting/Builder/HttpContextFactory.cs index 9c03e2fcb1..8089252955 100644 --- a/src/Microsoft.AspNet.Hosting/Builder/HttpContextFactory.cs +++ b/src/Microsoft.AspNet.Hosting/Builder/HttpContextFactory.cs @@ -11,9 +11,7 @@ namespace Microsoft.AspNet.Hosting.Builder { public HttpContext CreateHttpContext(IFeatureCollection featureCollection) { - var featureObject = featureCollection ?? new FeatureObject(null); - var httpContext = new DefaultHttpContext(new FeatureCollection(featureObject)); - return httpContext; + return new DefaultHttpContext(featureCollection); } } } \ No newline at end of file diff --git a/src/Microsoft.AspNet.Hosting/HostingContext.cs b/src/Microsoft.AspNet.Hosting/HostingContext.cs index c3bcba3d26..f5dd096850 100644 --- a/src/Microsoft.AspNet.Hosting/HostingContext.cs +++ b/src/Microsoft.AspNet.Hosting/HostingContext.cs @@ -10,7 +10,7 @@ namespace Microsoft.AspNet.Hosting { public class HostingContext { - public IApplicationLifetime ApplicationLifeTime { get; set; } + public IApplicationLifetime ApplicationLifetime { get; set; } public IConfiguration Configuration { get; set; } public IApplicationBuilder Builder { get; set; } @@ -20,7 +20,7 @@ namespace Microsoft.AspNet.Hosting public Action ApplicationStartup { get; set; } public RequestDelegate ApplicationDelegate { get; set; } - public string ServerFactoryAssembly { get; set; } + public string ServerFactoryLocation { get; set; } public IServerFactory ServerFactory { get; set; } public IServerInformation Server { get; set; } } diff --git a/src/Microsoft.AspNet.Hosting/HostingEngine.cs b/src/Microsoft.AspNet.Hosting/HostingEngine.cs index 7b86e8ce42..930b5d1851 100644 --- a/src/Microsoft.AspNet.Hosting/HostingEngine.cs +++ b/src/Microsoft.AspNet.Hosting/HostingEngine.cs @@ -40,7 +40,7 @@ namespace Microsoft.AspNet.Hosting InitalizeServerFactory(context); EnsureApplicationDelegate(context); - var applicationLifetime = (ApplicationLifetime)context.ApplicationLifeTime; + var applicationLifetime = (ApplicationLifetime)context.ApplicationLifetime; var pipeline = new PipelineInstance(_httpContextFactory, context.ApplicationDelegate, _contextAccessor); var server = context.ServerFactory.Start(context.Server, pipeline.Invoke); @@ -70,7 +70,7 @@ namespace Microsoft.AspNet.Hosting return; } - context.ServerFactory = _serverManager.LoadServerFactory(context.ServerFactoryAssembly); + context.ServerFactory = _serverManager.LoadServerFactory(context.ServerFactoryLocation); } private void InitalizeServerFactory(HostingContext context) @@ -114,7 +114,9 @@ namespace Microsoft.AspNet.Hosting if (context.ApplicationStartup == null) { - throw new Exception(diagnosticMessages.Aggregate("TODO: web application entrypoint not found message", (a, b) => a + "\r\n" + b)); + throw new ArgumentException( + diagnosticMessages.Aggregate("Failed to find an entry point for the web application.", (a, b) => a + "\r\n" + b), + nameof(context)); } } diff --git a/src/Microsoft.AspNet.Hosting/Program.cs b/src/Microsoft.AspNet.Hosting/Program.cs index 96b1478529..db44580208 100644 --- a/src/Microsoft.AspNet.Hosting/Program.cs +++ b/src/Microsoft.AspNet.Hosting/Program.cs @@ -39,13 +39,13 @@ namespace Microsoft.AspNet.Hosting var appEnv = services.GetRequiredService(); var hostingEnv = services.GetRequiredService(); - var applicationLifeTime = services.GetRequiredService(); + var applicationLifetime = services.GetRequiredService(); var context = new HostingContext() { - ApplicationLifeTime = applicationLifeTime, + ApplicationLifetime = applicationLifetime, Configuration = config, - ServerFactoryAssembly = config.Get("server"), // TODO: Key names + ServerFactoryLocation = config.Get("server"), // TODO: Key names ApplicationName = config.Get("app") // TODO: Key names ?? appEnv.ApplicationName, EnvironmentName = hostingEnv.EnvironmentName, diff --git a/src/Microsoft.AspNet.Hosting/Startup/StartupLoader.cs b/src/Microsoft.AspNet.Hosting/Startup/StartupLoader.cs index 2fb227d5f1..e162cc07d5 100644 --- a/src/Microsoft.AspNet.Hosting/Startup/StartupLoader.cs +++ b/src/Microsoft.AspNet.Hosting/Startup/StartupLoader.cs @@ -92,7 +92,7 @@ namespace Microsoft.AspNet.Hosting.Startup { if (string.IsNullOrEmpty(applicationName)) { - throw new ArgumentNullException("applicationName"); + throw new ArgumentException("applicationName"); } var assembly = Assembly.Load(new AssemblyName(applicationName)); diff --git a/src/Microsoft.AspNet.TestHost/TestServer.cs b/src/Microsoft.AspNet.TestHost/TestServer.cs index ef7c53c2d1..a626723572 100644 --- a/src/Microsoft.AspNet.TestHost/TestServer.cs +++ b/src/Microsoft.AspNet.TestHost/TestServer.cs @@ -29,12 +29,12 @@ namespace Microsoft.AspNet.TestHost public TestServer(IConfiguration config, IServiceProvider serviceProvider, Action appStartup) { var appEnv = serviceProvider.GetRequiredService(); - var applicationLifeTime = serviceProvider.GetRequiredService(); + var applicationLifetime = serviceProvider.GetRequiredService(); HostingContext hostContext = new HostingContext() { ApplicationName = appEnv.ApplicationName, - ApplicationLifeTime = applicationLifeTime, + ApplicationLifetime = applicationLifetime, Configuration = config, ServerFactory = this, ApplicationStartup = appStartup diff --git a/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs b/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs index e8395c649f..2af5628080 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs @@ -35,11 +35,11 @@ namespace Microsoft.AspNet.Hosting var services = HostingServices.Create().BuildServiceProvider(); var engine = services.GetRequiredService(); - var applicationLifeTime = services.GetRequiredService(); + var applicationLifetime = services.GetRequiredService(); var context = new HostingContext { - ApplicationLifeTime = applicationLifeTime, + ApplicationLifetime = applicationLifetime, ServerFactory = this, ApplicationName = "Microsoft.AspNet.Hosting.Tests" }; From 6bf5eabd9f862b1052743268f3fb576908d674b9 Mon Sep 17 00:00:00 2001 From: Praburaj Date: Fri, 27 Feb 2015 11:29:38 -0800 Subject: [PATCH 204/987] Hosting API review # 2 1. Moving HostingUtilities and PipelineInstance into internal namespaces. 2. Renaming some properties in IHostingEnvironment 3. Renaming IHttpContextAccessor HttpContext into Value. Addresses: https://github.com/aspnet/Hosting/issues/159 https://github.com/aspnet/Hosting/issues/157 https://github.com/aspnet/Hosting/issues/161 --- .../IHostingEnvironment.cs | 4 ++-- src/Microsoft.AspNet.Hosting/HostingEngine.cs | 1 + src/Microsoft.AspNet.Hosting/HostingEnvironment.cs | 9 +++++---- .../{ => Internal}/HostingUtilities.cs | 2 +- .../{ => Internal}/PipelineInstance.cs | 2 +- src/Microsoft.AspNet.Hosting/Server/ServerLoader.cs | 1 + src/Microsoft.AspNet.Hosting/Startup/StartupLoader.cs | 2 +- .../Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs | 2 +- .../HostingUtilitiesTests.cs | 1 + test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs | 2 +- 10 files changed, 15 insertions(+), 11 deletions(-) rename src/Microsoft.AspNet.Hosting/{ => Internal}/HostingUtilities.cs (97%) rename src/Microsoft.AspNet.Hosting/{ => Internal}/PipelineInstance.cs (96%) diff --git a/src/Microsoft.AspNet.Hosting.Interfaces/IHostingEnvironment.cs b/src/Microsoft.AspNet.Hosting.Interfaces/IHostingEnvironment.cs index c946e5d3ff..c38028a604 100644 --- a/src/Microsoft.AspNet.Hosting.Interfaces/IHostingEnvironment.cs +++ b/src/Microsoft.AspNet.Hosting.Interfaces/IHostingEnvironment.cs @@ -9,8 +9,8 @@ namespace Microsoft.AspNet.Hosting { string EnvironmentName { get; set; } - string WebRoot { get; } + string WebRootPath { get; } - IFileProvider WebRootFileProvider { get; set; } + IFileProvider WebRootFileProvider { get; } } } \ No newline at end of file diff --git a/src/Microsoft.AspNet.Hosting/HostingEngine.cs b/src/Microsoft.AspNet.Hosting/HostingEngine.cs index 930b5d1851..1970e48bef 100644 --- a/src/Microsoft.AspNet.Hosting/HostingEngine.cs +++ b/src/Microsoft.AspNet.Hosting/HostingEngine.cs @@ -6,6 +6,7 @@ using System.Collections.Generic; using System.Linq; using System.Threading; using Microsoft.AspNet.Hosting.Builder; +using Microsoft.AspNet.Hosting.Internal; using Microsoft.AspNet.Hosting.Server; using Microsoft.AspNet.Hosting.Startup; diff --git a/src/Microsoft.AspNet.Hosting/HostingEnvironment.cs b/src/Microsoft.AspNet.Hosting/HostingEnvironment.cs index 47d805f99b..03a7317453 100644 --- a/src/Microsoft.AspNet.Hosting/HostingEnvironment.cs +++ b/src/Microsoft.AspNet.Hosting/HostingEnvironment.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using Microsoft.AspNet.FileProviders; +using Microsoft.AspNet.Hosting.Internal; using Microsoft.Framework.Runtime; namespace Microsoft.AspNet.Hosting @@ -14,8 +15,8 @@ namespace Microsoft.AspNet.Hosting public HostingEnvironment(IApplicationEnvironment appEnvironment, IEnumerable configures) { EnvironmentName = DefaultEnvironmentName; - WebRoot = HostingUtilities.GetWebRoot(appEnvironment.ApplicationBasePath); - WebRootFileProvider = new PhysicalFileProvider(WebRoot); + WebRootPath = HostingUtilities.GetWebRoot(appEnvironment.ApplicationBasePath); + WebRootFileProvider = new PhysicalFileProvider(WebRootPath); foreach (var configure in configures) { configure.Configure(this); @@ -24,8 +25,8 @@ namespace Microsoft.AspNet.Hosting public string EnvironmentName { get; set; } - public string WebRoot { get; private set; } + public string WebRootPath { get; private set; } - public IFileProvider WebRootFileProvider { get; set; } + public IFileProvider WebRootFileProvider { get; private set; } } } \ No newline at end of file diff --git a/src/Microsoft.AspNet.Hosting/HostingUtilities.cs b/src/Microsoft.AspNet.Hosting/Internal/HostingUtilities.cs similarity index 97% rename from src/Microsoft.AspNet.Hosting/HostingUtilities.cs rename to src/Microsoft.AspNet.Hosting/Internal/HostingUtilities.cs index 5b90b251a2..7b48d72b8f 100644 --- a/src/Microsoft.AspNet.Hosting/HostingUtilities.cs +++ b/src/Microsoft.AspNet.Hosting/Internal/HostingUtilities.cs @@ -6,7 +6,7 @@ using System.IO; using Newtonsoft.Json; using Newtonsoft.Json.Linq; -namespace Microsoft.AspNet.Hosting +namespace Microsoft.AspNet.Hosting.Internal { public static class HostingUtilities { diff --git a/src/Microsoft.AspNet.Hosting/PipelineInstance.cs b/src/Microsoft.AspNet.Hosting/Internal/PipelineInstance.cs similarity index 96% rename from src/Microsoft.AspNet.Hosting/PipelineInstance.cs rename to src/Microsoft.AspNet.Hosting/Internal/PipelineInstance.cs index 3d14ee404c..9b8a84ca4b 100644 --- a/src/Microsoft.AspNet.Hosting/PipelineInstance.cs +++ b/src/Microsoft.AspNet.Hosting/Internal/PipelineInstance.cs @@ -7,7 +7,7 @@ using Microsoft.AspNet.Builder; using Microsoft.AspNet.FeatureModel; using Microsoft.AspNet.Hosting.Builder; -namespace Microsoft.AspNet.Hosting +namespace Microsoft.AspNet.Hosting.Internal { public class PipelineInstance : IDisposable { diff --git a/src/Microsoft.AspNet.Hosting/Server/ServerLoader.cs b/src/Microsoft.AspNet.Hosting/Server/ServerLoader.cs index 9354eff0a8..a11f8011e5 100644 --- a/src/Microsoft.AspNet.Hosting/Server/ServerLoader.cs +++ b/src/Microsoft.AspNet.Hosting/Server/ServerLoader.cs @@ -4,6 +4,7 @@ using System; using System.Linq; using System.Reflection; +using Microsoft.AspNet.Hosting.Internal; using Microsoft.Framework.DependencyInjection; namespace Microsoft.AspNet.Hosting.Server diff --git a/src/Microsoft.AspNet.Hosting/Startup/StartupLoader.cs b/src/Microsoft.AspNet.Hosting/Startup/StartupLoader.cs index f95de3279a..165e5a7da4 100644 --- a/src/Microsoft.AspNet.Hosting/Startup/StartupLoader.cs +++ b/src/Microsoft.AspNet.Hosting/Startup/StartupLoader.cs @@ -92,7 +92,7 @@ namespace Microsoft.AspNet.Hosting.Startup { if (string.IsNullOrEmpty(applicationName)) { - throw new ArgumentException("applicationName"); + throw new ArgumentException("Value cannot be null or empty.", "applicationName"); } var assembly = Assembly.Load(new AssemblyName(applicationName)); diff --git a/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs b/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs index 2af5628080..99be47cbf7 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs @@ -60,7 +60,7 @@ namespace Microsoft.AspNet.Hosting { var services = HostingServices.Create().BuildServiceProvider(); var env = services.GetRequiredService(); - Assert.Equal(Path.GetFullPath("testroot"), env.WebRoot); + Assert.Equal(Path.GetFullPath("testroot"), env.WebRootPath); Assert.True(env.WebRootFileProvider.GetFileInfo("TextFile.txt").Exists); } diff --git a/test/Microsoft.AspNet.Hosting.Tests/HostingUtilitiesTests.cs b/test/Microsoft.AspNet.Hosting.Tests/HostingUtilitiesTests.cs index 08daee6c9b..06cf95333b 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/HostingUtilitiesTests.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/HostingUtilitiesTests.cs @@ -1,6 +1,7 @@ // 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.Hosting.Internal; using Xunit; namespace Microsoft.AspNet.Hosting.Tests diff --git a/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs b/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs index 0a31db1b21..8d52493b27 100644 --- a/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs +++ b/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs @@ -75,7 +75,7 @@ namespace Microsoft.AspNet.TestHost TestServer server = TestServer.Create(app => { var env = app.ApplicationServices.GetRequiredService(); - Assert.Equal(Directory.GetCurrentDirectory(), env.WebRoot); + Assert.Equal(Directory.GetCurrentDirectory(), env.WebRootPath); }); } From 16c8d51d0b2cf0b35342b430fd77392eb59cbc9a Mon Sep 17 00:00:00 2001 From: Eilon Lipton Date: Sun, 1 Mar 2015 22:55:27 -0800 Subject: [PATCH 205/987] Fixes #76 - improve error messages in Hosting Removed the TODOs from messages, and generally made them more readable. --- src/Microsoft.AspNet.Hosting/Program.cs | 2 +- .../Server/ServerLoader.cs | 8 ++-- .../Startup/StartupLoader.cs | 42 ++++++++++--------- ...StartupWithConfigureServicesNotResolved.cs | 18 ++++++++ .../StartupManagerTests.cs | 20 ++++++++- 5 files changed, 65 insertions(+), 25 deletions(-) create mode 100644 test/Microsoft.AspNet.Hosting.Tests/Fakes/StartupWithConfigureServicesNotResolved.cs diff --git a/src/Microsoft.AspNet.Hosting/Program.cs b/src/Microsoft.AspNet.Hosting/Program.cs index db44580208..d050fbf10c 100644 --- a/src/Microsoft.AspNet.Hosting/Program.cs +++ b/src/Microsoft.AspNet.Hosting/Program.cs @@ -67,7 +67,7 @@ namespace Microsoft.AspNet.Hosting catch (Exception ex) { var logger = loggerFactory.Create(); - logger.WriteError("TODO: Dispose threw an exception", ex); + logger.WriteError("Dispose threw an exception.", ex); } shutdownHandle.Set(); }); diff --git a/src/Microsoft.AspNet.Hosting/Server/ServerLoader.cs b/src/Microsoft.AspNet.Hosting/Server/ServerLoader.cs index a11f8011e5..fd7c9a41ea 100644 --- a/src/Microsoft.AspNet.Hosting/Server/ServerLoader.cs +++ b/src/Microsoft.AspNet.Hosting/Server/ServerLoader.cs @@ -32,7 +32,7 @@ namespace Microsoft.AspNet.Hosting.Server var assembly = Assembly.Load(new AssemblyName(assemblyName)); if (assembly == null) { - throw new Exception(String.Format("TODO: assembly {0} failed to load message", assemblyName)); + throw new Exception(string.Format("The assembly {0} failed to load.", assemblyName)); } Type type = null; @@ -50,7 +50,7 @@ namespace Microsoft.AspNet.Hosting.Server if (type == null) { - throw new Exception(String.Format("TODO: type {0} failed to load message", typeName ?? "")); + throw new Exception(string.Format("The type {0} failed to load.", typeName ?? "")); } } else @@ -59,14 +59,14 @@ namespace Microsoft.AspNet.Hosting.Server if (type == null) { - throw new Exception(String.Format("TODO: type {0} failed to load message", typeName ?? "")); + throw new Exception(String.Format("The type {0} failed to load.", typeName ?? "")); } interfaceInfo = type.GetTypeInfo().ImplementedInterfaces.FirstOrDefault(interf => interf.Equals(typeof(IServerFactory))); if (interfaceInfo == null) { - throw new Exception("TODO: IServerFactory interface not found"); + throw new Exception(string.Format("The type '{0}' does not implement the '{1}' interface.", type, typeof(IServerFactory).FullName)); } } diff --git a/src/Microsoft.AspNet.Hosting/Startup/StartupLoader.cs b/src/Microsoft.AspNet.Hosting/Startup/StartupLoader.cs index 165e5a7da4..ba6c013f12 100644 --- a/src/Microsoft.AspNet.Hosting/Startup/StartupLoader.cs +++ b/src/Microsoft.AspNet.Hosting/Startup/StartupLoader.cs @@ -31,9 +31,10 @@ namespace Microsoft.AspNet.Hosting.Startup { if (required) { - throw new Exception(string.Format("TODO: {0} or {1} method not found", + throw new Exception(string.Format("A method named '{0}' or '{1}' in the type '{2}' could not be found.", methodNameWithEnv, - methodNameWithNoEnv)); + methodNameWithNoEnv, + startupType.FullName)); } return null; @@ -42,8 +43,10 @@ namespace Microsoft.AspNet.Hosting.Startup { if (required) { - throw new Exception(string.Format("TODO: {0} method does not return " + returnType.Name, - methodInfo.Name)); + throw new Exception(string.Format("The '{0}' method in the type '{1}' must have a return type of '{2}'.", + methodInfo.Name, + startupType.FullName, + returnType.Name)); } return null; } @@ -75,10 +78,11 @@ namespace Microsoft.AspNet.Hosting.Startup catch (Exception) { throw new Exception(string.Format( - "TODO: Unable to resolve service for {0} method {1} {2}", - methodInfo.Name, + "Could not resolve a service of type '{0}' for the parameter '{1}' of method '{2}' on type '{3}'.", + parameterInfo.ParameterType.FullName, parameterInfo.Name, - parameterInfo.ParameterType.FullName)); + methodInfo.Name, + methodInfo.DeclaringType.FullName)); } } } @@ -98,26 +102,26 @@ namespace Microsoft.AspNet.Hosting.Startup var assembly = Assembly.Load(new AssemblyName(applicationName)); if (assembly == null) { - throw new Exception(String.Format("TODO: assembly {0} failed to load message", applicationName)); + throw new Exception(String.Format("The assembly '{0}' failed to load.", applicationName)); } - var startupName1 = "Startup" + environmentName; - var startupName2 = "Startup"; + var startupNameWithEnv = "Startup" + environmentName; + var startupNameWithoutEnv = "Startup"; // Check the most likely places first var type = - assembly.GetType(startupName1) ?? - assembly.GetType(applicationName + "." + startupName1) ?? - assembly.GetType(startupName2) ?? - assembly.GetType(applicationName + "." + startupName2); + assembly.GetType(startupNameWithEnv) ?? + assembly.GetType(applicationName + "." + startupNameWithEnv) ?? + assembly.GetType(startupNameWithoutEnv) ?? + assembly.GetType(applicationName + "." + startupNameWithoutEnv); if (type == null) { // Full scan var definedTypes = assembly.DefinedTypes.ToList(); - var startupType1 = definedTypes.Where(info => info.Name.Equals(startupName1, StringComparison.Ordinal)); - var startupType2 = definedTypes.Where(info => info.Name.Equals(startupName2, StringComparison.Ordinal)); + var startupType1 = definedTypes.Where(info => info.Name.Equals(startupNameWithEnv, StringComparison.Ordinal)); + var startupType2 = definedTypes.Where(info => info.Name.Equals(startupNameWithoutEnv, StringComparison.Ordinal)); var typeInfo = startupType1.Concat(startupType2).FirstOrDefault(); if (typeInfo != null) @@ -128,9 +132,9 @@ namespace Microsoft.AspNet.Hosting.Startup if (type == null) { - throw new Exception(String.Format("TODO: {0} or {1} class not found in assembly {2}", - startupName1, - startupName2, + throw new Exception(String.Format("A type named '{0}' or '{1}' could not be found in assembly '{2}'.", + startupNameWithEnv, + startupNameWithoutEnv, applicationName)); } diff --git a/test/Microsoft.AspNet.Hosting.Tests/Fakes/StartupWithConfigureServicesNotResolved.cs b/test/Microsoft.AspNet.Hosting.Tests/Fakes/StartupWithConfigureServicesNotResolved.cs new file mode 100644 index 0000000000..8679e62093 --- /dev/null +++ b/test/Microsoft.AspNet.Hosting.Tests/Fakes/StartupWithConfigureServicesNotResolved.cs @@ -0,0 +1,18 @@ +// 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.Builder; + +namespace Microsoft.AspNet.Hosting.Fakes +{ + public class StartupWithConfigureServicesNotResolved + { + public StartupWithConfigureServicesNotResolved() + { + } + + public void Configure(IApplicationBuilder builder, int notAService) + { + } + } +} diff --git a/test/Microsoft.AspNet.Hosting.Tests/StartupManagerTests.cs b/test/Microsoft.AspNet.Hosting.Tests/StartupManagerTests.cs index 188333960a..db19ddc403 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/StartupManagerTests.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/StartupManagerTests.cs @@ -114,7 +114,25 @@ namespace Microsoft.AspNet.Hosting.Tests var diagnosticMessages = new List(); var ex = Assert.Throws(() => loader.LoadStartup("Microsoft.AspNet.Hosting.Tests", "Boom", diagnosticMessages)); - Assert.True(ex.Message.Contains("ConfigureBoom or Configure method not found")); + Assert.Equal("A method named 'ConfigureBoom' or 'Configure' in the type 'Microsoft.AspNet.Hosting.Fakes.StartupBoom' could not be found.", ex.Message); + } + + [Fact] + public void StartupWithConfigureServicesNotResolvedThrows() + { + var serviceCollection = HostingServices.Create(); + var services = serviceCollection.BuildServiceProvider(); + var loader = services.GetRequiredService(); + var diagnosticMessages = new List(); + + var startup = loader.LoadStartup("Microsoft.AspNet.Hosting.Tests", "WithConfigureServicesNotResolved", diagnosticMessages); + + + var app = new ApplicationBuilder(services); + + var ex = Assert.Throws(() => startup.Invoke(app)); + + Assert.Equal("Could not resolve a service of type 'System.Int32' for the parameter 'notAService' of method 'Configure' on type 'Microsoft.AspNet.Hosting.Fakes.StartupWithConfigureServicesNotResolved'.", ex.Message); } [Fact] From d6535eeba0511723ed484e91ab985769845d841e Mon Sep 17 00:00:00 2001 From: Praburaj Date: Mon, 2 Mar 2015 10:38:37 -0800 Subject: [PATCH 206/987] Rename IHttpContextAccessor.Value to IHttpContextAccessor.HttpContext Fixes: https://github.com/aspnet/Hosting/issues/160 --- src/Microsoft.AspNet.Hosting/HttpContextAccessor.cs | 4 ++-- src/Microsoft.AspNet.Hosting/IHttpContextAccessor.cs | 2 +- src/Microsoft.AspNet.Hosting/Internal/PipelineInstance.cs | 2 +- test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Microsoft.AspNet.Hosting/HttpContextAccessor.cs b/src/Microsoft.AspNet.Hosting/HttpContextAccessor.cs index 4507d384cf..59b5cbd8fa 100644 --- a/src/Microsoft.AspNet.Hosting/HttpContextAccessor.cs +++ b/src/Microsoft.AspNet.Hosting/HttpContextAccessor.cs @@ -17,7 +17,7 @@ namespace Microsoft.AspNet.Hosting #if ASPNET50 private const string LogicalDataKey = "__HttpContext_Current__"; - public HttpContext Value + public HttpContext HttpContext { get { @@ -32,7 +32,7 @@ namespace Microsoft.AspNet.Hosting #elif ASPNETCORE50 private AsyncLocal _httpContextCurrent = new AsyncLocal(); - public HttpContext Value + public HttpContext HttpContext { get { diff --git a/src/Microsoft.AspNet.Hosting/IHttpContextAccessor.cs b/src/Microsoft.AspNet.Hosting/IHttpContextAccessor.cs index 563808d7f8..8b1719880b 100644 --- a/src/Microsoft.AspNet.Hosting/IHttpContextAccessor.cs +++ b/src/Microsoft.AspNet.Hosting/IHttpContextAccessor.cs @@ -7,6 +7,6 @@ namespace Microsoft.AspNet.Hosting { public interface IHttpContextAccessor { - HttpContext Value { get; set; } + HttpContext HttpContext { get; set; } } } \ No newline at end of file diff --git a/src/Microsoft.AspNet.Hosting/Internal/PipelineInstance.cs b/src/Microsoft.AspNet.Hosting/Internal/PipelineInstance.cs index 9b8a84ca4b..b2f67c2eca 100644 --- a/src/Microsoft.AspNet.Hosting/Internal/PipelineInstance.cs +++ b/src/Microsoft.AspNet.Hosting/Internal/PipelineInstance.cs @@ -25,7 +25,7 @@ namespace Microsoft.AspNet.Hosting.Internal public Task Invoke(IFeatureCollection featureCollection) { var httpContext = _httpContextFactory.CreateHttpContext(featureCollection); - _contextAccessor.Value = httpContext; + _contextAccessor.HttpContext = httpContext; return _requestDelegate(httpContext); } diff --git a/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs b/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs index 8d52493b27..9838e1d0b3 100644 --- a/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs +++ b/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs @@ -46,7 +46,7 @@ namespace Microsoft.AspNet.TestHost app.Run(context => { var accessor = app.ApplicationServices.GetRequiredService(); - return context.Response.WriteAsync("HasContext:"+(accessor.Value != null)); + return context.Response.WriteAsync("HasContext:"+(accessor.HttpContext != null)); }); }); From fde3b0d2af5a7d8b595ef4f42e793c6263482caa Mon Sep 17 00:00:00 2001 From: Praburaj Date: Tue, 3 Mar 2015 12:02:42 -0800 Subject: [PATCH 207/987] OwinFeature collection throws NotSupported exception as the featurecollection is immutable Addresses: https://github.com/aspnet/HttpAbstractions/issues/207 --- src/Microsoft.AspNet.Hosting/Builder/HttpContextFactory.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Microsoft.AspNet.Hosting/Builder/HttpContextFactory.cs b/src/Microsoft.AspNet.Hosting/Builder/HttpContextFactory.cs index 8089252955..74312601df 100644 --- a/src/Microsoft.AspNet.Hosting/Builder/HttpContextFactory.cs +++ b/src/Microsoft.AspNet.Hosting/Builder/HttpContextFactory.cs @@ -11,7 +11,7 @@ namespace Microsoft.AspNet.Hosting.Builder { public HttpContext CreateHttpContext(IFeatureCollection featureCollection) { - return new DefaultHttpContext(featureCollection); + return new DefaultHttpContext(new FeatureCollection(featureCollection)); } } } \ No newline at end of file From f2d345855b872764eb42e53515b6ea4329a6bd15 Mon Sep 17 00:00:00 2001 From: Praburaj Date: Tue, 3 Mar 2015 14:07:10 -0800 Subject: [PATCH 208/987] Adding a test for mutable feature collection --- .../HttpContextFactoryFacts.cs | 44 +++++++++++++++++++ .../project.json | 5 ++- 2 files changed, 47 insertions(+), 2 deletions(-) create mode 100644 test/Microsoft.AspNet.Hosting.Tests/HttpContextFactoryFacts.cs diff --git a/test/Microsoft.AspNet.Hosting.Tests/HttpContextFactoryFacts.cs b/test/Microsoft.AspNet.Hosting.Tests/HttpContextFactoryFacts.cs new file mode 100644 index 0000000000..b6ab156902 --- /dev/null +++ b/test/Microsoft.AspNet.Hosting.Tests/HttpContextFactoryFacts.cs @@ -0,0 +1,44 @@ +// 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 System.Collections.Generic; +using Microsoft.AspNet.Hosting.Builder; +using Microsoft.AspNet.Owin; +using Xunit; + +namespace Microsoft.AspNet.Hosting.Tests +{ + public class HttpContextFactoryFacts + { + [Fact] + public void Mutable_FeatureCollection_Wrapped_For_OwinFeatureCollection() + { + var env = new Dictionary(); + var contextFactory = new HttpContextFactory(); + var context = contextFactory.CreateHttpContext(new OwinFeatureCollection(env)); + + // Setting a feature will throw if the above feature collection is not wrapped in a mutable feature collection. + context.SetFeature(new CustomFeature(100)); + Assert.Equal(100, context.GetFeature().Value); + } + + private interface ICustomFeature + { + int Value { get; } + } + + private class CustomFeature : ICustomFeature + { + private readonly int _value; + public CustomFeature(int value) + { + _value = value; + } + + public int Value + { + get { return _value; } + } + } + } +} \ No newline at end of file diff --git a/test/Microsoft.AspNet.Hosting.Tests/project.json b/test/Microsoft.AspNet.Hosting.Tests/project.json index 8adf1a1d0e..49c5506d3a 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/project.json +++ b/test/Microsoft.AspNet.Hosting.Tests/project.json @@ -1,14 +1,15 @@ { "dependencies": { "Microsoft.AspNet.Hosting": "1.0.0-*", + "Microsoft.AspNet.Owin": "1.0.0-*", "Microsoft.AspNet.RequestContainer": "1.0.0-*", "xunit.runner.kre": "1.0.0-*" }, "frameworks": { - "aspnet50": { } + "aspnet50": {} }, "commands": { "test": "xunit.runner.kre" }, "webroot": "testroot" -} +} \ No newline at end of file From 718d923c7dd1d1039fba3a5d987793226de117b7 Mon Sep 17 00:00:00 2001 From: Praburaj Date: Wed, 4 Mar 2015 15:48:31 -0800 Subject: [PATCH 209/987] Adding IApplicationLifetime to the manifest Since IApplicationLifetime is not added to the manifest, while calling HostingServices.Create() before invoking ConfigureServices() we end up creating a new instance of IApplicationLifetime. So the Cancellationtoken that hosting triggers on appshutdown is different from what the app is exposed. --- src/Microsoft.AspNet.Hosting/HostingServices.cs | 9 +++++++-- .../UseRequestServicesFacts.cs | 14 ++++++-------- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/src/Microsoft.AspNet.Hosting/HostingServices.cs b/src/Microsoft.AspNet.Hosting/HostingServices.cs index 46b0f94703..1a5ac71846 100644 --- a/src/Microsoft.AspNet.Hosting/HostingServices.cs +++ b/src/Microsoft.AspNet.Hosting/HostingServices.cs @@ -45,8 +45,13 @@ namespace Microsoft.AspNet.Hosting public HostingManifest(IServiceProvider fallback) { var manifest = fallback.GetRequiredService(); - Services = new Type[] { typeof(ITypeActivator), typeof(IHostingEnvironment), typeof(ILoggerFactory), typeof(IHttpContextAccessor) } - .Concat(manifest.Services).Distinct(); + Services = new Type[] { + typeof(ITypeActivator), + typeof(IHostingEnvironment), + typeof(ILoggerFactory), + typeof(IHttpContextAccessor), + typeof(IApplicationLifetime) + }.Concat(manifest.Services).Distinct(); } public IEnumerable Services { get; private set; } diff --git a/test/Microsoft.AspNet.Hosting.Tests/UseRequestServicesFacts.cs b/test/Microsoft.AspNet.Hosting.Tests/UseRequestServicesFacts.cs index 44cd34f8f9..10859e7323 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/UseRequestServicesFacts.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/UseRequestServicesFacts.cs @@ -3,8 +3,6 @@ using System; using Microsoft.AspNet.Builder; -using Microsoft.AspNet.Hosting.Builder; -using Microsoft.AspNet.Hosting.Server; using Microsoft.AspNet.Http.Core; using Microsoft.AspNet.RequestContainer; using Microsoft.Framework.DependencyInjection; @@ -81,14 +79,11 @@ namespace Microsoft.AspNet.Hosting.Tests } [Theory] - [InlineData(typeof(IHostingEngine))] - [InlineData(typeof(IServerLoader))] - [InlineData(typeof(IApplicationBuilderFactory))] - [InlineData(typeof(IHttpContextFactory))] [InlineData(typeof(ITypeActivator))] - [InlineData(typeof(IApplicationLifetime))] + [InlineData(typeof(IHostingEnvironment))] [InlineData(typeof(ILoggerFactory))] [InlineData(typeof(IHttpContextAccessor))] + [InlineData(typeof(IApplicationLifetime))] public void UseRequestServicesHostingImportedServicesAreDefined(Type service) { var baseServiceProvider = HostingServices.Create().BuildServiceProvider(); @@ -96,7 +91,10 @@ namespace Microsoft.AspNet.Hosting.Tests builder.UseRequestServices(); - Assert.NotNull(builder.ApplicationServices.GetRequiredService(service)); + var fromAppServices = builder.ApplicationServices.GetRequiredService(service); + + Assert.NotNull(fromAppServices); + Assert.Equal(baseServiceProvider.GetRequiredService(service), fromAppServices); } } } \ No newline at end of file From 2af733266701c735bd2d56d8b6df7bfc57d7e166 Mon Sep 17 00:00:00 2001 From: Praburaj Date: Wed, 4 Mar 2015 15:58:19 -0800 Subject: [PATCH 210/987] Adding ILogger<> to the manifest Change from Hao. --- src/Microsoft.AspNet.Hosting/HostingServices.cs | 1 + test/Microsoft.AspNet.Hosting.Tests/UseRequestServicesFacts.cs | 1 + 2 files changed, 2 insertions(+) diff --git a/src/Microsoft.AspNet.Hosting/HostingServices.cs b/src/Microsoft.AspNet.Hosting/HostingServices.cs index 1a5ac71846..d3556c06eb 100644 --- a/src/Microsoft.AspNet.Hosting/HostingServices.cs +++ b/src/Microsoft.AspNet.Hosting/HostingServices.cs @@ -49,6 +49,7 @@ namespace Microsoft.AspNet.Hosting typeof(ITypeActivator), typeof(IHostingEnvironment), typeof(ILoggerFactory), + typeof(ILogger<>), typeof(IHttpContextAccessor), typeof(IApplicationLifetime) }.Concat(manifest.Services).Distinct(); diff --git a/test/Microsoft.AspNet.Hosting.Tests/UseRequestServicesFacts.cs b/test/Microsoft.AspNet.Hosting.Tests/UseRequestServicesFacts.cs index 10859e7323..b5b8111942 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/UseRequestServicesFacts.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/UseRequestServicesFacts.cs @@ -82,6 +82,7 @@ namespace Microsoft.AspNet.Hosting.Tests [InlineData(typeof(ITypeActivator))] [InlineData(typeof(IHostingEnvironment))] [InlineData(typeof(ILoggerFactory))] + [InlineData(typeof(ILogger))] [InlineData(typeof(IHttpContextAccessor))] [InlineData(typeof(IApplicationLifetime))] public void UseRequestServicesHostingImportedServicesAreDefined(Type service) From 5655751d8402e27bf4f840fe376bb38db2dee80c Mon Sep 17 00:00:00 2001 From: Brennan Date: Wed, 4 Mar 2015 17:05:50 -0800 Subject: [PATCH 211/987] Logging API changes --- src/Microsoft.AspNet.Hosting/Program.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Microsoft.AspNet.Hosting/Program.cs b/src/Microsoft.AspNet.Hosting/Program.cs index d050fbf10c..c0816b1151 100644 --- a/src/Microsoft.AspNet.Hosting/Program.cs +++ b/src/Microsoft.AspNet.Hosting/Program.cs @@ -66,8 +66,8 @@ namespace Microsoft.AspNet.Hosting } catch (Exception ex) { - var logger = loggerFactory.Create(); - logger.WriteError("Dispose threw an exception.", ex); + var logger = loggerFactory.CreateLogger(); + logger.LogError("Dispose threw an exception.", ex); } shutdownHandle.Set(); }); From c632c8a6a4befa43bbe49f7b7caa71f38ea9cb6f Mon Sep 17 00:00:00 2001 From: Praburaj Date: Wed, 4 Mar 2015 17:48:08 -0800 Subject: [PATCH 212/987] Reverting change to include ILogger<> from manifest This seems to cause MVC to fail. --- src/Microsoft.AspNet.Hosting/HostingServices.cs | 1 - test/Microsoft.AspNet.Hosting.Tests/UseRequestServicesFacts.cs | 1 - 2 files changed, 2 deletions(-) diff --git a/src/Microsoft.AspNet.Hosting/HostingServices.cs b/src/Microsoft.AspNet.Hosting/HostingServices.cs index d3556c06eb..1a5ac71846 100644 --- a/src/Microsoft.AspNet.Hosting/HostingServices.cs +++ b/src/Microsoft.AspNet.Hosting/HostingServices.cs @@ -49,7 +49,6 @@ namespace Microsoft.AspNet.Hosting typeof(ITypeActivator), typeof(IHostingEnvironment), typeof(ILoggerFactory), - typeof(ILogger<>), typeof(IHttpContextAccessor), typeof(IApplicationLifetime) }.Concat(manifest.Services).Distinct(); diff --git a/test/Microsoft.AspNet.Hosting.Tests/UseRequestServicesFacts.cs b/test/Microsoft.AspNet.Hosting.Tests/UseRequestServicesFacts.cs index b5b8111942..10859e7323 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/UseRequestServicesFacts.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/UseRequestServicesFacts.cs @@ -82,7 +82,6 @@ namespace Microsoft.AspNet.Hosting.Tests [InlineData(typeof(ITypeActivator))] [InlineData(typeof(IHostingEnvironment))] [InlineData(typeof(ILoggerFactory))] - [InlineData(typeof(ILogger))] [InlineData(typeof(IHttpContextAccessor))] [InlineData(typeof(IApplicationLifetime))] public void UseRequestServicesHostingImportedServicesAreDefined(Type service) From 7adf11b7bc6eff92fb0322ed8221108c40e60e33 Mon Sep 17 00:00:00 2001 From: Hao Kung Date: Wed, 4 Mar 2015 18:25:49 -0800 Subject: [PATCH 213/987] React to DI changes --- .../HostingServicesCollectionExtensions.cs | 27 +++++++++---------- src/Microsoft.AspNet.Hosting/Program.cs | 1 - .../Startup/StartupLoader.cs | 1 - .../ContainerExtensions.cs | 3 +-- src/Microsoft.AspNet.TestHost/TestServer.cs | 1 - .../Fakes/Startup.cs | 1 - .../HostingEngineTests.cs | 1 - .../HostingServicesFacts.cs | 1 - .../StartupManagerTests.cs | 1 - .../UseRequestServicesFacts.cs | 1 - .../TestClientTests.cs | 2 +- .../TestServerTests.cs | 1 - 12 files changed, 14 insertions(+), 27 deletions(-) diff --git a/src/Microsoft.AspNet.Hosting/HostingServicesCollectionExtensions.cs b/src/Microsoft.AspNet.Hosting/HostingServicesCollectionExtensions.cs index 1c698d3f49..6445c1e4b1 100644 --- a/src/Microsoft.AspNet.Hosting/HostingServicesCollectionExtensions.cs +++ b/src/Microsoft.AspNet.Hosting/HostingServicesCollectionExtensions.cs @@ -13,33 +13,30 @@ namespace Microsoft.Framework.DependencyInjection public static class HostingServicesExtensions { // REVIEW: Logging doesn't depend on DI, where should this live? - public static IServiceCollection AddLogging(this IServiceCollection services, IConfiguration config = null) + public static IServiceCollection AddLogging(this IServiceCollection services) { - var describe = new ServiceDescriber(config); - services.TryAdd(describe.Singleton()); - services.TryAdd(describe.Singleton(typeof(ILogger<>), typeof(Logger<>))); + services.TryAdd(ServiceDescriptor.Singleton()); + services.TryAdd(ServiceDescriptor.Singleton(typeof(ILogger<>), typeof(Logger<>))); return services; } public static IServiceCollection AddHosting(this IServiceCollection services, IConfiguration configuration = null) { - var describer = new ServiceDescriber(configuration); + services.TryAdd(ServiceDescriptor.Transient()); + services.TryAdd(ServiceDescriptor.Transient()); - services.TryAdd(describer.Transient()); - services.TryAdd(describer.Transient()); + services.TryAdd(ServiceDescriptor.Transient()); - services.TryAdd(describer.Transient()); + services.TryAdd(ServiceDescriptor.Transient()); + services.TryAdd(ServiceDescriptor.Transient()); - services.TryAdd(describer.Transient()); - services.TryAdd(describer.Transient()); - - services.TryAdd(describer.Instance(new ApplicationLifetime())); + services.TryAdd(ServiceDescriptor.Instance(new ApplicationLifetime())); services.AddTypeActivator(configuration); // TODO: Do we expect this to be provide by the runtime eventually? - services.AddLogging(configuration); - services.TryAdd(describer.Singleton()); - services.TryAdd(describer.Singleton()); + services.AddLogging(); + services.TryAdd(ServiceDescriptor.Singleton()); + services.TryAdd(ServiceDescriptor.Singleton()); // REVIEW: don't try add because we pull out IEnumerable? services.AddInstance(new ConfigureHostingEnvironment(configuration)); diff --git a/src/Microsoft.AspNet.Hosting/Program.cs b/src/Microsoft.AspNet.Hosting/Program.cs index d050fbf10c..cec49ddb7f 100644 --- a/src/Microsoft.AspNet.Hosting/Program.cs +++ b/src/Microsoft.AspNet.Hosting/Program.cs @@ -7,7 +7,6 @@ using System.Threading; using System.Threading.Tasks; using Microsoft.Framework.ConfigurationModel; using Microsoft.Framework.DependencyInjection; -using Microsoft.Framework.DependencyInjection.Fallback; using Microsoft.Framework.Logging; using Microsoft.Framework.Runtime; diff --git a/src/Microsoft.AspNet.Hosting/Startup/StartupLoader.cs b/src/Microsoft.AspNet.Hosting/Startup/StartupLoader.cs index ba6c013f12..bed2a0190d 100644 --- a/src/Microsoft.AspNet.Hosting/Startup/StartupLoader.cs +++ b/src/Microsoft.AspNet.Hosting/Startup/StartupLoader.cs @@ -8,7 +8,6 @@ using System.Linq; using System.Reflection; using Microsoft.AspNet.Builder; using Microsoft.Framework.DependencyInjection; -using Microsoft.Framework.DependencyInjection.Fallback; namespace Microsoft.AspNet.Hosting.Startup { diff --git a/src/Microsoft.AspNet.RequestContainer/ContainerExtensions.cs b/src/Microsoft.AspNet.RequestContainer/ContainerExtensions.cs index 06d89995f2..35701937ac 100644 --- a/src/Microsoft.AspNet.RequestContainer/ContainerExtensions.cs +++ b/src/Microsoft.AspNet.RequestContainer/ContainerExtensions.cs @@ -6,7 +6,6 @@ using System.Collections.Generic; using Microsoft.AspNet.RequestContainer; using Microsoft.AspNet.Hosting; using Microsoft.Framework.DependencyInjection; -using Microsoft.Framework.DependencyInjection.Fallback; namespace Microsoft.AspNet.Builder { @@ -29,7 +28,7 @@ namespace Microsoft.AspNet.Builder // Note: Manifests are lost after UseServices, services are flattened into ApplicationServices - public static IApplicationBuilder UseServices(this IApplicationBuilder builder, IEnumerable applicationServices) + public static IApplicationBuilder UseServices(this IApplicationBuilder builder, IServiceCollection applicationServices) { return builder.UseServices(services => services.Add(applicationServices)); } diff --git a/src/Microsoft.AspNet.TestHost/TestServer.cs b/src/Microsoft.AspNet.TestHost/TestServer.cs index a626723572..b7350e7c13 100644 --- a/src/Microsoft.AspNet.TestHost/TestServer.cs +++ b/src/Microsoft.AspNet.TestHost/TestServer.cs @@ -11,7 +11,6 @@ using Microsoft.AspNet.Hosting.Server; using Microsoft.AspNet.Http; using Microsoft.Framework.ConfigurationModel; using Microsoft.Framework.DependencyInjection; -using Microsoft.Framework.DependencyInjection.Fallback; using Microsoft.Framework.Runtime; using Microsoft.Framework.Runtime.Infrastructure; diff --git a/test/Microsoft.AspNet.Hosting.Tests/Fakes/Startup.cs b/test/Microsoft.AspNet.Hosting.Tests/Fakes/Startup.cs index efcb11537a..8f61d7e4c3 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/Fakes/Startup.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/Fakes/Startup.cs @@ -3,7 +3,6 @@ using Microsoft.AspNet.Builder; using Microsoft.Framework.DependencyInjection; -using Microsoft.Framework.DependencyInjection.Fallback; using Microsoft.Framework.OptionsModel; using System; diff --git a/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs b/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs index 99be47cbf7..d66e77a396 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs @@ -10,7 +10,6 @@ using Microsoft.AspNet.FeatureModel; using Microsoft.AspNet.Hosting.Server; using Microsoft.Framework.ConfigurationModel; using Microsoft.Framework.DependencyInjection; -using Microsoft.Framework.DependencyInjection.Fallback; using Xunit; namespace Microsoft.AspNet.Hosting diff --git a/test/Microsoft.AspNet.Hosting.Tests/HostingServicesFacts.cs b/test/Microsoft.AspNet.Hosting.Tests/HostingServicesFacts.cs index 5e6e733da8..1ccae6b90c 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/HostingServicesFacts.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/HostingServicesFacts.cs @@ -5,7 +5,6 @@ using System; using System.Collections.Generic; using Microsoft.AspNet.Hosting.Fakes; using Microsoft.Framework.DependencyInjection; -using Microsoft.Framework.DependencyInjection.Fallback; using Microsoft.Framework.Runtime; using Xunit; diff --git a/test/Microsoft.AspNet.Hosting.Tests/StartupManagerTests.cs b/test/Microsoft.AspNet.Hosting.Tests/StartupManagerTests.cs index db19ddc403..cefc9877e7 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/StartupManagerTests.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/StartupManagerTests.cs @@ -7,7 +7,6 @@ using Microsoft.AspNet.Builder; using Microsoft.AspNet.Hosting.Fakes; using Microsoft.AspNet.Hosting.Startup; using Microsoft.Framework.DependencyInjection; -using Microsoft.Framework.DependencyInjection.Fallback; using Microsoft.Framework.OptionsModel; using Xunit; diff --git a/test/Microsoft.AspNet.Hosting.Tests/UseRequestServicesFacts.cs b/test/Microsoft.AspNet.Hosting.Tests/UseRequestServicesFacts.cs index 10859e7323..bc557d59e7 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/UseRequestServicesFacts.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/UseRequestServicesFacts.cs @@ -6,7 +6,6 @@ using Microsoft.AspNet.Builder; using Microsoft.AspNet.Http.Core; using Microsoft.AspNet.RequestContainer; using Microsoft.Framework.DependencyInjection; -using Microsoft.Framework.DependencyInjection.Fallback; using Microsoft.Framework.Logging; using Xunit; diff --git a/test/Microsoft.AspNet.TestHost.Tests/TestClientTests.cs b/test/Microsoft.AspNet.TestHost.Tests/TestClientTests.cs index 467aca2005..b392bac6ad 100644 --- a/test/Microsoft.AspNet.TestHost.Tests/TestClientTests.cs +++ b/test/Microsoft.AspNet.TestHost.Tests/TestClientTests.cs @@ -8,7 +8,7 @@ using System.Threading.Tasks; using Microsoft.AspNet.Builder; using Microsoft.AspNet.Hosting; using Microsoft.AspNet.Http; -using Microsoft.Framework.DependencyInjection.Fallback; +using Microsoft.Framework.DependencyInjection; using Xunit; namespace Microsoft.AspNet.TestHost diff --git a/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs b/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs index 9838e1d0b3..c9ef3bdf96 100644 --- a/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs +++ b/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs @@ -10,7 +10,6 @@ using Microsoft.AspNet.Builder; using Microsoft.AspNet.Hosting; using Microsoft.AspNet.Http; using Microsoft.Framework.DependencyInjection; -using Microsoft.Framework.DependencyInjection.Fallback; using Xunit; namespace Microsoft.AspNet.TestHost From 02ed770353b67f443a023eac18453b44ce1c04fd Mon Sep 17 00:00:00 2001 From: Brennan Date: Wed, 4 Mar 2015 17:05:50 -0800 Subject: [PATCH 214/987] Logging API changes --- src/Microsoft.AspNet.Hosting/Program.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Microsoft.AspNet.Hosting/Program.cs b/src/Microsoft.AspNet.Hosting/Program.cs index cec49ddb7f..65658f606b 100644 --- a/src/Microsoft.AspNet.Hosting/Program.cs +++ b/src/Microsoft.AspNet.Hosting/Program.cs @@ -65,8 +65,8 @@ namespace Microsoft.AspNet.Hosting } catch (Exception ex) { - var logger = loggerFactory.Create(); - logger.WriteError("Dispose threw an exception.", ex); + var logger = loggerFactory.CreateLogger(); + logger.LogError("Dispose threw an exception.", ex); } shutdownHandle.Set(); }); From a6ced0c60cf315f268fb371eeb4e927767ed922e Mon Sep 17 00:00:00 2001 From: David Fowler Date: Wed, 4 Mar 2015 21:23:59 -0800 Subject: [PATCH 215/987] Removed configuration parameter from AddTypeActivator --- .../HostingServicesCollectionExtensions.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Microsoft.AspNet.Hosting/HostingServicesCollectionExtensions.cs b/src/Microsoft.AspNet.Hosting/HostingServicesCollectionExtensions.cs index 6445c1e4b1..893736db02 100644 --- a/src/Microsoft.AspNet.Hosting/HostingServicesCollectionExtensions.cs +++ b/src/Microsoft.AspNet.Hosting/HostingServicesCollectionExtensions.cs @@ -32,7 +32,8 @@ namespace Microsoft.Framework.DependencyInjection services.TryAdd(ServiceDescriptor.Instance(new ApplicationLifetime())); - services.AddTypeActivator(configuration); + services.AddTypeActivator(); + // TODO: Do we expect this to be provide by the runtime eventually? services.AddLogging(); services.TryAdd(ServiceDescriptor.Singleton()); From d0980738e31cb80bab28c264feb5732ec41929e7 Mon Sep 17 00:00:00 2001 From: David Fowler Date: Thu, 5 Mar 2015 02:20:20 -0800 Subject: [PATCH 216/987] Removed AddLogging since it comes from Logging now --- .../HostingServicesCollectionExtensions.cs | 9 --------- 1 file changed, 9 deletions(-) diff --git a/src/Microsoft.AspNet.Hosting/HostingServicesCollectionExtensions.cs b/src/Microsoft.AspNet.Hosting/HostingServicesCollectionExtensions.cs index 893736db02..4ee17b7f65 100644 --- a/src/Microsoft.AspNet.Hosting/HostingServicesCollectionExtensions.cs +++ b/src/Microsoft.AspNet.Hosting/HostingServicesCollectionExtensions.cs @@ -6,20 +6,11 @@ using Microsoft.AspNet.Hosting.Builder; using Microsoft.AspNet.Hosting.Server; using Microsoft.AspNet.Hosting.Startup; using Microsoft.Framework.ConfigurationModel; -using Microsoft.Framework.Logging; namespace Microsoft.Framework.DependencyInjection { public static class HostingServicesExtensions { - // REVIEW: Logging doesn't depend on DI, where should this live? - public static IServiceCollection AddLogging(this IServiceCollection services) - { - services.TryAdd(ServiceDescriptor.Singleton()); - services.TryAdd(ServiceDescriptor.Singleton(typeof(ILogger<>), typeof(Logger<>))); - return services; - } - public static IServiceCollection AddHosting(this IServiceCollection services, IConfiguration configuration = null) { services.TryAdd(ServiceDescriptor.Transient()); From f7c78b8fbc29260a560bdd208b78462b7ef91728 Mon Sep 17 00:00:00 2001 From: Hao Kung Date: Thu, 5 Mar 2015 12:23:14 -0800 Subject: [PATCH 217/987] Make it easier to add hosting services Fixes https://github.com/aspnet/Hosting/issues/145 --- .../ConfigureHostingEnvironment.cs | 2 +- .../HostingServices.cs | 42 +++++++++--- .../HostingServicesCollectionExtensions.cs | 7 +- src/Microsoft.AspNet.TestHost/TestServer.cs | 14 +++- .../HostingServicesFacts.cs | 67 +++++++++++++++++++ .../Microsoft.AspNet.Hosting.Tests.kproj | 2 +- .../TestServerTests.cs | 47 ++++++++++++- 7 files changed, 165 insertions(+), 16 deletions(-) diff --git a/src/Microsoft.AspNet.Hosting/ConfigureHostingEnvironment.cs b/src/Microsoft.AspNet.Hosting/ConfigureHostingEnvironment.cs index a714c2cfef..892eaab372 100644 --- a/src/Microsoft.AspNet.Hosting/ConfigureHostingEnvironment.cs +++ b/src/Microsoft.AspNet.Hosting/ConfigureHostingEnvironment.cs @@ -17,7 +17,7 @@ namespace Microsoft.AspNet.Hosting public void Configure(IHostingEnvironment hostingEnv) { - hostingEnv.EnvironmentName = _config.Get(EnvironmentKey) ?? hostingEnv.EnvironmentName; + hostingEnv.EnvironmentName = _config?.Get(EnvironmentKey) ?? hostingEnv.EnvironmentName; } } } \ No newline at end of file diff --git a/src/Microsoft.AspNet.Hosting/HostingServices.cs b/src/Microsoft.AspNet.Hosting/HostingServices.cs index 1a5ac71846..108e7ae881 100644 --- a/src/Microsoft.AspNet.Hosting/HostingServices.cs +++ b/src/Microsoft.AspNet.Hosting/HostingServices.cs @@ -14,44 +14,66 @@ namespace Microsoft.AspNet.Hosting { public static class HostingServices { - private static IServiceCollection Import(IServiceProvider fallbackProvider) + private static IServiceCollection Import(IServiceProvider fallbackProvider, Action configureHostServices) { var services = new ServiceCollection(); + if (configureHostServices != null) + { + configureHostServices(services); + } var manifest = fallbackProvider.GetRequiredService(); foreach (var service in manifest.Services) { services.AddTransient(service, sp => fallbackProvider.GetService(service)); } + services.AddSingleton(sp => new HostingManifest(services)); return services; } - public static IServiceCollection Create(IConfiguration configuration = null) + public static IServiceCollection Create() { - return Create(CallContextServiceLocator.Locator.ServiceProvider, configuration); + return Create(CallContextServiceLocator.Locator.ServiceProvider, configureHostServices: null, configuration: null); } - public static IServiceCollection Create(IServiceProvider fallbackServices, IConfiguration configuration = null) + public static IServiceCollection Create(IServiceProvider fallbackServices) { - configuration = configuration ?? new Configuration(); - var services = Import(fallbackServices); + return Create(fallbackServices, configureHostServices: null, configuration: null); + } + + public static IServiceCollection Create(IServiceProvider fallbackServices, Action configureHostServices) + { + return Create(fallbackServices, configureHostServices, configuration: null); + } + + public static IServiceCollection Create(Action configureHostServices, IConfiguration configuration) + { + return Create(CallContextServiceLocator.Locator.ServiceProvider, configureHostServices, configuration); + } + + public static IServiceCollection Create(IServiceProvider fallbackServices, IConfiguration configuration) + { + return Create(CallContextServiceLocator.Locator.ServiceProvider, configureHostServices: null, configuration: configuration); + } + + public static IServiceCollection Create(IServiceProvider fallbackServices, Action configureHostServices, IConfiguration configuration) + { + var services = Import(fallbackServices, configureHostServices); services.AddHosting(configuration); - services.AddSingleton(sp => new HostingManifest(fallbackServices)); return services; } // Manifest exposes the fallback manifest in addition to ITypeActivator, IHostingEnvironment, and ILoggerFactory private class HostingManifest : IServiceManifest { - public HostingManifest(IServiceProvider fallback) + public HostingManifest(IServiceCollection hostServices) { - var manifest = fallback.GetRequiredService(); Services = new Type[] { typeof(ITypeActivator), typeof(IHostingEnvironment), typeof(ILoggerFactory), typeof(IHttpContextAccessor), typeof(IApplicationLifetime) - }.Concat(manifest.Services).Distinct(); + }.Concat(hostServices.Select(s => s.ServiceType)).Distinct(); } public IEnumerable Services { get; private set; } diff --git a/src/Microsoft.AspNet.Hosting/HostingServicesCollectionExtensions.cs b/src/Microsoft.AspNet.Hosting/HostingServicesCollectionExtensions.cs index 4ee17b7f65..8510ab43a5 100644 --- a/src/Microsoft.AspNet.Hosting/HostingServicesCollectionExtensions.cs +++ b/src/Microsoft.AspNet.Hosting/HostingServicesCollectionExtensions.cs @@ -11,7 +11,12 @@ namespace Microsoft.Framework.DependencyInjection { public static class HostingServicesExtensions { - public static IServiceCollection AddHosting(this IServiceCollection services, IConfiguration configuration = null) + public static IServiceCollection AddHosting(this IServiceCollection services) + { + return services.AddHosting(configuration: null); + } + + public static IServiceCollection AddHosting(this IServiceCollection services, IConfiguration configuration) { services.TryAdd(ServiceDescriptor.Transient()); services.TryAdd(ServiceDescriptor.Transient()); diff --git a/src/Microsoft.AspNet.TestHost/TestServer.cs b/src/Microsoft.AspNet.TestHost/TestServer.cs index b7350e7c13..2a6517a4a2 100644 --- a/src/Microsoft.AspNet.TestHost/TestServer.cs +++ b/src/Microsoft.AspNet.TestHost/TestServer.cs @@ -47,12 +47,22 @@ namespace Microsoft.AspNet.TestHost public static TestServer Create(Action app) { - return Create(CallContextServiceLocator.Locator.ServiceProvider, app); + return Create(CallContextServiceLocator.Locator.ServiceProvider, app, configureHostServices: null); + } + + public static TestServer Create(Action app, Action configureHostServices) + { + return Create(CallContextServiceLocator.Locator.ServiceProvider, app, configureHostServices); } public static TestServer Create(IServiceProvider serviceProvider, Action app) { - var appServices = HostingServices.Create(serviceProvider).BuildServiceProvider(); + return Create(serviceProvider, app, configureHostServices: null); + } + + public static TestServer Create(IServiceProvider serviceProvider, Action app, Action configureHostServices) + { + var appServices = HostingServices.Create(serviceProvider, configureHostServices).BuildServiceProvider(); var config = new Configuration(); return new TestServer(config, appServices, app); } diff --git a/test/Microsoft.AspNet.Hosting.Tests/HostingServicesFacts.cs b/test/Microsoft.AspNet.Hosting.Tests/HostingServicesFacts.cs index 1ccae6b90c..ebb9b1a892 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/HostingServicesFacts.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/HostingServicesFacts.cs @@ -52,6 +52,73 @@ namespace Microsoft.AspNet.Hosting.Tests Assert.Null(provider.GetService()); // Make sure we don't leak non manifest services } + [Fact] + public void CreateCanAddAdditionalServices() + { + // Arrange + var fallbackServices = new ServiceCollection(); + fallbackServices.AddTransient(); + fallbackServices.AddTransient(); // Don't register in manifest + + fallbackServices.AddInstance(new ServiceManifest( + new Type[] { + typeof(IFakeService), + })); + + var instance = new FakeService(); + var factoryInstance = new FakeFactoryService(instance); + + var services = HostingServices.Create(fallbackServices.BuildServiceProvider(), + additionalHostServices => + { + additionalHostServices.AddSingleton(); + additionalHostServices.AddInstance(instance); + additionalHostServices.AddSingleton(serviceProvider => factoryInstance); + }); + + // Act + var provider = services.BuildServiceProvider(); + var singleton = provider.GetRequiredService(); + var transient = provider.GetRequiredService(); + var factory = provider.GetRequiredService(); + var manifest = provider.GetRequiredService(); + + // Assert + Assert.Same(singleton, provider.GetRequiredService()); + Assert.NotSame(transient, provider.GetRequiredService()); + Assert.Same(instance, provider.GetRequiredService()); + Assert.Same(factoryInstance, factory); + Assert.Same(factory.FakeService, instance); + Assert.Null(provider.GetService()); + Assert.Null(provider.GetService()); // Make sure we don't leak non manifest services + Assert.Contains(typeof(IFakeSingletonService), manifest.Services); + Assert.Contains(typeof(IFakeServiceInstance), manifest.Services); + Assert.Contains(typeof(IFactoryService), manifest.Services); + } + + [Fact] + public void CreateAdditionalServicesDoNotOverrideFallback() + { + // Arrange + var fallbackServices = new ServiceCollection(); + fallbackServices.AddTransient(); + + fallbackServices.AddInstance(new ServiceManifest( + new Type[] { + typeof(IFakeService), + })); + + var services = HostingServices.Create(fallbackServices.BuildServiceProvider(), + additionalHostServices => additionalHostServices.AddSingleton()); + + // Act + var provider = services.BuildServiceProvider(); + var stillTransient = provider.GetRequiredService(); + + // Assert + Assert.NotSame(stillTransient, provider.GetRequiredService()); + } + [Fact] public void CanHideImportedServices() { diff --git a/test/Microsoft.AspNet.Hosting.Tests/Microsoft.AspNet.Hosting.Tests.kproj b/test/Microsoft.AspNet.Hosting.Tests/Microsoft.AspNet.Hosting.Tests.kproj index 766519fb73..59c5545a1f 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/Microsoft.AspNet.Hosting.Tests.kproj +++ b/test/Microsoft.AspNet.Hosting.Tests/Microsoft.AspNet.Hosting.Tests.kproj @@ -12,7 +12,7 @@ 2.0 - 23533 + 18007 \ No newline at end of file diff --git a/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs b/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs index c9ef3bdf96..899d3be45a 100644 --- a/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs +++ b/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs @@ -10,6 +10,7 @@ using Microsoft.AspNet.Builder; using Microsoft.AspNet.Hosting; using Microsoft.AspNet.Http; using Microsoft.Framework.DependencyInjection; +using Microsoft.Framework.Logging; using Xunit; namespace Microsoft.AspNet.TestHost @@ -36,10 +37,25 @@ namespace Microsoft.AspNet.TestHost Assert.Throws(() => TestServer.Create(services, new Startup().Configuration)); } + [Fact] + public async Task CanAccessLogger() + { + TestServer server = TestServer.Create(app => + { + app.Run(context => + { + var logger = app.ApplicationServices.GetRequiredService>(); + return context.Response.WriteAsync("FoundLogger:" + (logger != null)); + }); + }); + + string result = await server.CreateClient().GetStringAsync("/path"); + Assert.Equal("FoundLogger:True", result); + } + [Fact] public async Task CanAccessHttpContext() { - var services = new ServiceCollection().BuildServiceProvider(); TestServer server = TestServer.Create(app => { app.Run(context => @@ -53,6 +69,35 @@ namespace Microsoft.AspNet.TestHost Assert.Equal("HasContext:True", result); } + public class ContextHolder + { + public ContextHolder(IHttpContextAccessor accessor) + { + Accessor = accessor; + } + + public IHttpContextAccessor Accessor { get; set; } + } + + [Fact] + public async Task CanAddNewHostServices() + { + TestServer server = TestServer.Create(app => + { + var a = app.ApplicationServices.GetRequiredService(); + + app.Run(context => + { + var b = app.ApplicationServices.GetRequiredService(); + var accessor = app.ApplicationServices.GetRequiredService(); + return context.Response.WriteAsync("HasContext:" + (accessor.Accessor.HttpContext != null)); + }); + }, newHostServices => newHostServices.AddSingleton()); + + string result = await server.CreateClient().GetStringAsync("/path"); + Assert.Equal("HasContext:True", result); + } + [Fact] public async Task CreateInvokesApp() { From ca9d6bcd7764adcd3168fe94dd45ce226c239b47 Mon Sep 17 00:00:00 2001 From: Brennan Date: Thu, 5 Mar 2015 14:39:19 -0800 Subject: [PATCH 218/987] DI API changes --- src/Microsoft.AspNet.Hosting/HostingServices.cs | 1 - .../HostingServicesCollectionExtensions.cs | 2 -- test/Microsoft.AspNet.Hosting.Tests/UseRequestServicesFacts.cs | 1 - 3 files changed, 4 deletions(-) diff --git a/src/Microsoft.AspNet.Hosting/HostingServices.cs b/src/Microsoft.AspNet.Hosting/HostingServices.cs index 108e7ae881..35f5be77c9 100644 --- a/src/Microsoft.AspNet.Hosting/HostingServices.cs +++ b/src/Microsoft.AspNet.Hosting/HostingServices.cs @@ -68,7 +68,6 @@ namespace Microsoft.AspNet.Hosting public HostingManifest(IServiceCollection hostServices) { Services = new Type[] { - typeof(ITypeActivator), typeof(IHostingEnvironment), typeof(ILoggerFactory), typeof(IHttpContextAccessor), diff --git a/src/Microsoft.AspNet.Hosting/HostingServicesCollectionExtensions.cs b/src/Microsoft.AspNet.Hosting/HostingServicesCollectionExtensions.cs index 8510ab43a5..ba3336d541 100644 --- a/src/Microsoft.AspNet.Hosting/HostingServicesCollectionExtensions.cs +++ b/src/Microsoft.AspNet.Hosting/HostingServicesCollectionExtensions.cs @@ -28,8 +28,6 @@ namespace Microsoft.Framework.DependencyInjection services.TryAdd(ServiceDescriptor.Instance(new ApplicationLifetime())); - services.AddTypeActivator(); - // TODO: Do we expect this to be provide by the runtime eventually? services.AddLogging(); services.TryAdd(ServiceDescriptor.Singleton()); diff --git a/test/Microsoft.AspNet.Hosting.Tests/UseRequestServicesFacts.cs b/test/Microsoft.AspNet.Hosting.Tests/UseRequestServicesFacts.cs index bc557d59e7..0e235a45db 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/UseRequestServicesFacts.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/UseRequestServicesFacts.cs @@ -78,7 +78,6 @@ namespace Microsoft.AspNet.Hosting.Tests } [Theory] - [InlineData(typeof(ITypeActivator))] [InlineData(typeof(IHostingEnvironment))] [InlineData(typeof(ILoggerFactory))] [InlineData(typeof(IHttpContextAccessor))] From eeda8e3d7398e882d931ddefb55a7a4e16f5a2e4 Mon Sep 17 00:00:00 2001 From: Praburaj Date: Thu, 5 Mar 2015 16:17:13 -0800 Subject: [PATCH 219/987] Rename Microsoft.AspNet.Http.Interfaces => Microsoft.AspNet.Http --- src/Microsoft.AspNet.TestHost/ClientHandler.cs | 1 - src/Microsoft.AspNet.TestHost/RequestFeature.cs | 2 +- src/Microsoft.AspNet.TestHost/ResponseFeature.cs | 2 +- test/Microsoft.AspNet.TestHost.Tests/ClientHandlerTests.cs | 2 +- 4 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/Microsoft.AspNet.TestHost/ClientHandler.cs b/src/Microsoft.AspNet.TestHost/ClientHandler.cs index f190c0b539..a1e281a7ca 100644 --- a/src/Microsoft.AspNet.TestHost/ClientHandler.cs +++ b/src/Microsoft.AspNet.TestHost/ClientHandler.cs @@ -13,7 +13,6 @@ using System.Threading.Tasks; using Microsoft.AspNet.FeatureModel; using Microsoft.AspNet.Http; using Microsoft.AspNet.Http.Core; -using Microsoft.AspNet.Http.Interfaces; namespace Microsoft.AspNet.TestHost { diff --git a/src/Microsoft.AspNet.TestHost/RequestFeature.cs b/src/Microsoft.AspNet.TestHost/RequestFeature.cs index f23df6716a..3c043c6e98 100644 --- a/src/Microsoft.AspNet.TestHost/RequestFeature.cs +++ b/src/Microsoft.AspNet.TestHost/RequestFeature.cs @@ -4,7 +4,7 @@ using System; using System.Collections.Generic; using System.IO; -using Microsoft.AspNet.Http.Interfaces; +using Microsoft.AspNet.Http; namespace Microsoft.AspNet.TestHost { diff --git a/src/Microsoft.AspNet.TestHost/ResponseFeature.cs b/src/Microsoft.AspNet.TestHost/ResponseFeature.cs index 8c8aa08e60..de9765b383 100644 --- a/src/Microsoft.AspNet.TestHost/ResponseFeature.cs +++ b/src/Microsoft.AspNet.TestHost/ResponseFeature.cs @@ -4,7 +4,7 @@ using System; using System.Collections.Generic; using System.IO; -using Microsoft.AspNet.Http.Interfaces; +using Microsoft.AspNet.Http; namespace Microsoft.AspNet.TestHost { diff --git a/test/Microsoft.AspNet.TestHost.Tests/ClientHandlerTests.cs b/test/Microsoft.AspNet.TestHost.Tests/ClientHandlerTests.cs index 9956339096..c92a8ca35c 100644 --- a/test/Microsoft.AspNet.TestHost.Tests/ClientHandlerTests.cs +++ b/test/Microsoft.AspNet.TestHost.Tests/ClientHandlerTests.cs @@ -10,7 +10,7 @@ using System.Threading.Tasks; using Microsoft.AspNet.FeatureModel; using Microsoft.AspNet.Http; using Microsoft.AspNet.Http.Core; -using Microsoft.AspNet.Http.Interfaces; +using Microsoft.AspNet.Http; using Xunit; namespace Microsoft.AspNet.TestHost From 28cc37de96d8593e81ba5666db546ede764196f5 Mon Sep 17 00:00:00 2001 From: Hao Kung Date: Fri, 6 Mar 2015 08:53:31 -0800 Subject: [PATCH 220/987] Add another Create overload that was missing --- src/Microsoft.AspNet.Hosting/HostingServices.cs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/Microsoft.AspNet.Hosting/HostingServices.cs b/src/Microsoft.AspNet.Hosting/HostingServices.cs index 35f5be77c9..e49d792fee 100644 --- a/src/Microsoft.AspNet.Hosting/HostingServices.cs +++ b/src/Microsoft.AspNet.Hosting/HostingServices.cs @@ -40,6 +40,11 @@ namespace Microsoft.AspNet.Hosting return Create(fallbackServices, configureHostServices: null, configuration: null); } + public static IServiceCollection Create(Action configureHostServices) + { + return Create(CallContextServiceLocator.Locator.ServiceProvider, configureHostServices, configuration: null); + } + public static IServiceCollection Create(IServiceProvider fallbackServices, Action configureHostServices) { return Create(fallbackServices, configureHostServices, configuration: null); From 89a1ec1cb5460f7f7cce6b8c0d6270625dd792fa Mon Sep 17 00:00:00 2001 From: Doug Bunting Date: Fri, 6 Mar 2015 15:04:18 -0800 Subject: [PATCH 221/987] Apply `configureHostServices` after the `fallbackProvider` - allows MVC to override `IApplicationEnvironment` in functional tests --- src/Microsoft.AspNet.Hosting/HostingServices.cs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/Microsoft.AspNet.Hosting/HostingServices.cs b/src/Microsoft.AspNet.Hosting/HostingServices.cs index e49d792fee..55859c9a84 100644 --- a/src/Microsoft.AspNet.Hosting/HostingServices.cs +++ b/src/Microsoft.AspNet.Hosting/HostingServices.cs @@ -17,16 +17,19 @@ namespace Microsoft.AspNet.Hosting private static IServiceCollection Import(IServiceProvider fallbackProvider, Action configureHostServices) { var services = new ServiceCollection(); - if (configureHostServices != null) - { - configureHostServices(services); - } var manifest = fallbackProvider.GetRequiredService(); foreach (var service in manifest.Services) { services.AddTransient(service, sp => fallbackProvider.GetService(service)); } + services.AddSingleton(sp => new HostingManifest(services)); + + if (configureHostServices != null) + { + configureHostServices(services); + } + return services; } From 9618dfa272b18488060c3add9063cf1f8008b151 Mon Sep 17 00:00:00 2001 From: Doug Bunting Date: Fri, 6 Mar 2015 15:55:47 -0800 Subject: [PATCH 222/987] Correct one unit test --- .../HostingServicesFacts.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/Microsoft.AspNet.Hosting.Tests/HostingServicesFacts.cs b/test/Microsoft.AspNet.Hosting.Tests/HostingServicesFacts.cs index ebb9b1a892..25baae8074 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/HostingServicesFacts.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/HostingServicesFacts.cs @@ -97,7 +97,7 @@ namespace Microsoft.AspNet.Hosting.Tests } [Fact] - public void CreateAdditionalServicesDoNotOverrideFallback() + public void CreateAdditionalServicesOverridesFallback() { // Arrange var fallbackServices = new ServiceCollection(); @@ -108,15 +108,15 @@ namespace Microsoft.AspNet.Hosting.Tests typeof(IFakeService), })); - var services = HostingServices.Create(fallbackServices.BuildServiceProvider(), + var services = HostingServices.Create(fallbackServices.BuildServiceProvider(), additionalHostServices => additionalHostServices.AddSingleton()); // Act var provider = services.BuildServiceProvider(); - var stillTransient = provider.GetRequiredService(); + var singleton = provider.GetRequiredService(); // Assert - Assert.NotSame(stillTransient, provider.GetRequiredService()); + Assert.Same(singleton, provider.GetRequiredService()); } [Fact] From ee55e382606f37c77b2e2c10365602e982c18f58 Mon Sep 17 00:00:00 2001 From: Doug Bunting Date: Fri, 6 Mar 2015 16:44:55 -0800 Subject: [PATCH 223/987] CR comments - change order a bit and add a unit test --- .../HostingServices.cs | 4 +-- .../HostingServicesFacts.cs | 27 +++++++++++++++++++ 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/src/Microsoft.AspNet.Hosting/HostingServices.cs b/src/Microsoft.AspNet.Hosting/HostingServices.cs index 55859c9a84..6a321a0098 100644 --- a/src/Microsoft.AspNet.Hosting/HostingServices.cs +++ b/src/Microsoft.AspNet.Hosting/HostingServices.cs @@ -23,13 +23,13 @@ namespace Microsoft.AspNet.Hosting services.AddTransient(service, sp => fallbackProvider.GetService(service)); } - services.AddSingleton(sp => new HostingManifest(services)); - if (configureHostServices != null) { configureHostServices(services); } + services.AddSingleton(sp => new HostingManifest(services)); + return services; } diff --git a/test/Microsoft.AspNet.Hosting.Tests/HostingServicesFacts.cs b/test/Microsoft.AspNet.Hosting.Tests/HostingServicesFacts.cs index 25baae8074..a0fff83ac5 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/HostingServicesFacts.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/HostingServicesFacts.cs @@ -119,6 +119,33 @@ namespace Microsoft.AspNet.Hosting.Tests Assert.Same(singleton, provider.GetRequiredService()); } + [Fact] + public void CreateAdditionalServices_IncludesServicesInManifest() + { + // Arrange + var fallbackServices = new ServiceCollection(); + fallbackServices.AddTransient(); + fallbackServices.AddInstance(new ServiceManifest( + new Type[] { + typeof(IFakeService), + })); + var expectedInstance = new FakeService(); + var services = HostingServices.Create( + fallbackServices.BuildServiceProvider(), + additionalHostServices => additionalHostServices.AddInstance(expectedInstance)); + + // Act + var provider = services.BuildServiceProvider(); + var instance = provider.GetRequiredService(); + var anotherInstance = provider.GetRequiredService(); + var manifest = provider.GetRequiredService(); + + // Assert + Assert.Same(expectedInstance, instance); + Assert.Same(expectedInstance, anotherInstance); + Assert.Contains(typeof(IFakeServiceInstance), manifest.Services); + } + [Fact] public void CanHideImportedServices() { From 19df67f33e89043f1eb2d75e3de6a0d2eab0e762 Mon Sep 17 00:00:00 2001 From: "N. Taylor Mullen" Date: Sun, 8 Mar 2015 12:50:29 -0700 Subject: [PATCH 224/987] Update aspnet50/aspnetcore50 => dnx451/dnxcore50. --- src/Microsoft.AspNet.Hosting.Interfaces/project.json | 6 +++--- src/Microsoft.AspNet.Hosting/HttpContextAccessor.cs | 10 +++++----- src/Microsoft.AspNet.Hosting/project.json | 6 +++--- src/Microsoft.AspNet.RequestContainer/project.json | 6 +++--- src/Microsoft.AspNet.TestHost/ResponseStream.cs | 6 +++--- src/Microsoft.AspNet.TestHost/project.json | 6 +++--- test/Microsoft.AspNet.Hosting.Tests/project.json | 6 +++--- test/Microsoft.AspNet.TestHost.Tests/project.json | 4 ++-- 8 files changed, 25 insertions(+), 25 deletions(-) diff --git a/src/Microsoft.AspNet.Hosting.Interfaces/project.json b/src/Microsoft.AspNet.Hosting.Interfaces/project.json index 6f33dd5cea..bb1e04e39b 100644 --- a/src/Microsoft.AspNet.Hosting.Interfaces/project.json +++ b/src/Microsoft.AspNet.Hosting.Interfaces/project.json @@ -7,7 +7,7 @@ "Microsoft.Framework.ConfigurationModel": "1.0.0-*" }, "frameworks": { - "aspnet50": {}, - "aspnetcore50": {} + "dnx451": {}, + "dnxcore50": {} } -} \ No newline at end of file +} diff --git a/src/Microsoft.AspNet.Hosting/HttpContextAccessor.cs b/src/Microsoft.AspNet.Hosting/HttpContextAccessor.cs index 59b5cbd8fa..5b1e0ef9e1 100644 --- a/src/Microsoft.AspNet.Hosting/HttpContextAccessor.cs +++ b/src/Microsoft.AspNet.Hosting/HttpContextAccessor.cs @@ -1,11 +1,11 @@ -// 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. using System; -#if ASPNET50 +#if DNX451 using System.Runtime.Remoting.Messaging; using System.Runtime.Remoting; -#elif ASPNETCORE50 +#elif DNXCORE50 using System.Threading; #endif using Microsoft.AspNet.Http; @@ -14,7 +14,7 @@ namespace Microsoft.AspNet.Hosting { public class HttpContextAccessor : IHttpContextAccessor { -#if ASPNET50 +#if DNX451 private const string LogicalDataKey = "__HttpContext_Current__"; public HttpContext HttpContext @@ -30,7 +30,7 @@ namespace Microsoft.AspNet.Hosting } } -#elif ASPNETCORE50 +#elif DNXCORE50 private AsyncLocal _httpContextCurrent = new AsyncLocal(); public HttpContext HttpContext { diff --git a/src/Microsoft.AspNet.Hosting/project.json b/src/Microsoft.AspNet.Hosting/project.json index f4deb14aca..03a441eba0 100644 --- a/src/Microsoft.AspNet.Hosting/project.json +++ b/src/Microsoft.AspNet.Hosting/project.json @@ -1,4 +1,4 @@ -{ +{ "version": "1.0.0-*", "description": "ASP.NET 5 core hosting infrastructure and startup logic for web applications.", "dependencies": { @@ -11,8 +11,8 @@ "Newtonsoft.Json": "6.0.6" }, "frameworks": { - "aspnet50": { }, - "aspnetcore50": { + "dnx451": { }, + "dnxcore50": { "dependencies": { "System.Console": "4.0.0-beta-*" } diff --git a/src/Microsoft.AspNet.RequestContainer/project.json b/src/Microsoft.AspNet.RequestContainer/project.json index 076064ad98..b2729bd744 100644 --- a/src/Microsoft.AspNet.RequestContainer/project.json +++ b/src/Microsoft.AspNet.RequestContainer/project.json @@ -1,4 +1,4 @@ -{ +{ "version": "1.0.0-*", "description": "ASP.NET 5 enables per-request scoping of services.", "dependencies": { @@ -7,8 +7,8 @@ "Microsoft.Framework.OptionsModel": "1.0.0-*" }, "frameworks": { - "aspnet50": {}, - "aspnetcore50": { + "dnx451": {}, + "dnxcore50": { "dependencies": { "System.Threading": "4.0.10-beta-*" } diff --git a/src/Microsoft.AspNet.TestHost/ResponseStream.cs b/src/Microsoft.AspNet.TestHost/ResponseStream.cs index 64e64c0c64..a3b555bd70 100644 --- a/src/Microsoft.AspNet.TestHost/ResponseStream.cs +++ b/src/Microsoft.AspNet.TestHost/ResponseStream.cs @@ -1,4 +1,4 @@ -// 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. using System; @@ -161,7 +161,7 @@ namespace Microsoft.AspNet.TestHost _readLock.Release(); } } -#if ASPNET50 +#if DNX451 public override IAsyncResult BeginRead(byte[] buffer, int offset, int count, AsyncCallback callback, object state) { // TODO: This option doesn't preserve the state object. @@ -258,7 +258,7 @@ namespace Microsoft.AspNet.TestHost _writeLock.Release(); } } -#if ASPNET50 +#if DNX451 public override IAsyncResult BeginWrite(byte[] buffer, int offset, int count, AsyncCallback callback, object state) { Write(buffer, offset, count); diff --git a/src/Microsoft.AspNet.TestHost/project.json b/src/Microsoft.AspNet.TestHost/project.json index c63c7dba59..c6360f74da 100644 --- a/src/Microsoft.AspNet.TestHost/project.json +++ b/src/Microsoft.AspNet.TestHost/project.json @@ -1,16 +1,16 @@ -{ +{ "version": "1.0.0-*", "description": "ASP.NET 5 web server for writing and running tests.", "dependencies": { "Microsoft.AspNet.Hosting": "1.0.0-*" }, "frameworks": { - "aspnet50": { + "dnx451": { "frameworkAssemblies": { "System.Net.Http": "" } }, - "aspnetcore50": { + "dnxcore50": { "dependencies": { "System.Diagnostics.Contracts": "4.0.0-beta-*", "System.Net.Http": "4.0.0-beta-*" diff --git a/test/Microsoft.AspNet.Hosting.Tests/project.json b/test/Microsoft.AspNet.Hosting.Tests/project.json index 49c5506d3a..22e492d189 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/project.json +++ b/test/Microsoft.AspNet.Hosting.Tests/project.json @@ -1,4 +1,4 @@ -{ +{ "dependencies": { "Microsoft.AspNet.Hosting": "1.0.0-*", "Microsoft.AspNet.Owin": "1.0.0-*", @@ -6,10 +6,10 @@ "xunit.runner.kre": "1.0.0-*" }, "frameworks": { - "aspnet50": {} + "dnx451": {} }, "commands": { "test": "xunit.runner.kre" }, "webroot": "testroot" -} \ No newline at end of file +} diff --git a/test/Microsoft.AspNet.TestHost.Tests/project.json b/test/Microsoft.AspNet.TestHost.Tests/project.json index cf98630c3f..df5be3e395 100644 --- a/test/Microsoft.AspNet.TestHost.Tests/project.json +++ b/test/Microsoft.AspNet.TestHost.Tests/project.json @@ -1,4 +1,4 @@ -{ +{ "dependencies": { "Microsoft.AspNet.TestHost": "1.0.0-*", "xunit.runner.kre": "1.0.0-*" @@ -7,6 +7,6 @@ "test": "xunit.runner.kre" }, "frameworks": { - "aspnet50": { } + "dnx451": { } } } From 1bf2c7c7f3468da6a2b8b1d6af9f117d33878b07 Mon Sep 17 00:00:00 2001 From: "N. Taylor Mullen" Date: Sun, 8 Mar 2015 12:50:29 -0700 Subject: [PATCH 225/987] Update K_BUILD_VERSION/kre/KRE/.k => DNX_BUILD_VERSION/dnx/DNX/.dnx. --- build.cmd | 4 ++-- .../ContainerExtensions.cs | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/build.cmd b/build.cmd index 86ca5bbbf1..49ba0692de 100644 --- a/build.cmd +++ b/build.cmd @@ -1,4 +1,4 @@ -@echo off +@echo off cd %~dp0 SETLOCAL @@ -19,7 +19,7 @@ IF EXIST packages\KoreBuild goto run .nuget\NuGet.exe install KoreBuild -ExcludeVersion -o packages -nocache -pre .nuget\NuGet.exe install Sake -version 0.2 -o packages -ExcludeVersion -IF "%SKIP_KRE_INSTALL%"=="1" goto run +IF "%SKIP_DNX_INSTALL%"=="1" goto run CALL packages\KoreBuild\build\kvm upgrade -runtime CLR -x86 CALL packages\KoreBuild\build\kvm install default -runtime CoreCLR -x86 diff --git a/src/Microsoft.AspNet.RequestContainer/ContainerExtensions.cs b/src/Microsoft.AspNet.RequestContainer/ContainerExtensions.cs index 35701937ac..919df65864 100644 --- a/src/Microsoft.AspNet.RequestContainer/ContainerExtensions.cs +++ b/src/Microsoft.AspNet.RequestContainer/ContainerExtensions.cs @@ -1,4 +1,4 @@ -// 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. using System; @@ -44,7 +44,7 @@ namespace Microsoft.AspNet.Builder public static IApplicationBuilder UseServices(this IApplicationBuilder builder, Func configureServices) { - // Import services from hosting/KRE as fallback + // Import services from hosting/DNX as fallback var serviceCollection = HostingServices.Create(builder.ApplicationServices); builder.ApplicationServices = configureServices(serviceCollection); @@ -52,4 +52,4 @@ namespace Microsoft.AspNet.Builder return builder.UseMiddleware(); } } -} \ No newline at end of file +} From fc5f2c55cfb65520b8babb92aa54c38fb04faa67 Mon Sep 17 00:00:00 2001 From: "N. Taylor Mullen" Date: Sun, 8 Mar 2015 12:50:30 -0700 Subject: [PATCH 226/987] Update kvm/KVM/Kvm => dnvm/DNVM/Dnvm. --- build.cmd | 6 +++--- build.sh | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/build.cmd b/build.cmd index 49ba0692de..77be0a6627 100644 --- a/build.cmd +++ b/build.cmd @@ -20,9 +20,9 @@ IF EXIST packages\KoreBuild goto run .nuget\NuGet.exe install Sake -version 0.2 -o packages -ExcludeVersion IF "%SKIP_DNX_INSTALL%"=="1" goto run -CALL packages\KoreBuild\build\kvm upgrade -runtime CLR -x86 -CALL packages\KoreBuild\build\kvm install default -runtime CoreCLR -x86 +CALL packages\KoreBuild\build\dnvm upgrade -runtime CLR -x86 +CALL packages\KoreBuild\build\dnvm install default -runtime CoreCLR -x86 :run -CALL packages\KoreBuild\build\kvm use default -runtime CLR -x86 +CALL packages\KoreBuild\build\dnvm use default -runtime CLR -x86 packages\Sake\tools\Sake.exe -I packages\KoreBuild\build -f makefile.shade %* diff --git a/build.sh b/build.sh index c7873ef58e..74cb3421e6 100755 --- a/build.sh +++ b/build.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/bash if test `uname` = Darwin; then cachedir=~/Library/Caches/KBuild @@ -28,11 +28,11 @@ if test ! -d packages/KoreBuild; then fi if ! type k > /dev/null 2>&1; then - source packages/KoreBuild/build/kvm.sh + source packages/KoreBuild/build/dnvm.sh fi if ! type k > /dev/null 2>&1; then - kvm upgrade + dnvm upgrade fi mono packages/Sake/tools/Sake.exe -I packages/KoreBuild/build -f makefile.shade "$@" From 8385418d913f3134f2e3c498ade39ba397804f27 Mon Sep 17 00:00:00 2001 From: "N. Taylor Mullen" Date: Sun, 8 Mar 2015 12:50:30 -0700 Subject: [PATCH 227/987] Update build.sh to use dnvm correctly. --- build.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/build.sh b/build.sh index 74cb3421e6..a9ce06d087 100755 --- a/build.sh +++ b/build.sh @@ -27,7 +27,7 @@ if test ! -d packages/KoreBuild; then mono .nuget/nuget.exe install Sake -version 0.2 -o packages -ExcludeVersion fi -if ! type k > /dev/null 2>&1; then +if ! type dnvm > /dev/null 2>&1; then source packages/KoreBuild/build/dnvm.sh fi @@ -36,3 +36,4 @@ if ! type k > /dev/null 2>&1; then fi mono packages/Sake/tools/Sake.exe -I packages/KoreBuild/build -f makefile.shade "$@" + From 48c6facf2966056e25e3854423802df0f5708eda Mon Sep 17 00:00:00 2001 From: "N. Taylor Mullen" Date: Mon, 9 Mar 2015 12:54:37 -0700 Subject: [PATCH 228/987] Remove BOM from project.json, *.cmd, *.sh and *.shade files. --- build.cmd | 2 +- build.sh | 2 +- src/Microsoft.AspNet.Hosting.Interfaces/project.json | 2 +- src/Microsoft.AspNet.Hosting/project.json | 2 +- src/Microsoft.AspNet.RequestContainer/project.json | 2 +- src/Microsoft.AspNet.TestHost/project.json | 2 +- test/Microsoft.AspNet.Hosting.Tests/project.json | 2 +- test/Microsoft.AspNet.TestHost.Tests/project.json | 2 +- 8 files changed, 8 insertions(+), 8 deletions(-) diff --git a/build.cmd b/build.cmd index 77be0a6627..68a732c182 100644 --- a/build.cmd +++ b/build.cmd @@ -1,4 +1,4 @@ -@echo off +@echo off cd %~dp0 SETLOCAL diff --git a/build.sh b/build.sh index a9ce06d087..ec3263114a 100755 --- a/build.sh +++ b/build.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/bash if test `uname` = Darwin; then cachedir=~/Library/Caches/KBuild diff --git a/src/Microsoft.AspNet.Hosting.Interfaces/project.json b/src/Microsoft.AspNet.Hosting.Interfaces/project.json index bb1e04e39b..496ff1441a 100644 --- a/src/Microsoft.AspNet.Hosting.Interfaces/project.json +++ b/src/Microsoft.AspNet.Hosting.Interfaces/project.json @@ -1,4 +1,4 @@ -{ +{ "version": "1.0.0-*", "dependencies": { "Microsoft.AspNet.Http": "1.0.0-*", diff --git a/src/Microsoft.AspNet.Hosting/project.json b/src/Microsoft.AspNet.Hosting/project.json index 03a441eba0..9d97fb6f7d 100644 --- a/src/Microsoft.AspNet.Hosting/project.json +++ b/src/Microsoft.AspNet.Hosting/project.json @@ -1,4 +1,4 @@ -{ +{ "version": "1.0.0-*", "description": "ASP.NET 5 core hosting infrastructure and startup logic for web applications.", "dependencies": { diff --git a/src/Microsoft.AspNet.RequestContainer/project.json b/src/Microsoft.AspNet.RequestContainer/project.json index b2729bd744..fdb20e9e8f 100644 --- a/src/Microsoft.AspNet.RequestContainer/project.json +++ b/src/Microsoft.AspNet.RequestContainer/project.json @@ -1,4 +1,4 @@ -{ +{ "version": "1.0.0-*", "description": "ASP.NET 5 enables per-request scoping of services.", "dependencies": { diff --git a/src/Microsoft.AspNet.TestHost/project.json b/src/Microsoft.AspNet.TestHost/project.json index c6360f74da..28acab776a 100644 --- a/src/Microsoft.AspNet.TestHost/project.json +++ b/src/Microsoft.AspNet.TestHost/project.json @@ -1,4 +1,4 @@ -{ +{ "version": "1.0.0-*", "description": "ASP.NET 5 web server for writing and running tests.", "dependencies": { diff --git a/test/Microsoft.AspNet.Hosting.Tests/project.json b/test/Microsoft.AspNet.Hosting.Tests/project.json index 22e492d189..ae45cb6fa0 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/project.json +++ b/test/Microsoft.AspNet.Hosting.Tests/project.json @@ -1,4 +1,4 @@ -{ +{ "dependencies": { "Microsoft.AspNet.Hosting": "1.0.0-*", "Microsoft.AspNet.Owin": "1.0.0-*", diff --git a/test/Microsoft.AspNet.TestHost.Tests/project.json b/test/Microsoft.AspNet.TestHost.Tests/project.json index df5be3e395..68b0f58d1f 100644 --- a/test/Microsoft.AspNet.TestHost.Tests/project.json +++ b/test/Microsoft.AspNet.TestHost.Tests/project.json @@ -1,4 +1,4 @@ -{ +{ "dependencies": { "Microsoft.AspNet.TestHost": "1.0.0-*", "xunit.runner.kre": "1.0.0-*" From 062214538e69566c46a0552efc5f60face5ce1f4 Mon Sep 17 00:00:00 2001 From: Praburaj Date: Mon, 9 Mar 2015 20:50:46 -0700 Subject: [PATCH 229/987] Renaming Nuget.org feed key name to Nuget. fixes https://github.com/aspnet/Universe/issues/174 --- NuGet.Config | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/NuGet.Config b/NuGet.Config index f41e9c631d..da57d47267 100644 --- a/NuGet.Config +++ b/NuGet.Config @@ -2,6 +2,6 @@ - + - + \ No newline at end of file From e3e0f1a1c365af479caaffbf0a11790dbb7ed910 Mon Sep 17 00:00:00 2001 From: "N. Taylor Mullen" Date: Wed, 11 Mar 2015 14:07:29 -0700 Subject: [PATCH 230/987] Update .kproj => .xproj. --- Hosting.sln | 12 +++---- ...Microsoft.AspNet.Hosting.Interfaces.xproj} | 0 ...g.kproj => Microsoft.AspNet.Hosting.xproj} | 0 ...> Microsoft.AspNet.RequestContainer.xproj} | 0 ....kproj => Microsoft.AspNet.TestHost.xproj} | 0 ...j => Microsoft.AspNet.Hosting.Tests.xproj} | 34 +++++++++---------- ... => Microsoft.AspNet.TestHost.Tests.xproj} | 34 +++++++++---------- 7 files changed, 40 insertions(+), 40 deletions(-) rename src/Microsoft.AspNet.Hosting.Interfaces/{Microsoft.AspNet.Hosting.Interfaces.kproj => Microsoft.AspNet.Hosting.Interfaces.xproj} (100%) rename src/Microsoft.AspNet.Hosting/{Microsoft.AspNet.Hosting.kproj => Microsoft.AspNet.Hosting.xproj} (100%) rename src/Microsoft.AspNet.RequestContainer/{Microsoft.AspNet.RequestContainer.kproj => Microsoft.AspNet.RequestContainer.xproj} (100%) rename src/Microsoft.AspNet.TestHost/{Microsoft.AspNet.TestHost.kproj => Microsoft.AspNet.TestHost.xproj} (100%) rename test/Microsoft.AspNet.Hosting.Tests/{Microsoft.AspNet.Hosting.Tests.kproj => Microsoft.AspNet.Hosting.Tests.xproj} (97%) rename test/Microsoft.AspNet.TestHost.Tests/{Microsoft.AspNet.TestHost.Tests.kproj => Microsoft.AspNet.TestHost.Tests.xproj} (98%) diff --git a/Hosting.sln b/Hosting.sln index 33c4336fb9..b698bea6b8 100644 --- a/Hosting.sln +++ b/Hosting.sln @@ -7,22 +7,22 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{E0497F39-AFF EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{FEB39027-9158-4DE2-997F-7ADAEF8188D0}" EndProject -Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNet.TestHost.Tests", "test\Microsoft.AspNet.TestHost.Tests\Microsoft.AspNet.TestHost.Tests.kproj", "{0ACB2719-9484-49B5-B8E3-117091192511}" +Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNet.TestHost.Tests", "test\Microsoft.AspNet.TestHost.Tests\Microsoft.AspNet.TestHost.Tests.xproj", "{0ACB2719-9484-49B5-B8E3-117091192511}" EndProject -Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNet.TestHost", "src\Microsoft.AspNet.TestHost\Microsoft.AspNet.TestHost.kproj", "{1A415A3F-1081-45DB-809B-EE19CEA02DC0}" +Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNet.TestHost", "src\Microsoft.AspNet.TestHost\Microsoft.AspNet.TestHost.xproj", "{1A415A3F-1081-45DB-809B-EE19CEA02DC0}" EndProject -Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNet.Hosting", "src\Microsoft.AspNet.Hosting\Microsoft.AspNet.Hosting.kproj", "{3944F036-7E75-47E8-AA52-C4B89A64EC3A}" +Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNet.Hosting", "src\Microsoft.AspNet.Hosting\Microsoft.AspNet.Hosting.xproj", "{3944F036-7E75-47E8-AA52-C4B89A64EC3A}" EndProject -Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNet.Hosting.Tests", "test\Microsoft.AspNet.Hosting.Tests\Microsoft.AspNet.Hosting.Tests.kproj", "{D4F18D58-52B1-435D-A012-10F2CDF158C4}" +Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNet.Hosting.Tests", "test\Microsoft.AspNet.Hosting.Tests\Microsoft.AspNet.Hosting.Tests.xproj", "{D4F18D58-52B1-435D-A012-10F2CDF158C4}" EndProject -Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNet.RequestContainer", "src\Microsoft.AspNet.RequestContainer\Microsoft.AspNet.RequestContainer.kproj", "{374A5B0C-3E93-4A23-A4A0-EE2AB6DF7814}" +Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNet.RequestContainer", "src\Microsoft.AspNet.RequestContainer\Microsoft.AspNet.RequestContainer.xproj", "{374A5B0C-3E93-4A23-A4A0-EE2AB6DF7814}" EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{A66E3673-3976-4152-B902-2D0EC1428EA2}" ProjectSection(SolutionItems) = preProject global.json = global.json EndProjectSection EndProject -Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNet.Hosting.Interfaces", "src\Microsoft.AspNet.Hosting.Interfaces\Microsoft.AspNet.Hosting.Interfaces.kproj", "{BB780FBB-7842-4759-8DE7-96FA2E5571C1}" +Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNet.Hosting.Interfaces", "src\Microsoft.AspNet.Hosting.Interfaces\Microsoft.AspNet.Hosting.Interfaces.xproj", "{BB780FBB-7842-4759-8DE7-96FA2E5571C1}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution diff --git a/src/Microsoft.AspNet.Hosting.Interfaces/Microsoft.AspNet.Hosting.Interfaces.kproj b/src/Microsoft.AspNet.Hosting.Interfaces/Microsoft.AspNet.Hosting.Interfaces.xproj similarity index 100% rename from src/Microsoft.AspNet.Hosting.Interfaces/Microsoft.AspNet.Hosting.Interfaces.kproj rename to src/Microsoft.AspNet.Hosting.Interfaces/Microsoft.AspNet.Hosting.Interfaces.xproj diff --git a/src/Microsoft.AspNet.Hosting/Microsoft.AspNet.Hosting.kproj b/src/Microsoft.AspNet.Hosting/Microsoft.AspNet.Hosting.xproj similarity index 100% rename from src/Microsoft.AspNet.Hosting/Microsoft.AspNet.Hosting.kproj rename to src/Microsoft.AspNet.Hosting/Microsoft.AspNet.Hosting.xproj diff --git a/src/Microsoft.AspNet.RequestContainer/Microsoft.AspNet.RequestContainer.kproj b/src/Microsoft.AspNet.RequestContainer/Microsoft.AspNet.RequestContainer.xproj similarity index 100% rename from src/Microsoft.AspNet.RequestContainer/Microsoft.AspNet.RequestContainer.kproj rename to src/Microsoft.AspNet.RequestContainer/Microsoft.AspNet.RequestContainer.xproj diff --git a/src/Microsoft.AspNet.TestHost/Microsoft.AspNet.TestHost.kproj b/src/Microsoft.AspNet.TestHost/Microsoft.AspNet.TestHost.xproj similarity index 100% rename from src/Microsoft.AspNet.TestHost/Microsoft.AspNet.TestHost.kproj rename to src/Microsoft.AspNet.TestHost/Microsoft.AspNet.TestHost.xproj diff --git a/test/Microsoft.AspNet.Hosting.Tests/Microsoft.AspNet.Hosting.Tests.kproj b/test/Microsoft.AspNet.Hosting.Tests/Microsoft.AspNet.Hosting.Tests.xproj similarity index 97% rename from test/Microsoft.AspNet.Hosting.Tests/Microsoft.AspNet.Hosting.Tests.kproj rename to test/Microsoft.AspNet.Hosting.Tests/Microsoft.AspNet.Hosting.Tests.xproj index 59c5545a1f..8f9318a85a 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/Microsoft.AspNet.Hosting.Tests.kproj +++ b/test/Microsoft.AspNet.Hosting.Tests/Microsoft.AspNet.Hosting.Tests.xproj @@ -1,18 +1,18 @@ - - - - 14.0 - $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) - - - - d4f18d58-52b1-435d-a012-10f2cdf158c4 - ..\..\artifacts\obj\$(MSBuildProjectName) - ..\..\artifacts\bin\$(MSBuildProjectName)\ - - - 2.0 - 18007 - - + + + + 14.0 + $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) + + + + d4f18d58-52b1-435d-a012-10f2cdf158c4 + ..\..\artifacts\obj\$(MSBuildProjectName) + ..\..\artifacts\bin\$(MSBuildProjectName)\ + + + 2.0 + 18007 + + \ No newline at end of file diff --git a/test/Microsoft.AspNet.TestHost.Tests/Microsoft.AspNet.TestHost.Tests.kproj b/test/Microsoft.AspNet.TestHost.Tests/Microsoft.AspNet.TestHost.Tests.xproj similarity index 98% rename from test/Microsoft.AspNet.TestHost.Tests/Microsoft.AspNet.TestHost.Tests.kproj rename to test/Microsoft.AspNet.TestHost.Tests/Microsoft.AspNet.TestHost.Tests.xproj index 04d1606ca3..b70af08ea5 100644 --- a/test/Microsoft.AspNet.TestHost.Tests/Microsoft.AspNet.TestHost.Tests.kproj +++ b/test/Microsoft.AspNet.TestHost.Tests/Microsoft.AspNet.TestHost.Tests.xproj @@ -1,17 +1,17 @@ - - - - 14.0 - $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) - - - - 0acb2719-9484-49b5-b8e3-117091192511 - ..\..\artifacts\obj\$(MSBuildProjectName) - ..\..\artifacts\bin\$(MSBuildProjectName)\ - - - 2.0 - - - + + + + 14.0 + $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) + + + + 0acb2719-9484-49b5-b8e3-117091192511 + ..\..\artifacts\obj\$(MSBuildProjectName) + ..\..\artifacts\bin\$(MSBuildProjectName)\ + + + 2.0 + + + From ebcb6196b879336f6fb8c9f378569229e3590d76 Mon Sep 17 00:00:00 2001 From: Doug Bunting Date: Wed, 11 Mar 2015 16:58:25 -0700 Subject: [PATCH 231/987] Do not use deprecated `dnvm -x86` switch --- build.cmd | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/build.cmd b/build.cmd index 68a732c182..41025afb26 100644 --- a/build.cmd +++ b/build.cmd @@ -20,9 +20,9 @@ IF EXIST packages\KoreBuild goto run .nuget\NuGet.exe install Sake -version 0.2 -o packages -ExcludeVersion IF "%SKIP_DNX_INSTALL%"=="1" goto run -CALL packages\KoreBuild\build\dnvm upgrade -runtime CLR -x86 -CALL packages\KoreBuild\build\dnvm install default -runtime CoreCLR -x86 +CALL packages\KoreBuild\build\dnvm upgrade -runtime CLR -arch x86 +CALL packages\KoreBuild\build\dnvm install default -runtime CoreCLR -arch x86 :run -CALL packages\KoreBuild\build\dnvm use default -runtime CLR -x86 +CALL packages\KoreBuild\build\dnvm use default -runtime CLR -arch x86 packages\Sake\tools\Sake.exe -I packages\KoreBuild\build -f makefile.shade %* From a10acfd4cdc896493896a61be034bd6b5e5f3f7b Mon Sep 17 00:00:00 2001 From: "N. Taylor Mullen" Date: Thu, 12 Mar 2015 17:17:33 -0700 Subject: [PATCH 232/987] Update xunit.runner.kre => xunit.runner.aspnet. --- test/Microsoft.AspNet.Hosting.Tests/project.json | 4 ++-- test/Microsoft.AspNet.TestHost.Tests/project.json | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/test/Microsoft.AspNet.Hosting.Tests/project.json b/test/Microsoft.AspNet.Hosting.Tests/project.json index ae45cb6fa0..a87f3cffd7 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/project.json +++ b/test/Microsoft.AspNet.Hosting.Tests/project.json @@ -3,13 +3,13 @@ "Microsoft.AspNet.Hosting": "1.0.0-*", "Microsoft.AspNet.Owin": "1.0.0-*", "Microsoft.AspNet.RequestContainer": "1.0.0-*", - "xunit.runner.kre": "1.0.0-*" + "xunit.runner.aspnet": "2.0.0-aspnet-*" }, "frameworks": { "dnx451": {} }, "commands": { - "test": "xunit.runner.kre" + "test": "xunit.runner.aspnet" }, "webroot": "testroot" } diff --git a/test/Microsoft.AspNet.TestHost.Tests/project.json b/test/Microsoft.AspNet.TestHost.Tests/project.json index 68b0f58d1f..968dba2a54 100644 --- a/test/Microsoft.AspNet.TestHost.Tests/project.json +++ b/test/Microsoft.AspNet.TestHost.Tests/project.json @@ -1,10 +1,10 @@ { "dependencies": { "Microsoft.AspNet.TestHost": "1.0.0-*", - "xunit.runner.kre": "1.0.0-*" + "xunit.runner.aspnet": "2.0.0-aspnet-*" }, "commands": { - "test": "xunit.runner.kre" + "test": "xunit.runner.aspnet" }, "frameworks": { "dnx451": { } From 3b0d5fd422e46691cdeddefc5ebd17053c63b932 Mon Sep 17 00:00:00 2001 From: Praburaj Date: Mon, 16 Mar 2015 13:13:50 -0700 Subject: [PATCH 233/987] Add extension method for getting environment name Fixes: https://github.com/aspnet/Hosting/issues/100 --- .../HostingEnvironmentExtensions.cs | 27 +++++++++++++++++++ .../project.json | 5 ++-- .../HostingEngineTests.cs | 26 ++++++++++++++++++ 3 files changed, 56 insertions(+), 2 deletions(-) create mode 100644 src/Microsoft.AspNet.Hosting.Interfaces/HostingEnvironmentExtensions.cs diff --git a/src/Microsoft.AspNet.Hosting.Interfaces/HostingEnvironmentExtensions.cs b/src/Microsoft.AspNet.Hosting.Interfaces/HostingEnvironmentExtensions.cs new file mode 100644 index 0000000000..b39316a281 --- /dev/null +++ b/src/Microsoft.AspNet.Hosting.Interfaces/HostingEnvironmentExtensions.cs @@ -0,0 +1,27 @@ +// 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 System; +using Microsoft.Framework.Internal; + +namespace Microsoft.AspNet.Hosting +{ + public static class HostingEnvironmentExtensions + { + /// + /// Compares the current hosting environment name against the specified value. + /// + /// An instance of service. + /// Environment name to validate against. + /// True if the specified name is same as the current environment. + public static bool IsEnvironment( + [NotNull]this IHostingEnvironment hostingEnvironment, + [NotNull]string environmentName) + { + return string.Equals( + hostingEnvironment.EnvironmentName, + environmentName, + StringComparison.OrdinalIgnoreCase); + } + } +} \ No newline at end of file diff --git a/src/Microsoft.AspNet.Hosting.Interfaces/project.json b/src/Microsoft.AspNet.Hosting.Interfaces/project.json index 496ff1441a..e21eb01c51 100644 --- a/src/Microsoft.AspNet.Hosting.Interfaces/project.json +++ b/src/Microsoft.AspNet.Hosting.Interfaces/project.json @@ -4,10 +4,11 @@ "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-*" + "Microsoft.Framework.ConfigurationModel": "1.0.0-*", + "Microsoft.Framework.NotNullAttribute.Internal": { "type": "build", "version": "1.0.0-*" } }, "frameworks": { "dnx451": {}, "dnxcore50": {} } -} +} \ No newline at end of file diff --git a/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs b/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs index d66e77a396..d6e1e64be5 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs @@ -63,6 +63,32 @@ namespace Microsoft.AspNet.Hosting Assert.True(env.WebRootFileProvider.GetFileInfo("TextFile.txt").Exists); } + [Fact] + public void Validate_Environment_Name() + { + var services = HostingServices.Create().BuildServiceProvider(); + var env = services.GetRequiredService(); + Assert.Equal("Development", env.EnvironmentName); + + var config = new Configuration() + .AddCommandLine(new string[] { "--ASPNET_ENV", "Overridden_Environment" }); + + services = HostingServices.Create(fallbackServices: null, configuration: config) + .BuildServiceProvider(); + + env = services.GetRequiredService(); + Assert.Equal("Overridden_Environment", env.EnvironmentName); + } + + [Fact] + public void IsEnvironment_Extension_Is_Case_Insensitive() + { + var services = HostingServices.Create().BuildServiceProvider(); + var env = services.GetRequiredService(); + Assert.True(env.IsEnvironment("Development")); + Assert.True(env.IsEnvironment("developMent")); + } + public void Initialize(IApplicationBuilder builder) { From de44c3be996514ba13c8ea92f1f7c159b6b57c58 Mon Sep 17 00:00:00 2001 From: Ajay Bhargav Baaskaran Date: Thu, 19 Feb 2015 14:33:26 -0800 Subject: [PATCH 234/987] React to aspnet/HttpAbstractions#160 - Implementing OnResponseCompleted in TestHost --- src/Microsoft.AspNet.TestHost/ClientHandler.cs | 1 + src/Microsoft.AspNet.TestHost/ResponseFeature.cs | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/src/Microsoft.AspNet.TestHost/ClientHandler.cs b/src/Microsoft.AspNet.TestHost/ClientHandler.cs index a1e281a7ca..8d8855d81e 100644 --- a/src/Microsoft.AspNet.TestHost/ClientHandler.cs +++ b/src/Microsoft.AspNet.TestHost/ClientHandler.cs @@ -174,6 +174,7 @@ namespace Microsoft.AspNet.TestHost if (!_responseTcs.Task.IsCompleted) { var response = GenerateResponse(); + _responseFeature.FireOnResponseCompleted(); // Dispatch, as TrySetResult will synchronously execute the waiters callback and block our Write. Task.Factory.StartNew(() => _responseTcs.TrySetResult(response)); } diff --git a/src/Microsoft.AspNet.TestHost/ResponseFeature.cs b/src/Microsoft.AspNet.TestHost/ResponseFeature.cs index de9765b383..b8bf81dcba 100644 --- a/src/Microsoft.AspNet.TestHost/ResponseFeature.cs +++ b/src/Microsoft.AspNet.TestHost/ResponseFeature.cs @@ -11,6 +11,7 @@ namespace Microsoft.AspNet.TestHost internal class ResponseFeature : IHttpResponseFeature { private Action _sendingHeaders = () => { }; + private Action _responseCompleted = () => { }; public ResponseFeature() { @@ -42,10 +43,25 @@ namespace Microsoft.AspNet.TestHost }; } + public void OnResponseCompleted(Action callback, object state) + { + var prior = _responseCompleted; + _responseCompleted = () => + { + callback(state); + prior(); + }; + } + public void FireOnSendingHeaders() { _sendingHeaders(); HeadersSent = true; } + + public void FireOnResponseCompleted() + { + _responseCompleted(); + } } } From 19b75b688ad8df06772041b3f8cef88388935699 Mon Sep 17 00:00:00 2001 From: Hao Kung Date: Thu, 19 Mar 2015 10:57:34 -0700 Subject: [PATCH 235/987] Rework hosting - IStartupFilter support - Rework HostingEngine - AutoRequestScope by default via (IStartupFilter) - RIP RequestContainer --- Hosting.sln | 15 +- .../IHostingEnvironment.cs | 2 +- .../ConfigureHostingEnvironment.cs | 23 -- .../HostingContext.cs | 11 +- src/Microsoft.AspNet.Hosting/HostingEngine.cs | 207 +++++++++++++---- .../HostingEnvironment.cs | 10 +- .../HostingServices.cs | 89 -------- .../HostingServicesCollectionExtensions.cs | 42 ---- .../IHostingEngine.cs | 12 - .../AutoRequestServicesStartupFilter.cs | 21 ++ .../Internal/PipelineInstance.cs | 37 --- .../Internal}/RequestServicesContainer.cs | 2 +- .../RequestServicesContainerMiddleware.cs} | 11 +- src/Microsoft.AspNet.Hosting/Program.cs | 24 +- .../Startup/ApplicationStartup.cs | 125 +++++++++++ .../Startup/ConfigureDelegate.cs | 60 +++++ .../Startup/ConfigureServicesDelegate.cs | 43 ++++ .../{IStartupLoader.cs => IStartupFilter.cs} | 9 +- .../Startup/StartupLoader.cs | 174 --------------- .../Startup/StartupMethods.cs | 22 ++ src/Microsoft.AspNet.Hosting/project.json | 1 + .../ContainerExtensions.cs | 55 ----- .../Microsoft.AspNet.RequestContainer.xproj | 17 -- .../project.json | 17 -- src/Microsoft.AspNet.TestHost/TestServer.cs | 59 +++-- .../Fakes/StartupUseServices.cs | 30 --- .../Fakes/StartupWithNullConfigureServices.cs | 16 ++ .../HostingEngineTests.cs | 122 ++++++---- .../HostingServicesFacts.cs | 210 ------------------ .../StartupManagerTests.cs | 96 ++------ .../UseRequestServicesFacts.cs | 98 -------- .../project.json | 2 +- .../ClientHandlerTests.cs | 1 - .../TestApplicationEnvironment.cs | 37 --- .../TestClientTests.cs | 14 +- .../TestServerTests.cs | 22 +- 36 files changed, 654 insertions(+), 1082 deletions(-) delete mode 100644 src/Microsoft.AspNet.Hosting/ConfigureHostingEnvironment.cs delete mode 100644 src/Microsoft.AspNet.Hosting/HostingServices.cs delete mode 100644 src/Microsoft.AspNet.Hosting/HostingServicesCollectionExtensions.cs delete mode 100644 src/Microsoft.AspNet.Hosting/IHostingEngine.cs create mode 100644 src/Microsoft.AspNet.Hosting/Internal/AutoRequestServicesStartupFilter.cs delete mode 100644 src/Microsoft.AspNet.Hosting/Internal/PipelineInstance.cs rename src/{Microsoft.AspNet.RequestContainer => Microsoft.AspNet.Hosting/Internal}/RequestServicesContainer.cs (98%) rename src/{Microsoft.AspNet.RequestContainer/ContainerMiddleware.cs => Microsoft.AspNet.Hosting/Internal/RequestServicesContainerMiddleware.cs} (67%) create mode 100644 src/Microsoft.AspNet.Hosting/Startup/ApplicationStartup.cs create mode 100644 src/Microsoft.AspNet.Hosting/Startup/ConfigureDelegate.cs create mode 100644 src/Microsoft.AspNet.Hosting/Startup/ConfigureServicesDelegate.cs rename src/Microsoft.AspNet.Hosting/Startup/{IStartupLoader.cs => IStartupFilter.cs} (54%) delete mode 100644 src/Microsoft.AspNet.Hosting/Startup/StartupLoader.cs create mode 100644 src/Microsoft.AspNet.Hosting/Startup/StartupMethods.cs delete mode 100644 src/Microsoft.AspNet.RequestContainer/ContainerExtensions.cs delete mode 100644 src/Microsoft.AspNet.RequestContainer/Microsoft.AspNet.RequestContainer.xproj delete mode 100644 src/Microsoft.AspNet.RequestContainer/project.json delete mode 100644 test/Microsoft.AspNet.Hosting.Tests/Fakes/StartupUseServices.cs create mode 100644 test/Microsoft.AspNet.Hosting.Tests/Fakes/StartupWithNullConfigureServices.cs delete mode 100644 test/Microsoft.AspNet.Hosting.Tests/HostingServicesFacts.cs delete mode 100644 test/Microsoft.AspNet.Hosting.Tests/UseRequestServicesFacts.cs delete mode 100644 test/Microsoft.AspNet.TestHost.Tests/TestApplicationEnvironment.cs diff --git a/Hosting.sln b/Hosting.sln index b698bea6b8..1110900290 100644 --- a/Hosting.sln +++ b/Hosting.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 14 -VisualStudioVersion = 14.0.22530.0 +VisualStudioVersion = 14.0.22710.0 MinimumVisualStudioVersion = 10.0.40219.1 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{E0497F39-AFFB-4819-A116-E39E361915AB}" EndProject @@ -15,8 +15,6 @@ Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNet.Hosting", EndProject Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNet.Hosting.Tests", "test\Microsoft.AspNet.Hosting.Tests\Microsoft.AspNet.Hosting.Tests.xproj", "{D4F18D58-52B1-435D-A012-10F2CDF158C4}" EndProject -Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNet.RequestContainer", "src\Microsoft.AspNet.RequestContainer\Microsoft.AspNet.RequestContainer.xproj", "{374A5B0C-3E93-4A23-A4A0-EE2AB6DF7814}" -EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{A66E3673-3976-4152-B902-2D0EC1428EA2}" ProjectSection(SolutionItems) = preProject global.json = global.json @@ -74,16 +72,6 @@ Global {D4F18D58-52B1-435D-A012-10F2CDF158C4}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU {D4F18D58-52B1-435D-A012-10F2CDF158C4}.Release|Mixed Platforms.Build.0 = Release|Any CPU {D4F18D58-52B1-435D-A012-10F2CDF158C4}.Release|x86.ActiveCfg = Release|Any CPU - {374A5B0C-3E93-4A23-A4A0-EE2AB6DF7814}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {374A5B0C-3E93-4A23-A4A0-EE2AB6DF7814}.Debug|Any CPU.Build.0 = Debug|Any CPU - {374A5B0C-3E93-4A23-A4A0-EE2AB6DF7814}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU - {374A5B0C-3E93-4A23-A4A0-EE2AB6DF7814}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU - {374A5B0C-3E93-4A23-A4A0-EE2AB6DF7814}.Debug|x86.ActiveCfg = Debug|Any CPU - {374A5B0C-3E93-4A23-A4A0-EE2AB6DF7814}.Release|Any CPU.ActiveCfg = Release|Any CPU - {374A5B0C-3E93-4A23-A4A0-EE2AB6DF7814}.Release|Any CPU.Build.0 = Release|Any CPU - {374A5B0C-3E93-4A23-A4A0-EE2AB6DF7814}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU - {374A5B0C-3E93-4A23-A4A0-EE2AB6DF7814}.Release|Mixed Platforms.Build.0 = Release|Any CPU - {374A5B0C-3E93-4A23-A4A0-EE2AB6DF7814}.Release|x86.ActiveCfg = Release|Any CPU {BB780FBB-7842-4759-8DE7-96FA2E5571C1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {BB780FBB-7842-4759-8DE7-96FA2E5571C1}.Debug|Any CPU.Build.0 = Debug|Any CPU {BB780FBB-7842-4759-8DE7-96FA2E5571C1}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU @@ -105,7 +93,6 @@ Global {1A415A3F-1081-45DB-809B-EE19CEA02DC0} = {E0497F39-AFFB-4819-A116-E39E361915AB} {3944F036-7E75-47E8-AA52-C4B89A64EC3A} = {E0497F39-AFFB-4819-A116-E39E361915AB} {D4F18D58-52B1-435D-A012-10F2CDF158C4} = {FEB39027-9158-4DE2-997F-7ADAEF8188D0} - {374A5B0C-3E93-4A23-A4A0-EE2AB6DF7814} = {E0497F39-AFFB-4819-A116-E39E361915AB} {BB780FBB-7842-4759-8DE7-96FA2E5571C1} = {E0497F39-AFFB-4819-A116-E39E361915AB} EndGlobalSection EndGlobal diff --git a/src/Microsoft.AspNet.Hosting.Interfaces/IHostingEnvironment.cs b/src/Microsoft.AspNet.Hosting.Interfaces/IHostingEnvironment.cs index c38028a604..393c963e20 100644 --- a/src/Microsoft.AspNet.Hosting.Interfaces/IHostingEnvironment.cs +++ b/src/Microsoft.AspNet.Hosting.Interfaces/IHostingEnvironment.cs @@ -7,7 +7,7 @@ namespace Microsoft.AspNet.Hosting { public interface IHostingEnvironment { - string EnvironmentName { get; set; } + string EnvironmentName { get; set; } string WebRootPath { get; } diff --git a/src/Microsoft.AspNet.Hosting/ConfigureHostingEnvironment.cs b/src/Microsoft.AspNet.Hosting/ConfigureHostingEnvironment.cs deleted file mode 100644 index 892eaab372..0000000000 --- a/src/Microsoft.AspNet.Hosting/ConfigureHostingEnvironment.cs +++ /dev/null @@ -1,23 +0,0 @@ -// 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 System; -using Microsoft.Framework.ConfigurationModel; - -namespace Microsoft.AspNet.Hosting -{ - internal class ConfigureHostingEnvironment : IConfigureHostingEnvironment - { - private IConfiguration _config; - private const string EnvironmentKey = "ASPNET_ENV"; - - public ConfigureHostingEnvironment(IConfiguration config) - { - _config = config; - } - - public void Configure(IHostingEnvironment hostingEnv) - { - hostingEnv.EnvironmentName = _config?.Get(EnvironmentKey) ?? hostingEnv.EnvironmentName; - } - } -} \ No newline at end of file diff --git a/src/Microsoft.AspNet.Hosting/HostingContext.cs b/src/Microsoft.AspNet.Hosting/HostingContext.cs index f5dd096850..3ff679a6b3 100644 --- a/src/Microsoft.AspNet.Hosting/HostingContext.cs +++ b/src/Microsoft.AspNet.Hosting/HostingContext.cs @@ -4,22 +4,29 @@ using System; using Microsoft.AspNet.Builder; using Microsoft.AspNet.Hosting.Server; +using Microsoft.AspNet.Hosting.Startup; using Microsoft.Framework.ConfigurationModel; +using Microsoft.Framework.DependencyInjection; namespace Microsoft.AspNet.Hosting { public class HostingContext { - public IApplicationLifetime ApplicationLifetime { get; set; } public IConfiguration Configuration { get; set; } public IApplicationBuilder Builder { get; set; } public string ApplicationName { get; set; } + public string WebRootPath { get; set; } public string EnvironmentName { get; set; } - public Action ApplicationStartup { get; set; } + public StartupMethods StartupMethods { get; set; } public RequestDelegate ApplicationDelegate { get; set; } + public IServiceCollection Services { get; } = new ServiceCollection(); + + // Result of ConfigureServices + public IServiceProvider ApplicationServices { get; set; } + public string ServerFactoryLocation { get; set; } public IServerFactory ServerFactory { get; set; } public IServerInformation Server { get; set; } diff --git a/src/Microsoft.AspNet.Hosting/HostingEngine.cs b/src/Microsoft.AspNet.Hosting/HostingEngine.cs index 1970e48bef..01fae429d5 100644 --- a/src/Microsoft.AspNet.Hosting/HostingEngine.cs +++ b/src/Microsoft.AspNet.Hosting/HostingEngine.cs @@ -9,51 +9,116 @@ using Microsoft.AspNet.Hosting.Builder; using Microsoft.AspNet.Hosting.Internal; using Microsoft.AspNet.Hosting.Server; using Microsoft.AspNet.Hosting.Startup; +using Microsoft.Framework.DependencyInjection; +using Microsoft.Framework.Runtime; +using Microsoft.Framework.Runtime.Infrastructure; namespace Microsoft.AspNet.Hosting { - public class HostingEngine : IHostingEngine + public class HostingEngine { - private readonly IServerLoader _serverManager; - private readonly IStartupLoader _startupLoader; - private readonly IApplicationBuilderFactory _builderFactory; - private readonly IHttpContextFactory _httpContextFactory; - private readonly IHttpContextAccessor _contextAccessor; + private const string EnvironmentKey = "ASPNET_ENV"; - public HostingEngine( - IServerLoader serverManager, - IStartupLoader startupLoader, - IApplicationBuilderFactory builderFactory, - IHttpContextFactory httpContextFactory, - IHttpContextAccessor contextAccessor) + private readonly IServiceProvider _fallbackServices; + private readonly ApplicationLifetime _appLifetime; + private readonly IApplicationEnvironment _applicationEnvironment; + private readonly HostingEnvironment _hostingEnvironment; + + private IServerLoader _serverLoader; + private IApplicationBuilderFactory _builderFactory; + + public HostingEngine() : this(fallbackServices: null) { } + + public HostingEngine(IServiceProvider fallbackServices) { - _serverManager = serverManager; - _startupLoader = startupLoader; - _builderFactory = builderFactory; - _httpContextFactory = httpContextFactory; - _contextAccessor = contextAccessor; + _fallbackServices = fallbackServices ?? CallContextServiceLocator.Locator.ServiceProvider; + _appLifetime = new ApplicationLifetime(); + _applicationEnvironment = _fallbackServices.GetRequiredService(); + _hostingEnvironment = new HostingEnvironment(_applicationEnvironment); + _fallbackServices = new WrappingServiceProvider(_fallbackServices, _hostingEnvironment, _appLifetime); } public IDisposable Start(HostingContext context) { + EnsureContextDefaults(context); + EnsureApplicationServices(context); EnsureBuilder(context); EnsureServerFactory(context); InitalizeServerFactory(context); EnsureApplicationDelegate(context); - var applicationLifetime = (ApplicationLifetime)context.ApplicationLifetime; - var pipeline = new PipelineInstance(_httpContextFactory, context.ApplicationDelegate, _contextAccessor); - var server = context.ServerFactory.Start(context.Server, pipeline.Invoke); + var contextFactory = context.ApplicationServices.GetRequiredService(); + var contextAccessor = context.ApplicationServices.GetRequiredService(); + var server = context.ServerFactory.Start(context.Server, + features => + { + var httpContext = contextFactory.CreateHttpContext(features); + contextAccessor.HttpContext = httpContext; + return context.ApplicationDelegate(httpContext); + }); return new Disposable(() => { - applicationLifetime.NotifyStopping(); + _appLifetime.NotifyStopping(); server.Dispose(); - pipeline.Dispose(); - applicationLifetime.NotifyStopped(); + _appLifetime.NotifyStopped(); }); } + private void EnsureContextDefaults(HostingContext context) + { + if (context.ApplicationName == null) + { + context.ApplicationName = _applicationEnvironment.ApplicationName; + } + + if (context.EnvironmentName == null) + { + context.EnvironmentName = context.Configuration?.Get(EnvironmentKey) ?? HostingEnvironment.DefaultEnvironmentName; + } + + _hostingEnvironment.EnvironmentName = context.EnvironmentName; + + if (context.WebRootPath != null) + { + _hostingEnvironment.WebRootPath = context.WebRootPath; + } + } + + private void EnsureApplicationServices(HostingContext context) + { + if (context.ApplicationServices != null) + { + return; + } + + EnsureStartupMethods(context); + + context.ApplicationServices = context.StartupMethods.ConfigureServicesDelegate(CreateHostingServices(context)); + } + + private void EnsureStartupMethods(HostingContext context) + { + if (context.StartupMethods != null) + { + return; + } + + var diagnosticMessages = new List(); + context.StartupMethods = ApplicationStartup.LoadStartupMethods( + _fallbackServices, + context.ApplicationName, + context.EnvironmentName, + diagnosticMessages); + + if (context.StartupMethods == null) + { + throw new ArgumentException( + diagnosticMessages.Aggregate("Failed to find an entry point for the web application.", (a, b) => a + "\r\n" + b), + nameof(context)); + } + } + private void EnsureBuilder(HostingContext context) { if (context.Builder != null) @@ -61,7 +126,13 @@ namespace Microsoft.AspNet.Hosting return; } + if (_builderFactory == null) + { + _builderFactory = context.ApplicationServices.GetRequiredService(); + } + context.Builder = _builderFactory.CreateBuilder(); + context.Builder.ApplicationServices = context.ApplicationServices; } private void EnsureServerFactory(HostingContext context) @@ -71,7 +142,12 @@ namespace Microsoft.AspNet.Hosting return; } - context.ServerFactory = _serverManager.LoadServerFactory(context.ServerFactoryLocation); + if (_serverLoader == null) + { + _serverLoader = context.ApplicationServices.GetRequiredService(); + } + + context.ServerFactory = _serverLoader.LoadServerFactory(context.ServerFactoryLocation); } private void InitalizeServerFactory(HostingContext context) @@ -87,6 +163,32 @@ namespace Microsoft.AspNet.Hosting } } + private IServiceCollection CreateHostingServices(HostingContext context) + { + var services = Import(_fallbackServices); + + services.TryAdd(ServiceDescriptor.Transient()); + + services.TryAdd(ServiceDescriptor.Transient()); + services.TryAdd(ServiceDescriptor.Transient()); + + // TODO: Do we expect this to be provide by the runtime eventually? + services.AddLogging(); + services.TryAdd(ServiceDescriptor.Singleton()); + + // Apply user services + services.Add(context.Services); + + // Jamming in app lifetime and hosting env since these must not be replaceable + services.AddInstance(_appLifetime); + services.AddInstance(_hostingEnvironment); + + // Conjure up a RequestServices + services.AddTransient(); + + return services; + } + private void EnsureApplicationDelegate(HostingContext context) { if (context.ApplicationDelegate != null) @@ -94,30 +196,59 @@ namespace Microsoft.AspNet.Hosting return; } - EnsureApplicationStartup(context); + // REVIEW: should we call EnsureApplicationServices? + var startupFilters = context.ApplicationServices.GetService>(); + var configure = context.StartupMethods.ConfigureDelegate; + foreach (var filter in startupFilters) + { + configure = filter.Configure(context.Builder, configure); + } + + configure(context.Builder); - context.ApplicationStartup.Invoke(context.Builder); context.ApplicationDelegate = context.Builder.Build(); } - private void EnsureApplicationStartup(HostingContext context) + private static IServiceCollection Import(IServiceProvider fallbackProvider) { - if (context.ApplicationStartup != null) + var services = new ServiceCollection(); + var manifest = fallbackProvider.GetRequiredService(); + foreach (var service in manifest.Services) { - return; + services.AddTransient(service, sp => fallbackProvider.GetService(service)); } - var diagnosticMessages = new List(); - context.ApplicationStartup = _startupLoader.LoadStartup( - context.ApplicationName, - context.EnvironmentName, - diagnosticMessages); + return services; + } - if (context.ApplicationStartup == null) + private class WrappingServiceProvider : IServiceProvider + { + private readonly IServiceProvider _sp; + private readonly IHostingEnvironment _hostingEnvironment; + private readonly IApplicationLifetime _applicationLifetime; + + public WrappingServiceProvider(IServiceProvider sp, + IHostingEnvironment hostingEnvironment, + IApplicationLifetime applicationLifetime) { - throw new ArgumentException( - diagnosticMessages.Aggregate("Failed to find an entry point for the web application.", (a, b) => a + "\r\n" + b), - nameof(context)); + _sp = sp; + _hostingEnvironment = hostingEnvironment; + _applicationLifetime = applicationLifetime; + } + + public object GetService(Type serviceType) + { + if (serviceType == typeof(IHostingEnvironment)) + { + return _hostingEnvironment; + } + + if (serviceType == typeof(IApplicationLifetime)) + { + return _applicationLifetime; + } + + return _sp.GetService(serviceType); } } diff --git a/src/Microsoft.AspNet.Hosting/HostingEnvironment.cs b/src/Microsoft.AspNet.Hosting/HostingEnvironment.cs index 03a7317453..b7a0249319 100644 --- a/src/Microsoft.AspNet.Hosting/HostingEnvironment.cs +++ b/src/Microsoft.AspNet.Hosting/HostingEnvironment.cs @@ -10,22 +10,18 @@ namespace Microsoft.AspNet.Hosting { public class HostingEnvironment : IHostingEnvironment { - private const string DefaultEnvironmentName = "Development"; + internal const string DefaultEnvironmentName = "Development"; - public HostingEnvironment(IApplicationEnvironment appEnvironment, IEnumerable configures) + public HostingEnvironment(IApplicationEnvironment appEnvironment) { EnvironmentName = DefaultEnvironmentName; WebRootPath = HostingUtilities.GetWebRoot(appEnvironment.ApplicationBasePath); WebRootFileProvider = new PhysicalFileProvider(WebRootPath); - foreach (var configure in configures) - { - configure.Configure(this); - } } public string EnvironmentName { get; set; } - public string WebRootPath { get; private set; } + public string WebRootPath { get; set; } public IFileProvider WebRootFileProvider { get; private set; } } diff --git a/src/Microsoft.AspNet.Hosting/HostingServices.cs b/src/Microsoft.AspNet.Hosting/HostingServices.cs deleted file mode 100644 index 6a321a0098..0000000000 --- a/src/Microsoft.AspNet.Hosting/HostingServices.cs +++ /dev/null @@ -1,89 +0,0 @@ -// 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 System; -using System.Collections.Generic; -using System.Linq; -using Microsoft.Framework.ConfigurationModel; -using Microsoft.Framework.DependencyInjection; -using Microsoft.Framework.Logging; -using Microsoft.Framework.Runtime; -using Microsoft.Framework.Runtime.Infrastructure; - -namespace Microsoft.AspNet.Hosting -{ - public static class HostingServices - { - private static IServiceCollection Import(IServiceProvider fallbackProvider, Action configureHostServices) - { - var services = new ServiceCollection(); - var manifest = fallbackProvider.GetRequiredService(); - foreach (var service in manifest.Services) - { - services.AddTransient(service, sp => fallbackProvider.GetService(service)); - } - - if (configureHostServices != null) - { - configureHostServices(services); - } - - services.AddSingleton(sp => new HostingManifest(services)); - - return services; - } - - public static IServiceCollection Create() - { - return Create(CallContextServiceLocator.Locator.ServiceProvider, configureHostServices: null, configuration: null); - } - - public static IServiceCollection Create(IServiceProvider fallbackServices) - { - return Create(fallbackServices, configureHostServices: null, configuration: null); - } - - public static IServiceCollection Create(Action configureHostServices) - { - return Create(CallContextServiceLocator.Locator.ServiceProvider, configureHostServices, configuration: null); - } - - public static IServiceCollection Create(IServiceProvider fallbackServices, Action configureHostServices) - { - return Create(fallbackServices, configureHostServices, configuration: null); - } - - public static IServiceCollection Create(Action configureHostServices, IConfiguration configuration) - { - return Create(CallContextServiceLocator.Locator.ServiceProvider, configureHostServices, configuration); - } - - public static IServiceCollection Create(IServiceProvider fallbackServices, IConfiguration configuration) - { - return Create(CallContextServiceLocator.Locator.ServiceProvider, configureHostServices: null, configuration: configuration); - } - - public static IServiceCollection Create(IServiceProvider fallbackServices, Action configureHostServices, IConfiguration configuration) - { - var services = Import(fallbackServices, configureHostServices); - services.AddHosting(configuration); - return services; - } - - // Manifest exposes the fallback manifest in addition to ITypeActivator, IHostingEnvironment, and ILoggerFactory - private class HostingManifest : IServiceManifest - { - public HostingManifest(IServiceCollection hostServices) - { - Services = new Type[] { - typeof(IHostingEnvironment), - typeof(ILoggerFactory), - typeof(IHttpContextAccessor), - typeof(IApplicationLifetime) - }.Concat(hostServices.Select(s => s.ServiceType)).Distinct(); - } - - public IEnumerable Services { get; private set; } - } - } -} \ No newline at end of file diff --git a/src/Microsoft.AspNet.Hosting/HostingServicesCollectionExtensions.cs b/src/Microsoft.AspNet.Hosting/HostingServicesCollectionExtensions.cs deleted file mode 100644 index ba3336d541..0000000000 --- a/src/Microsoft.AspNet.Hosting/HostingServicesCollectionExtensions.cs +++ /dev/null @@ -1,42 +0,0 @@ -// 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.Hosting; -using Microsoft.AspNet.Hosting.Builder; -using Microsoft.AspNet.Hosting.Server; -using Microsoft.AspNet.Hosting.Startup; -using Microsoft.Framework.ConfigurationModel; - -namespace Microsoft.Framework.DependencyInjection -{ - public static class HostingServicesExtensions - { - public static IServiceCollection AddHosting(this IServiceCollection services) - { - return services.AddHosting(configuration: null); - } - - public static IServiceCollection AddHosting(this IServiceCollection services, IConfiguration configuration) - { - services.TryAdd(ServiceDescriptor.Transient()); - services.TryAdd(ServiceDescriptor.Transient()); - - services.TryAdd(ServiceDescriptor.Transient()); - - services.TryAdd(ServiceDescriptor.Transient()); - services.TryAdd(ServiceDescriptor.Transient()); - - services.TryAdd(ServiceDescriptor.Instance(new ApplicationLifetime())); - - // TODO: Do we expect this to be provide by the runtime eventually? - services.AddLogging(); - services.TryAdd(ServiceDescriptor.Singleton()); - services.TryAdd(ServiceDescriptor.Singleton()); - - // REVIEW: don't try add because we pull out IEnumerable? - services.AddInstance(new ConfigureHostingEnvironment(configuration)); - - return services; - } - } -} \ No newline at end of file diff --git a/src/Microsoft.AspNet.Hosting/IHostingEngine.cs b/src/Microsoft.AspNet.Hosting/IHostingEngine.cs deleted file mode 100644 index ba6c74ecd1..0000000000 --- a/src/Microsoft.AspNet.Hosting/IHostingEngine.cs +++ /dev/null @@ -1,12 +0,0 @@ -// 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 System; - -namespace Microsoft.AspNet.Hosting -{ - public interface IHostingEngine - { - IDisposable Start(HostingContext context); - } -} \ No newline at end of file diff --git a/src/Microsoft.AspNet.Hosting/Internal/AutoRequestServicesStartupFilter.cs b/src/Microsoft.AspNet.Hosting/Internal/AutoRequestServicesStartupFilter.cs new file mode 100644 index 0000000000..0d28da169c --- /dev/null +++ b/src/Microsoft.AspNet.Hosting/Internal/AutoRequestServicesStartupFilter.cs @@ -0,0 +1,21 @@ +// 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 System; +using Microsoft.AspNet.Builder; +using Microsoft.AspNet.Hosting.Startup; + +namespace Microsoft.AspNet.Hosting.Internal +{ + public class AutoRequestServicesStartupFilter : IStartupFilter + { + public Action Configure(IApplicationBuilder app, Action next) + { + return builder => + { + app.UseMiddleware(); + next(builder); + }; + } + } +} diff --git a/src/Microsoft.AspNet.Hosting/Internal/PipelineInstance.cs b/src/Microsoft.AspNet.Hosting/Internal/PipelineInstance.cs deleted file mode 100644 index b2f67c2eca..0000000000 --- a/src/Microsoft.AspNet.Hosting/Internal/PipelineInstance.cs +++ /dev/null @@ -1,37 +0,0 @@ -// 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 System; -using System.Threading.Tasks; -using Microsoft.AspNet.Builder; -using Microsoft.AspNet.FeatureModel; -using Microsoft.AspNet.Hosting.Builder; - -namespace Microsoft.AspNet.Hosting.Internal -{ - public class PipelineInstance : IDisposable - { - private readonly IHttpContextFactory _httpContextFactory; - private readonly RequestDelegate _requestDelegate; - private readonly IHttpContextAccessor _contextAccessor; - - public PipelineInstance(IHttpContextFactory httpContextFactory, RequestDelegate requestDelegate, IHttpContextAccessor contextAccessor) - { - _httpContextFactory = httpContextFactory; - _requestDelegate = requestDelegate; - _contextAccessor = contextAccessor; - } - - public Task Invoke(IFeatureCollection featureCollection) - { - var httpContext = _httpContextFactory.CreateHttpContext(featureCollection); - _contextAccessor.HttpContext = httpContext; - return _requestDelegate(httpContext); - } - - public void Dispose() - { - // TODO: application notification of disposal - } - } -} diff --git a/src/Microsoft.AspNet.RequestContainer/RequestServicesContainer.cs b/src/Microsoft.AspNet.Hosting/Internal/RequestServicesContainer.cs similarity index 98% rename from src/Microsoft.AspNet.RequestContainer/RequestServicesContainer.cs rename to src/Microsoft.AspNet.Hosting/Internal/RequestServicesContainer.cs index 747aae5012..716c2ed3be 100644 --- a/src/Microsoft.AspNet.RequestContainer/RequestServicesContainer.cs +++ b/src/Microsoft.AspNet.Hosting/Internal/RequestServicesContainer.cs @@ -5,7 +5,7 @@ using System; using Microsoft.AspNet.Http; using Microsoft.Framework.DependencyInjection; -namespace Microsoft.AspNet.RequestContainer +namespace Microsoft.AspNet.Hosting.Internal { public class RequestServicesContainer : IDisposable { diff --git a/src/Microsoft.AspNet.RequestContainer/ContainerMiddleware.cs b/src/Microsoft.AspNet.Hosting/Internal/RequestServicesContainerMiddleware.cs similarity index 67% rename from src/Microsoft.AspNet.RequestContainer/ContainerMiddleware.cs rename to src/Microsoft.AspNet.Hosting/Internal/RequestServicesContainerMiddleware.cs index 097acf6d1b..8ffd9f7a06 100644 --- a/src/Microsoft.AspNet.RequestContainer/ContainerMiddleware.cs +++ b/src/Microsoft.AspNet.Hosting/Internal/RequestServicesContainerMiddleware.cs @@ -6,14 +6,14 @@ using System.Threading.Tasks; using Microsoft.AspNet.Builder; using Microsoft.AspNet.Http; -namespace Microsoft.AspNet.RequestContainer +namespace Microsoft.AspNet.Hosting.Internal { - public class ContainerMiddleware + public class RequestServicesContainerMiddleware { private readonly RequestDelegate _next; private readonly IServiceProvider _services; - public ContainerMiddleware(RequestDelegate next, IServiceProvider services) + public RequestServicesContainerMiddleware(RequestDelegate next, IServiceProvider services) { _services = services; _next = next; @@ -21,11 +21,6 @@ namespace Microsoft.AspNet.RequestContainer public async Task Invoke(HttpContext httpContext) { - if (httpContext.RequestServices != null) - { - throw new Exception("TODO: nested request container scope? this is probably a mistake on your part?"); - } - using (var container = RequestServicesContainer.EnsureRequestServices(httpContext, _services)) { await _next.Invoke(httpContext); diff --git a/src/Microsoft.AspNet.Hosting/Program.cs b/src/Microsoft.AspNet.Hosting/Program.cs index 65658f606b..47211a65ed 100644 --- a/src/Microsoft.AspNet.Hosting/Program.cs +++ b/src/Microsoft.AspNet.Hosting/Program.cs @@ -33,29 +33,19 @@ namespace Microsoft.AspNet.Hosting config.AddEnvironmentVariables(); config.AddCommandLine(args); - var services = HostingServices.Create(_serviceProvider, config) - .BuildServiceProvider(); - - var appEnv = services.GetRequiredService(); - var hostingEnv = services.GetRequiredService(); - var applicationLifetime = services.GetRequiredService(); - var context = new HostingContext() { - ApplicationLifetime = applicationLifetime, Configuration = config, - ServerFactoryLocation = config.Get("server"), // TODO: Key names - ApplicationName = config.Get("app") // TODO: Key names - ?? appEnv.ApplicationName, - EnvironmentName = hostingEnv.EnvironmentName, + ServerFactoryLocation = config.Get("server"), + ApplicationName = config.Get("app") }; - var engine = services.GetRequiredService(); - var loggerFactory = services.GetRequiredService(); - var appShutdownService = _serviceProvider.GetRequiredService(); - var shutdownHandle = new ManualResetEvent(false); - + var engine = new HostingEngine(_serviceProvider); + var serverShutdown = engine.Start(context); + var loggerFactory = context.ApplicationServices.GetRequiredService(); + var appShutdownService = context.ApplicationServices.GetRequiredService(); + var shutdownHandle = new ManualResetEvent(false); appShutdownService.ShutdownRequested.Register(() => { diff --git a/src/Microsoft.AspNet.Hosting/Startup/ApplicationStartup.cs b/src/Microsoft.AspNet.Hosting/Startup/ApplicationStartup.cs new file mode 100644 index 0000000000..811afb5590 --- /dev/null +++ b/src/Microsoft.AspNet.Hosting/Startup/ApplicationStartup.cs @@ -0,0 +1,125 @@ +// 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 System; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; +using System.Reflection; +using Microsoft.Framework.DependencyInjection; + +namespace Microsoft.AspNet.Hosting.Startup +{ + public static class ApplicationStartup + { + internal static ConfigureServicesDelegate DefaultBuildServiceProvider = s => s.BuildServiceProvider(); + + public static StartupMethods LoadStartupMethods( + IServiceProvider services, + string applicationName, + string environmentName, + IList diagnosticMessages) + { + if (string.IsNullOrEmpty(applicationName)) + { + throw new ArgumentException("Value cannot be null or empty.", "applicationName"); + } + + var assembly = Assembly.Load(new AssemblyName(applicationName)); + if (assembly == null) + { + throw new InvalidOperationException(String.Format("The assembly '{0}' failed to load.", applicationName)); + } + + var startupNameWithEnv = "Startup" + environmentName; + var startupNameWithoutEnv = "Startup"; + + // Check the most likely places first + var type = + assembly.GetType(startupNameWithEnv) ?? + assembly.GetType(applicationName + "." + startupNameWithEnv) ?? + assembly.GetType(startupNameWithoutEnv) ?? + assembly.GetType(applicationName + "." + startupNameWithoutEnv); + + if (type == null) + { + // Full scan + var definedTypes = assembly.DefinedTypes.ToList(); + + var startupType1 = definedTypes.Where(info => info.Name.Equals(startupNameWithEnv, StringComparison.Ordinal)); + var startupType2 = definedTypes.Where(info => info.Name.Equals(startupNameWithoutEnv, StringComparison.Ordinal)); + + var typeInfo = startupType1.Concat(startupType2).FirstOrDefault(); + if (typeInfo != null) + { + type = typeInfo.AsType(); + } + } + + if (type == null) + { + throw new InvalidOperationException(String.Format("A type named '{0}' or '{1}' could not be found in assembly '{2}'.", + startupNameWithEnv, + startupNameWithoutEnv, + applicationName)); + } + + var configureMethod = FindConfigureDelegate(type, environmentName); + var servicesMethod = FindConfigureServicesDelegate(type, environmentName); + + object instance = null; + if (!configureMethod.MethodInfo.IsStatic || (servicesMethod != null && !servicesMethod.MethodInfo.IsStatic)) + { + instance = ActivatorUtilities.GetServiceOrCreateInstance(services, type); + } + + return new StartupMethods(configureMethod.Build(instance), servicesMethod?.Build(instance)); + } + + + public static ConfigureBuilder FindConfigureDelegate(Type startupType, string environmentName) + { + var configureMethod = FindMethod(startupType, "Configure{0}", environmentName, typeof(void), required: true); + return new ConfigureBuilder(configureMethod); + } + + public static ConfigureServicesBuilder FindConfigureServicesDelegate(Type startupType, string environmentName) + { + var servicesMethod = FindMethod(startupType, "Configure{0}Services", environmentName, typeof(IServiceProvider), required: false) + ?? FindMethod(startupType, "Configure{0}Services", environmentName, typeof(void), required: false); + return servicesMethod == null ? null : new ConfigureServicesBuilder(servicesMethod); + } + + private static MethodInfo FindMethod(Type startupType, string methodName, string environmentName, Type returnType = null, bool required = true) + { + var methodNameWithEnv = string.Format(CultureInfo.InvariantCulture, methodName, environmentName); + var methodNameWithNoEnv = string.Format(CultureInfo.InvariantCulture, methodName, ""); + var methodInfo = startupType.GetMethod(methodNameWithEnv, BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static) + ?? startupType.GetMethod(methodNameWithNoEnv, BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static); + if (methodInfo == null) + { + if (required) + { + throw new InvalidOperationException(string.Format("A method named '{0}' or '{1}' in the type '{2}' could not be found.", + methodNameWithEnv, + methodNameWithNoEnv, + startupType.FullName)); + + } + return null; + } + if (returnType != null && methodInfo.ReturnType != returnType) + { + if (required) + { + throw new InvalidOperationException(string.Format("The '{0}' method in the type '{1}' must have a return type of '{2}'.", + methodInfo.Name, + startupType.FullName, + returnType.Name)); + } + return null; + } + return methodInfo; + } + } +} \ No newline at end of file diff --git a/src/Microsoft.AspNet.Hosting/Startup/ConfigureDelegate.cs b/src/Microsoft.AspNet.Hosting/Startup/ConfigureDelegate.cs new file mode 100644 index 0000000000..415302a961 --- /dev/null +++ b/src/Microsoft.AspNet.Hosting/Startup/ConfigureDelegate.cs @@ -0,0 +1,60 @@ +// 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 System; +using System.Reflection; +using Microsoft.AspNet.Builder; +using Microsoft.Framework.DependencyInjection; + +namespace Microsoft.AspNet.Hosting.Startup +{ + // TODO: replace all Action eventually with this + public delegate void ConfigureDelegate(IApplicationBuilder builder); + + public class ConfigureBuilder + { + public ConfigureBuilder(MethodInfo configure) + { + MethodInfo = configure; + } + + public MethodInfo MethodInfo { get; } + + public Action Build(object instance) + { + return builder => Invoke(instance, builder); + } + + private void Invoke(object instance, IApplicationBuilder builder) + { + var serviceProvider = builder.ApplicationServices; + var parameterInfos = MethodInfo.GetParameters(); + var parameters = new object[parameterInfos.Length]; + for (var index = 0; index != parameterInfos.Length; ++index) + { + var parameterInfo = parameterInfos[index]; + if (parameterInfo.ParameterType == typeof(IApplicationBuilder)) + { + parameters[index] = builder; + } + else + { + try + { + parameters[index] = serviceProvider.GetRequiredService(parameterInfo.ParameterType); + } + catch (Exception) + { + throw new Exception(string.Format( + "Could not resolve a service of type '{0}' for the parameter '{1}' of method '{2}' on type '{3}'.", + parameterInfo.ParameterType.FullName, + parameterInfo.Name, + MethodInfo.Name, + MethodInfo.DeclaringType.FullName)); + } + } + } + MethodInfo.Invoke(instance, parameters); + } + } +} \ No newline at end of file diff --git a/src/Microsoft.AspNet.Hosting/Startup/ConfigureServicesDelegate.cs b/src/Microsoft.AspNet.Hosting/Startup/ConfigureServicesDelegate.cs new file mode 100644 index 0000000000..c55eee4c6f --- /dev/null +++ b/src/Microsoft.AspNet.Hosting/Startup/ConfigureServicesDelegate.cs @@ -0,0 +1,43 @@ +// 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 System; +using System.Reflection; +using Microsoft.Framework.DependencyInjection; + +namespace Microsoft.AspNet.Hosting.Startup +{ + public delegate IServiceProvider ConfigureServicesDelegate(IServiceCollection services); + + public class ConfigureServicesBuilder + { + public ConfigureServicesBuilder(MethodInfo configureServices) + { + MethodInfo = configureServices; + } + + public MethodInfo MethodInfo { get; } + + public ConfigureServicesDelegate Build(object instance) + { + return services => Invoke(instance, services); + } + + private IServiceProvider Invoke(object instance, IServiceCollection exportServices) + { + var parameterInfos = MethodInfo.GetParameters(); + var parameters = new object[parameterInfos.Length]; + for (var index = 0; index != parameterInfos.Length; ++index) + { + var parameterInfo = parameterInfos[index]; + if (exportServices != null && parameterInfo.ParameterType == typeof(IServiceCollection)) + { + parameters[index] = exportServices; + } + } + + // REVIEW: We null ref if exportServices is null, cuz it should not be null + return MethodInfo.Invoke(instance, parameters) as IServiceProvider ?? exportServices.BuildServiceProvider(); + } + } +} \ No newline at end of file diff --git a/src/Microsoft.AspNet.Hosting/Startup/IStartupLoader.cs b/src/Microsoft.AspNet.Hosting/Startup/IStartupFilter.cs similarity index 54% rename from src/Microsoft.AspNet.Hosting/Startup/IStartupLoader.cs rename to src/Microsoft.AspNet.Hosting/Startup/IStartupFilter.cs index 24667a0c42..943c8aed32 100644 --- a/src/Microsoft.AspNet.Hosting/Startup/IStartupLoader.cs +++ b/src/Microsoft.AspNet.Hosting/Startup/IStartupFilter.cs @@ -2,16 +2,13 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using System.Collections.Generic; using Microsoft.AspNet.Builder; namespace Microsoft.AspNet.Hosting.Startup { - public interface IStartupLoader + public interface IStartupFilter { - Action LoadStartup( - string applicationName, - string environmentName, - IList diagnosticMessages); + // TODO: replace with ConfigureDelegate? + Action Configure(IApplicationBuilder app, Action next); } } diff --git a/src/Microsoft.AspNet.Hosting/Startup/StartupLoader.cs b/src/Microsoft.AspNet.Hosting/Startup/StartupLoader.cs deleted file mode 100644 index bed2a0190d..0000000000 --- a/src/Microsoft.AspNet.Hosting/Startup/StartupLoader.cs +++ /dev/null @@ -1,174 +0,0 @@ -// 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 System; -using System.Collections.Generic; -using System.Globalization; -using System.Linq; -using System.Reflection; -using Microsoft.AspNet.Builder; -using Microsoft.Framework.DependencyInjection; - -namespace Microsoft.AspNet.Hosting.Startup -{ - public class StartupLoader : IStartupLoader - { - private readonly IServiceProvider _services; - - public StartupLoader(IServiceProvider services) - { - _services = services; - } - - private MethodInfo FindMethod(Type startupType, string methodName, string environmentName, Type returnType = null, bool required = true) - { - var methodNameWithEnv = string.Format(CultureInfo.InvariantCulture, methodName, environmentName); - var methodNameWithNoEnv = string.Format(CultureInfo.InvariantCulture, methodName, ""); - var methodInfo = startupType.GetMethod(methodNameWithEnv, BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static) - ?? startupType.GetMethod(methodNameWithNoEnv, BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static); - if (methodInfo == null) - { - if (required) - { - throw new Exception(string.Format("A method named '{0}' or '{1}' in the type '{2}' could not be found.", - methodNameWithEnv, - methodNameWithNoEnv, - startupType.FullName)); - - } - return null; - } - if (returnType != null && methodInfo.ReturnType != returnType) - { - if (required) - { - throw new Exception(string.Format("The '{0}' method in the type '{1}' must have a return type of '{2}'.", - methodInfo.Name, - startupType.FullName, - returnType.Name)); - } - return null; - } - return methodInfo; - } - - private object Invoke(MethodInfo methodInfo, object instance, IApplicationBuilder builder, IServiceCollection services = null) - { - var serviceProvider = builder.ApplicationServices ?? _services; - var parameterInfos = methodInfo.GetParameters(); - var parameters = new object[parameterInfos.Length]; - for (var index = 0; index != parameterInfos.Length; ++index) - { - var parameterInfo = parameterInfos[index]; - if (parameterInfo.ParameterType == typeof(IApplicationBuilder)) - { - parameters[index] = builder; - } - else if (services != null && parameterInfo.ParameterType == typeof(IServiceCollection)) - { - parameters[index] = services; - } - else - { - try - { - parameters[index] = serviceProvider.GetRequiredService(parameterInfo.ParameterType); - } - catch (Exception) - { - throw new Exception(string.Format( - "Could not resolve a service of type '{0}' for the parameter '{1}' of method '{2}' on type '{3}'.", - parameterInfo.ParameterType.FullName, - parameterInfo.Name, - methodInfo.Name, - methodInfo.DeclaringType.FullName)); - } - } - } - return methodInfo.Invoke(instance, parameters); - } - - public Action LoadStartup( - string applicationName, - string environmentName, - IList diagnosticMessages) - { - if (string.IsNullOrEmpty(applicationName)) - { - throw new ArgumentException("Value cannot be null or empty.", "applicationName"); - } - - var assembly = Assembly.Load(new AssemblyName(applicationName)); - if (assembly == null) - { - throw new Exception(String.Format("The assembly '{0}' failed to load.", applicationName)); - } - - var startupNameWithEnv = "Startup" + environmentName; - var startupNameWithoutEnv = "Startup"; - - // Check the most likely places first - var type = - assembly.GetType(startupNameWithEnv) ?? - assembly.GetType(applicationName + "." + startupNameWithEnv) ?? - assembly.GetType(startupNameWithoutEnv) ?? - assembly.GetType(applicationName + "." + startupNameWithoutEnv); - - if (type == null) - { - // Full scan - var definedTypes = assembly.DefinedTypes.ToList(); - - var startupType1 = definedTypes.Where(info => info.Name.Equals(startupNameWithEnv, StringComparison.Ordinal)); - var startupType2 = definedTypes.Where(info => info.Name.Equals(startupNameWithoutEnv, StringComparison.Ordinal)); - - var typeInfo = startupType1.Concat(startupType2).FirstOrDefault(); - if (typeInfo != null) - { - type = typeInfo.AsType(); - } - } - - if (type == null) - { - throw new Exception(String.Format("A type named '{0}' or '{1}' could not be found in assembly '{2}'.", - startupNameWithEnv, - startupNameWithoutEnv, - applicationName)); - } - - var configureMethod = FindMethod(type, "Configure{0}", environmentName, typeof(void), required: true); - var servicesMethod = FindMethod(type, "Configure{0}Services", environmentName, typeof(IServiceProvider), required: false) - ?? FindMethod(type, "Configure{0}Services", environmentName, typeof(void), required: false); - - object instance = null; - if (!configureMethod.IsStatic || (servicesMethod != null && !servicesMethod.IsStatic)) - { - instance = ActivatorUtilities.GetServiceOrCreateInstance(_services, type); - } - return builder => - { - if (servicesMethod != null) - { - var services = HostingServices.Create(builder.ApplicationServices); - if (servicesMethod.ReturnType == typeof(IServiceProvider)) - { - // IServiceProvider ConfigureServices(IServiceCollection) - builder.ApplicationServices = (Invoke(servicesMethod, instance, builder, services) as IServiceProvider) - ?? builder.ApplicationServices; - } - else - { - // void ConfigureServices(IServiceCollection) - Invoke(servicesMethod, instance, builder, services); - if (builder != null) - { - builder.ApplicationServices = services.BuildServiceProvider(); - } - } - } - Invoke(configureMethod, instance, builder); - }; - } - } -} diff --git a/src/Microsoft.AspNet.Hosting/Startup/StartupMethods.cs b/src/Microsoft.AspNet.Hosting/Startup/StartupMethods.cs new file mode 100644 index 0000000000..4b3a5c9c5c --- /dev/null +++ b/src/Microsoft.AspNet.Hosting/Startup/StartupMethods.cs @@ -0,0 +1,22 @@ +// 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 System; +using Microsoft.AspNet.Builder; + +namespace Microsoft.AspNet.Hosting.Startup +{ + public class StartupMethods + { + // TODO: switch to ConfigureDelegate eventually + public StartupMethods(Action configure, ConfigureServicesDelegate configureServices) + { + ConfigureDelegate = configure; + ConfigureServicesDelegate = configureServices ?? ApplicationStartup.DefaultBuildServiceProvider; + } + + public ConfigureServicesDelegate ConfigureServicesDelegate { get; } + public Action ConfigureDelegate { get; } + + } +} \ No newline at end of file diff --git a/src/Microsoft.AspNet.Hosting/project.json b/src/Microsoft.AspNet.Hosting/project.json index 9d97fb6f7d..4763927417 100644 --- a/src/Microsoft.AspNet.Hosting/project.json +++ b/src/Microsoft.AspNet.Hosting/project.json @@ -6,6 +6,7 @@ "Microsoft.Framework.Runtime.Interfaces": "1.0.0-*", "Microsoft.AspNet.FileProviders": "1.0.0-*", "Microsoft.AspNet.Http.Core": "1.0.0-*", + "Microsoft.AspNet.Http.Extensions": "1.0.0-*", "Microsoft.Framework.Logging": "1.0.0-*", "Microsoft.Framework.DependencyInjection": "1.0.0-*", "Newtonsoft.Json": "6.0.6" diff --git a/src/Microsoft.AspNet.RequestContainer/ContainerExtensions.cs b/src/Microsoft.AspNet.RequestContainer/ContainerExtensions.cs deleted file mode 100644 index 919df65864..0000000000 --- a/src/Microsoft.AspNet.RequestContainer/ContainerExtensions.cs +++ /dev/null @@ -1,55 +0,0 @@ -// 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 System; -using System.Collections.Generic; -using Microsoft.AspNet.RequestContainer; -using Microsoft.AspNet.Hosting; -using Microsoft.Framework.DependencyInjection; - -namespace Microsoft.AspNet.Builder -{ - public static class ContainerExtensions - { - public static IApplicationBuilder UseRequestServices(this IApplicationBuilder builder) - { - return builder.UseMiddleware(); - } - - // Review: what do we use these for? - - public static IApplicationBuilder UseRequestServices(this IApplicationBuilder builder, IServiceProvider applicationServices) - { - // REVIEW: should this be doing fallback? - builder.ApplicationServices = applicationServices; - - return builder.UseMiddleware(); - } - - // Note: Manifests are lost after UseServices, services are flattened into ApplicationServices - - public static IApplicationBuilder UseServices(this IApplicationBuilder builder, IServiceCollection applicationServices) - { - return builder.UseServices(services => services.Add(applicationServices)); - } - - public static IApplicationBuilder UseServices(this IApplicationBuilder builder, Action configureServices) - { - return builder.UseServices(serviceCollection => - { - configureServices(serviceCollection); - return serviceCollection.BuildServiceProvider(); - }); - } - - public static IApplicationBuilder UseServices(this IApplicationBuilder builder, Func configureServices) - { - // Import services from hosting/DNX as fallback - var serviceCollection = HostingServices.Create(builder.ApplicationServices); - - builder.ApplicationServices = configureServices(serviceCollection); - - return builder.UseMiddleware(); - } - } -} diff --git a/src/Microsoft.AspNet.RequestContainer/Microsoft.AspNet.RequestContainer.xproj b/src/Microsoft.AspNet.RequestContainer/Microsoft.AspNet.RequestContainer.xproj deleted file mode 100644 index 9740be9106..0000000000 --- a/src/Microsoft.AspNet.RequestContainer/Microsoft.AspNet.RequestContainer.xproj +++ /dev/null @@ -1,17 +0,0 @@ - - - - 14.0 - $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) - - - - 374a5b0c-3e93-4a23-a4a0-ee2ab6df7814 - ..\..\artifacts\obj\$(MSBuildProjectName) - ..\..\artifacts\bin\$(MSBuildProjectName)\ - - - 2.0 - - - diff --git a/src/Microsoft.AspNet.RequestContainer/project.json b/src/Microsoft.AspNet.RequestContainer/project.json deleted file mode 100644 index fdb20e9e8f..0000000000 --- a/src/Microsoft.AspNet.RequestContainer/project.json +++ /dev/null @@ -1,17 +0,0 @@ -{ - "version": "1.0.0-*", - "description": "ASP.NET 5 enables per-request scoping of services.", - "dependencies": { - "Microsoft.AspNet.Http.Extensions": "1.0.0-*", - "Microsoft.AspNet.Hosting": "1.0.0-*", - "Microsoft.Framework.OptionsModel": "1.0.0-*" - }, - "frameworks": { - "dnx451": {}, - "dnxcore50": { - "dependencies": { - "System.Threading": "4.0.10-beta-*" - } - }, - } -} diff --git a/src/Microsoft.AspNet.TestHost/TestServer.cs b/src/Microsoft.AspNet.TestHost/TestServer.cs index 2a6517a4a2..0cc7b83a65 100644 --- a/src/Microsoft.AspNet.TestHost/TestServer.cs +++ b/src/Microsoft.AspNet.TestHost/TestServer.cs @@ -8,10 +8,10 @@ using Microsoft.AspNet.Builder; using Microsoft.AspNet.FeatureModel; using Microsoft.AspNet.Hosting; using Microsoft.AspNet.Hosting.Server; +using Microsoft.AspNet.Hosting.Startup; using Microsoft.AspNet.Http; using Microsoft.Framework.ConfigurationModel; using Microsoft.Framework.DependencyInjection; -using Microsoft.Framework.Runtime; using Microsoft.Framework.Runtime.Infrastructure; namespace Microsoft.AspNet.TestHost @@ -25,46 +25,63 @@ namespace Microsoft.AspNet.TestHost private IDisposable _appInstance; private bool _disposed = false; - public TestServer(IConfiguration config, IServiceProvider serviceProvider, Action appStartup) + // REVIEW: we can configure services via AppStartup or via hostContext.Services + public TestServer(IConfiguration config, IServiceProvider serviceProvider, Action configureApp, ConfigureServicesDelegate configureServices) { - var appEnv = serviceProvider.GetRequiredService(); - var applicationLifetime = serviceProvider.GetRequiredService(); - - HostingContext hostContext = new HostingContext() + var hostContext = new HostingContext() { - ApplicationName = appEnv.ApplicationName, - ApplicationLifetime = applicationLifetime, + ApplicationName = "Test App", Configuration = config, ServerFactory = this, - ApplicationStartup = appStartup + StartupMethods = new StartupMethods(configureApp, configureServices) }; - var engine = serviceProvider.GetRequiredService(); - _appInstance = engine.Start(hostContext); + _appInstance = new HostingEngine(serviceProvider).Start(hostContext); } public Uri BaseAddress { get; set; } = new Uri("http://localhost/"); - public static TestServer Create(Action app) + public static TestServer Create(Action configureApp) { - return Create(CallContextServiceLocator.Locator.ServiceProvider, app, configureHostServices: null); + return Create(CallContextServiceLocator.Locator.ServiceProvider, configureApp, configureServices: null); } - public static TestServer Create(Action app, Action configureHostServices) + public static TestServer Create(Action configureApp, Action configureServices) { - return Create(CallContextServiceLocator.Locator.ServiceProvider, app, configureHostServices); + return Create(CallContextServiceLocator.Locator.ServiceProvider, configureApp, + sc => + { + if (configureServices != null) + { + configureServices(sc); + } + return sc.BuildServiceProvider(); + }); } - public static TestServer Create(IServiceProvider serviceProvider, Action app) + public static TestServer Create(IServiceProvider serviceProvider, Action configureApp) { - return Create(serviceProvider, app, configureHostServices: null); + return Create(serviceProvider, configureApp, configureServices: null); } - public static TestServer Create(IServiceProvider serviceProvider, Action app, Action configureHostServices) + public static TestServer Create(IServiceProvider serviceProvider, Action configureApp, Action configureServices) { - var appServices = HostingServices.Create(serviceProvider, configureHostServices).BuildServiceProvider(); + return Create(serviceProvider, configureApp, + sc => + { + if (configureServices != null) + { + configureServices(sc); + } + return sc.BuildServiceProvider(); + }); + } + + public static TestServer Create(IServiceProvider serviceProvider, Action configureApp, ConfigureServicesDelegate configureServices) + { + // REVIEW: do we need an overload that takes Config for Create? var config = new Configuration(); - return new TestServer(config, appServices, app); + return new TestServer(config, serviceProvider, configureApp, configureServices); } public HttpMessageHandler CreateHandler() @@ -124,7 +141,7 @@ namespace Microsoft.AspNet.TestHost { public string Name { - get { return TestServer.ServerName; } + get { return ServerName; } } } } diff --git a/test/Microsoft.AspNet.Hosting.Tests/Fakes/StartupUseServices.cs b/test/Microsoft.AspNet.Hosting.Tests/Fakes/StartupUseServices.cs deleted file mode 100644 index bfd85da550..0000000000 --- a/test/Microsoft.AspNet.Hosting.Tests/Fakes/StartupUseServices.cs +++ /dev/null @@ -1,30 +0,0 @@ -// 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.Builder; -using Microsoft.Framework.DependencyInjection; - -namespace Microsoft.AspNet.Hosting.Fakes -{ - public class StartupUseServices - { - public StartupUseServices() - { - } - - public void ConfigureUseServicesServices(IServiceCollection services) - { - services.Configure(o => o.Configured = true); - services.AddTransient(); - } - - public void Configure(IApplicationBuilder builder) - { - builder.UseServices(services => - { - services.AddTransient(); - services.Configure(o => o.Message = "Configured"); - }); - } - } -} \ No newline at end of file diff --git a/test/Microsoft.AspNet.Hosting.Tests/Fakes/StartupWithNullConfigureServices.cs b/test/Microsoft.AspNet.Hosting.Tests/Fakes/StartupWithNullConfigureServices.cs new file mode 100644 index 0000000000..b14bf11e99 --- /dev/null +++ b/test/Microsoft.AspNet.Hosting.Tests/Fakes/StartupWithNullConfigureServices.cs @@ -0,0 +1,16 @@ +using System; +using Microsoft.AspNet.Builder; +using Microsoft.Framework.DependencyInjection; + +namespace Microsoft.AspNet.Hosting.Fakes +{ + public class StartupWithNullConfigureServices + { + public IServiceProvider ConfigureServices(IServiceCollection services) + { + return null; + } + + public void Configure(IApplicationBuilder app) { } + } +} \ No newline at end of file diff --git a/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs b/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs index d6e1e64be5..078bc3681e 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs @@ -18,32 +18,16 @@ namespace Microsoft.AspNet.Hosting { private readonly IList _startInstances = new List(); - [Fact] - public void HostingEngineCanBeResolvedWithDefaultServices() - { - var services = HostingServices.Create().BuildServiceProvider(); - - var engine = services.GetRequiredService(); - - Assert.NotNull(engine); - } - [Fact] public void HostingEngineCanBeStarted() { - var services = HostingServices.Create().BuildServiceProvider(); - - var engine = services.GetRequiredService(); - var applicationLifetime = services.GetRequiredService(); - var context = new HostingContext { - ApplicationLifetime = applicationLifetime, ServerFactory = this, ApplicationName = "Microsoft.AspNet.Hosting.Tests" }; - var engineStart = engine.Start(context); + var engineStart = new HostingEngine().Start(context); Assert.NotNull(engineStart); Assert.Equal(1, _startInstances.Count); @@ -54,39 +38,97 @@ namespace Microsoft.AspNet.Hosting Assert.Equal(1, _startInstances[0].DisposeCalls); } + [Fact] + public void ApplicationNameDefaultsToApplicationEnvironmentName() + { + var context = new HostingContext + { + ServerFactory = this + }; + + var engine = new HostingEngine(); + + using (engine.Start(context)) + { + Assert.Equal("Microsoft.AspNet.Hosting.Tests", context.ApplicationName); + } + } + + [Fact] + public void EnvDefaultsToDevelopmentIfNoConfig() + { + var context = new HostingContext + { + ServerFactory = this + }; + + var engine = new HostingEngine(); + + using (engine.Start(context)) + { + Assert.Equal("Development", context.EnvironmentName); + var env = context.ApplicationServices.GetRequiredService(); + Assert.Equal("Development", env.EnvironmentName); + } + } + + [Fact] + public void EnvDefaultsToDevelopmentConfigValueIfSpecified() + { + var vals = new Dictionary + { + { "ASPNET_ENV", "Staging" } + }; + + var config = new Configuration() + .Add(new MemoryConfigurationSource(vals)); + + var context = new HostingContext + { + ServerFactory = this, + Configuration = config + }; + + var engine = new HostingEngine(); + + using (engine.Start(context)) + { + Assert.Equal("Staging", context.EnvironmentName); + var env = context.ApplicationServices.GetRequiredService(); + Assert.Equal("Staging", env.EnvironmentName); + } + } + [Fact] public void WebRootCanBeResolvedFromTheProjectJson() { - var services = HostingServices.Create().BuildServiceProvider(); - var env = services.GetRequiredService(); + var context = new HostingContext + { + ServerFactory = this + }; + + var engineStart = new HostingEngine().Start(context); + var env = context.ApplicationServices.GetRequiredService(); Assert.Equal(Path.GetFullPath("testroot"), env.WebRootPath); Assert.True(env.WebRootFileProvider.GetFileInfo("TextFile.txt").Exists); } - [Fact] - public void Validate_Environment_Name() - { - var services = HostingServices.Create().BuildServiceProvider(); - var env = services.GetRequiredService(); - Assert.Equal("Development", env.EnvironmentName); - - var config = new Configuration() - .AddCommandLine(new string[] { "--ASPNET_ENV", "Overridden_Environment" }); - - services = HostingServices.Create(fallbackServices: null, configuration: config) - .BuildServiceProvider(); - - env = services.GetRequiredService(); - Assert.Equal("Overridden_Environment", env.EnvironmentName); - } - [Fact] public void IsEnvironment_Extension_Is_Case_Insensitive() { - var services = HostingServices.Create().BuildServiceProvider(); - var env = services.GetRequiredService(); - Assert.True(env.IsEnvironment("Development")); - Assert.True(env.IsEnvironment("developMent")); + var context = new HostingContext + { + ServerFactory = this + }; + + var engine = new HostingEngine(); + + using (engine.Start(context)) + { + var env = context.ApplicationServices.GetRequiredService(); + Assert.True(env.IsEnvironment("Development")); + Assert.True(env.IsEnvironment("developMent")); + } } public void Initialize(IApplicationBuilder builder) diff --git a/test/Microsoft.AspNet.Hosting.Tests/HostingServicesFacts.cs b/test/Microsoft.AspNet.Hosting.Tests/HostingServicesFacts.cs deleted file mode 100644 index a0fff83ac5..0000000000 --- a/test/Microsoft.AspNet.Hosting.Tests/HostingServicesFacts.cs +++ /dev/null @@ -1,210 +0,0 @@ -// 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 System; -using System.Collections.Generic; -using Microsoft.AspNet.Hosting.Fakes; -using Microsoft.Framework.DependencyInjection; -using Microsoft.Framework.Runtime; -using Xunit; - -namespace Microsoft.AspNet.Hosting.Tests -{ - public class HostingServicesFacts - { - [Fact] - public void CreateImportsServices() - { - // Arrange - var fallbackServices = new ServiceCollection(); - fallbackServices.AddSingleton(); - var instance = new FakeService(); - var factoryInstance = new FakeFactoryService(instance); - fallbackServices.AddInstance(instance); - fallbackServices.AddTransient(); - fallbackServices.AddSingleton(serviceProvider => factoryInstance); - fallbackServices.AddTransient(); // Don't register in manifest - - fallbackServices.AddInstance(new ServiceManifest( - new Type[] { - typeof(IFakeServiceInstance), - typeof(IFakeService), - typeof(IFakeSingletonService), - typeof(IFactoryService), - typeof(INonexistentService) - })); - - var services = HostingServices.Create(fallbackServices.BuildServiceProvider()); - - // Act - var provider = services.BuildServiceProvider(); - var singleton = provider.GetRequiredService(); - var transient = provider.GetRequiredService(); - var factory = provider.GetRequiredService(); - - // Assert - Assert.Same(singleton, provider.GetRequiredService()); - Assert.NotSame(transient, provider.GetRequiredService()); - Assert.Same(instance, provider.GetRequiredService()); - Assert.Same(factoryInstance, factory); - Assert.Same(factory.FakeService, instance); - Assert.Null(provider.GetService()); - Assert.Null(provider.GetService()); // Make sure we don't leak non manifest services - } - - [Fact] - public void CreateCanAddAdditionalServices() - { - // Arrange - var fallbackServices = new ServiceCollection(); - fallbackServices.AddTransient(); - fallbackServices.AddTransient(); // Don't register in manifest - - fallbackServices.AddInstance(new ServiceManifest( - new Type[] { - typeof(IFakeService), - })); - - var instance = new FakeService(); - var factoryInstance = new FakeFactoryService(instance); - - var services = HostingServices.Create(fallbackServices.BuildServiceProvider(), - additionalHostServices => - { - additionalHostServices.AddSingleton(); - additionalHostServices.AddInstance(instance); - additionalHostServices.AddSingleton(serviceProvider => factoryInstance); - }); - - // Act - var provider = services.BuildServiceProvider(); - var singleton = provider.GetRequiredService(); - var transient = provider.GetRequiredService(); - var factory = provider.GetRequiredService(); - var manifest = provider.GetRequiredService(); - - // Assert - Assert.Same(singleton, provider.GetRequiredService()); - Assert.NotSame(transient, provider.GetRequiredService()); - Assert.Same(instance, provider.GetRequiredService()); - Assert.Same(factoryInstance, factory); - Assert.Same(factory.FakeService, instance); - Assert.Null(provider.GetService()); - Assert.Null(provider.GetService()); // Make sure we don't leak non manifest services - Assert.Contains(typeof(IFakeSingletonService), manifest.Services); - Assert.Contains(typeof(IFakeServiceInstance), manifest.Services); - Assert.Contains(typeof(IFactoryService), manifest.Services); - } - - [Fact] - public void CreateAdditionalServicesOverridesFallback() - { - // Arrange - var fallbackServices = new ServiceCollection(); - fallbackServices.AddTransient(); - - fallbackServices.AddInstance(new ServiceManifest( - new Type[] { - typeof(IFakeService), - })); - - var services = HostingServices.Create(fallbackServices.BuildServiceProvider(), - additionalHostServices => additionalHostServices.AddSingleton()); - - // Act - var provider = services.BuildServiceProvider(); - var singleton = provider.GetRequiredService(); - - // Assert - Assert.Same(singleton, provider.GetRequiredService()); - } - - [Fact] - public void CreateAdditionalServices_IncludesServicesInManifest() - { - // Arrange - var fallbackServices = new ServiceCollection(); - fallbackServices.AddTransient(); - fallbackServices.AddInstance(new ServiceManifest( - new Type[] { - typeof(IFakeService), - })); - var expectedInstance = new FakeService(); - var services = HostingServices.Create( - fallbackServices.BuildServiceProvider(), - additionalHostServices => additionalHostServices.AddInstance(expectedInstance)); - - // Act - var provider = services.BuildServiceProvider(); - var instance = provider.GetRequiredService(); - var anotherInstance = provider.GetRequiredService(); - var manifest = provider.GetRequiredService(); - - // Assert - Assert.Same(expectedInstance, instance); - Assert.Same(expectedInstance, anotherInstance); - Assert.Contains(typeof(IFakeServiceInstance), manifest.Services); - } - - [Fact] - public void CanHideImportedServices() - { - // Arrange - var fallbackServices = new ServiceCollection(); - var fallbackInstance = new FakeService(); - fallbackServices.AddInstance(fallbackInstance); - fallbackServices.AddInstance(new ServiceManifest(new Type[] { typeof(IFakeService) })); - - var services = HostingServices.Create(fallbackServices.BuildServiceProvider()); - var realInstance = new FakeService(); - services.AddInstance(realInstance); - - // Act - var provider = services.BuildServiceProvider(); - - // Assert - Assert.Equal(realInstance, provider.GetRequiredService()); - } - - [Fact] - public void CreateThrowsWithNoManifest() - { - // Arrange - var fallbackServices = new ServiceCollection(); - fallbackServices.AddSingleton(); - var instance = new FakeService(); - fallbackServices.AddInstance(instance); - fallbackServices.AddTransient(); - - // Act - var exception = Assert.Throws(() => HostingServices.Create(fallbackServices.BuildServiceProvider())); - - - // Assert - Assert.Equal($"No service for type '{typeof(IServiceManifest).FullName}' has been registered.", - exception.Message); - } - - private class ServiceManifest : IServiceManifest - { - public ServiceManifest(IEnumerable services) - { - Services = services; - } - - public IEnumerable Services { get; private set; } - } - - private class FakeFactoryService : IFactoryService - { - public FakeFactoryService(FakeService service) - { - FakeService = service; - } - - public IFakeService FakeService { get; private set; } - - public int Value { get; private set; } - } - } -} \ No newline at end of file diff --git a/test/Microsoft.AspNet.Hosting.Tests/StartupManagerTests.cs b/test/Microsoft.AspNet.Hosting.Tests/StartupManagerTests.cs index cefc9877e7..a7ecf91aaa 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/StartupManagerTests.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/StartupManagerTests.cs @@ -12,7 +12,6 @@ using Xunit; namespace Microsoft.AspNet.Hosting.Tests { - public class StartupManagerTests : IFakeStartupCallback { private readonly IList _configurationMethodCalledList = new List(); @@ -20,16 +19,16 @@ namespace Microsoft.AspNet.Hosting.Tests [Fact] public void StartupClassMayHaveHostingServicesInjected() { - var serviceCollection = new ServiceCollection().AddHosting(); + var serviceCollection = new ServiceCollection(); serviceCollection.AddInstance(this); var services = serviceCollection.BuildServiceProvider(); - var loader = services.GetRequiredService(); - var diagnosticMessages = new List(); - var startup = loader.LoadStartup("Microsoft.AspNet.Hosting.Tests", "WithServices", diagnosticMessages); + var startup = ApplicationStartup.LoadStartupMethods(services, "Microsoft.AspNet.Hosting.Tests", "WithServices", diagnosticMessages); - startup.Invoke(new ApplicationBuilder(services)); + var app = new ApplicationBuilder(services); + app.ApplicationServices = startup.ConfigureServicesDelegate(serviceCollection); + startup.ConfigureDelegate(app); Assert.Equal(2, _configurationMethodCalledList.Count); } @@ -45,15 +44,14 @@ namespace Microsoft.AspNet.Hosting.Tests [InlineData("BaseClass")] public void StartupClassAddsConfigureServicesToApplicationServices(string environment) { - var services = HostingServices.Create().BuildServiceProvider(); - var loader = services.GetRequiredService(); + var services = new ServiceCollection().BuildServiceProvider(); var diagnosticMesssages = new List(); - var startup = loader.LoadStartup("Microsoft.AspNet.Hosting.Tests", environment ?? "", diagnosticMesssages); + var startup = ApplicationStartup.LoadStartupMethods(services, "Microsoft.AspNet.Hosting.Tests", environment ?? "", diagnosticMesssages); var app = new ApplicationBuilder(services); - - startup.Invoke(app); + app.ApplicationServices = startup.ConfigureServicesDelegate(new ServiceCollection()); + startup.ConfigureDelegate(app); var options = app.ApplicationServices.GetRequiredService>().Options; Assert.NotNull(options); @@ -61,92 +59,46 @@ namespace Microsoft.AspNet.Hosting.Tests Assert.Equal(environment, options.Environment); } - [Theory] - [InlineData("Null")] - [InlineData("FallbackProvider")] - public void StartupClassConfigureServicesThatFallsbackToApplicationServices(string env) - { - var services = HostingServices.Create().BuildServiceProvider(); - var loader = services.GetRequiredService(); - var diagnosticMessages = new List(); - - var startup = loader.LoadStartup("Microsoft.AspNet.Hosting.Tests", env, diagnosticMessages); - - var app = new ApplicationBuilder(services); - - startup.Invoke(app); - - Assert.Equal(services, app.ApplicationServices); - } - - // REVIEW: With the manifest change, Since the ConfigureServices are not imported, UseServices will mask what's in ConfigureServices - // This will throw since ConfigureServices consumes manifest and then UseServices will blow up - [Fact(Skip = "Review Failure")] - public void StartupClassWithConfigureServicesAndUseServicesHidesConfigureServices() - { - var services = HostingServices.Create().BuildServiceProvider(); - var loader = services.GetRequiredService(); - var diagnosticMessages = new List(); - - var startup = loader.LoadStartup("Microsoft.AspNet.Hosting.Tests", "UseServices", diagnosticMessages); - - var app = new ApplicationBuilder(services); - - startup.Invoke(app); - - Assert.NotNull(app.ApplicationServices.GetRequiredService()); - Assert.Null(app.ApplicationServices.GetService()); - - var options = app.ApplicationServices.GetRequiredService>().Options; - Assert.NotNull(options); - Assert.Equal("Configured", options.Message); - Assert.False(options.Configured); // Options never resolved from inner containers - } - [Fact] public void StartupWithNoConfigureThrows() { - var serviceCollection = HostingServices.Create(); + var serviceCollection = new ServiceCollection(); serviceCollection.AddInstance(this); var services = serviceCollection.BuildServiceProvider(); - var loader = services.GetRequiredService(); var diagnosticMessages = new List(); - var ex = Assert.Throws(() => loader.LoadStartup("Microsoft.AspNet.Hosting.Tests", "Boom", diagnosticMessages)); + var ex = Assert.Throws(() => ApplicationStartup.LoadStartupMethods(services, "Microsoft.AspNet.Hosting.Tests", "Boom", diagnosticMessages)); Assert.Equal("A method named 'ConfigureBoom' or 'Configure' in the type 'Microsoft.AspNet.Hosting.Fakes.StartupBoom' could not be found.", ex.Message); } [Fact] - public void StartupWithConfigureServicesNotResolvedThrows() + public void StartupClassCanHandleConfigureServicesThatReturnsNull() { - var serviceCollection = HostingServices.Create(); + var serviceCollection = new ServiceCollection(); var services = serviceCollection.BuildServiceProvider(); - var loader = services.GetRequiredService(); + var diagnosticMessages = new List(); - - var startup = loader.LoadStartup("Microsoft.AspNet.Hosting.Tests", "WithConfigureServicesNotResolved", diagnosticMessages); - + var startup = ApplicationStartup.LoadStartupMethods(services, "Microsoft.AspNet.Hosting.Tests", "WithNullConfigureServices", diagnosticMessages); var app = new ApplicationBuilder(services); - - var ex = Assert.Throws(() => startup.Invoke(app)); - - Assert.Equal("Could not resolve a service of type 'System.Int32' for the parameter 'notAService' of method 'Configure' on type 'Microsoft.AspNet.Hosting.Fakes.StartupWithConfigureServicesNotResolved'.", ex.Message); + app.ApplicationServices = startup.ConfigureServicesDelegate(new ServiceCollection()); + Assert.NotNull(app.ApplicationServices); + startup.ConfigureDelegate(app); + Assert.NotNull(app.ApplicationServices); } [Fact] public void StartupClassWithConfigureServicesShouldMakeServiceAvailableInConfigure() { - var serviceCollection = HostingServices.Create(); + var serviceCollection = new ServiceCollection(); var services = serviceCollection.BuildServiceProvider(); - var loader = services.GetRequiredService(); - - var app = new ApplicationBuilder(services); var diagnosticMessages = new List(); - var startup = loader.LoadStartup("Microsoft.AspNet.Hosting.Tests", "WithConfigureServices", diagnosticMessages); + var startup = ApplicationStartup.LoadStartupMethods(services, "Microsoft.AspNet.Hosting.Tests", "WithConfigureServices", diagnosticMessages); - startup.Invoke(app); + var app = new ApplicationBuilder(services); + app.ApplicationServices = startup.ConfigureServicesDelegate(serviceCollection); + startup.ConfigureDelegate(app); var foo = app.ApplicationServices.GetRequiredService(); Assert.True(foo.Invoked); diff --git a/test/Microsoft.AspNet.Hosting.Tests/UseRequestServicesFacts.cs b/test/Microsoft.AspNet.Hosting.Tests/UseRequestServicesFacts.cs deleted file mode 100644 index 0e235a45db..0000000000 --- a/test/Microsoft.AspNet.Hosting.Tests/UseRequestServicesFacts.cs +++ /dev/null @@ -1,98 +0,0 @@ -// 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 System; -using Microsoft.AspNet.Builder; -using Microsoft.AspNet.Http.Core; -using Microsoft.AspNet.RequestContainer; -using Microsoft.Framework.DependencyInjection; -using Microsoft.Framework.Logging; -using Xunit; - -namespace Microsoft.AspNet.Hosting.Tests -{ - public class RequestServicesContainerFacts - { - [Fact] - public void RequestServicesAvailableOnlyAfterRequestServices() - { - var baseServiceProvider = HostingServices.Create().BuildServiceProvider(); - var builder = new ApplicationBuilder(baseServiceProvider); - - bool foundRequestServicesBefore = false; - builder.Use(next => async c => - { - foundRequestServicesBefore = c.RequestServices != null; - await next.Invoke(c); - }); - builder.UseRequestServices(); - bool foundRequestServicesAfter = false; - builder.Use(next => async c => - { - foundRequestServicesAfter = c.RequestServices != null; - await next.Invoke(c); - }); - - var context = new DefaultHttpContext(); - builder.Build().Invoke(context); - Assert.False(foundRequestServicesBefore); - Assert.True(foundRequestServicesAfter); - } - - [Theory] - [InlineData(true)] - [InlineData(false)] - public void EnsureRequestServicesSetsRequestServices(bool initializeApplicationServices) - { - var baseServiceProvider = HostingServices.Create().BuildServiceProvider(); - var builder = new ApplicationBuilder(baseServiceProvider); - - bool foundRequestServicesBefore = false; - builder.Use(next => async c => - { - foundRequestServicesBefore = c.RequestServices != null; - await next.Invoke(c); - }); - builder.Use(next => async c => - { - using (var container = RequestServicesContainer.EnsureRequestServices(c, baseServiceProvider)) - { - await next.Invoke(c); - } - }); - bool foundRequestServicesAfter = false; - builder.Use(next => async c => - { - foundRequestServicesAfter = c.RequestServices != null; - await next.Invoke(c); - }); - - var context = new DefaultHttpContext(); - if (initializeApplicationServices) - { - context.ApplicationServices = baseServiceProvider; - } - builder.Build().Invoke(context); - Assert.False(foundRequestServicesBefore); - Assert.True(foundRequestServicesAfter); - } - - [Theory] - [InlineData(typeof(IHostingEnvironment))] - [InlineData(typeof(ILoggerFactory))] - [InlineData(typeof(IHttpContextAccessor))] - [InlineData(typeof(IApplicationLifetime))] - public void UseRequestServicesHostingImportedServicesAreDefined(Type service) - { - var baseServiceProvider = HostingServices.Create().BuildServiceProvider(); - var builder = new ApplicationBuilder(baseServiceProvider); - - builder.UseRequestServices(); - - var fromAppServices = builder.ApplicationServices.GetRequiredService(service); - - Assert.NotNull(fromAppServices); - Assert.Equal(baseServiceProvider.GetRequiredService(service), fromAppServices); - } - } -} \ No newline at end of file diff --git a/test/Microsoft.AspNet.Hosting.Tests/project.json b/test/Microsoft.AspNet.Hosting.Tests/project.json index a87f3cffd7..aa3d3b7bb0 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/project.json +++ b/test/Microsoft.AspNet.Hosting.Tests/project.json @@ -2,7 +2,7 @@ "dependencies": { "Microsoft.AspNet.Hosting": "1.0.0-*", "Microsoft.AspNet.Owin": "1.0.0-*", - "Microsoft.AspNet.RequestContainer": "1.0.0-*", + "Microsoft.Framework.OptionsModel": "1.0.0-*", "xunit.runner.aspnet": "2.0.0-aspnet-*" }, "frameworks": { diff --git a/test/Microsoft.AspNet.TestHost.Tests/ClientHandlerTests.cs b/test/Microsoft.AspNet.TestHost.Tests/ClientHandlerTests.cs index c92a8ca35c..74838032eb 100644 --- a/test/Microsoft.AspNet.TestHost.Tests/ClientHandlerTests.cs +++ b/test/Microsoft.AspNet.TestHost.Tests/ClientHandlerTests.cs @@ -10,7 +10,6 @@ using System.Threading.Tasks; using Microsoft.AspNet.FeatureModel; using Microsoft.AspNet.Http; using Microsoft.AspNet.Http.Core; -using Microsoft.AspNet.Http; using Xunit; namespace Microsoft.AspNet.TestHost diff --git a/test/Microsoft.AspNet.TestHost.Tests/TestApplicationEnvironment.cs b/test/Microsoft.AspNet.TestHost.Tests/TestApplicationEnvironment.cs deleted file mode 100644 index de715c253c..0000000000 --- a/test/Microsoft.AspNet.TestHost.Tests/TestApplicationEnvironment.cs +++ /dev/null @@ -1,37 +0,0 @@ -// 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 System; -using System.Runtime.Versioning; -using Microsoft.Framework.Runtime; - -namespace Microsoft.AspNet.TestHost -{ - public class TestApplicationEnvironment : IApplicationEnvironment - { - public string ApplicationName - { - get { return "Test App environment"; } - } - - public string Version - { - get { return "1.0.0"; } - } - - public string ApplicationBasePath - { - get { return Environment.CurrentDirectory; } - } - - public string Configuration - { - get { return "Test"; } - } - - public FrameworkName RuntimeFramework - { - get { return new FrameworkName(".NETFramework", new Version(4, 5)); } - } - } -} diff --git a/test/Microsoft.AspNet.TestHost.Tests/TestClientTests.cs b/test/Microsoft.AspNet.TestHost.Tests/TestClientTests.cs index b392bac6ad..19b54c06f5 100644 --- a/test/Microsoft.AspNet.TestHost.Tests/TestClientTests.cs +++ b/test/Microsoft.AspNet.TestHost.Tests/TestClientTests.cs @@ -20,9 +20,7 @@ namespace Microsoft.AspNet.TestHost public TestClientTests() { - _services = HostingServices.Create().BuildServiceProvider(); - - _server = TestServer.Create(_services, app => app.Run(ctx => Task.FromResult(0))); + _server = TestServer.Create(app => app.Run(ctx => Task.FromResult(0))); } [Fact] @@ -32,7 +30,7 @@ namespace Microsoft.AspNet.TestHost var expected = "GET Response"; RequestDelegate appDelegate = ctx => ctx.Response.WriteAsync(expected); - var server = TestServer.Create(_services, app => app.Run(appDelegate)); + var server = TestServer.Create(app => app.Run(appDelegate)); var client = server.CreateClient(); // Act @@ -53,7 +51,7 @@ namespace Microsoft.AspNet.TestHost Assert.Equal("/", ctx.Request.Path.Value); return ctx.Response.WriteAsync(expected); }; - var server = TestServer.Create(_services, app => app.Run(appDelegate)); + var server = TestServer.Create(app => app.Run(appDelegate)); var client = server.CreateClient(); // Act @@ -74,7 +72,7 @@ namespace Microsoft.AspNet.TestHost Assert.Equal("/", ctx.Request.Path.Value); return ctx.Response.WriteAsync(expected); }; - var server = TestServer.Create(_services, app => app.Run(appDelegate)); + var server = TestServer.Create(app => app.Run(appDelegate)); var client = server.CreateClient(); // Act @@ -90,7 +88,7 @@ namespace Microsoft.AspNet.TestHost // Arrange RequestDelegate appDelegate = ctx => ctx.Response.WriteAsync(new StreamReader(ctx.Request.Body).ReadToEnd() + " PUT Response"); - var server = TestServer.Create(_services, app => app.Run(appDelegate)); + var server = TestServer.Create(app => app.Run(appDelegate)); var client = server.CreateClient(); // Act @@ -107,7 +105,7 @@ namespace Microsoft.AspNet.TestHost // Arrange RequestDelegate appDelegate = async ctx => await ctx.Response.WriteAsync(new StreamReader(ctx.Request.Body).ReadToEnd() + " POST Response"); - var server = TestServer.Create(_services, app => app.Run(appDelegate)); + var server = TestServer.Create(app => app.Run(appDelegate)); var client = server.CreateClient(); // Act diff --git a/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs b/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs index 899d3be45a..f3a3fc0bef 100644 --- a/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs +++ b/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs @@ -21,10 +21,8 @@ namespace Microsoft.AspNet.TestHost public void CreateWithDelegate() { // Arrange - var services = HostingServices.Create().BuildServiceProvider(); - // Act & Assert (Does not throw) - TestServer.Create(services, app => { }); + TestServer.Create(app => { }); } [Fact] @@ -37,6 +35,21 @@ namespace Microsoft.AspNet.TestHost Assert.Throws(() => TestServer.Create(services, new Startup().Configuration)); } + [Fact] + public async Task RequestServicesAutoCreated() + { + TestServer server = TestServer.Create(app => + { + app.Run(context => + { + return context.Response.WriteAsync("RequestServices:" + (context.RequestServices != null)); + }); + }); + + string result = await server.CreateClient().GetStringAsync("/path"); + Assert.Equal("RequestServices:True", result); + } + [Fact] public async Task CanAccessLogger() { @@ -92,7 +105,8 @@ namespace Microsoft.AspNet.TestHost var accessor = app.ApplicationServices.GetRequiredService(); return context.Response.WriteAsync("HasContext:" + (accessor.Accessor.HttpContext != null)); }); - }, newHostServices => newHostServices.AddSingleton()); + }, + services => services.AddSingleton().BuildServiceProvider()); string result = await server.CreateClient().GetStringAsync("/path"); Assert.Equal("HasContext:True", result); From f35bfcd271a284edd8921e9528e820bd72f892f7 Mon Sep 17 00:00:00 2001 From: Praburaj Date: Sat, 21 Mar 2015 07:18:40 -0700 Subject: [PATCH 236/987] Adding MapPath extension --- .../HostingEnvironmentExtensions.cs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/Microsoft.AspNet.Hosting.Interfaces/HostingEnvironmentExtensions.cs b/src/Microsoft.AspNet.Hosting.Interfaces/HostingEnvironmentExtensions.cs index b39316a281..0af82fee14 100644 --- a/src/Microsoft.AspNet.Hosting.Interfaces/HostingEnvironmentExtensions.cs +++ b/src/Microsoft.AspNet.Hosting.Interfaces/HostingEnvironmentExtensions.cs @@ -2,6 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.IO; using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Hosting @@ -23,5 +24,23 @@ namespace Microsoft.AspNet.Hosting environmentName, StringComparison.OrdinalIgnoreCase); } + + /// + /// Gives the physical path corresponding to the given virtual path. + /// + /// An instance of service. + /// Path relative to the root. + /// Physical path corresponding to virtual path. + public static string MapPath( + [NotNull]this IHostingEnvironment hostingEnvironment, + string virtualPath) + { + if (virtualPath == null) + { + return hostingEnvironment.WebRootPath; + } + + return Path.Combine(hostingEnvironment.WebRootPath, virtualPath); + } } } \ No newline at end of file From 0dbbd2f655b7b7490a799881bd02b77629e70c9e Mon Sep 17 00:00:00 2001 From: Praburaj Date: Mon, 23 Mar 2015 17:19:27 -0700 Subject: [PATCH 237/987] Adding some tests for the MapPath extension method And looks like I pushed the MapPath extension change too soon. I had to fix an issue in the path for forward and backward slash. For example if an application tries to do MapPath("/resource") then this code does not work cross plat unless the directory separator characters are fixed appropriately. Fixed it and also added some test coverage. --- .../HostingEnvironmentExtensions.cs | 2 ++ .../HostingEngineTests.cs | 26 +++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/src/Microsoft.AspNet.Hosting.Interfaces/HostingEnvironmentExtensions.cs b/src/Microsoft.AspNet.Hosting.Interfaces/HostingEnvironmentExtensions.cs index 0af82fee14..8de0d9f97a 100644 --- a/src/Microsoft.AspNet.Hosting.Interfaces/HostingEnvironmentExtensions.cs +++ b/src/Microsoft.AspNet.Hosting.Interfaces/HostingEnvironmentExtensions.cs @@ -40,6 +40,8 @@ namespace Microsoft.AspNet.Hosting return hostingEnvironment.WebRootPath; } + // On windows replace / with \. + virtualPath = virtualPath.Replace('/', Path.DirectorySeparatorChar); return Path.Combine(hostingEnvironment.WebRootPath, virtualPath); } } diff --git a/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs b/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs index 078bc3681e..7bebf1c0e7 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs @@ -131,6 +131,32 @@ namespace Microsoft.AspNet.Hosting } } + [Theory] + [InlineData(null, "")] + [InlineData("", "")] + [InlineData("/", "/")] + [InlineData(@"\", @"\")] + [InlineData("sub", "sub")] + [InlineData("sub/sub2/sub3", @"sub/sub2/sub3")] + [InlineData(@"sub/sub2\sub3\", @"sub/sub2/sub3/")] + public void MapPath_Facts(string virtualPath, string expectedSuffix) + { + var context = new HostingContext + { + ServerFactory = this + }; + + var engine = new HostingEngine(); + + using (engine.Start(context)) + { + var env = context.ApplicationServices.GetRequiredService(); + var mappedPath = env.MapPath(virtualPath); + expectedSuffix = expectedSuffix.Replace('/', Path.DirectorySeparatorChar); + Assert.Equal(Path.Combine(env.WebRootPath, expectedSuffix), mappedPath); + } + } + public void Initialize(IApplicationBuilder builder) { From 65ef65e2d8f2021fa44acbb72eb3f9d232e44977 Mon Sep 17 00:00:00 2001 From: Praburaj Date: Tue, 24 Mar 2015 13:08:04 -0700 Subject: [PATCH 238/987] PR feedback on IsEnvironment extension removing [NotNull] on environmentName parameter. String.Equals is expected to handle this appropriately. --- .../HostingEnvironmentExtensions.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Microsoft.AspNet.Hosting.Interfaces/HostingEnvironmentExtensions.cs b/src/Microsoft.AspNet.Hosting.Interfaces/HostingEnvironmentExtensions.cs index 8de0d9f97a..9e9b5fd2ce 100644 --- a/src/Microsoft.AspNet.Hosting.Interfaces/HostingEnvironmentExtensions.cs +++ b/src/Microsoft.AspNet.Hosting.Interfaces/HostingEnvironmentExtensions.cs @@ -17,7 +17,7 @@ namespace Microsoft.AspNet.Hosting /// True if the specified name is same as the current environment. public static bool IsEnvironment( [NotNull]this IHostingEnvironment hostingEnvironment, - [NotNull]string environmentName) + string environmentName) { return string.Equals( hostingEnvironment.EnvironmentName, From 6f5bf881d5dd50abdd5bd4c9ceaa40bec24f78c7 Mon Sep 17 00:00:00 2001 From: Wei Wang Date: Tue, 24 Mar 2015 21:31:30 -0700 Subject: [PATCH 239/987] Remove k command and use dnx instead --- build.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.sh b/build.sh index ec3263114a..d81164353c 100755 --- a/build.sh +++ b/build.sh @@ -31,7 +31,7 @@ if ! type dnvm > /dev/null 2>&1; then source packages/KoreBuild/build/dnvm.sh fi -if ! type k > /dev/null 2>&1; then +if ! type dnx > /dev/null 2>&1; then dnvm upgrade fi From b62578d4a151cfdce01cfa2dfe9dc83f85a63f26 Mon Sep 17 00:00:00 2001 From: suhasj Date: Wed, 25 Mar 2015 11:46:49 -0700 Subject: [PATCH 240/987] Updating to release NuGet.config --- NuGet.Config | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/NuGet.Config b/NuGet.Config index da57d47267..1978dc065a 100644 --- a/NuGet.Config +++ b/NuGet.Config @@ -1,7 +1,7 @@  - + - \ No newline at end of file + From 77e2dc263f11655312d4c73bb8e22d7b6254d485 Mon Sep 17 00:00:00 2001 From: Hao Kung Date: Mon, 30 Mar 2015 18:05:51 -0700 Subject: [PATCH 241/987] Hosting rework #2 - Merge HostingContext and HostingEngine - Cleanup usage via builder pattern --- .../IConfigureHostingEnvironment.cs | 12 - .../IHostingEnvironment.cs | 7 +- .../ApplicationLifetime.cs | 4 - .../HostingContext.cs | 34 -- src/Microsoft.AspNet.Hosting/HostingEngine.cs | 300 ++++++++---------- .../HostingEnvironment.cs | 13 +- .../HostingEnvironmentExtensions.cs | 18 ++ .../HostingFactory.cs | 35 ++ .../IHostingEngine.cs | 32 ++ .../IHostingFactory.cs | 12 + .../IHttpContextAccessor.cs | 1 + ...RootHostingServiceCollectionInitializer.cs | 66 ++++ src/Microsoft.AspNet.Hosting/Program.cs | 17 +- .../Startup/IStartupLoader.cs | 16 + ...ApplicationStartup.cs => StartupLoader.cs} | 61 ++-- .../Startup/StartupMethods.cs | 8 +- src/Microsoft.AspNet.Hosting/WebHost.cs | 63 ++++ src/Microsoft.AspNet.TestHost/TestServer.cs | 111 ++++--- .../TestServerBuilder.cs | 126 ++++++++ .../HostingEngineTests.cs | 137 ++++---- .../Microsoft.AspNet.Hosting.Tests.xproj | 3 + .../StartupManagerTests.cs | 77 ++++- .../project.json | 1 + .../Microsoft.AspNet.TestHost.Tests.xproj | 7 +- .../RequestBuilderTests.cs | 4 +- .../TestServerTests.cs | 120 ++++++- 26 files changed, 887 insertions(+), 398 deletions(-) delete mode 100644 src/Microsoft.AspNet.Hosting.Interfaces/IConfigureHostingEnvironment.cs delete mode 100644 src/Microsoft.AspNet.Hosting/HostingContext.cs create mode 100644 src/Microsoft.AspNet.Hosting/HostingEnvironmentExtensions.cs create mode 100644 src/Microsoft.AspNet.Hosting/HostingFactory.cs create mode 100644 src/Microsoft.AspNet.Hosting/IHostingEngine.cs create mode 100644 src/Microsoft.AspNet.Hosting/IHostingFactory.cs create mode 100644 src/Microsoft.AspNet.Hosting/Internal/RootHostingServiceCollectionInitializer.cs create mode 100644 src/Microsoft.AspNet.Hosting/Startup/IStartupLoader.cs rename src/Microsoft.AspNet.Hosting/Startup/{ApplicationStartup.cs => StartupLoader.cs} (76%) create mode 100644 src/Microsoft.AspNet.Hosting/WebHost.cs create mode 100644 src/Microsoft.AspNet.TestHost/TestServerBuilder.cs diff --git a/src/Microsoft.AspNet.Hosting.Interfaces/IConfigureHostingEnvironment.cs b/src/Microsoft.AspNet.Hosting.Interfaces/IConfigureHostingEnvironment.cs deleted file mode 100644 index 6ea92fde03..0000000000 --- a/src/Microsoft.AspNet.Hosting.Interfaces/IConfigureHostingEnvironment.cs +++ /dev/null @@ -1,12 +0,0 @@ -// 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.Framework.Runtime; - -namespace Microsoft.AspNet.Hosting -{ - public interface IConfigureHostingEnvironment - { - void Configure(IHostingEnvironment hostingEnv); - } -} \ No newline at end of file diff --git a/src/Microsoft.AspNet.Hosting.Interfaces/IHostingEnvironment.cs b/src/Microsoft.AspNet.Hosting.Interfaces/IHostingEnvironment.cs index 393c963e20..da774985c4 100644 --- a/src/Microsoft.AspNet.Hosting.Interfaces/IHostingEnvironment.cs +++ b/src/Microsoft.AspNet.Hosting.Interfaces/IHostingEnvironment.cs @@ -7,10 +7,13 @@ namespace Microsoft.AspNet.Hosting { public interface IHostingEnvironment { + // This must be settable! string EnvironmentName { get; set; } - string WebRootPath { get; } + // This must be settable! + string WebRootPath { get; set; } - IFileProvider WebRootFileProvider { get; } + // This must be settable! + IFileProvider WebRootFileProvider { get; set; } } } \ No newline at end of file diff --git a/src/Microsoft.AspNet.Hosting/ApplicationLifetime.cs b/src/Microsoft.AspNet.Hosting/ApplicationLifetime.cs index 3d9fa53b8b..a8bb03860b 100644 --- a/src/Microsoft.AspNet.Hosting/ApplicationLifetime.cs +++ b/src/Microsoft.AspNet.Hosting/ApplicationLifetime.cs @@ -14,10 +14,6 @@ namespace Microsoft.AspNet.Hosting private readonly CancellationTokenSource _stoppingSource = new CancellationTokenSource(); private readonly CancellationTokenSource _stoppedSource = new CancellationTokenSource(); - public ApplicationLifetime() - { - } - /// /// Triggered when the application host is performing a graceful shutdown. /// Request may still be in flight. Shutdown will block until this event completes. diff --git a/src/Microsoft.AspNet.Hosting/HostingContext.cs b/src/Microsoft.AspNet.Hosting/HostingContext.cs deleted file mode 100644 index 3ff679a6b3..0000000000 --- a/src/Microsoft.AspNet.Hosting/HostingContext.cs +++ /dev/null @@ -1,34 +0,0 @@ -// 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 System; -using Microsoft.AspNet.Builder; -using Microsoft.AspNet.Hosting.Server; -using Microsoft.AspNet.Hosting.Startup; -using Microsoft.Framework.ConfigurationModel; -using Microsoft.Framework.DependencyInjection; - -namespace Microsoft.AspNet.Hosting -{ - public class HostingContext - { - public IConfiguration Configuration { get; set; } - - public IApplicationBuilder Builder { get; set; } - - public string ApplicationName { get; set; } - public string WebRootPath { get; set; } - public string EnvironmentName { get; set; } - public StartupMethods StartupMethods { get; set; } - public RequestDelegate ApplicationDelegate { get; set; } - - public IServiceCollection Services { get; } = new ServiceCollection(); - - // Result of ConfigureServices - public IServiceProvider ApplicationServices { get; set; } - - public string ServerFactoryLocation { get; set; } - public IServerFactory ServerFactory { get; set; } - public IServerInformation Server { get; set; } - } -} \ No newline at end of file diff --git a/src/Microsoft.AspNet.Hosting/HostingEngine.cs b/src/Microsoft.AspNet.Hosting/HostingEngine.cs index 01fae429d5..69ca5e6883 100644 --- a/src/Microsoft.AspNet.Hosting/HostingEngine.cs +++ b/src/Microsoft.AspNet.Hosting/HostingEngine.cs @@ -5,251 +5,219 @@ using System; using System.Collections.Generic; using System.Linq; using System.Threading; +using Microsoft.AspNet.Builder; using Microsoft.AspNet.Hosting.Builder; -using Microsoft.AspNet.Hosting.Internal; using Microsoft.AspNet.Hosting.Server; using Microsoft.AspNet.Hosting.Startup; +using Microsoft.Framework.ConfigurationModel; using Microsoft.Framework.DependencyInjection; -using Microsoft.Framework.Runtime; -using Microsoft.Framework.Runtime.Infrastructure; namespace Microsoft.AspNet.Hosting { - public class HostingEngine + public class HostingEngine : IHostingEngine { - private const string EnvironmentKey = "ASPNET_ENV"; + private readonly IServiceCollection _applicationServiceCollection; + private readonly IStartupLoader _startupLoader; + private readonly ApplicationLifetime _applicationLifetime; + private readonly IHostingEnvironment _hostingEnvironment; + private readonly IConfiguration _config; - private readonly IServiceProvider _fallbackServices; - private readonly ApplicationLifetime _appLifetime; - private readonly IApplicationEnvironment _applicationEnvironment; - private readonly HostingEnvironment _hostingEnvironment; + // Start/ApplicationServices block use methods + private bool _useDisabled; private IServerLoader _serverLoader; private IApplicationBuilderFactory _builderFactory; + private IApplicationBuilder _builder; + private IServiceProvider _applicationServices; - public HostingEngine() : this(fallbackServices: null) { } + // Only one of these should be set + private string _startupAssemblyName; + private StartupMethods _startup; - public HostingEngine(IServiceProvider fallbackServices) + // Only one of these should be set + private string _serverFactoryLocation; + private IServerFactory _serverFactory; + private IServerInformation _serverInstance; + + public HostingEngine(IServiceCollection appServices, IStartupLoader startupLoader, IConfiguration config, IHostingEnvironment hostingEnv, string appName) { - _fallbackServices = fallbackServices ?? CallContextServiceLocator.Locator.ServiceProvider; - _appLifetime = new ApplicationLifetime(); - _applicationEnvironment = _fallbackServices.GetRequiredService(); - _hostingEnvironment = new HostingEnvironment(_applicationEnvironment); - _fallbackServices = new WrappingServiceProvider(_fallbackServices, _hostingEnvironment, _appLifetime); + _config = config ?? new Configuration(); + _applicationServiceCollection = appServices; + _startupLoader = startupLoader; + _startupAssemblyName = appName; + _applicationLifetime = new ApplicationLifetime(); + _hostingEnvironment = hostingEnv; } - public IDisposable Start(HostingContext context) + public virtual IDisposable Start() { - EnsureContextDefaults(context); - EnsureApplicationServices(context); - EnsureBuilder(context); - EnsureServerFactory(context); - InitalizeServerFactory(context); - EnsureApplicationDelegate(context); + EnsureApplicationServices(); + EnsureBuilder(); + EnsureServer(); - var contextFactory = context.ApplicationServices.GetRequiredService(); - var contextAccessor = context.ApplicationServices.GetRequiredService(); - var server = context.ServerFactory.Start(context.Server, + var applicationDelegate = BuildApplicationDelegate(); + + var _contextFactory = _applicationServices.GetRequiredService(); + var _contextAccessor = _applicationServices.GetRequiredService(); + var server = _serverFactory.Start(_serverInstance, features => { - var httpContext = contextFactory.CreateHttpContext(features); - contextAccessor.HttpContext = httpContext; - return context.ApplicationDelegate(httpContext); + var httpContext = _contextFactory.CreateHttpContext(features); + _contextAccessor.HttpContext = httpContext; + return applicationDelegate(httpContext); }); return new Disposable(() => { - _appLifetime.NotifyStopping(); + _applicationLifetime.NotifyStopping(); server.Dispose(); - _appLifetime.NotifyStopped(); + _applicationLifetime.NotifyStopped(); }); } - private void EnsureContextDefaults(HostingContext context) + private void EnsureApplicationServices() { - if (context.ApplicationName == null) - { - context.ApplicationName = _applicationEnvironment.ApplicationName; - } + _useDisabled = true; + EnsureStartup(); - if (context.EnvironmentName == null) - { - context.EnvironmentName = context.Configuration?.Get(EnvironmentKey) ?? HostingEnvironment.DefaultEnvironmentName; - } + _applicationServiceCollection.AddInstance(_applicationLifetime); - _hostingEnvironment.EnvironmentName = context.EnvironmentName; - - if (context.WebRootPath != null) - { - _hostingEnvironment.WebRootPath = context.WebRootPath; - } + _applicationServices = _startup.ConfigureServicesDelegate(_applicationServiceCollection); } - private void EnsureApplicationServices(HostingContext context) + private void EnsureStartup() { - if (context.ApplicationServices != null) - { - return; - } - - EnsureStartupMethods(context); - - context.ApplicationServices = context.StartupMethods.ConfigureServicesDelegate(CreateHostingServices(context)); - } - - private void EnsureStartupMethods(HostingContext context) - { - if (context.StartupMethods != null) + if (_startup != null) { return; } var diagnosticMessages = new List(); - context.StartupMethods = ApplicationStartup.LoadStartupMethods( - _fallbackServices, - context.ApplicationName, - context.EnvironmentName, + _startup = _startupLoader.Load( + _startupAssemblyName, + _hostingEnvironment.EnvironmentName, diagnosticMessages); - if (context.StartupMethods == null) + if (_startup == null) { throw new ArgumentException( - diagnosticMessages.Aggregate("Failed to find an entry point for the web application.", (a, b) => a + "\r\n" + b), - nameof(context)); + diagnosticMessages.Aggregate("Failed to find a startup entry point for the web application.", (a, b) => a + "\r\n" + b), + _startupAssemblyName); } } - private void EnsureBuilder(HostingContext context) + private void EnsureBuilder() { - if (context.Builder != null) - { - return; - } - if (_builderFactory == null) { - _builderFactory = context.ApplicationServices.GetRequiredService(); + _builderFactory = _applicationServices.GetRequiredService(); } - context.Builder = _builderFactory.CreateBuilder(); - context.Builder.ApplicationServices = context.ApplicationServices; + _builder = _builderFactory.CreateBuilder(); + _builder.ApplicationServices = _applicationServices; } - private void EnsureServerFactory(HostingContext context) + private void EnsureServer() { - if (context.ServerFactory != null) + if (_serverFactory == null) { - return; + // Blow up if we don't have a server set at this point + if (_serverFactoryLocation == null) + { + throw new InvalidOperationException("UseStartup() is required for Start()"); + } + + _serverFactory = _applicationServices.GetRequiredService().LoadServerFactory(_serverFactoryLocation); } - if (_serverLoader == null) - { - _serverLoader = context.ApplicationServices.GetRequiredService(); - } - - context.ServerFactory = _serverLoader.LoadServerFactory(context.ServerFactoryLocation); + _serverInstance = _serverFactory.Initialize(_config); + _builder.Server = _serverInstance; } - private void InitalizeServerFactory(HostingContext context) + private RequestDelegate BuildApplicationDelegate() { - if (context.Server == null) - { - context.Server = context.ServerFactory.Initialize(context.Configuration); - } - - if (context.Builder.Server == null) - { - context.Builder.Server = context.Server; - } - } - - private IServiceCollection CreateHostingServices(HostingContext context) - { - var services = Import(_fallbackServices); - - services.TryAdd(ServiceDescriptor.Transient()); - - services.TryAdd(ServiceDescriptor.Transient()); - services.TryAdd(ServiceDescriptor.Transient()); - - // TODO: Do we expect this to be provide by the runtime eventually? - services.AddLogging(); - services.TryAdd(ServiceDescriptor.Singleton()); - - // Apply user services - services.Add(context.Services); - - // Jamming in app lifetime and hosting env since these must not be replaceable - services.AddInstance(_appLifetime); - services.AddInstance(_hostingEnvironment); - - // Conjure up a RequestServices - services.AddTransient(); - - return services; - } - - private void EnsureApplicationDelegate(HostingContext context) - { - if (context.ApplicationDelegate != null) - { - return; - } - - // REVIEW: should we call EnsureApplicationServices? - var startupFilters = context.ApplicationServices.GetService>(); - var configure = context.StartupMethods.ConfigureDelegate; + var startupFilters = _applicationServices.GetService>(); + var configure = _startup.ConfigureDelegate; foreach (var filter in startupFilters) { - configure = filter.Configure(context.Builder, configure); + configure = filter.Configure(_builder, configure); } - configure(context.Builder); + configure(_builder); - context.ApplicationDelegate = context.Builder.Build(); + return _builder.Build(); } - private static IServiceCollection Import(IServiceProvider fallbackProvider) + public IServiceProvider ApplicationServices { - var services = new ServiceCollection(); - var manifest = fallbackProvider.GetRequiredService(); - foreach (var service in manifest.Services) + get { - services.AddTransient(service, sp => fallbackProvider.GetService(service)); + EnsureApplicationServices(); + return _applicationServices; } - - return services; } - private class WrappingServiceProvider : IServiceProvider + private void CheckUseAllowed() { - private readonly IServiceProvider _sp; - private readonly IHostingEnvironment _hostingEnvironment; - private readonly IApplicationLifetime _applicationLifetime; - - public WrappingServiceProvider(IServiceProvider sp, - IHostingEnvironment hostingEnvironment, - IApplicationLifetime applicationLifetime) + if (_useDisabled) { - _sp = sp; - _hostingEnvironment = hostingEnvironment; - _applicationLifetime = applicationLifetime; + throw new InvalidOperationException("HostingEngine has already been started."); } + } - public object GetService(Type serviceType) - { - if (serviceType == typeof(IHostingEnvironment)) - { - return _hostingEnvironment; - } + // Consider cutting + public IHostingEngine UseEnvironment(string environment) + { + CheckUseAllowed(); + _hostingEnvironment.EnvironmentName = environment; + return this; + } - if (serviceType == typeof(IApplicationLifetime)) - { - return _applicationLifetime; - } + public IHostingEngine UseServer(string assemblyName) + { + CheckUseAllowed(); + _serverFactoryLocation = assemblyName; + return this; + } - return _sp.GetService(serviceType); - } + public IHostingEngine UseServer(IServerFactory factory) + { + CheckUseAllowed(); + _serverFactory = factory; + return this; + } + + public IHostingEngine UseStartup(string startupAssemblyName) + { + CheckUseAllowed(); + _startupAssemblyName = startupAssemblyName; + return this; + } + + public IHostingEngine UseStartup(Action configureApp) + { + return UseStartup(configureApp, configureServices: null); + } + + public IHostingEngine UseStartup(Action configureApp, ConfigureServicesDelegate configureServices) + { + CheckUseAllowed(); + _startup = new StartupMethods(configureApp, configureServices); + return this; + } + + public IHostingEngine UseStartup(Action configureApp, Action configureServices) + { + CheckUseAllowed(); + _startup = new StartupMethods(configureApp, + services => { + if (configureServices != null) + { + configureServices(services); + } + return services.BuildServiceProvider(); + }); + return this; } private class Disposable : IDisposable diff --git a/src/Microsoft.AspNet.Hosting/HostingEnvironment.cs b/src/Microsoft.AspNet.Hosting/HostingEnvironment.cs index b7a0249319..dac9b27d89 100644 --- a/src/Microsoft.AspNet.Hosting/HostingEnvironment.cs +++ b/src/Microsoft.AspNet.Hosting/HostingEnvironment.cs @@ -1,10 +1,8 @@ // 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 System.Collections.Generic; using Microsoft.AspNet.FileProviders; using Microsoft.AspNet.Hosting.Internal; -using Microsoft.Framework.Runtime; namespace Microsoft.AspNet.Hosting { @@ -12,17 +10,10 @@ namespace Microsoft.AspNet.Hosting { internal const string DefaultEnvironmentName = "Development"; - public HostingEnvironment(IApplicationEnvironment appEnvironment) - { - EnvironmentName = DefaultEnvironmentName; - WebRootPath = HostingUtilities.GetWebRoot(appEnvironment.ApplicationBasePath); - WebRootFileProvider = new PhysicalFileProvider(WebRootPath); - } - - public string EnvironmentName { get; set; } + public string EnvironmentName { get; set; } = DefaultEnvironmentName; public string WebRootPath { get; set; } - public IFileProvider WebRootFileProvider { get; private set; } + public IFileProvider WebRootFileProvider { get; set; } } } \ No newline at end of file diff --git a/src/Microsoft.AspNet.Hosting/HostingEnvironmentExtensions.cs b/src/Microsoft.AspNet.Hosting/HostingEnvironmentExtensions.cs new file mode 100644 index 0000000000..cd18889034 --- /dev/null +++ b/src/Microsoft.AspNet.Hosting/HostingEnvironmentExtensions.cs @@ -0,0 +1,18 @@ +// 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.FileProviders; +using Microsoft.AspNet.Hosting.Internal; + +namespace Microsoft.AspNet.Hosting +{ + public static class HostingEnvironmentExtensions + { + public static void Initialize(this IHostingEnvironment hostingEnvironment, string applicationBasePath, string environmentName) + { + hostingEnvironment.WebRootPath = HostingUtilities.GetWebRoot(applicationBasePath); + hostingEnvironment.WebRootFileProvider = new PhysicalFileProvider(hostingEnvironment.WebRootPath); + hostingEnvironment.EnvironmentName = environmentName ?? hostingEnvironment.EnvironmentName; + } + } +} \ No newline at end of file diff --git a/src/Microsoft.AspNet.Hosting/HostingFactory.cs b/src/Microsoft.AspNet.Hosting/HostingFactory.cs new file mode 100644 index 0000000000..1b77dc7e59 --- /dev/null +++ b/src/Microsoft.AspNet.Hosting/HostingFactory.cs @@ -0,0 +1,35 @@ +// 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.Hosting.Internal; +using Microsoft.AspNet.Hosting.Startup; +using Microsoft.Framework.ConfigurationModel; +using Microsoft.Framework.Runtime; + +namespace Microsoft.AspNet.Hosting +{ + public class HostingFactory : IHostingFactory + { + public const string EnvironmentKey = "ASPNET_ENV"; + + private readonly RootHostingServiceCollectionInitializer _serviceInitializer; + private readonly IStartupLoader _startupLoader; + private readonly IApplicationEnvironment _applicationEnvironment; + private readonly IHostingEnvironment _hostingEnvironment; + + public HostingFactory(RootHostingServiceCollectionInitializer initializer, IStartupLoader startupLoader, IApplicationEnvironment appEnv, IHostingEnvironment hostingEnv) + { + _serviceInitializer = initializer; + _startupLoader = startupLoader; + _applicationEnvironment = appEnv; + _hostingEnvironment = hostingEnv; + } + + public IHostingEngine Create(IConfiguration config) + { + _hostingEnvironment.Initialize(_applicationEnvironment.ApplicationBasePath, config?[EnvironmentKey]); + + return new HostingEngine(_serviceInitializer.Build(), _startupLoader, config, _hostingEnvironment, _applicationEnvironment.ApplicationName); + } + } +} \ No newline at end of file diff --git a/src/Microsoft.AspNet.Hosting/IHostingEngine.cs b/src/Microsoft.AspNet.Hosting/IHostingEngine.cs new file mode 100644 index 0000000000..dbd6577b05 --- /dev/null +++ b/src/Microsoft.AspNet.Hosting/IHostingEngine.cs @@ -0,0 +1,32 @@ +// 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 System; +using Microsoft.AspNet.Builder; +using Microsoft.AspNet.Hosting.Server; +using Microsoft.AspNet.Hosting.Startup; +using Microsoft.Framework.DependencyInjection; + +namespace Microsoft.AspNet.Hosting +{ + public interface IHostingEngine + { + IDisposable Start(); + + // Accessing this will block Use methods + IServiceProvider ApplicationServices { get; } + + // Use methods blow up after any of the above methods are called + IHostingEngine UseEnvironment(string environment); + + // Mutually exclusive + IHostingEngine UseServer(string assemblyName); + IHostingEngine UseServer(IServerFactory factory); + + // Mutually exclusive + IHostingEngine UseStartup(string startupAssemblyName); + IHostingEngine UseStartup(Action configureApp); + IHostingEngine UseStartup(Action configureApp, ConfigureServicesDelegate configureServices); + IHostingEngine UseStartup(Action configureApp, Action configureServices); + } +} \ No newline at end of file diff --git a/src/Microsoft.AspNet.Hosting/IHostingFactory.cs b/src/Microsoft.AspNet.Hosting/IHostingFactory.cs new file mode 100644 index 0000000000..f44b02c1db --- /dev/null +++ b/src/Microsoft.AspNet.Hosting/IHostingFactory.cs @@ -0,0 +1,12 @@ +// 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.Framework.ConfigurationModel; + +namespace Microsoft.AspNet.Hosting +{ + public interface IHostingFactory + { + IHostingEngine Create(IConfiguration config); + } +} \ No newline at end of file diff --git a/src/Microsoft.AspNet.Hosting/IHttpContextAccessor.cs b/src/Microsoft.AspNet.Hosting/IHttpContextAccessor.cs index 8b1719880b..f406c8e3b3 100644 --- a/src/Microsoft.AspNet.Hosting/IHttpContextAccessor.cs +++ b/src/Microsoft.AspNet.Hosting/IHttpContextAccessor.cs @@ -5,6 +5,7 @@ using Microsoft.AspNet.Http; namespace Microsoft.AspNet.Hosting { + // REVIEW: move to interfaces public interface IHttpContextAccessor { HttpContext HttpContext { get; set; } diff --git a/src/Microsoft.AspNet.Hosting/Internal/RootHostingServiceCollectionInitializer.cs b/src/Microsoft.AspNet.Hosting/Internal/RootHostingServiceCollectionInitializer.cs new file mode 100644 index 0000000000..3e9a9babec --- /dev/null +++ b/src/Microsoft.AspNet.Hosting/Internal/RootHostingServiceCollectionInitializer.cs @@ -0,0 +1,66 @@ +// 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 System; +using Microsoft.AspNet.Hosting.Builder; +using Microsoft.AspNet.Hosting.Internal; +using Microsoft.AspNet.Hosting.Server; +using Microsoft.AspNet.Hosting.Startup; +using Microsoft.Framework.DependencyInjection; +using Microsoft.Framework.Logging; +using Microsoft.Framework.Runtime; +using Microsoft.Framework.Runtime.Infrastructure; + +namespace Microsoft.AspNet.Hosting.Internal +{ + public class RootHostingServiceCollectionInitializer + { + private readonly IServiceProvider _fallbackServices; + private readonly Action _configureServices; + private readonly IHostingEnvironment _hostingEnvironment; + private readonly ILoggerFactory _loggerFactory; + + public RootHostingServiceCollectionInitializer(IServiceProvider fallbackServices, Action configureServices) + { + _fallbackServices = fallbackServices; + _configureServices = configureServices; + _hostingEnvironment = new HostingEnvironment(); + _loggerFactory = new LoggerFactory(); + } + + public IServiceCollection Build() + { + var services = new ServiceCollection(); + + // Import from manifest + var manifest = _fallbackServices.GetRequiredService(); + foreach (var service in manifest.Services) + { + services.AddTransient(service, sp => _fallbackServices.GetService(service)); + } + + services.AddInstance(_hostingEnvironment); + services.AddInstance(this); + services.AddInstance(_loggerFactory); + + services.AddTransient(); + services.AddTransient(); + + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddSingleton(); + services.AddLogging(); + + // Conjure up a RequestServices + services.AddTransient(); + + if (_configureServices != null) + { + _configureServices(services); + } + + return services; + } + } +} \ No newline at end of file diff --git a/src/Microsoft.AspNet.Hosting/Program.cs b/src/Microsoft.AspNet.Hosting/Program.cs index 47211a65ed..555fc241a8 100644 --- a/src/Microsoft.AspNet.Hosting/Program.cs +++ b/src/Microsoft.AspNet.Hosting/Program.cs @@ -33,18 +33,13 @@ namespace Microsoft.AspNet.Hosting config.AddEnvironmentVariables(); config.AddCommandLine(args); - var context = new HostingContext() - { - Configuration = config, - ServerFactoryLocation = config.Get("server"), - ApplicationName = config.Get("app") - }; - - var engine = new HostingEngine(_serviceProvider); + var engine = WebHost.CreateEngine(_serviceProvider, config) + .UseServer(config.Get("server")) + .UseStartup(config.Get("app")); - var serverShutdown = engine.Start(context); - var loggerFactory = context.ApplicationServices.GetRequiredService(); - var appShutdownService = context.ApplicationServices.GetRequiredService(); + var serverShutdown = engine.Start(); + var loggerFactory = engine.ApplicationServices.GetRequiredService(); + var appShutdownService = engine.ApplicationServices.GetRequiredService(); var shutdownHandle = new ManualResetEvent(false); appShutdownService.ShutdownRequested.Register(() => diff --git a/src/Microsoft.AspNet.Hosting/Startup/IStartupLoader.cs b/src/Microsoft.AspNet.Hosting/Startup/IStartupLoader.cs new file mode 100644 index 0000000000..cab29b61ce --- /dev/null +++ b/src/Microsoft.AspNet.Hosting/Startup/IStartupLoader.cs @@ -0,0 +1,16 @@ +// 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 System; +using System.Collections.Generic; + +namespace Microsoft.AspNet.Hosting.Startup +{ + public interface IStartupLoader + { + StartupMethods Load( + string startupAssemblyName, + string environmentName, + IList diagnosticMessages); + } +} diff --git a/src/Microsoft.AspNet.Hosting/Startup/ApplicationStartup.cs b/src/Microsoft.AspNet.Hosting/Startup/StartupLoader.cs similarity index 76% rename from src/Microsoft.AspNet.Hosting/Startup/ApplicationStartup.cs rename to src/Microsoft.AspNet.Hosting/Startup/StartupLoader.cs index 811afb5590..6ebc09f04e 100644 --- a/src/Microsoft.AspNet.Hosting/Startup/ApplicationStartup.cs +++ b/src/Microsoft.AspNet.Hosting/Startup/StartupLoader.cs @@ -10,25 +10,46 @@ using Microsoft.Framework.DependencyInjection; namespace Microsoft.AspNet.Hosting.Startup { - public static class ApplicationStartup + public class StartupLoader : IStartupLoader { - internal static ConfigureServicesDelegate DefaultBuildServiceProvider = s => s.BuildServiceProvider(); + private readonly IServiceProvider _services; - public static StartupMethods LoadStartupMethods( - IServiceProvider services, - string applicationName, + public StartupLoader(IServiceProvider services) + { + _services = services; + } + + public StartupMethods Load( + Type startupType, string environmentName, IList diagnosticMessages) { - if (string.IsNullOrEmpty(applicationName)) + var configureMethod = FindConfigureDelegate(startupType, environmentName); + var servicesMethod = FindConfigureServicesDelegate(startupType, environmentName); + + object instance = null; + if (!configureMethod.MethodInfo.IsStatic || (servicesMethod != null && !servicesMethod.MethodInfo.IsStatic)) { - throw new ArgumentException("Value cannot be null or empty.", "applicationName"); + instance = ActivatorUtilities.GetServiceOrCreateInstance(_services, startupType); } - var assembly = Assembly.Load(new AssemblyName(applicationName)); + return new StartupMethods(configureMethod.Build(instance), servicesMethod?.Build(instance)); + } + + public StartupMethods Load( + string startupAssemblyName, + string environmentName, + IList diagnosticMessages) + { + if (string.IsNullOrEmpty(startupAssemblyName)) + { + throw new ArgumentException("Value cannot be null or empty.", nameof(startupAssemblyName)); + } + + var assembly = Assembly.Load(new AssemblyName(startupAssemblyName)); if (assembly == null) { - throw new InvalidOperationException(String.Format("The assembly '{0}' failed to load.", applicationName)); + throw new InvalidOperationException(String.Format("The assembly '{0}' failed to load.", startupAssemblyName)); } var startupNameWithEnv = "Startup" + environmentName; @@ -37,9 +58,9 @@ namespace Microsoft.AspNet.Hosting.Startup // Check the most likely places first var type = assembly.GetType(startupNameWithEnv) ?? - assembly.GetType(applicationName + "." + startupNameWithEnv) ?? + assembly.GetType(startupAssemblyName + "." + startupNameWithEnv) ?? assembly.GetType(startupNameWithoutEnv) ?? - assembly.GetType(applicationName + "." + startupNameWithoutEnv); + assembly.GetType(startupAssemblyName + "." + startupNameWithoutEnv); if (type == null) { @@ -61,29 +82,19 @@ namespace Microsoft.AspNet.Hosting.Startup throw new InvalidOperationException(String.Format("A type named '{0}' or '{1}' could not be found in assembly '{2}'.", startupNameWithEnv, startupNameWithoutEnv, - applicationName)); + startupAssemblyName)); } - var configureMethod = FindConfigureDelegate(type, environmentName); - var servicesMethod = FindConfigureServicesDelegate(type, environmentName); - - object instance = null; - if (!configureMethod.MethodInfo.IsStatic || (servicesMethod != null && !servicesMethod.MethodInfo.IsStatic)) - { - instance = ActivatorUtilities.GetServiceOrCreateInstance(services, type); - } - - return new StartupMethods(configureMethod.Build(instance), servicesMethod?.Build(instance)); + return Load(type, environmentName, diagnosticMessages); } - - public static ConfigureBuilder FindConfigureDelegate(Type startupType, string environmentName) + private static ConfigureBuilder FindConfigureDelegate(Type startupType, string environmentName) { var configureMethod = FindMethod(startupType, "Configure{0}", environmentName, typeof(void), required: true); return new ConfigureBuilder(configureMethod); } - public static ConfigureServicesBuilder FindConfigureServicesDelegate(Type startupType, string environmentName) + private static ConfigureServicesBuilder FindConfigureServicesDelegate(Type startupType, string environmentName) { var servicesMethod = FindMethod(startupType, "Configure{0}Services", environmentName, typeof(IServiceProvider), required: false) ?? FindMethod(startupType, "Configure{0}Services", environmentName, typeof(void), required: false); diff --git a/src/Microsoft.AspNet.Hosting/Startup/StartupMethods.cs b/src/Microsoft.AspNet.Hosting/Startup/StartupMethods.cs index 4b3a5c9c5c..4644b5a55e 100644 --- a/src/Microsoft.AspNet.Hosting/Startup/StartupMethods.cs +++ b/src/Microsoft.AspNet.Hosting/Startup/StartupMethods.cs @@ -3,16 +3,22 @@ using System; using Microsoft.AspNet.Builder; +using Microsoft.Framework.DependencyInjection; namespace Microsoft.AspNet.Hosting.Startup { public class StartupMethods { + internal static ConfigureServicesDelegate DefaultBuildServiceProvider = s => s.BuildServiceProvider(); + + public StartupMethods(Action configure) + : this(configure, configureServices: null) { } + // TODO: switch to ConfigureDelegate eventually public StartupMethods(Action configure, ConfigureServicesDelegate configureServices) { ConfigureDelegate = configure; - ConfigureServicesDelegate = configureServices ?? ApplicationStartup.DefaultBuildServiceProvider; + ConfigureServicesDelegate = configureServices ?? DefaultBuildServiceProvider; } public ConfigureServicesDelegate ConfigureServicesDelegate { get; } diff --git a/src/Microsoft.AspNet.Hosting/WebHost.cs b/src/Microsoft.AspNet.Hosting/WebHost.cs new file mode 100644 index 0000000000..c1d331e0c4 --- /dev/null +++ b/src/Microsoft.AspNet.Hosting/WebHost.cs @@ -0,0 +1,63 @@ +// 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 System; +using Microsoft.AspNet.Hosting.Internal; +using Microsoft.Framework.ConfigurationModel; +using Microsoft.Framework.DependencyInjection; +using Microsoft.Framework.Runtime.Infrastructure; + +namespace Microsoft.AspNet.Hosting +{ + public static class WebHost + { + public static IHostingEngine CreateEngine() + { + return CreateEngine(new Configuration()); + } + + public static IHostingEngine CreateEngine(Action configureServices) + { + return CreateEngine(new Configuration(), configureServices); + } + + public static IHostingEngine CreateEngine(IConfiguration config) + { + return CreateEngine(config, configureServices: null); + } + + public static IHostingEngine CreateEngine(IConfiguration config, Action configureServices) + { + return CreateEngine(fallbackServices: null, config: config, configureServices: configureServices); + } + + public static IHostingEngine CreateEngine(IServiceProvider fallbackServices, IConfiguration config) + { + return CreateEngine(fallbackServices, config, configureServices: null); + } + + public static IHostingEngine CreateEngine(IServiceProvider fallbackServices, IConfiguration config, Action configureServices) + { + return CreateFactory(fallbackServices, configureServices).Create(config); + } + + public static IHostingFactory CreateFactory() + { + return CreateFactory(fallbackServices: null, configureServices: null); + } + + public static IHostingFactory CreateFactory(Action configureServices) + { + return CreateFactory(fallbackServices: null, configureServices: configureServices); + } + + public static IHostingFactory CreateFactory(IServiceProvider fallbackServices, Action configureServices) + { + fallbackServices = fallbackServices ?? CallContextServiceLocator.Locator.ServiceProvider; + return new RootHostingServiceCollectionInitializer(fallbackServices, configureServices) + .Build() + .BuildServiceProvider() + .GetRequiredService(); + } + } +} \ No newline at end of file diff --git a/src/Microsoft.AspNet.TestHost/TestServer.cs b/src/Microsoft.AspNet.TestHost/TestServer.cs index 0cc7b83a65..0e3a9927b5 100644 --- a/src/Microsoft.AspNet.TestHost/TestServer.cs +++ b/src/Microsoft.AspNet.TestHost/TestServer.cs @@ -12,7 +12,6 @@ using Microsoft.AspNet.Hosting.Startup; using Microsoft.AspNet.Http; using Microsoft.Framework.ConfigurationModel; using Microsoft.Framework.DependencyInjection; -using Microsoft.Framework.Runtime.Infrastructure; namespace Microsoft.AspNet.TestHost { @@ -25,63 +24,95 @@ namespace Microsoft.AspNet.TestHost private IDisposable _appInstance; private bool _disposed = false; - // REVIEW: we can configure services via AppStartup or via hostContext.Services - public TestServer(IConfiguration config, IServiceProvider serviceProvider, Action configureApp, ConfigureServicesDelegate configureServices) + public TestServer(IHostingEngine engine) { - var hostContext = new HostingContext() - { - ApplicationName = "Test App", - Configuration = config, - ServerFactory = this, - StartupMethods = new StartupMethods(configureApp, configureServices) - }; - - _appInstance = new HostingEngine(serviceProvider).Start(hostContext); + _appInstance = engine.UseServer(this).Start(); } public Uri BaseAddress { get; set; } = new Uri("http://localhost/"); + public static TestServer Create() + { + return Create(fallbackServices: null, config: null, configureApp: null, configureServices: null); + } + public static TestServer Create(Action configureApp) { - return Create(CallContextServiceLocator.Locator.ServiceProvider, configureApp, configureServices: null); + return Create(fallbackServices: null, config: null, configureApp: configureApp, configureServices: null); } public static TestServer Create(Action configureApp, Action configureServices) { - return Create(CallContextServiceLocator.Locator.ServiceProvider, configureApp, - sc => + return Create(fallbackServices: null, config: null, configureApp: configureApp, configureServices: configureServices); + } + + public static TestServer Create(IServiceProvider fallbackServices, Action configureApp, ConfigureServicesDelegate configureServices) + { + return CreateBuilder(fallbackServices, config: null, configureApp: configureApp, configureServices: configureServices).Build(); + } + + public static TestServer Create(IServiceProvider fallbackServices, IConfiguration config, Action configureApp, Action configureServices) + { + return CreateBuilder(fallbackServices, config, configureApp, configureServices).Build(); + } + + public static TestServer Create() where TStartup : class + { + return Create(fallbackServices: null, config: null, configureApp: null, configureServices: null); + } + + public static TestServer Create(Action configureApp) where TStartup : class + { + return Create(fallbackServices: null, config: null, configureApp: configureApp, configureServices: null); + } + + public static TestServer Create(Action configureApp, Action configureServices) where TStartup : class + { + return Create(fallbackServices: null, config: null, configureApp: configureApp, configureServices: configureServices); + } + + public static TestServer Create(IServiceProvider fallbackServices, IConfiguration config, Action configureApp, Action configureServices) where TStartup : class + { + var builder = CreateBuilder(fallbackServices, config, configureApp, configureServices); + builder.StartupType = typeof(TStartup); + return builder.Build(); + } + + public static TestServerBuilder CreateBuilder() where TStartup : class + { + var builder = CreateBuilder(fallbackServices: null, config: null, configureApp: null, configureServices: null); + builder.StartupType = typeof(TStartup); + return builder; + } + + public static TestServerBuilder CreateBuilder(IServiceProvider fallbackServices, IConfiguration config, Action configureApp, Action configureServices) where TStartup : class + { + var builder = CreateBuilder(fallbackServices, config, configureApp, configureServices); + builder.StartupType = typeof(TStartup); + return builder; + } + + public static TestServerBuilder CreateBuilder(IServiceProvider fallbackServices, IConfiguration config, Action configureApp, Action configureServices) + { + return CreateBuilder(fallbackServices, config, configureApp, + services => { if (configureServices != null) { - configureServices(sc); + configureServices(services); } - return sc.BuildServiceProvider(); + return services.BuildServiceProvider(); }); } - public static TestServer Create(IServiceProvider serviceProvider, Action configureApp) + public static TestServerBuilder CreateBuilder(IServiceProvider fallbackServices, IConfiguration config, Action configureApp, ConfigureServicesDelegate configureServices) { - return Create(serviceProvider, configureApp, configureServices: null); - } - - public static TestServer Create(IServiceProvider serviceProvider, Action configureApp, Action configureServices) - { - return Create(serviceProvider, configureApp, - sc => - { - if (configureServices != null) - { - configureServices(sc); - } - return sc.BuildServiceProvider(); - }); - } - - public static TestServer Create(IServiceProvider serviceProvider, Action configureApp, ConfigureServicesDelegate configureServices) - { - // REVIEW: do we need an overload that takes Config for Create? - var config = new Configuration(); - return new TestServer(config, serviceProvider, configureApp, configureServices); + return new TestServerBuilder + { + FallbackServices = fallbackServices, + Startup = new StartupMethods(configureApp, configureServices), + Config = config + }; } public HttpMessageHandler CreateHandler() @@ -145,4 +176,4 @@ namespace Microsoft.AspNet.TestHost } } } -} +} \ No newline at end of file diff --git a/src/Microsoft.AspNet.TestHost/TestServerBuilder.cs b/src/Microsoft.AspNet.TestHost/TestServerBuilder.cs new file mode 100644 index 0000000000..74425f89f5 --- /dev/null +++ b/src/Microsoft.AspNet.TestHost/TestServerBuilder.cs @@ -0,0 +1,126 @@ +// 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 System; +using System.Collections.Generic; +using System.Runtime.Versioning; +using Microsoft.AspNet.Hosting; +using Microsoft.AspNet.Hosting.Startup; +using Microsoft.Framework.ConfigurationModel; +using Microsoft.Framework.DependencyInjection; +using Microsoft.Framework.Runtime; +using Microsoft.Framework.Runtime.Infrastructure; + +namespace Microsoft.AspNet.TestHost +{ + public class TestServerBuilder + { + public IServiceProvider FallbackServices { get; set; } + public string Environment { get; set; } + public string ApplicationName { get; set; } + public string ApplicationBasePath { get; set; } + + public Type StartupType { get; set; } + public string StartupAssemblyName { get; set; } + public IConfiguration Config { get; set; } + + public IServiceCollection AdditionalServices { get; } = new ServiceCollection(); + + public StartupMethods Startup { get; set; } + + public TestServer Build() + { + var fallbackServices = FallbackServices ?? CallContextServiceLocator.Locator.ServiceProvider; + var config = Config ?? new Configuration(); + if (Environment != null) + { + config[HostingFactory.EnvironmentKey] = Environment; + } + if (ApplicationName != null || ApplicationBasePath != null) + { + var appEnv = new TestApplicationEnvironment(fallbackServices.GetRequiredService()); + appEnv.ApplicationBasePath = ApplicationBasePath; + appEnv.ApplicationName = ApplicationName; + AdditionalServices.AddInstance(appEnv); + } + + var engine = WebHost.CreateEngine(fallbackServices, + config, + services => services.Add(AdditionalServices)); + if (StartupType != null) + { + Startup = new StartupLoader(fallbackServices).Load(StartupType, Environment, new List()); + } + if (Startup != null) + { + engine.UseStartup(Startup.ConfigureDelegate, Startup.ConfigureServicesDelegate); + } + else if (StartupAssemblyName != null) + { + engine.UseStartup(StartupAssemblyName); + } + + return new TestServer(engine); + } + + private class TestApplicationEnvironment : IApplicationEnvironment + { + private readonly IApplicationEnvironment _appEnv; + private string _appName; + private string _appBasePath; + + public TestApplicationEnvironment(IApplicationEnvironment appEnv) + { + _appEnv = appEnv; + } + + public string ApplicationBasePath + { + get + { + return _appBasePath ?? _appEnv.ApplicationBasePath; + } + set + { + _appBasePath = value; + } + } + + public string ApplicationName + { + get + { + return _appName ?? _appEnv.ApplicationName; + } + set + { + _appName = value; + } + } + + public string Configuration + { + get + { + return _appEnv.Configuration; + } + } + + public FrameworkName RuntimeFramework + { + get + { + return _appEnv.RuntimeFramework; + } + } + + public string Version + { + get + { + throw new NotImplementedException(); + } + } + } + } +} \ No newline at end of file diff --git a/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs b/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs index 7bebf1c0e7..6e2547f0ed 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs @@ -8,8 +8,10 @@ using System.Threading.Tasks; using Microsoft.AspNet.Builder; using Microsoft.AspNet.FeatureModel; using Microsoft.AspNet.Hosting.Server; +using Microsoft.AspNet.Hosting.Startup; using Microsoft.Framework.ConfigurationModel; using Microsoft.Framework.DependencyInjection; +using Microsoft.Framework.OptionsModel; using Xunit; namespace Microsoft.AspNet.Hosting @@ -18,58 +20,60 @@ namespace Microsoft.AspNet.Hosting { private readonly IList _startInstances = new List(); + [Fact] + public void HostingEngineThrowsWithNoServer() + { + Assert.Throws(() => WebHost.CreateEngine().Start()); + } + [Fact] public void HostingEngineCanBeStarted() { - var context = new HostingContext - { - ServerFactory = this, - ApplicationName = "Microsoft.AspNet.Hosting.Tests" - }; + var engine = WebHost.CreateEngine() + .UseServer(this) + .UseStartup("Microsoft.AspNet.Hosting.Tests") + .Start(); - var engineStart = new HostingEngine().Start(context); - - Assert.NotNull(engineStart); + Assert.NotNull(engine); Assert.Equal(1, _startInstances.Count); Assert.Equal(0, _startInstances[0].DisposeCalls); - engineStart.Dispose(); + engine.Dispose(); Assert.Equal(1, _startInstances[0].DisposeCalls); } [Fact] - public void ApplicationNameDefaultsToApplicationEnvironmentName() + public void CanReplaceHostingFactory() { - var context = new HostingContext - { - ServerFactory = this - }; + var factory = WebHost.CreateFactory(services => services.AddTransient()); - var engine = new HostingEngine(); + Assert.NotNull(factory as TestEngineFactory); + } - using (engine.Start(context)) - { - Assert.Equal("Microsoft.AspNet.Hosting.Tests", context.ApplicationName); - } + [Fact] + public void CanReplaceStartupLoader() + { + var engine = WebHost.CreateEngine(services => services.AddTransient()) + .UseServer(this) + .UseStartup("Microsoft.AspNet.Hosting.Tests"); + + Assert.Throws(() => engine.Start()); + } + + [Fact] + public void CanCreateApplicationServicesWithAddedServices() + { + var engineStart = WebHost.CreateEngine(services => services.AddOptions()); + Assert.NotNull(engineStart.ApplicationServices.GetRequiredService>()); } [Fact] public void EnvDefaultsToDevelopmentIfNoConfig() { - var context = new HostingContext - { - ServerFactory = this - }; - - var engine = new HostingEngine(); - - using (engine.Start(context)) - { - Assert.Equal("Development", context.EnvironmentName); - var env = context.ApplicationServices.GetRequiredService(); - Assert.Equal("Development", env.EnvironmentName); - } + var engine = WebHost.CreateEngine(new Configuration()); + var env = engine.ApplicationServices.GetRequiredService(); + Assert.Equal("Development", env.EnvironmentName); } [Fact] @@ -83,32 +87,16 @@ namespace Microsoft.AspNet.Hosting var config = new Configuration() .Add(new MemoryConfigurationSource(vals)); - var context = new HostingContext - { - ServerFactory = this, - Configuration = config - }; - - var engine = new HostingEngine(); - - using (engine.Start(context)) - { - Assert.Equal("Staging", context.EnvironmentName); - var env = context.ApplicationServices.GetRequiredService(); - Assert.Equal("Staging", env.EnvironmentName); - } + var engine = WebHost.CreateEngine(config); + var env = engine.ApplicationServices.GetRequiredService(); + Assert.Equal("Staging", env.EnvironmentName); } [Fact] public void WebRootCanBeResolvedFromTheProjectJson() { - var context = new HostingContext - { - ServerFactory = this - }; - - var engineStart = new HostingEngine().Start(context); - var env = context.ApplicationServices.GetRequiredService(); + var engine = WebHost.CreateEngine().UseServer(this); + var env = engine.ApplicationServices.GetRequiredService(); Assert.Equal(Path.GetFullPath("testroot"), env.WebRootPath); Assert.True(env.WebRootFileProvider.GetFileInfo("TextFile.txt").Exists); } @@ -116,16 +104,11 @@ namespace Microsoft.AspNet.Hosting [Fact] public void IsEnvironment_Extension_Is_Case_Insensitive() { - var context = new HostingContext - { - ServerFactory = this - }; + var engine = WebHost.CreateEngine().UseServer(this); - var engine = new HostingEngine(); - - using (engine.Start(context)) + using (engine.Start()) { - var env = context.ApplicationServices.GetRequiredService(); + var env = engine.ApplicationServices.GetRequiredService(); Assert.True(env.IsEnvironment("Development")); Assert.True(env.IsEnvironment("developMent")); } @@ -141,27 +124,17 @@ namespace Microsoft.AspNet.Hosting [InlineData(@"sub/sub2\sub3\", @"sub/sub2/sub3/")] public void MapPath_Facts(string virtualPath, string expectedSuffix) { - var context = new HostingContext - { - ServerFactory = this - }; + var engine = WebHost.CreateEngine().UseServer(this); - var engine = new HostingEngine(); - - using (engine.Start(context)) + using (engine.Start()) { - var env = context.ApplicationServices.GetRequiredService(); + var env = engine.ApplicationServices.GetRequiredService(); var mappedPath = env.MapPath(virtualPath); expectedSuffix = expectedSuffix.Replace('/', Path.DirectorySeparatorChar); Assert.Equal(Path.Combine(env.WebRootPath, expectedSuffix), mappedPath); } } - public void Initialize(IApplicationBuilder builder) - { - - } - public IServerInformation Initialize(IConfiguration configuration) { return null; @@ -190,5 +163,21 @@ namespace Microsoft.AspNet.Hosting DisposeCalls += 1; } } + + private class TestLoader : IStartupLoader + { + public StartupMethods Load(string startupAssemblyName, string environmentName, IList diagnosticMessages) + { + throw new NotImplementedException(); + } + } + + private class TestEngineFactory : IHostingFactory + { + public IHostingEngine Create(IConfiguration config) + { + throw new NotImplementedException(); + } + } } } diff --git a/test/Microsoft.AspNet.Hosting.Tests/Microsoft.AspNet.Hosting.Tests.xproj b/test/Microsoft.AspNet.Hosting.Tests/Microsoft.AspNet.Hosting.Tests.xproj index 8f9318a85a..d4b7ee1bcd 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/Microsoft.AspNet.Hosting.Tests.xproj +++ b/test/Microsoft.AspNet.Hosting.Tests/Microsoft.AspNet.Hosting.Tests.xproj @@ -14,5 +14,8 @@ 2.0 18007 + + + \ No newline at end of file diff --git a/test/Microsoft.AspNet.Hosting.Tests/StartupManagerTests.cs b/test/Microsoft.AspNet.Hosting.Tests/StartupManagerTests.cs index a7ecf91aaa..cce2931e22 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/StartupManagerTests.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/StartupManagerTests.cs @@ -3,6 +3,8 @@ using System; using System.Collections.Generic; +using System.Diagnostics; +using System.Reflection; using Microsoft.AspNet.Builder; using Microsoft.AspNet.Hosting.Fakes; using Microsoft.AspNet.Hosting.Startup; @@ -24,7 +26,7 @@ namespace Microsoft.AspNet.Hosting.Tests var services = serviceCollection.BuildServiceProvider(); var diagnosticMessages = new List(); - var startup = ApplicationStartup.LoadStartupMethods(services, "Microsoft.AspNet.Hosting.Tests", "WithServices", diagnosticMessages); + var startup = new StartupLoader(services).Load("Microsoft.AspNet.Hosting.Tests", "WithServices", diagnosticMessages); var app = new ApplicationBuilder(services); app.ApplicationServices = startup.ConfigureServicesDelegate(serviceCollection); @@ -47,7 +49,7 @@ namespace Microsoft.AspNet.Hosting.Tests var services = new ServiceCollection().BuildServiceProvider(); var diagnosticMesssages = new List(); - var startup = ApplicationStartup.LoadStartupMethods(services, "Microsoft.AspNet.Hosting.Tests", environment ?? "", diagnosticMesssages); + var startup = new StartupLoader(services).Load("Microsoft.AspNet.Hosting.Tests", environment ?? "", diagnosticMesssages); var app = new ApplicationBuilder(services); app.ApplicationServices = startup.ConfigureServicesDelegate(new ServiceCollection()); @@ -67,7 +69,7 @@ namespace Microsoft.AspNet.Hosting.Tests var services = serviceCollection.BuildServiceProvider(); var diagnosticMessages = new List(); - var ex = Assert.Throws(() => ApplicationStartup.LoadStartupMethods(services, "Microsoft.AspNet.Hosting.Tests", "Boom", diagnosticMessages)); + var ex = Assert.Throws(() => new StartupLoader(services).Load("Microsoft.AspNet.Hosting.Tests", "Boom", diagnosticMessages)); Assert.Equal("A method named 'ConfigureBoom' or 'Configure' in the type 'Microsoft.AspNet.Hosting.Fakes.StartupBoom' could not be found.", ex.Message); } @@ -78,7 +80,7 @@ namespace Microsoft.AspNet.Hosting.Tests var services = serviceCollection.BuildServiceProvider(); var diagnosticMessages = new List(); - var startup = ApplicationStartup.LoadStartupMethods(services, "Microsoft.AspNet.Hosting.Tests", "WithNullConfigureServices", diagnosticMessages); + var startup = new StartupLoader(services).Load("Microsoft.AspNet.Hosting.Tests", "WithNullConfigureServices", diagnosticMessages); var app = new ApplicationBuilder(services); app.ApplicationServices = startup.ConfigureServicesDelegate(new ServiceCollection()); @@ -94,7 +96,7 @@ namespace Microsoft.AspNet.Hosting.Tests var services = serviceCollection.BuildServiceProvider(); var diagnosticMessages = new List(); - var startup = ApplicationStartup.LoadStartupMethods(services, "Microsoft.AspNet.Hosting.Tests", "WithConfigureServices", diagnosticMessages); + var startup = new StartupLoader(services).Load("Microsoft.AspNet.Hosting.Tests", "WithConfigureServices", diagnosticMessages); var app = new ApplicationBuilder(services); app.ApplicationServices = startup.ConfigureServicesDelegate(serviceCollection); @@ -104,6 +106,71 @@ namespace Microsoft.AspNet.Hosting.Tests Assert.True(foo.Invoked); } + [Fact] + public void StartupLoaderCanLoadByType() + { + var serviceCollection = new ServiceCollection(); + var services = serviceCollection.BuildServiceProvider(); + + var diagnosticMessages = new List(); + var startup = new StartupLoader(services).Load(typeof(TestStartup), "", diagnosticMessages); + + var app = new ApplicationBuilder(services); + app.ApplicationServices = startup.ConfigureServicesDelegate(serviceCollection); + startup.ConfigureDelegate(app); + + var foo = app.ApplicationServices.GetRequiredService(); + Assert.Equal("Configure", foo.Message); + } + + [Fact] + public void StartupLoaderCanLoadByTypeWithEnvironment() + { + var serviceCollection = new ServiceCollection(); + var services = serviceCollection.BuildServiceProvider(); + + var diagnosticMessages = new List(); + var startup = new StartupLoader(services).Load(typeof(TestStartup), "No", diagnosticMessages); + + var app = new ApplicationBuilder(services); + app.ApplicationServices = startup.ConfigureServicesDelegate(serviceCollection); + + var ex = Assert.Throws(() => startup.ConfigureDelegate(app)); + Assert.IsAssignableFrom(typeof(InvalidOperationException), ex.InnerException); + } + + public class SimpleService + { + public SimpleService() + { + } + + public string Message { get; set; } + } + + public class TestStartup + { + public void ConfigureServices(IServiceCollection services) + { + services.AddSingleton(); + } + + public void ConfigureNoServices(IServiceCollection services) + { + } + + public void Configure(IApplicationBuilder app) + { + var service = app.ApplicationServices.GetRequiredService(); + service.Message = "Configure"; + } + + public void ConfigureNo(IApplicationBuilder app) + { + var service = app.ApplicationServices.GetRequiredService(); + } + } + public void ConfigurationMethodCalled(object instance) { _configurationMethodCalledList.Add(instance); diff --git a/test/Microsoft.AspNet.Hosting.Tests/project.json b/test/Microsoft.AspNet.Hosting.Tests/project.json index aa3d3b7bb0..6dc7086527 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/project.json +++ b/test/Microsoft.AspNet.Hosting.Tests/project.json @@ -3,6 +3,7 @@ "Microsoft.AspNet.Hosting": "1.0.0-*", "Microsoft.AspNet.Owin": "1.0.0-*", "Microsoft.Framework.OptionsModel": "1.0.0-*", + "Microsoft.Framework.Runtime.Interfaces": "1.0.0-*", "xunit.runner.aspnet": "2.0.0-aspnet-*" }, "frameworks": { diff --git a/test/Microsoft.AspNet.TestHost.Tests/Microsoft.AspNet.TestHost.Tests.xproj b/test/Microsoft.AspNet.TestHost.Tests/Microsoft.AspNet.TestHost.Tests.xproj index b70af08ea5..55caa51ccf 100644 --- a/test/Microsoft.AspNet.TestHost.Tests/Microsoft.AspNet.TestHost.Tests.xproj +++ b/test/Microsoft.AspNet.TestHost.Tests/Microsoft.AspNet.TestHost.Tests.xproj @@ -1,4 +1,4 @@ - + 14.0 @@ -13,5 +13,8 @@ 2.0 + + + - + \ No newline at end of file diff --git a/test/Microsoft.AspNet.TestHost.Tests/RequestBuilderTests.cs b/test/Microsoft.AspNet.TestHost.Tests/RequestBuilderTests.cs index 0f637c7d24..6a005fd0dc 100644 --- a/test/Microsoft.AspNet.TestHost.Tests/RequestBuilderTests.cs +++ b/test/Microsoft.AspNet.TestHost.Tests/RequestBuilderTests.cs @@ -10,7 +10,7 @@ namespace Microsoft.AspNet.TestHost [Fact] public void AddRequestHeader() { - TestServer server = TestServer.Create(app => { }); + var server = TestServer.Create(app => { }); server.CreateRequest("/") .AddHeader("Host", "MyHost:90") .And(request => @@ -22,7 +22,7 @@ namespace Microsoft.AspNet.TestHost [Fact] public void AddContentHeaders() { - TestServer server = TestServer.Create(app => { }); + var server = TestServer.Create(app => { }); server.CreateRequest("/") .AddHeader("Content-Type", "Test/Value") .And(request => diff --git a/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs b/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs index f3a3fc0bef..72f7277990 100644 --- a/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs +++ b/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs @@ -2,15 +2,21 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.Diagnostics; using System.IO; using System.Net; using System.Net.Http; +using System.Runtime.Versioning; using System.Threading.Tasks; using Microsoft.AspNet.Builder; using Microsoft.AspNet.Hosting; +using Microsoft.AspNet.Hosting.Startup; using Microsoft.AspNet.Http; +using Microsoft.Framework.ConfigurationModel; using Microsoft.Framework.DependencyInjection; using Microsoft.Framework.Logging; +using Microsoft.Framework.Runtime; +using Microsoft.Framework.Runtime.Infrastructure; using Xunit; namespace Microsoft.AspNet.TestHost @@ -32,7 +38,7 @@ namespace Microsoft.AspNet.TestHost var services = new ServiceCollection().BuildServiceProvider(); // Act & Assert - Assert.Throws(() => TestServer.Create(services, new Startup().Configuration)); + Assert.Throws(() => TestServer.Create(services, new Configuration(), new Startup().Configure, configureServices: null)); } [Fact] @@ -50,6 +56,54 @@ namespace Microsoft.AspNet.TestHost Assert.Equal("RequestServices:True", result); } + [Fact] + public async Task CanChangeApplicationName() + { + var fallbackServices = CallContextServiceLocator.Locator.ServiceProvider; + var appName = "gobblegobble"; + + var builder = TestServer.CreateBuilder(fallbackServices, new Configuration(), + app => + { + app.Run(context => + { + var appEnv = app.ApplicationServices.GetRequiredService(); + return context.Response.WriteAsync("AppName:" + appEnv.ApplicationName); + }); + }, + configureServices: null); + + builder.ApplicationName = appName; + var server = builder.Build(); + + string result = await server.CreateClient().GetStringAsync("/path"); + Assert.Equal("AppName:" + appName, result); + } + + [Fact] + public async Task CanChangeAppPath() + { + var fallbackServices = CallContextServiceLocator.Locator.ServiceProvider; + var appPath = "."; + + var builder = TestServer.CreateBuilder(fallbackServices, new Configuration(), + app => + { + app.Run(context => + { + var env = app.ApplicationServices.GetRequiredService(); + return context.Response.WriteAsync("AppPath:" + env.ApplicationBasePath); + }); + }, + configureServices: null); + + builder.ApplicationBasePath = appPath; + var server = builder.Build(); + + string result = await server.CreateClient().GetStringAsync("/path"); + Assert.Equal("AppPath:" + appPath, result); + } + [Fact] public async Task CanAccessLogger() { @@ -97,16 +151,13 @@ namespace Microsoft.AspNet.TestHost { TestServer server = TestServer.Create(app => { - var a = app.ApplicationServices.GetRequiredService(); - app.Run(context => { - var b = app.ApplicationServices.GetRequiredService(); var accessor = app.ApplicationServices.GetRequiredService(); return context.Response.WriteAsync("HasContext:" + (accessor.Accessor.HttpContext != null)); }); }, - services => services.AddSingleton().BuildServiceProvider()); + services => services.AddSingleton()); string result = await server.CreateClient().GetStringAsync("/path"); Assert.Equal("HasContext:True", result); @@ -188,19 +239,70 @@ namespace Microsoft.AspNet.TestHost Assert.Throws(() => { string result = server.CreateClient().GetStringAsync("/path").Result; }); } + [Fact] + public async Task CanCreateViaStartupType() + { + TestServer server = TestServer.Create(); + HttpResponseMessage result = await server.CreateClient().GetAsync("/"); + Assert.Equal(HttpStatusCode.OK, result.StatusCode); + Assert.Equal("FoundService:True", await result.Content.ReadAsStringAsync()); + } + + [Fact] + public async Task CanCreateViaStartupTypeAndSpecifyEnv() + { + var builder = TestServer.CreateBuilder(); + builder.Environment = "Foo"; + var server = builder.Build(); + HttpResponseMessage result = await server.CreateClient().GetAsync("/"); + Assert.Equal(HttpStatusCode.OK, result.StatusCode); + Assert.Equal("FoundFoo:False", await result.Content.ReadAsStringAsync()); + } + public class Startup { - public void Configuration(IApplicationBuilder builder) + public void Configure(IApplicationBuilder builder) { builder.Run(ctx => ctx.Response.WriteAsync("Startup")); } } - public class AnotherStartup + public class SimpleService { - public void Configuration(IApplicationBuilder builder) + public SimpleService() { - builder.Run(ctx => ctx.Response.WriteAsync("Another Startup")); + } + + public string Message { get; set; } + } + + public class TestStartup + { + public void ConfigureServices(IServiceCollection services) + { + services.AddSingleton(); + } + + public void ConfigureFooServices(IServiceCollection services) + { + } + + public void Configure(IApplicationBuilder app) + { + app.Run(context => + { + var service = app.ApplicationServices.GetRequiredService(); + return context.Response.WriteAsync("FoundService:" + (service != null)); + }); + } + + public void ConfigureFoo(IApplicationBuilder app) + { + app.Run(context => + { + var service = app.ApplicationServices.GetService(); + return context.Response.WriteAsync("FoundFoo:" + (service != null)); + }); } } } From fd9f845dc96c49c3fc838ef4c2f41fb9945b8e19 Mon Sep 17 00:00:00 2001 From: Hao Kung Date: Mon, 30 Mar 2015 20:46:23 -0700 Subject: [PATCH 242/987] Don't blast null values into UseStartup/Server --- src/Microsoft.AspNet.Hosting/Program.cs | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/Microsoft.AspNet.Hosting/Program.cs b/src/Microsoft.AspNet.Hosting/Program.cs index 555fc241a8..6c4a24ae1c 100644 --- a/src/Microsoft.AspNet.Hosting/Program.cs +++ b/src/Microsoft.AspNet.Hosting/Program.cs @@ -33,10 +33,18 @@ namespace Microsoft.AspNet.Hosting config.AddEnvironmentVariables(); config.AddCommandLine(args); - var engine = WebHost.CreateEngine(_serviceProvider, config) - .UseServer(config.Get("server")) - .UseStartup(config.Get("app")); - + var engine = WebHost.CreateEngine(_serviceProvider, config); + var server = config.Get("server"); + if (server != null) + { + engine.UseServer(server); + } + var startup = config.Get("app"); + if (startup != null) + { + engine.UseStartup(startup); + } + var serverShutdown = engine.Start(); var loggerFactory = engine.ApplicationServices.GetRequiredService(); var appShutdownService = engine.ApplicationServices.GetRequiredService(); From 04e5a558abcb454274112b9ba26eb11c8c2926e7 Mon Sep 17 00:00:00 2001 From: David Fowler Date: Wed, 1 Apr 2015 02:34:01 -0700 Subject: [PATCH 243/987] Move interfaces around - Moved IServerFactory to Microsoft.AspNet.Server.Interfaces - Moved IHttpContextAccessor to Microsoft.AspNet.Hosting.Interfaces - Fixed dependencies so that they are minimal #172 --- Hosting.sln | 15 ++++++++++++++ .../IHttpContextAccessor.cs | 1 - .../project.json | 2 -- src/Microsoft.AspNet.Hosting/HostingEngine.cs | 3 +-- src/Microsoft.AspNet.Hosting/project.json | 9 ++++++--- .../IServerFactory.cs | 0 .../Microsoft.AspNet.Server.Interfaces.xproj | 20 +++++++++++++++++++ .../project.json | 13 ++++++++++++ 8 files changed, 55 insertions(+), 8 deletions(-) rename src/{Microsoft.AspNet.Hosting => Microsoft.AspNet.Hosting.Interfaces}/IHttpContextAccessor.cs (90%) rename src/{Microsoft.AspNet.Hosting.Interfaces => Microsoft.AspNet.Server.Interfaces}/IServerFactory.cs (100%) create mode 100644 src/Microsoft.AspNet.Server.Interfaces/Microsoft.AspNet.Server.Interfaces.xproj create mode 100644 src/Microsoft.AspNet.Server.Interfaces/project.json diff --git a/Hosting.sln b/Hosting.sln index 1110900290..392ee75154 100644 --- a/Hosting.sln +++ b/Hosting.sln @@ -22,6 +22,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution EndProject Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNet.Hosting.Interfaces", "src\Microsoft.AspNet.Hosting.Interfaces\Microsoft.AspNet.Hosting.Interfaces.xproj", "{BB780FBB-7842-4759-8DE7-96FA2E5571C1}" EndProject +Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNet.Server.Interfaces", "src\Microsoft.AspNet.Server.Interfaces\Microsoft.AspNet.Server.Interfaces.xproj", "{3DCD2CB4-0E15-4BB5-9A24-091E00694DCF}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -84,6 +86,18 @@ Global {BB780FBB-7842-4759-8DE7-96FA2E5571C1}.Release|Mixed Platforms.Build.0 = Release|Any CPU {BB780FBB-7842-4759-8DE7-96FA2E5571C1}.Release|x86.ActiveCfg = Release|Any CPU {BB780FBB-7842-4759-8DE7-96FA2E5571C1}.Release|x86.Build.0 = Release|Any CPU + {3DCD2CB4-0E15-4BB5-9A24-091E00694DCF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {3DCD2CB4-0E15-4BB5-9A24-091E00694DCF}.Debug|Any CPU.Build.0 = Debug|Any CPU + {3DCD2CB4-0E15-4BB5-9A24-091E00694DCF}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU + {3DCD2CB4-0E15-4BB5-9A24-091E00694DCF}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU + {3DCD2CB4-0E15-4BB5-9A24-091E00694DCF}.Debug|x86.ActiveCfg = Debug|Any CPU + {3DCD2CB4-0E15-4BB5-9A24-091E00694DCF}.Debug|x86.Build.0 = Debug|Any CPU + {3DCD2CB4-0E15-4BB5-9A24-091E00694DCF}.Release|Any CPU.ActiveCfg = Release|Any CPU + {3DCD2CB4-0E15-4BB5-9A24-091E00694DCF}.Release|Any CPU.Build.0 = Release|Any CPU + {3DCD2CB4-0E15-4BB5-9A24-091E00694DCF}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU + {3DCD2CB4-0E15-4BB5-9A24-091E00694DCF}.Release|Mixed Platforms.Build.0 = Release|Any CPU + {3DCD2CB4-0E15-4BB5-9A24-091E00694DCF}.Release|x86.ActiveCfg = Release|Any CPU + {3DCD2CB4-0E15-4BB5-9A24-091E00694DCF}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -94,5 +108,6 @@ Global {3944F036-7E75-47E8-AA52-C4B89A64EC3A} = {E0497F39-AFFB-4819-A116-E39E361915AB} {D4F18D58-52B1-435D-A012-10F2CDF158C4} = {FEB39027-9158-4DE2-997F-7ADAEF8188D0} {BB780FBB-7842-4759-8DE7-96FA2E5571C1} = {E0497F39-AFFB-4819-A116-E39E361915AB} + {3DCD2CB4-0E15-4BB5-9A24-091E00694DCF} = {E0497F39-AFFB-4819-A116-E39E361915AB} EndGlobalSection EndGlobal diff --git a/src/Microsoft.AspNet.Hosting/IHttpContextAccessor.cs b/src/Microsoft.AspNet.Hosting.Interfaces/IHttpContextAccessor.cs similarity index 90% rename from src/Microsoft.AspNet.Hosting/IHttpContextAccessor.cs rename to src/Microsoft.AspNet.Hosting.Interfaces/IHttpContextAccessor.cs index f406c8e3b3..8b1719880b 100644 --- a/src/Microsoft.AspNet.Hosting/IHttpContextAccessor.cs +++ b/src/Microsoft.AspNet.Hosting.Interfaces/IHttpContextAccessor.cs @@ -5,7 +5,6 @@ using Microsoft.AspNet.Http; namespace Microsoft.AspNet.Hosting { - // REVIEW: move to interfaces public interface IHttpContextAccessor { HttpContext HttpContext { get; set; } diff --git a/src/Microsoft.AspNet.Hosting.Interfaces/project.json b/src/Microsoft.AspNet.Hosting.Interfaces/project.json index e21eb01c51..1bd0d4e29b 100644 --- a/src/Microsoft.AspNet.Hosting.Interfaces/project.json +++ b/src/Microsoft.AspNet.Hosting.Interfaces/project.json @@ -2,9 +2,7 @@ "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-*", "Microsoft.Framework.NotNullAttribute.Internal": { "type": "build", "version": "1.0.0-*" } }, "frameworks": { diff --git a/src/Microsoft.AspNet.Hosting/HostingEngine.cs b/src/Microsoft.AspNet.Hosting/HostingEngine.cs index 69ca5e6883..0f6826737c 100644 --- a/src/Microsoft.AspNet.Hosting/HostingEngine.cs +++ b/src/Microsoft.AspNet.Hosting/HostingEngine.cs @@ -24,8 +24,7 @@ namespace Microsoft.AspNet.Hosting // Start/ApplicationServices block use methods private bool _useDisabled; - - private IServerLoader _serverLoader; + private IApplicationBuilderFactory _builderFactory; private IApplicationBuilder _builder; private IServiceProvider _applicationServices; diff --git a/src/Microsoft.AspNet.Hosting/project.json b/src/Microsoft.AspNet.Hosting/project.json index 4763927417..f4f5871964 100644 --- a/src/Microsoft.AspNet.Hosting/project.json +++ b/src/Microsoft.AspNet.Hosting/project.json @@ -1,14 +1,17 @@ { "version": "1.0.0-*", "description": "ASP.NET 5 core hosting infrastructure and startup logic for web applications.", + "compilationOptions": { "warningsAsErrors": "true" }, "dependencies": { - "Microsoft.AspNet.Hosting.Interfaces": "1.0.0-*", - "Microsoft.Framework.Runtime.Interfaces": "1.0.0-*", "Microsoft.AspNet.FileProviders": "1.0.0-*", + "Microsoft.AspNet.Server.Interfaces": "1.0.0-*", + "Microsoft.AspNet.Hosting.Interfaces": "1.0.0-*", "Microsoft.AspNet.Http.Core": "1.0.0-*", "Microsoft.AspNet.Http.Extensions": "1.0.0-*", - "Microsoft.Framework.Logging": "1.0.0-*", + "Microsoft.Framework.ConfigurationModel": "1.0.0-*", "Microsoft.Framework.DependencyInjection": "1.0.0-*", + "Microsoft.Framework.Logging": "1.0.0-*", + "Microsoft.Framework.Runtime.Interfaces": "1.0.0-*", "Newtonsoft.Json": "6.0.6" }, "frameworks": { diff --git a/src/Microsoft.AspNet.Hosting.Interfaces/IServerFactory.cs b/src/Microsoft.AspNet.Server.Interfaces/IServerFactory.cs similarity index 100% rename from src/Microsoft.AspNet.Hosting.Interfaces/IServerFactory.cs rename to src/Microsoft.AspNet.Server.Interfaces/IServerFactory.cs diff --git a/src/Microsoft.AspNet.Server.Interfaces/Microsoft.AspNet.Server.Interfaces.xproj b/src/Microsoft.AspNet.Server.Interfaces/Microsoft.AspNet.Server.Interfaces.xproj new file mode 100644 index 0000000000..8561614f22 --- /dev/null +++ b/src/Microsoft.AspNet.Server.Interfaces/Microsoft.AspNet.Server.Interfaces.xproj @@ -0,0 +1,20 @@ + + + + 14.0 + $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) + + + + + 3dcd2cb4-0e15-4bb5-9a24-091e00694dcf + Microsoft.AspNet.Server.Interfaces + ..\..\artifacts\obj\$(MSBuildProjectName) + ..\..\artifacts\bin\$(MSBuildProjectName)\ + + + + 2.0 + + + diff --git a/src/Microsoft.AspNet.Server.Interfaces/project.json b/src/Microsoft.AspNet.Server.Interfaces/project.json new file mode 100644 index 0000000000..90fc3f0f67 --- /dev/null +++ b/src/Microsoft.AspNet.Server.Interfaces/project.json @@ -0,0 +1,13 @@ +{ + "version": "1.0.0-*", + "dependencies": { + "Microsoft.AspNet.Http": "1.0.0-*", + "Microsoft.Framework.ConfigurationModel.Interfaces": "1.0.0-*", + "Microsoft.AspNet.FeatureModel": "1.0.0-*" + }, + + "frameworks": { + "dnx451": { }, + "dnxcore50": { } + } +} From 4b8f02d7af32a1366aa9e65edd4f46f6eee19d73 Mon Sep 17 00:00:00 2001 From: David Fowler Date: Wed, 1 Apr 2015 03:24:20 -0700 Subject: [PATCH 244/987] Sort dependencies --- src/Microsoft.AspNet.Server.Interfaces/project.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Interfaces/project.json b/src/Microsoft.AspNet.Server.Interfaces/project.json index 90fc3f0f67..88b8b45a6a 100644 --- a/src/Microsoft.AspNet.Server.Interfaces/project.json +++ b/src/Microsoft.AspNet.Server.Interfaces/project.json @@ -1,9 +1,9 @@ { "version": "1.0.0-*", "dependencies": { + "Microsoft.AspNet.FeatureModel": "1.0.0-*", "Microsoft.AspNet.Http": "1.0.0-*", - "Microsoft.Framework.ConfigurationModel.Interfaces": "1.0.0-*", - "Microsoft.AspNet.FeatureModel": "1.0.0-*" + "Microsoft.Framework.ConfigurationModel.Interfaces": "1.0.0-*" }, "frameworks": { From 8639f3edbca5159bb10aa97740f1420bad220d93 Mon Sep 17 00:00:00 2001 From: David Fowler Date: Wed, 1 Apr 2015 03:45:02 -0700 Subject: [PATCH 245/987] Renamed M.A.Server.Interfaces -> M.A.Hosting.Server.Interfaces --- Hosting.sln | 28 +++++++++---------- .../IServerFactory.cs | 0 ...ft.AspNet.Hosting.Server.Interfaces.xproj} | 14 +++++----- .../project.json | 0 src/Microsoft.AspNet.Hosting/project.json | 2 +- 5 files changed, 22 insertions(+), 22 deletions(-) rename src/{Microsoft.AspNet.Server.Interfaces => Microsoft.AspNet.Hosting.Server.Interfaces}/IServerFactory.cs (100%) rename src/{Microsoft.AspNet.Server.Interfaces/Microsoft.AspNet.Server.Interfaces.xproj => Microsoft.AspNet.Hosting.Server.Interfaces/Microsoft.AspNet.Hosting.Server.Interfaces.xproj} (56%) rename src/{Microsoft.AspNet.Server.Interfaces => Microsoft.AspNet.Hosting.Server.Interfaces}/project.json (100%) diff --git a/Hosting.sln b/Hosting.sln index 392ee75154..fd29a14db9 100644 --- a/Hosting.sln +++ b/Hosting.sln @@ -22,7 +22,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution EndProject Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNet.Hosting.Interfaces", "src\Microsoft.AspNet.Hosting.Interfaces\Microsoft.AspNet.Hosting.Interfaces.xproj", "{BB780FBB-7842-4759-8DE7-96FA2E5571C1}" EndProject -Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNet.Server.Interfaces", "src\Microsoft.AspNet.Server.Interfaces\Microsoft.AspNet.Server.Interfaces.xproj", "{3DCD2CB4-0E15-4BB5-9A24-091E00694DCF}" +Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNet.Hosting.Server.Interfaces", "src\Microsoft.AspNet.Hosting.Server.Interfaces\Microsoft.AspNet.Hosting.Server.Interfaces.xproj", "{FDBBA081-5248-4FC0-9E08-B46BEF3FA438}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -86,18 +86,18 @@ Global {BB780FBB-7842-4759-8DE7-96FA2E5571C1}.Release|Mixed Platforms.Build.0 = Release|Any CPU {BB780FBB-7842-4759-8DE7-96FA2E5571C1}.Release|x86.ActiveCfg = Release|Any CPU {BB780FBB-7842-4759-8DE7-96FA2E5571C1}.Release|x86.Build.0 = Release|Any CPU - {3DCD2CB4-0E15-4BB5-9A24-091E00694DCF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {3DCD2CB4-0E15-4BB5-9A24-091E00694DCF}.Debug|Any CPU.Build.0 = Debug|Any CPU - {3DCD2CB4-0E15-4BB5-9A24-091E00694DCF}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU - {3DCD2CB4-0E15-4BB5-9A24-091E00694DCF}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU - {3DCD2CB4-0E15-4BB5-9A24-091E00694DCF}.Debug|x86.ActiveCfg = Debug|Any CPU - {3DCD2CB4-0E15-4BB5-9A24-091E00694DCF}.Debug|x86.Build.0 = Debug|Any CPU - {3DCD2CB4-0E15-4BB5-9A24-091E00694DCF}.Release|Any CPU.ActiveCfg = Release|Any CPU - {3DCD2CB4-0E15-4BB5-9A24-091E00694DCF}.Release|Any CPU.Build.0 = Release|Any CPU - {3DCD2CB4-0E15-4BB5-9A24-091E00694DCF}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU - {3DCD2CB4-0E15-4BB5-9A24-091E00694DCF}.Release|Mixed Platforms.Build.0 = Release|Any CPU - {3DCD2CB4-0E15-4BB5-9A24-091E00694DCF}.Release|x86.ActiveCfg = Release|Any CPU - {3DCD2CB4-0E15-4BB5-9A24-091E00694DCF}.Release|x86.Build.0 = Release|Any CPU + {FDBBA081-5248-4FC0-9E08-B46BEF3FA438}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {FDBBA081-5248-4FC0-9E08-B46BEF3FA438}.Debug|Any CPU.Build.0 = Debug|Any CPU + {FDBBA081-5248-4FC0-9E08-B46BEF3FA438}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU + {FDBBA081-5248-4FC0-9E08-B46BEF3FA438}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU + {FDBBA081-5248-4FC0-9E08-B46BEF3FA438}.Debug|x86.ActiveCfg = Debug|Any CPU + {FDBBA081-5248-4FC0-9E08-B46BEF3FA438}.Debug|x86.Build.0 = Debug|Any CPU + {FDBBA081-5248-4FC0-9E08-B46BEF3FA438}.Release|Any CPU.ActiveCfg = Release|Any CPU + {FDBBA081-5248-4FC0-9E08-B46BEF3FA438}.Release|Any CPU.Build.0 = Release|Any CPU + {FDBBA081-5248-4FC0-9E08-B46BEF3FA438}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU + {FDBBA081-5248-4FC0-9E08-B46BEF3FA438}.Release|Mixed Platforms.Build.0 = Release|Any CPU + {FDBBA081-5248-4FC0-9E08-B46BEF3FA438}.Release|x86.ActiveCfg = Release|Any CPU + {FDBBA081-5248-4FC0-9E08-B46BEF3FA438}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -108,6 +108,6 @@ Global {3944F036-7E75-47E8-AA52-C4B89A64EC3A} = {E0497F39-AFFB-4819-A116-E39E361915AB} {D4F18D58-52B1-435D-A012-10F2CDF158C4} = {FEB39027-9158-4DE2-997F-7ADAEF8188D0} {BB780FBB-7842-4759-8DE7-96FA2E5571C1} = {E0497F39-AFFB-4819-A116-E39E361915AB} - {3DCD2CB4-0E15-4BB5-9A24-091E00694DCF} = {E0497F39-AFFB-4819-A116-E39E361915AB} + {FDBBA081-5248-4FC0-9E08-B46BEF3FA438} = {E0497F39-AFFB-4819-A116-E39E361915AB} EndGlobalSection EndGlobal diff --git a/src/Microsoft.AspNet.Server.Interfaces/IServerFactory.cs b/src/Microsoft.AspNet.Hosting.Server.Interfaces/IServerFactory.cs similarity index 100% rename from src/Microsoft.AspNet.Server.Interfaces/IServerFactory.cs rename to src/Microsoft.AspNet.Hosting.Server.Interfaces/IServerFactory.cs diff --git a/src/Microsoft.AspNet.Server.Interfaces/Microsoft.AspNet.Server.Interfaces.xproj b/src/Microsoft.AspNet.Hosting.Server.Interfaces/Microsoft.AspNet.Hosting.Server.Interfaces.xproj similarity index 56% rename from src/Microsoft.AspNet.Server.Interfaces/Microsoft.AspNet.Server.Interfaces.xproj rename to src/Microsoft.AspNet.Hosting.Server.Interfaces/Microsoft.AspNet.Hosting.Server.Interfaces.xproj index 8561614f22..17228558fd 100644 --- a/src/Microsoft.AspNet.Server.Interfaces/Microsoft.AspNet.Server.Interfaces.xproj +++ b/src/Microsoft.AspNet.Hosting.Server.Interfaces/Microsoft.AspNet.Hosting.Server.Interfaces.xproj @@ -1,20 +1,20 @@  - + 14.0 $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) - - 3dcd2cb4-0e15-4bb5-9a24-091e00694dcf - Microsoft.AspNet.Server.Interfaces - ..\..\artifacts\obj\$(MSBuildProjectName) - ..\..\artifacts\bin\$(MSBuildProjectName)\ + fdbba081-5248-4fc0-9e08-b46bef3fa438 + + + + 2.0 - + \ No newline at end of file diff --git a/src/Microsoft.AspNet.Server.Interfaces/project.json b/src/Microsoft.AspNet.Hosting.Server.Interfaces/project.json similarity index 100% rename from src/Microsoft.AspNet.Server.Interfaces/project.json rename to src/Microsoft.AspNet.Hosting.Server.Interfaces/project.json diff --git a/src/Microsoft.AspNet.Hosting/project.json b/src/Microsoft.AspNet.Hosting/project.json index f4f5871964..09c50d4135 100644 --- a/src/Microsoft.AspNet.Hosting/project.json +++ b/src/Microsoft.AspNet.Hosting/project.json @@ -4,8 +4,8 @@ "compilationOptions": { "warningsAsErrors": "true" }, "dependencies": { "Microsoft.AspNet.FileProviders": "1.0.0-*", - "Microsoft.AspNet.Server.Interfaces": "1.0.0-*", "Microsoft.AspNet.Hosting.Interfaces": "1.0.0-*", + "Microsoft.AspNet.Hosting.Server.Interfaces": "1.0.0-*", "Microsoft.AspNet.Http.Core": "1.0.0-*", "Microsoft.AspNet.Http.Extensions": "1.0.0-*", "Microsoft.Framework.ConfigurationModel": "1.0.0-*", From 13d3d5042ef340dea5ccc88fc7490becb0b27aeb Mon Sep 17 00:00:00 2001 From: "N. Taylor Mullen" Date: Wed, 1 Apr 2015 15:44:53 -0700 Subject: [PATCH 246/987] Add travis and appveyor CI support. --- .travis.yml | 3 +++ appveyor.yml | 5 +++++ 2 files changed, 8 insertions(+) create mode 100644 .travis.yml create mode 100644 appveyor.yml diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000000..0f4cb93e59 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,3 @@ +language: csharp +script: + - ./build.sh verify \ No newline at end of file diff --git a/appveyor.yml b/appveyor.yml new file mode 100644 index 0000000000..88cb9ef145 --- /dev/null +++ b/appveyor.yml @@ -0,0 +1,5 @@ +build_script: + - build.cmd verify +clone_depth: 1 +test: off +deploy: off \ No newline at end of file From 9fffd3ebeb39910b9986ef6d68ed0e1731cb7e46 Mon Sep 17 00:00:00 2001 From: "N. Taylor Mullen" Date: Wed, 1 Apr 2015 16:28:58 -0700 Subject: [PATCH 247/987] Turn off sudo for .travis.yml. --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 0f4cb93e59..5939a529e5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,3 +1,4 @@ language: csharp +sudo: false script: - ./build.sh verify \ No newline at end of file From 7a41c727115694c493368a6e0df320153ccc9d48 Mon Sep 17 00:00:00 2001 From: Pranav K Date: Wed, 1 Apr 2015 18:43:56 -0700 Subject: [PATCH 248/987] Adding status badges --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index 8bf71cfc4d..057175f9dd 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,8 @@ Hosting ======= +AppVeyor: [![AppVeyor](https://ci.appveyor.com/api/projects/status/99mq30o3hcs9p39n/branch/dev?svg=true)](https://ci.appveyor.com/project/aspnetci/Hosting/branch/dev) + +Travis: [![Travis](https://travis-ci.org/aspnet/Hosting.svg?branch=dev)](https://travis-ci.org/aspnet/Hosting) The Hosting repo contains code required to host an ASP.NET 5 application, it is the entry point used when self-hosting an application. From 2b07b1a5fa4895d485720dfbadbeadcdfe212b5f Mon Sep 17 00:00:00 2001 From: David Fowler Date: Wed, 1 Apr 2015 21:59:14 -0700 Subject: [PATCH 249/987] Added test that injects IHostingEnvironment #221 --- .../Fakes/StartupWithHostingEnvironment.cs | 18 ++++++++++++++++++ .../HostingEngineTests.cs | 15 +++++++++++++++ 2 files changed, 33 insertions(+) create mode 100644 test/Microsoft.AspNet.Hosting.Tests/Fakes/StartupWithHostingEnvironment.cs diff --git a/test/Microsoft.AspNet.Hosting.Tests/Fakes/StartupWithHostingEnvironment.cs b/test/Microsoft.AspNet.Hosting.Tests/Fakes/StartupWithHostingEnvironment.cs new file mode 100644 index 0000000000..9ddda3881c --- /dev/null +++ b/test/Microsoft.AspNet.Hosting.Tests/Fakes/StartupWithHostingEnvironment.cs @@ -0,0 +1,18 @@ +using System; +using Microsoft.AspNet.Builder; + +namespace Microsoft.AspNet.Hosting.Tests.Fakes +{ + public class StartupWithHostingEnvironment + { + public StartupWithHostingEnvironment(IHostingEnvironment env) + { + env.EnvironmentName = "Changed"; + } + + public void Configure(IApplicationBuilder app, IHostingEnvironment env) + { + + } + } +} \ No newline at end of file diff --git a/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs b/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs index 6e2547f0ed..da2cb518e5 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs @@ -43,6 +43,21 @@ namespace Microsoft.AspNet.Hosting Assert.Equal(1, _startInstances[0].DisposeCalls); } + [Fact] + public void HostingEngineInjectsHostingEnvironment() + { + var engine = WebHost.CreateEngine() + .UseServer(this) + .UseStartup("Microsoft.AspNet.Hosting.Tests") + .UseEnvironment("WithHostingEnvironment"); + + using (var server = engine.Start()) + { + var env = engine.ApplicationServices.GetRequiredService(); + Assert.Equal("Changed", env.EnvironmentName); + } + } + [Fact] public void CanReplaceHostingFactory() { From e75f40bd24d5e3d52647918b651851f22a50ab4b Mon Sep 17 00:00:00 2001 From: David Fowler Date: Thu, 2 Apr 2015 00:12:41 -0700 Subject: [PATCH 250/987] Fix paths in map path test --- .../HostingEngineTests.cs | 15 ++++++++++++++- test/Microsoft.AspNet.Hosting.Tests/project.json | 1 + 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs b/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs index da2cb518e5..01de9f14ed 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs @@ -9,6 +9,7 @@ using Microsoft.AspNet.Builder; using Microsoft.AspNet.FeatureModel; using Microsoft.AspNet.Hosting.Server; using Microsoft.AspNet.Hosting.Startup; +using Microsoft.AspNet.Testing.xunit; using Microsoft.Framework.ConfigurationModel; using Microsoft.Framework.DependencyInjection; using Microsoft.Framework.OptionsModel; @@ -136,8 +137,20 @@ namespace Microsoft.AspNet.Hosting [InlineData(@"\", @"\")] [InlineData("sub", "sub")] [InlineData("sub/sub2/sub3", @"sub/sub2/sub3")] - [InlineData(@"sub/sub2\sub3\", @"sub/sub2/sub3/")] public void MapPath_Facts(string virtualPath, string expectedSuffix) + { + RunMapPath(virtualPath, expectedSuffix); + } + + [ConditionalTheory] + [OSSkipCondition(OperatingSystems.Unix | OperatingSystems.MacOSX)] + [InlineData(@"sub/sub2\sub3\", @"sub/sub2/sub3/")] + public void MapPath_Windows_Facts(string virtualPath, string expectedSuffix) + { + RunMapPath(virtualPath, expectedSuffix); + } + + private void RunMapPath(string virtualPath, string expectedSuffix) { var engine = WebHost.CreateEngine().UseServer(this); diff --git a/test/Microsoft.AspNet.Hosting.Tests/project.json b/test/Microsoft.AspNet.Hosting.Tests/project.json index 6dc7086527..0d307555cb 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/project.json +++ b/test/Microsoft.AspNet.Hosting.Tests/project.json @@ -2,6 +2,7 @@ "dependencies": { "Microsoft.AspNet.Hosting": "1.0.0-*", "Microsoft.AspNet.Owin": "1.0.0-*", + "Microsoft.AspNet.Testing": "1.0.0-*", "Microsoft.Framework.OptionsModel": "1.0.0-*", "Microsoft.Framework.Runtime.Interfaces": "1.0.0-*", "xunit.runner.aspnet": "2.0.0-aspnet-*" From ef49606ea644b9db5b638d7c2fe8483706d45f26 Mon Sep 17 00:00:00 2001 From: Troy Dai Date: Thu, 2 Apr 2015 09:20:11 -0700 Subject: [PATCH 251/987] Update global.json, sources=>projects --- global.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/global.json b/global.json index 840c36f6ad..983ba0401e 100644 --- a/global.json +++ b/global.json @@ -1,3 +1,3 @@ { - "sources": ["src"] -} \ No newline at end of file + "projects": ["src"] +} From 8be4a1a0af015c5b33229df66bdded90df682a09 Mon Sep 17 00:00:00 2001 From: Doug Bunting Date: Thu, 2 Apr 2015 13:49:26 -0700 Subject: [PATCH 252/987] Update .xproj files for Microsoft.Web.AspNet.* -> Microsoft.DNX.* rename --- .../Microsoft.AspNet.Hosting.Interfaces.xproj | 7 ++----- .../Microsoft.AspNet.Hosting.xproj | 8 ++++---- .../Microsoft.AspNet.TestHost.xproj | 8 ++++---- .../Microsoft.AspNet.Hosting.Tests.xproj | 4 ++-- .../Microsoft.AspNet.TestHost.Tests.xproj | 8 ++++---- 5 files changed, 16 insertions(+), 19 deletions(-) diff --git a/src/Microsoft.AspNet.Hosting.Interfaces/Microsoft.AspNet.Hosting.Interfaces.xproj b/src/Microsoft.AspNet.Hosting.Interfaces/Microsoft.AspNet.Hosting.Interfaces.xproj index b50140bec2..d7e8b6e399 100644 --- a/src/Microsoft.AspNet.Hosting.Interfaces/Microsoft.AspNet.Hosting.Interfaces.xproj +++ b/src/Microsoft.AspNet.Hosting.Interfaces/Microsoft.AspNet.Hosting.Interfaces.xproj @@ -4,17 +4,14 @@ 14.0 $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) - - + bb780fbb-7842-4759-8de7-96fa2e5571c1 - Microsoft.AspNet.Hosting.Interfaces ..\..\artifacts\obj\$(MSBuildProjectName) ..\..\artifacts\bin\$(MSBuildProjectName)\ - 2.0 - + \ No newline at end of file diff --git a/src/Microsoft.AspNet.Hosting/Microsoft.AspNet.Hosting.xproj b/src/Microsoft.AspNet.Hosting/Microsoft.AspNet.Hosting.xproj index e98519ce8c..9c87bfc28c 100644 --- a/src/Microsoft.AspNet.Hosting/Microsoft.AspNet.Hosting.xproj +++ b/src/Microsoft.AspNet.Hosting/Microsoft.AspNet.Hosting.xproj @@ -1,10 +1,10 @@ - + 14.0 $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) - + 3944f036-7e75-47e8-aa52-c4b89a64ec3a ..\..\artifacts\obj\$(MSBuildProjectName) @@ -13,5 +13,5 @@ 2.0 - - + + \ No newline at end of file diff --git a/src/Microsoft.AspNet.TestHost/Microsoft.AspNet.TestHost.xproj b/src/Microsoft.AspNet.TestHost/Microsoft.AspNet.TestHost.xproj index 67078fd3b5..947a955cd1 100644 --- a/src/Microsoft.AspNet.TestHost/Microsoft.AspNet.TestHost.xproj +++ b/src/Microsoft.AspNet.TestHost/Microsoft.AspNet.TestHost.xproj @@ -1,10 +1,10 @@ - + 14.0 $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) - + 1a415a3f-1081-45db-809b-ee19cea02dc0 ..\..\artifacts\obj\$(MSBuildProjectName) @@ -13,5 +13,5 @@ 2.0 - - + + \ No newline at end of file diff --git a/test/Microsoft.AspNet.Hosting.Tests/Microsoft.AspNet.Hosting.Tests.xproj b/test/Microsoft.AspNet.Hosting.Tests/Microsoft.AspNet.Hosting.Tests.xproj index 8f9318a85a..e9c9c0dcac 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/Microsoft.AspNet.Hosting.Tests.xproj +++ b/test/Microsoft.AspNet.Hosting.Tests/Microsoft.AspNet.Hosting.Tests.xproj @@ -4,7 +4,7 @@ 14.0 $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) - + d4f18d58-52b1-435d-a012-10f2cdf158c4 ..\..\artifacts\obj\$(MSBuildProjectName) @@ -14,5 +14,5 @@ 2.0 18007 - + \ No newline at end of file diff --git a/test/Microsoft.AspNet.TestHost.Tests/Microsoft.AspNet.TestHost.Tests.xproj b/test/Microsoft.AspNet.TestHost.Tests/Microsoft.AspNet.TestHost.Tests.xproj index b70af08ea5..781dbf794a 100644 --- a/test/Microsoft.AspNet.TestHost.Tests/Microsoft.AspNet.TestHost.Tests.xproj +++ b/test/Microsoft.AspNet.TestHost.Tests/Microsoft.AspNet.TestHost.Tests.xproj @@ -1,10 +1,10 @@ - + 14.0 $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) - + 0acb2719-9484-49b5-b8e3-117091192511 ..\..\artifacts\obj\$(MSBuildProjectName) @@ -13,5 +13,5 @@ 2.0 - - + + \ No newline at end of file From ee511e4181c96271df179691963f610b93352cac Mon Sep 17 00:00:00 2001 From: Doug Bunting Date: Fri, 3 Apr 2015 12:29:47 -0700 Subject: [PATCH 253/987] Update .xproj files for Microsoft.Web.AspNet.* -> Microsoft.DNX.* rename - one new file --- ...Microsoft.AspNet.Hosting.Server.Interfaces.xproj | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/Microsoft.AspNet.Hosting.Server.Interfaces/Microsoft.AspNet.Hosting.Server.Interfaces.xproj b/src/Microsoft.AspNet.Hosting.Server.Interfaces/Microsoft.AspNet.Hosting.Server.Interfaces.xproj index 17228558fd..815bc0ce57 100644 --- a/src/Microsoft.AspNet.Hosting.Server.Interfaces/Microsoft.AspNet.Hosting.Server.Interfaces.xproj +++ b/src/Microsoft.AspNet.Hosting.Server.Interfaces/Microsoft.AspNet.Hosting.Server.Interfaces.xproj @@ -1,20 +1,17 @@  - + 14.0 $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) - + fdbba081-5248-4fc0-9e08-b46bef3fa438 - - - - - + ..\..\artifacts\obj\$(MSBuildProjectName) + ..\..\artifacts\bin\$(MSBuildProjectName)\ 2.0 - + \ No newline at end of file From f0fcaa91fe8a8fcded5bc07a52d87ef3d7476427 Mon Sep 17 00:00:00 2001 From: Wei Wang Date: Fri, 3 Apr 2015 17:11:10 -0700 Subject: [PATCH 254/987] Fix AppVeyor git line ending config --- appveyor.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/appveyor.yml b/appveyor.yml index 88cb9ef145..3fab83e134 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,3 +1,5 @@ +init: + - git config --global core.autocrlf true build_script: - build.cmd verify clone_depth: 1 From 40490593ce68dc2e078c020710d54588e89f3425 Mon Sep 17 00:00:00 2001 From: "N. Taylor Mullen" Date: Tue, 7 Apr 2015 14:45:23 -0700 Subject: [PATCH 255/987] Add serviceable attribute to projects. aspnet/DNX#1600 --- .../Properties/AssemblyInfo.cs | 6 ++++++ src/Microsoft.AspNet.Hosting/Properties/AssemblyInfo.cs | 6 ++++++ src/Microsoft.AspNet.TestHost/Properties/AssemblyInfo.cs | 3 ++- 3 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 src/Microsoft.AspNet.Hosting.Interfaces/Properties/AssemblyInfo.cs create mode 100644 src/Microsoft.AspNet.Hosting/Properties/AssemblyInfo.cs diff --git a/src/Microsoft.AspNet.Hosting.Interfaces/Properties/AssemblyInfo.cs b/src/Microsoft.AspNet.Hosting.Interfaces/Properties/AssemblyInfo.cs new file mode 100644 index 0000000000..f5c6f4a83a --- /dev/null +++ b/src/Microsoft.AspNet.Hosting.Interfaces/Properties/AssemblyInfo.cs @@ -0,0 +1,6 @@ +// 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 System.Reflection; + +[assembly: AssemblyMetadata("Serviceable", "True")] \ No newline at end of file diff --git a/src/Microsoft.AspNet.Hosting/Properties/AssemblyInfo.cs b/src/Microsoft.AspNet.Hosting/Properties/AssemblyInfo.cs new file mode 100644 index 0000000000..f5c6f4a83a --- /dev/null +++ b/src/Microsoft.AspNet.Hosting/Properties/AssemblyInfo.cs @@ -0,0 +1,6 @@ +// 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 System.Reflection; + +[assembly: AssemblyMetadata("Serviceable", "True")] \ No newline at end of file diff --git a/src/Microsoft.AspNet.TestHost/Properties/AssemblyInfo.cs b/src/Microsoft.AspNet.TestHost/Properties/AssemblyInfo.cs index 5eb8f1ffac..23c410c805 100644 --- a/src/Microsoft.AspNet.TestHost/Properties/AssemblyInfo.cs +++ b/src/Microsoft.AspNet.TestHost/Properties/AssemblyInfo.cs @@ -35,4 +35,5 @@ using System.Runtime.InteropServices; // The following GUID is for the ID of the typelib if this project is exposed to COM [assembly: Guid("12A3EDBB-65B6-4D47-98FC-2B80CEC71E51")] -[assembly: InternalsVisibleTo("Microsoft.AspNet.TestHost.Tests")] \ No newline at end of file +[assembly: InternalsVisibleTo("Microsoft.AspNet.TestHost.Tests")] +[assembly: AssemblyMetadata("Serviceable", "True")] From 992f4bab5d4cb22caed2b42cfd575ceabba838ee Mon Sep 17 00:00:00 2001 From: "N. Taylor Mullen" Date: Tue, 7 Apr 2015 16:15:15 -0700 Subject: [PATCH 256/987] Update .travis.yml and appveyor.yml to build quietly. --- .travis.yml | 2 +- appveyor.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 5939a529e5..947bf868ee 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,4 +1,4 @@ language: csharp sudo: false script: - - ./build.sh verify \ No newline at end of file + - ./build.sh --quiet verify \ No newline at end of file diff --git a/appveyor.yml b/appveyor.yml index 3fab83e134..636a7618d3 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,7 +1,7 @@ init: - git config --global core.autocrlf true build_script: - - build.cmd verify + - build.cmd --quiet verify clone_depth: 1 test: off deploy: off \ No newline at end of file From f337f8cd04459e541431df04d859b705f3d2f6f7 Mon Sep 17 00:00:00 2001 From: Hao Kung Date: Wed, 8 Apr 2015 14:27:38 -0700 Subject: [PATCH 257/987] Add TestServer.CreateBuilder overload --- src/Microsoft.AspNet.TestHost/TestServer.cs | 10 ++++++++-- .../Microsoft.AspNet.TestHost.Tests/TestClientTests.cs | 4 ---- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/Microsoft.AspNet.TestHost/TestServer.cs b/src/Microsoft.AspNet.TestHost/TestServer.cs index 0e3a9927b5..f290092609 100644 --- a/src/Microsoft.AspNet.TestHost/TestServer.cs +++ b/src/Microsoft.AspNet.TestHost/TestServer.cs @@ -105,16 +105,22 @@ namespace Microsoft.AspNet.TestHost }); } - public static TestServerBuilder CreateBuilder(IServiceProvider fallbackServices, IConfiguration config, Action configureApp, ConfigureServicesDelegate configureServices) + public static TestServerBuilder CreateBuilder(IServiceProvider fallbackServices, IConfiguration config) { return new TestServerBuilder { FallbackServices = fallbackServices, - Startup = new StartupMethods(configureApp, configureServices), Config = config }; } + public static TestServerBuilder CreateBuilder(IServiceProvider fallbackServices, IConfiguration config, Action configureApp, ConfigureServicesDelegate configureServices) + { + var builder = CreateBuilder(fallbackServices, config); + builder.Startup = new StartupMethods(configureApp, configureServices); + return builder; + } + public HttpMessageHandler CreateHandler() { var pathBase = BaseAddress == null ? PathString.Empty : PathString.FromUriComponent(BaseAddress); diff --git a/test/Microsoft.AspNet.TestHost.Tests/TestClientTests.cs b/test/Microsoft.AspNet.TestHost.Tests/TestClientTests.cs index 19b54c06f5..c710d01da1 100644 --- a/test/Microsoft.AspNet.TestHost.Tests/TestClientTests.cs +++ b/test/Microsoft.AspNet.TestHost.Tests/TestClientTests.cs @@ -1,21 +1,17 @@ // 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 System; using System.IO; using System.Net.Http; using System.Threading.Tasks; using Microsoft.AspNet.Builder; -using Microsoft.AspNet.Hosting; using Microsoft.AspNet.Http; -using Microsoft.Framework.DependencyInjection; using Xunit; namespace Microsoft.AspNet.TestHost { public class TestClientTests { - private readonly IServiceProvider _services; private readonly TestServer _server; public TestClientTests() From 7fb8053700a467e0f3551fd26c55359f9ba1646b Mon Sep 17 00:00:00 2001 From: Chris Ross Date: Fri, 10 Apr 2015 10:03:04 -0700 Subject: [PATCH 258/987] Move IServerInformation to Server.Interfaces. --- .../IServerFactory.cs | 1 - .../IServerInformation.cs | 10 ++++++++++ .../project.json | 1 - 3 files changed, 10 insertions(+), 2 deletions(-) create mode 100644 src/Microsoft.AspNet.Hosting.Server.Interfaces/IServerInformation.cs diff --git a/src/Microsoft.AspNet.Hosting.Server.Interfaces/IServerFactory.cs b/src/Microsoft.AspNet.Hosting.Server.Interfaces/IServerFactory.cs index f389a1ec4c..fe46b8fc69 100644 --- a/src/Microsoft.AspNet.Hosting.Server.Interfaces/IServerFactory.cs +++ b/src/Microsoft.AspNet.Hosting.Server.Interfaces/IServerFactory.cs @@ -3,7 +3,6 @@ using System; using System.Threading.Tasks; -using Microsoft.AspNet.Builder; using Microsoft.AspNet.FeatureModel; using Microsoft.Framework.ConfigurationModel; diff --git a/src/Microsoft.AspNet.Hosting.Server.Interfaces/IServerInformation.cs b/src/Microsoft.AspNet.Hosting.Server.Interfaces/IServerInformation.cs new file mode 100644 index 0000000000..c30e0d00e3 --- /dev/null +++ b/src/Microsoft.AspNet.Hosting.Server.Interfaces/IServerInformation.cs @@ -0,0 +1,10 @@ +// 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. + +namespace Microsoft.AspNet.Hosting.Server +{ + public interface IServerInformation + { + string Name { get; } + } +} diff --git a/src/Microsoft.AspNet.Hosting.Server.Interfaces/project.json b/src/Microsoft.AspNet.Hosting.Server.Interfaces/project.json index 88b8b45a6a..fd590e5417 100644 --- a/src/Microsoft.AspNet.Hosting.Server.Interfaces/project.json +++ b/src/Microsoft.AspNet.Hosting.Server.Interfaces/project.json @@ -2,7 +2,6 @@ "version": "1.0.0-*", "dependencies": { "Microsoft.AspNet.FeatureModel": "1.0.0-*", - "Microsoft.AspNet.Http": "1.0.0-*", "Microsoft.Framework.ConfigurationModel.Interfaces": "1.0.0-*" }, From 98e70636fe67a37c17b3cb12b94065fd3de7ef80 Mon Sep 17 00:00:00 2001 From: Praburaj Date: Wed, 15 Apr 2015 11:10:18 -0700 Subject: [PATCH 259/987] Adding a description for hosting interfaces package. Fixes: https://github.com/aspnet/Hosting/issues/193 --- src/Microsoft.AspNet.Hosting.Interfaces/project.json | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Microsoft.AspNet.Hosting.Interfaces/project.json b/src/Microsoft.AspNet.Hosting.Interfaces/project.json index 1bd0d4e29b..12c554a356 100644 --- a/src/Microsoft.AspNet.Hosting.Interfaces/project.json +++ b/src/Microsoft.AspNet.Hosting.Interfaces/project.json @@ -1,5 +1,6 @@ { "version": "1.0.0-*", + "description": "ASP.NET 5 Hosting interfaces.", "dependencies": { "Microsoft.AspNet.Http": "1.0.0-*", "Microsoft.AspNet.FileProviders.Interfaces": "1.0.0-*", From ee554439cf0c92073c0391715ed7e823aa9b2e24 Mon Sep 17 00:00:00 2001 From: Chris Ross Date: Thu, 16 Apr 2015 12:13:40 -0700 Subject: [PATCH 260/987] Handle Http.Core rename. --- src/Microsoft.AspNet.Hosting.Interfaces/project.json | 2 +- src/Microsoft.AspNet.Hosting/Builder/HttpContextFactory.cs | 1 - src/Microsoft.AspNet.Hosting/project.json | 2 +- src/Microsoft.AspNet.TestHost/ClientHandler.cs | 1 - test/Microsoft.AspNet.TestHost.Tests/ClientHandlerTests.cs | 1 - 5 files changed, 2 insertions(+), 5 deletions(-) diff --git a/src/Microsoft.AspNet.Hosting.Interfaces/project.json b/src/Microsoft.AspNet.Hosting.Interfaces/project.json index 12c554a356..fa914dfcab 100644 --- a/src/Microsoft.AspNet.Hosting.Interfaces/project.json +++ b/src/Microsoft.AspNet.Hosting.Interfaces/project.json @@ -2,7 +2,7 @@ "version": "1.0.0-*", "description": "ASP.NET 5 Hosting interfaces.", "dependencies": { - "Microsoft.AspNet.Http": "1.0.0-*", + "Microsoft.AspNet.Http.Core": "1.0.0-*", "Microsoft.AspNet.FileProviders.Interfaces": "1.0.0-*", "Microsoft.Framework.NotNullAttribute.Internal": { "type": "build", "version": "1.0.0-*" } }, diff --git a/src/Microsoft.AspNet.Hosting/Builder/HttpContextFactory.cs b/src/Microsoft.AspNet.Hosting/Builder/HttpContextFactory.cs index 74312601df..f8411eee1a 100644 --- a/src/Microsoft.AspNet.Hosting/Builder/HttpContextFactory.cs +++ b/src/Microsoft.AspNet.Hosting/Builder/HttpContextFactory.cs @@ -3,7 +3,6 @@ using Microsoft.AspNet.FeatureModel; using Microsoft.AspNet.Http; -using Microsoft.AspNet.Http.Core; namespace Microsoft.AspNet.Hosting.Builder { diff --git a/src/Microsoft.AspNet.Hosting/project.json b/src/Microsoft.AspNet.Hosting/project.json index 09c50d4135..8253c2503b 100644 --- a/src/Microsoft.AspNet.Hosting/project.json +++ b/src/Microsoft.AspNet.Hosting/project.json @@ -6,7 +6,7 @@ "Microsoft.AspNet.FileProviders": "1.0.0-*", "Microsoft.AspNet.Hosting.Interfaces": "1.0.0-*", "Microsoft.AspNet.Hosting.Server.Interfaces": "1.0.0-*", - "Microsoft.AspNet.Http.Core": "1.0.0-*", + "Microsoft.AspNet.Http": "1.0.0-*", "Microsoft.AspNet.Http.Extensions": "1.0.0-*", "Microsoft.Framework.ConfigurationModel": "1.0.0-*", "Microsoft.Framework.DependencyInjection": "1.0.0-*", diff --git a/src/Microsoft.AspNet.TestHost/ClientHandler.cs b/src/Microsoft.AspNet.TestHost/ClientHandler.cs index 8d8855d81e..75a954296c 100644 --- a/src/Microsoft.AspNet.TestHost/ClientHandler.cs +++ b/src/Microsoft.AspNet.TestHost/ClientHandler.cs @@ -12,7 +12,6 @@ using System.Threading; using System.Threading.Tasks; using Microsoft.AspNet.FeatureModel; using Microsoft.AspNet.Http; -using Microsoft.AspNet.Http.Core; namespace Microsoft.AspNet.TestHost { diff --git a/test/Microsoft.AspNet.TestHost.Tests/ClientHandlerTests.cs b/test/Microsoft.AspNet.TestHost.Tests/ClientHandlerTests.cs index 74838032eb..f8772ee570 100644 --- a/test/Microsoft.AspNet.TestHost.Tests/ClientHandlerTests.cs +++ b/test/Microsoft.AspNet.TestHost.Tests/ClientHandlerTests.cs @@ -9,7 +9,6 @@ using System.Threading; using System.Threading.Tasks; using Microsoft.AspNet.FeatureModel; using Microsoft.AspNet.Http; -using Microsoft.AspNet.Http.Core; using Xunit; namespace Microsoft.AspNet.TestHost From fc96d4d3a53a3f72fc9bab78a712f3e24b6d0a05 Mon Sep 17 00:00:00 2001 From: Praburaj Date: Fri, 17 Apr 2015 12:25:57 -0700 Subject: [PATCH 261/987] Server deployment helpers in testing repo. --- Hosting.sln | 17 +- .../Common/DeploymentParameters.cs | 104 ++++++++ .../Common/DeploymentResult.cs | 34 +++ .../Common/DotnetArchitecture.cs | 11 + .../Common/DotnetFlavor.cs | 12 + .../Common/RetryHelper.cs | 74 ++++++ .../Common/ServerType.cs | 14 ++ .../Deployers/ApplicationDeployer.cs | 227 ++++++++++++++++++ .../Deployers/ApplicationDeployerFactory.cs | 57 +++++ .../Deployers/IApplicationDeployer.cs | 19 ++ .../Deployers/IISDeployer.cs | 213 ++++++++++++++++ .../Deployers/IISExpressDeployer.cs | 208 ++++++++++++++++ .../Deployers/MonoDeployer.cs | 111 +++++++++ .../Deployers/SelfHostDeployer.cs | 95 ++++++++ .../Microsoft.AspNet.Server.Testing.xproj | 20 ++ .../project.json | 31 +++ .../xunit/SkipIfCurrentRuntimeIsCoreClr.cs | 32 +++ ...fIISNativeVariationsNotEnabledAttribute.cs | 33 +++ .../SkipIfIISVariationsNotEnabledAttribute.cs | 33 +++ .../xunit/SkipOn32BitOSAttribute.cs | 33 +++ 20 files changed, 1377 insertions(+), 1 deletion(-) create mode 100644 src/Microsoft.AspNet.Server.Testing/Common/DeploymentParameters.cs create mode 100644 src/Microsoft.AspNet.Server.Testing/Common/DeploymentResult.cs create mode 100644 src/Microsoft.AspNet.Server.Testing/Common/DotnetArchitecture.cs create mode 100644 src/Microsoft.AspNet.Server.Testing/Common/DotnetFlavor.cs create mode 100644 src/Microsoft.AspNet.Server.Testing/Common/RetryHelper.cs create mode 100644 src/Microsoft.AspNet.Server.Testing/Common/ServerType.cs create mode 100644 src/Microsoft.AspNet.Server.Testing/Deployers/ApplicationDeployer.cs create mode 100644 src/Microsoft.AspNet.Server.Testing/Deployers/ApplicationDeployerFactory.cs create mode 100644 src/Microsoft.AspNet.Server.Testing/Deployers/IApplicationDeployer.cs create mode 100644 src/Microsoft.AspNet.Server.Testing/Deployers/IISDeployer.cs create mode 100644 src/Microsoft.AspNet.Server.Testing/Deployers/IISExpressDeployer.cs create mode 100644 src/Microsoft.AspNet.Server.Testing/Deployers/MonoDeployer.cs create mode 100644 src/Microsoft.AspNet.Server.Testing/Deployers/SelfHostDeployer.cs create mode 100644 src/Microsoft.AspNet.Server.Testing/Microsoft.AspNet.Server.Testing.xproj create mode 100644 src/Microsoft.AspNet.Server.Testing/project.json create mode 100644 src/Microsoft.AspNet.Server.Testing/xunit/SkipIfCurrentRuntimeIsCoreClr.cs create mode 100644 src/Microsoft.AspNet.Server.Testing/xunit/SkipIfIISNativeVariationsNotEnabledAttribute.cs create mode 100644 src/Microsoft.AspNet.Server.Testing/xunit/SkipIfIISVariationsNotEnabledAttribute.cs create mode 100644 src/Microsoft.AspNet.Server.Testing/xunit/SkipOn32BitOSAttribute.cs diff --git a/Hosting.sln b/Hosting.sln index fd29a14db9..b7b4361fe4 100644 --- a/Hosting.sln +++ b/Hosting.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 14 -VisualStudioVersion = 14.0.22710.0 +VisualStudioVersion = 14.0.22803.0 MinimumVisualStudioVersion = 10.0.40219.1 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{E0497F39-AFFB-4819-A116-E39E361915AB}" EndProject @@ -24,6 +24,8 @@ Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNet.Hosting.In EndProject Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNet.Hosting.Server.Interfaces", "src\Microsoft.AspNet.Hosting.Server.Interfaces\Microsoft.AspNet.Hosting.Server.Interfaces.xproj", "{FDBBA081-5248-4FC0-9E08-B46BEF3FA438}" EndProject +Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNet.Server.Testing", "src\Microsoft.AspNet.Server.Testing\Microsoft.AspNet.Server.Testing.xproj", "{3DA89347-6731-4366-80C4-548F24E8607B}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -98,6 +100,18 @@ Global {FDBBA081-5248-4FC0-9E08-B46BEF3FA438}.Release|Mixed Platforms.Build.0 = Release|Any CPU {FDBBA081-5248-4FC0-9E08-B46BEF3FA438}.Release|x86.ActiveCfg = Release|Any CPU {FDBBA081-5248-4FC0-9E08-B46BEF3FA438}.Release|x86.Build.0 = Release|Any CPU + {3DA89347-6731-4366-80C4-548F24E8607B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {3DA89347-6731-4366-80C4-548F24E8607B}.Debug|Any CPU.Build.0 = Debug|Any CPU + {3DA89347-6731-4366-80C4-548F24E8607B}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU + {3DA89347-6731-4366-80C4-548F24E8607B}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU + {3DA89347-6731-4366-80C4-548F24E8607B}.Debug|x86.ActiveCfg = Debug|Any CPU + {3DA89347-6731-4366-80C4-548F24E8607B}.Debug|x86.Build.0 = Debug|Any CPU + {3DA89347-6731-4366-80C4-548F24E8607B}.Release|Any CPU.ActiveCfg = Release|Any CPU + {3DA89347-6731-4366-80C4-548F24E8607B}.Release|Any CPU.Build.0 = Release|Any CPU + {3DA89347-6731-4366-80C4-548F24E8607B}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU + {3DA89347-6731-4366-80C4-548F24E8607B}.Release|Mixed Platforms.Build.0 = Release|Any CPU + {3DA89347-6731-4366-80C4-548F24E8607B}.Release|x86.ActiveCfg = Release|Any CPU + {3DA89347-6731-4366-80C4-548F24E8607B}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -109,5 +123,6 @@ Global {D4F18D58-52B1-435D-A012-10F2CDF158C4} = {FEB39027-9158-4DE2-997F-7ADAEF8188D0} {BB780FBB-7842-4759-8DE7-96FA2E5571C1} = {E0497F39-AFFB-4819-A116-E39E361915AB} {FDBBA081-5248-4FC0-9E08-B46BEF3FA438} = {E0497F39-AFFB-4819-A116-E39E361915AB} + {3DA89347-6731-4366-80C4-548F24E8607B} = {E0497F39-AFFB-4819-A116-E39E361915AB} EndGlobalSection EndGlobal diff --git a/src/Microsoft.AspNet.Server.Testing/Common/DeploymentParameters.cs b/src/Microsoft.AspNet.Server.Testing/Common/DeploymentParameters.cs new file mode 100644 index 0000000000..39278112b2 --- /dev/null +++ b/src/Microsoft.AspNet.Server.Testing/Common/DeploymentParameters.cs @@ -0,0 +1,104 @@ +// 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 System; +using System.Collections.Generic; +using System.IO; + +namespace Microsoft.AspNet.Server.Testing +{ + /// + /// Parameters to control application deployment. + /// + public class DeploymentParameters + { + /// + /// Creates an instance of . + /// + /// Source code location of the target location to be deployed. + /// Where to be deployed on. + /// Flavor of the clr to run against. + /// Architecture of the DNX to be used. + public DeploymentParameters( + string applicationPath, + ServerType serverType, + RuntimeFlavor runtimeFlavor, + RuntimeArchitecture runtimeArchitecture) + { + if (string.IsNullOrEmpty(applicationPath)) + { + throw new ArgumentException("Value cannot be null.", "applicationPath"); + } + + if (!Directory.Exists(applicationPath)) + { + throw new DirectoryNotFoundException(string.Format("Application path {0} does not exist.", applicationPath)); + } + + ApplicationPath = applicationPath; + ServerType = serverType; + RuntimeFlavor = runtimeFlavor; + RuntimeArchitecture = runtimeArchitecture; + } + + public ServerType ServerType { get; private set; } + + public RuntimeFlavor RuntimeFlavor { get; private set; } + + public RuntimeArchitecture RuntimeArchitecture { get; private set; } + + /// + /// Suggested base url for the deployed application. The final deployed url could be + /// different than this. Use for the + /// deployed url. + /// + public string ApplicationBaseUriHint { get; set; } + + public string EnvironmentName { get; set; } + + public string ApplicationHostConfigTemplateContent { get; set; } + + public string ApplicationHostConfigLocation { get; set; } + + public string SiteName { get; set; } + + public string ApplicationPath { get; set; } + + /// + /// To publish the application before deployment. + /// + public bool PublishApplicationBeforeDeployment { get; set; } + + public string PublishedApplicationRootPath { get; set; } + + /// + /// Passes the --no-source option when publishing. + /// + public bool PublishWithNoSource { get; set; } + + public string DnxRuntime { get; set; } + + /// + /// Environment variables to be set before starting the host. + /// Not applicable for IIS Scenarios. + /// + public List> EnvironmentVariables { get; private set; } = new List>(); + + /// + /// For any application level cleanup to be invoked after performing host cleanup. + /// + public Action UserAdditionalCleanup { get; set; } + + public override string ToString() + { + return string.Format( + "[Variation] :: ServerType={0}, Runtime={1}, Arch={2}, BaseUrlHint={3}, Publish={4}, NoSource={5}", + ServerType, + RuntimeFlavor, + RuntimeArchitecture, + ApplicationBaseUriHint, + PublishApplicationBeforeDeployment, + PublishWithNoSource); + } + } +} \ No newline at end of file diff --git a/src/Microsoft.AspNet.Server.Testing/Common/DeploymentResult.cs b/src/Microsoft.AspNet.Server.Testing/Common/DeploymentResult.cs new file mode 100644 index 0000000000..6a2c1a69d4 --- /dev/null +++ b/src/Microsoft.AspNet.Server.Testing/Common/DeploymentResult.cs @@ -0,0 +1,34 @@ +// 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 System.Threading; + +namespace Microsoft.AspNet.Server.Testing +{ + /// + /// Result of a deployment. + /// + public class DeploymentResult + { + /// + /// Base Uri of the deployment application. + /// + public string ApplicationBaseUri { get; set; } + + /// + /// The web root folder where the application is hosted. This path can be different from the + /// original application source location if published before deployment. + /// + public string WebRootLocation { get; set; } + + /// + /// Original deployment parameters used for this deployment. + /// + public DeploymentParameters DeploymentParameters { get; set; } + + /// + /// Triggered when the host process dies or pulled down. + /// + public CancellationToken HostShutdownToken { get; set; } + } +} \ No newline at end of file diff --git a/src/Microsoft.AspNet.Server.Testing/Common/DotnetArchitecture.cs b/src/Microsoft.AspNet.Server.Testing/Common/DotnetArchitecture.cs new file mode 100644 index 0000000000..11b1a3d5e3 --- /dev/null +++ b/src/Microsoft.AspNet.Server.Testing/Common/DotnetArchitecture.cs @@ -0,0 +1,11 @@ +// 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. + +namespace Microsoft.AspNet.Server.Testing +{ + public enum RuntimeArchitecture + { + x64, + x86 + } +} \ No newline at end of file diff --git a/src/Microsoft.AspNet.Server.Testing/Common/DotnetFlavor.cs b/src/Microsoft.AspNet.Server.Testing/Common/DotnetFlavor.cs new file mode 100644 index 0000000000..99913581b7 --- /dev/null +++ b/src/Microsoft.AspNet.Server.Testing/Common/DotnetFlavor.cs @@ -0,0 +1,12 @@ +// 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. + +namespace Microsoft.AspNet.Server.Testing +{ + public enum RuntimeFlavor + { + Clr, + CoreClr, + Mono + } +} diff --git a/src/Microsoft.AspNet.Server.Testing/Common/RetryHelper.cs b/src/Microsoft.AspNet.Server.Testing/Common/RetryHelper.cs new file mode 100644 index 0000000000..1c6e6949dd --- /dev/null +++ b/src/Microsoft.AspNet.Server.Testing/Common/RetryHelper.cs @@ -0,0 +1,74 @@ +// 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 System; +using System.Net; +using System.Net.Http; +using System.Threading; +using System.Threading.Tasks; +using Microsoft.Framework.Logging; + +namespace Microsoft.AspNet.Server.Testing +{ + public class RetryHelper + { + /// + /// Retries every 1 sec for 60 times by default. + /// + /// + /// + /// + /// + public static async Task RetryRequest( + Func> retryBlock, + ILogger logger, + CancellationToken cancellationToken = default(CancellationToken), + int retryCount = 60) + { + for (int retry = 0; retry < retryCount; retry++) + { + try + { + if (cancellationToken.IsCancellationRequested) + { + logger.LogInformation("Stopping retry as cancellation token is triggered."); + break; + } + + logger.LogWarning("Retry count {retryCount}..", retry + 1); + var response = await retryBlock(); + + if (response.StatusCode == HttpStatusCode.ServiceUnavailable) + { + // Automatically retry on 503. May be application is still booting. + logger.LogWarning("Retrying a service unavailable error."); + continue; + } + + return response; //Went through successfully + } + catch (Exception exception) + { + if (retry == retryCount - 1) + { + throw; + } + else + { + if (exception is HttpRequestException +#if DNX451 + || exception is System.Net.WebException +#endif + ) + { + logger.LogWarning("Failed to complete the request : {0}.", exception.Message); + await Task.Delay(1 * 1000); //Wait for a while before retry. + } + } + } + } + + return null; + } + } +} \ No newline at end of file diff --git a/src/Microsoft.AspNet.Server.Testing/Common/ServerType.cs b/src/Microsoft.AspNet.Server.Testing/Common/ServerType.cs new file mode 100644 index 0000000000..9756b1496b --- /dev/null +++ b/src/Microsoft.AspNet.Server.Testing/Common/ServerType.cs @@ -0,0 +1,14 @@ +// 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. + +namespace Microsoft.AspNet.Server.Testing +{ + public enum ServerType + { + IISExpress, + IIS, + IISNativeModule, + WebListener, + Kestrel + } +} \ No newline at end of file diff --git a/src/Microsoft.AspNet.Server.Testing/Deployers/ApplicationDeployer.cs b/src/Microsoft.AspNet.Server.Testing/Deployers/ApplicationDeployer.cs new file mode 100644 index 0000000000..c974840a22 --- /dev/null +++ b/src/Microsoft.AspNet.Server.Testing/Deployers/ApplicationDeployer.cs @@ -0,0 +1,227 @@ +// 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 System; +using System.Diagnostics; +using System.IO; +using System.Text; +using System.Text.RegularExpressions; +using System.Threading; +using Microsoft.Framework.Logging; + +namespace Microsoft.AspNet.Server.Testing +{ + /// + /// Abstract base class of all deplolyers with a back bone implementation of some of the common helpers. + /// + public abstract class ApplicationDeployer : IApplicationDeployer + { + protected string ChosenRuntimePath { get; set; } + + protected string ChosenRuntimeName { get; set; } + + protected DeploymentParameters DeploymentParameters { get; private set; } + + protected ILogger Logger { get; private set; } + + protected Stopwatch StopWatch { get; private set; } = new Stopwatch(); + + public abstract DeploymentResult Deploy(); + + public ApplicationDeployer( + DeploymentParameters deploymentParameters, + ILogger logger) + { + DeploymentParameters = deploymentParameters; + Logger = logger; + } + + protected string PopulateChosenRuntimeInformation() + { + var runtimePath = Process.GetCurrentProcess().MainModule.FileName; + Logger.LogInformation(string.Empty); + Logger.LogInformation("Current runtime path is : {0}", runtimePath); + + var replaceStr = new StringBuilder(). + Append("dnx"). + Append((DeploymentParameters.RuntimeFlavor == RuntimeFlavor.CoreClr) ? "-coreclr" : "-clr"). + Append("-win"). + Append((DeploymentParameters.RuntimeArchitecture == RuntimeArchitecture.x86) ? "-x86" : "-x64"). + ToString(); + + runtimePath = Regex.Replace(runtimePath, "dnx-(clr|coreclr)-win-(x86|x64)", replaceStr, RegexOptions.IgnoreCase); + ChosenRuntimePath = Path.GetDirectoryName(runtimePath); + + var runtimeDirectoryInfo = new DirectoryInfo(ChosenRuntimePath); + if (!runtimeDirectoryInfo.Exists) + { + throw new Exception( + string.Format("Requested runtime at location '{0}' does not exist. Please make sure it is installed before running test.", + runtimeDirectoryInfo.FullName)); + } + + ChosenRuntimeName = runtimeDirectoryInfo.Parent.Name; + Logger.LogInformation(string.Empty); + Logger.LogInformation("Changing to use runtime : {runtimeName}", ChosenRuntimeName); + return ChosenRuntimeName; + } + + protected void DnuPublish(string publishRoot = null) + { + DeploymentParameters.PublishedApplicationRootPath = Path.Combine(publishRoot ?? Path.GetTempPath(), Guid.NewGuid().ToString()); + + var parameters = + string.Format( + "publish {0} -o {1} --runtime {2} {3}", + DeploymentParameters.ApplicationPath, + DeploymentParameters.PublishedApplicationRootPath, + DeploymentParameters.DnxRuntime, + DeploymentParameters.PublishWithNoSource ? "--no-source" : string.Empty); + + Logger.LogInformation("Executing command dnu {args}", parameters); + + var startInfo = new ProcessStartInfo + { + FileName = Path.Combine(ChosenRuntimePath, "dnu.cmd"), + Arguments = parameters, + UseShellExecute = false, + CreateNoWindow = true + }; + + var hostProcess = Process.Start(startInfo); + hostProcess.WaitForExit(60 * 1000); + + DeploymentParameters.ApplicationPath = + (DeploymentParameters.ServerType == ServerType.IISExpress || + DeploymentParameters.ServerType == ServerType.IISNativeModule || + DeploymentParameters.ServerType == ServerType.IIS) ? + Path.Combine(DeploymentParameters.PublishedApplicationRootPath, "wwwroot") : + Path.Combine(DeploymentParameters.PublishedApplicationRootPath, "approot", "src", + new DirectoryInfo(DeploymentParameters.ApplicationPath).Name); + + Logger.LogInformation("dnu publish finished with exit code : {exitCode}", hostProcess.ExitCode); + } + + protected void CleanPublishedOutput() + { + try + { + // We've originally published the application in a temp folder. We need to delete it. + Directory.Delete(DeploymentParameters.PublishedApplicationRootPath, true); + } + catch (Exception exception) + { + Logger.LogWarning("Failed to delete directory : {error}", exception.Message); + } + } + + protected void ShutDownIfAnyHostProcess(Process hostProcess) + { + if (hostProcess != null && !hostProcess.HasExited) + { + // Shutdown the host process. + hostProcess.Kill(); + hostProcess.WaitForExit(5 * 1000); + if (!hostProcess.HasExited) + { + Logger.LogWarning("Unable to terminate the host process with process Id '{processId}", hostProcess.Id); + } + else + { + Logger.LogInformation("Successfully terminated host process with process Id '{processId}'", hostProcess.Id); + } + } + else + { + Logger.LogWarning("Host process already exited or never started successfully."); + } + } + + protected void AddEnvironmentVariablesToProcess(ProcessStartInfo startInfo) + { + var environment = +#if DNX451 + startInfo.EnvironmentVariables; +#elif DNXCORE50 + startInfo.Environment; +#endif + + SetEnvironmentVariable(environment, "ASPNET_ENV", DeploymentParameters.EnvironmentName); + + // Work around for https://github.com/aspnet/dnx/issues/1515 + if (DeploymentParameters.PublishWithNoSource) + { + SetEnvironmentVariable(environment, "DNX_PACKAGES", null); + } + + SetEnvironmentVariable(environment, "DNX_DEFAULT_LIB", null); + + foreach (var environmentVariable in DeploymentParameters.EnvironmentVariables) + { + SetEnvironmentVariable(environment, environmentVariable.Key, environmentVariable.Value); + } + } + +#if DNX451 + protected void SetEnvironmentVariable(System.Collections.Specialized.StringDictionary environment, string name, string value) + { +#elif DNXCORE50 + protected void SetEnvironmentVariable(System.Collections.Generic.IDictionary environment, string name, string value) + { +#endif + if (value == null) + { + Logger.LogInformation("Removing environment variable {name}", name); + environment.Remove(name); + } + else + { + Logger.LogInformation("SET {name}={value}", name, value); + environment[name] = value; + } + } + + protected void InvokeUserApplicationCleanup() + { + if (DeploymentParameters.UserAdditionalCleanup != null) + { + // User cleanup. + try + { + DeploymentParameters.UserAdditionalCleanup(DeploymentParameters); + } + catch (Exception exception) + { + Logger.LogWarning("User cleanup code failed with exception : {exception}", exception.Message); + } + } + } + + protected void TriggerHostShutdown(CancellationTokenSource hostShutdownSource) + { + Logger.LogInformation("Host process shutting down."); + try + { + hostShutdownSource.Cancel(); + } + catch (Exception) + { + // Suppress errors. + } + } + + protected void StartTimer() + { + Logger.LogInformation("Deploying {VariationDetails}", DeploymentParameters.ToString()); + StopWatch.Start(); + } + + protected void StopTimer() + { + StopWatch.Stop(); + Logger.LogInformation("[Time]: Total time taken for this test variation '{t}' seconds", StopWatch.Elapsed.TotalSeconds); + } + + public abstract void Dispose(); + } +} \ No newline at end of file diff --git a/src/Microsoft.AspNet.Server.Testing/Deployers/ApplicationDeployerFactory.cs b/src/Microsoft.AspNet.Server.Testing/Deployers/ApplicationDeployerFactory.cs new file mode 100644 index 0000000000..5308609815 --- /dev/null +++ b/src/Microsoft.AspNet.Server.Testing/Deployers/ApplicationDeployerFactory.cs @@ -0,0 +1,57 @@ +// 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 System; +using Microsoft.Framework.Logging; + +namespace Microsoft.AspNet.Server.Testing +{ + /// + /// Factory to create an appropriate deployer based on . + /// + public class ApplicationDeployerFactory + { + /// + /// Creates a deployer instance based on settings in . + /// + /// + /// + /// + public static IApplicationDeployer Create(DeploymentParameters deploymentParameters, ILogger logger) + { + if (deploymentParameters == null) + { + throw new ArgumentNullException(nameof(deploymentParameters)); + } + + if (logger == null) + { + throw new ArgumentNullException(nameof(logger)); + } + + if (deploymentParameters.RuntimeFlavor == RuntimeFlavor.Mono) + { + return new MonoDeployer(deploymentParameters, logger); + } + + switch (deploymentParameters.ServerType) + { + case ServerType.IISExpress: + return new IISExpressDeployer(deploymentParameters, logger); +#if DNX451 + case ServerType.IIS: + case ServerType.IISNativeModule: + return new IISDeployer(deploymentParameters, logger); +#endif + case ServerType.WebListener: + case ServerType.Kestrel: + return new SelfHostDeployer(deploymentParameters, logger); + default: + throw new NotSupportedException( + string.Format("Found no deployers suitable for server type '{0}' with the current runtime.", + deploymentParameters.ServerType) + ); + } + } + } +} \ No newline at end of file diff --git a/src/Microsoft.AspNet.Server.Testing/Deployers/IApplicationDeployer.cs b/src/Microsoft.AspNet.Server.Testing/Deployers/IApplicationDeployer.cs new file mode 100644 index 0000000000..c027632ccd --- /dev/null +++ b/src/Microsoft.AspNet.Server.Testing/Deployers/IApplicationDeployer.cs @@ -0,0 +1,19 @@ +// 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 System; + +namespace Microsoft.AspNet.Server.Testing +{ + /// + /// Common operations on an application deployer. + /// + public interface IApplicationDeployer : IDisposable + { + /// + /// Deploys the application to the target with specified . + /// + /// + DeploymentResult Deploy(); + } +} \ No newline at end of file diff --git a/src/Microsoft.AspNet.Server.Testing/Deployers/IISDeployer.cs b/src/Microsoft.AspNet.Server.Testing/Deployers/IISDeployer.cs new file mode 100644 index 0000000000..bdc5ac70c6 --- /dev/null +++ b/src/Microsoft.AspNet.Server.Testing/Deployers/IISDeployer.cs @@ -0,0 +1,213 @@ +// 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. + +#if DNX451 +using System; +using System.IO; +using System.Linq; +using System.Threading; +using System.Xml; +using Microsoft.Framework.Logging; +using Microsoft.Web.Administration; + +namespace Microsoft.AspNet.Server.Testing +{ + /// + /// Deployer for IIS. + /// + public class IISDeployer : ApplicationDeployer + { + private IISApplication _application; + private CancellationTokenSource _hostShutdownToken = new CancellationTokenSource(); + private static object _syncObject = new object(); + + public IISDeployer(DeploymentParameters startParameters, ILogger logger) + : base(startParameters, logger) + { + } + + public override DeploymentResult Deploy() + { + // Start timer + StartTimer(); + + // Only supports publish and run on IIS. + DeploymentParameters.PublishApplicationBeforeDeployment = true; + + _application = new IISApplication(DeploymentParameters, Logger); + + DeploymentParameters.DnxRuntime = PopulateChosenRuntimeInformation(); + + // Publish to IIS root\application folder. + DnuPublish(publishRoot: _application.WebSiteRootFolder); + + // Drop an ini file instead of setting environment variable. + SetAspEnvironmentWithIni(); + + // Setup the IIS Application. + if (DeploymentParameters.ServerType == ServerType.IISNativeModule) + { + TurnRammFarOnNativeModule(); + } + + lock (_syncObject) + { + // To prevent modifying the IIS setup concurrently. + _application.Deploy(); + } + + // Warm up time for IIS setup. + Thread.Sleep(1 * 1000); + Logger.LogInformation("Successfully finished IIS application directory setup."); + + return new DeploymentResult + { + WebRootLocation = DeploymentParameters.ApplicationPath, + DeploymentParameters = DeploymentParameters, + // Accomodate the vdir name. + ApplicationBaseUri = new UriBuilder(Uri.UriSchemeHttp, "localhost", IISApplication.Port, _application.VirtualDirectoryName).Uri.AbsoluteUri + "/", + HostShutdownToken = _hostShutdownToken.Token + }; + } + + private void SetAspEnvironmentWithIni() + { + // Drop a Microsoft.AspNet.Hosting.ini with ASPNET_ENV information. + Logger.LogInformation("Creating Microsoft.AspNet.Hosting.ini file with ASPNET_ENV."); + var iniFile = Path.Combine(DeploymentParameters.ApplicationPath, "Microsoft.AspNet.Hosting.ini"); + File.WriteAllText(iniFile, string.Format("ASPNET_ENV={0}", DeploymentParameters.EnvironmentName)); + } + + private void TurnRammFarOnNativeModule() + { + Logger.LogInformation("Turning runAllManagedModulesForAllRequests=true in web.config for native module."); + var webConfig = Path.Combine(DeploymentParameters.ApplicationPath, "web.config"); + var configuration = new XmlDocument(); + configuration.LoadXml(File.ReadAllText(webConfig)); + + // https://github.com/aspnet/Helios/issues/77 + var rammfarAttribute = configuration.CreateAttribute("runAllManagedModulesForAllRequests"); + rammfarAttribute.Value = "true"; + var modulesNode = configuration.CreateElement("modules"); + modulesNode.Attributes.Append(rammfarAttribute); + var systemWebServerNode = configuration.CreateElement("system.webServer"); + systemWebServerNode.AppendChild(modulesNode); + configuration.SelectSingleNode("//configuration").AppendChild(systemWebServerNode); + configuration.Save(webConfig); + } + + public override void Dispose() + { + if (_application != null) + { + lock (_syncObject) + { + // Sequentialize IIS operations. + _application.StopAndDeleteAppPool(); + } + + TriggerHostShutdown(_hostShutdownToken); + } + + CleanPublishedOutput(); + InvokeUserApplicationCleanup(); + + StopTimer(); + } + + private class IISApplication + { + private const string WEBSITE_NAME = "ASPNETTESTRUNS"; + private const string NATIVE_MODULE_MANAGED_RUNTIME_VERSION = "vCoreFX"; + + private readonly ServerManager _serverManager = new ServerManager(); + private readonly DeploymentParameters _deploymentParameters; + private readonly ILogger _logger; + private ApplicationPool _applicationPool; + private Application _application; + private Site _website; + + public string VirtualDirectoryName { get; set; } + + // Always create website with the same port. + public const int Port = 5100; + + public string WebSiteRootFolder + { + get + { + return Path.Combine( + Environment.GetEnvironmentVariable("SystemDrive") + @"\", + "inetpub", + WEBSITE_NAME); + } + } + + public IISApplication(DeploymentParameters deploymentParameters, ILogger logger) + { + _deploymentParameters = deploymentParameters; + _logger = logger; + } + + public void Deploy() + { + VirtualDirectoryName = new DirectoryInfo(_deploymentParameters.ApplicationPath).Parent.Name; + _applicationPool = CreateAppPool(VirtualDirectoryName); + _application = Website.Applications.Add("/" + VirtualDirectoryName, _deploymentParameters.ApplicationPath); + _application.ApplicationPoolName = _applicationPool.Name; + _serverManager.CommitChanges(); + } + + private Site Website + { + get + { + _website = _serverManager.Sites.Where(s => s.Name == WEBSITE_NAME).FirstOrDefault(); + if (_website == null) + { + _website = _serverManager.Sites.Add(WEBSITE_NAME, WebSiteRootFolder, Port); + } + + return _website; + } + } + + private ApplicationPool CreateAppPool(string appPoolName) + { + var applicationPool = _serverManager.ApplicationPools.Add(appPoolName); + if (_deploymentParameters.ServerType == ServerType.IISNativeModule) + { + // Not assigning a runtime version will choose v4.0 default. + applicationPool.ManagedRuntimeVersion = NATIVE_MODULE_MANAGED_RUNTIME_VERSION; + } + + applicationPool.Enable32BitAppOnWin64 = (_deploymentParameters.RuntimeArchitecture == RuntimeArchitecture.x86); + _logger.LogInformation("Created {bit} application pool '{name}' with runtime version {runtime}.", + _deploymentParameters.RuntimeArchitecture, applicationPool.Name, + string.IsNullOrEmpty(applicationPool.ManagedRuntimeVersion) ? "that is default" : applicationPool.ManagedRuntimeVersion); + return applicationPool; + } + + public void StopAndDeleteAppPool() + { + _logger.LogInformation("Stopping application pool '{name}' and deleting application.", _applicationPool.Name); + + if (_applicationPool != null) + { + _applicationPool.Stop(); + } + + // Remove the application from website. + if (_application != null) + { + _application = Website.Applications.Where(a => a.Path == _application.Path).FirstOrDefault(); + Website.Applications.Remove(_application); + _serverManager.ApplicationPools.Remove(_serverManager.ApplicationPools[_applicationPool.Name]); + _serverManager.CommitChanges(); + _logger.LogInformation("Successfully stopped application pool '{name}' and deleted application from IIS.", _applicationPool.Name); + } + } + } + } +} +#endif \ No newline at end of file diff --git a/src/Microsoft.AspNet.Server.Testing/Deployers/IISExpressDeployer.cs b/src/Microsoft.AspNet.Server.Testing/Deployers/IISExpressDeployer.cs new file mode 100644 index 0000000000..30dc94bfdc --- /dev/null +++ b/src/Microsoft.AspNet.Server.Testing/Deployers/IISExpressDeployer.cs @@ -0,0 +1,208 @@ +// 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 System; +using System.Diagnostics; +using System.IO; +using System.Threading; +using Microsoft.Framework.Logging; +using Microsoft.Framework.Runtime; +using Microsoft.Framework.Runtime.Infrastructure; + +namespace Microsoft.AspNet.Server.Testing +{ + /// + /// Deployment helper for IISExpress. + /// + public class IISExpressDeployer : ApplicationDeployer + { + private Process _hostProcess; + + public IISExpressDeployer(DeploymentParameters deploymentParameters, ILogger logger) + : base(deploymentParameters, logger) + { + } + + public override DeploymentResult Deploy() + { + // Start timer + StartTimer(); + + DeploymentParameters.DnxRuntime = PopulateChosenRuntimeInformation(); + + if (DeploymentParameters.PublishApplicationBeforeDeployment) + { + DnuPublish(); + } + + // Launch the host process. + var hostExitToken = StartIISExpress(); + + return new DeploymentResult + { + WebRootLocation = DeploymentParameters.ApplicationPath, + DeploymentParameters = DeploymentParameters, + // Right now this works only for urls like http://localhost:5001/. Does not work for http://localhost:5001/subpath. + ApplicationBaseUri = DeploymentParameters.ApplicationBaseUriHint, + HostShutdownToken = hostExitToken + }; + } + + private CancellationToken StartIISExpress() + { + if (!string.IsNullOrWhiteSpace(DeploymentParameters.ApplicationHostConfigTemplateContent)) + { + // Pass on the applicationhost.config to iis express. With this don't need to pass in the /path /port switches as they are in the applicationHost.config + // We take a copy of the original specified applicationHost.Config to prevent modifying the one in the repo. + + DeploymentParameters.ApplicationHostConfigTemplateContent = + DeploymentParameters.ApplicationHostConfigTemplateContent + .Replace("[ApplicationPhysicalPath]", Path.Combine(DeploymentParameters.ApplicationPath, "wwwroot")) + .Replace("[PORT]", new Uri(DeploymentParameters.ApplicationBaseUriHint).Port.ToString()); + + DeploymentParameters.ApplicationHostConfigLocation = Path.GetTempFileName(); + + File.WriteAllText(DeploymentParameters.ApplicationHostConfigLocation, + DeploymentParameters.ApplicationHostConfigTemplateContent.Replace("[ApplicationPhysicalPath]", DeploymentParameters.ApplicationPath)); + } + + if (!DeploymentParameters.PublishApplicationBeforeDeployment) + { + CopyAspNetLoader(); + } + + var webroot = DeploymentParameters.ApplicationPath; + if (!webroot.EndsWith("wwwroot")) + { + webroot = Path.Combine(webroot, "wwwroot"); + } + + var parameters = string.IsNullOrWhiteSpace(DeploymentParameters.ApplicationHostConfigLocation) ? + string.Format("/port:{0} /path:\"{1}\" /trace:error", new Uri(DeploymentParameters.ApplicationBaseUriHint).Port, webroot) : + string.Format("/site:{0} /config:{1} /trace:error", DeploymentParameters.SiteName, DeploymentParameters.ApplicationHostConfigLocation); + + var iisExpressPath = GetIISExpressPath(); + + Logger.LogInformation("Executing command : {iisExpress} {args}", iisExpressPath, parameters); + + var startInfo = new ProcessStartInfo + { + FileName = iisExpressPath, + Arguments = parameters, + UseShellExecute = false, + CreateNoWindow = false + }; + + AddEnvironmentVariablesToProcess(startInfo); + + // IIS express figures out the DNX from %PATH%. +#if DNX451 + SetEnvironmentVariable(startInfo.EnvironmentVariables, "PATH", ChosenRuntimePath + ";" + startInfo.EnvironmentVariables["PATH"]); + SetEnvironmentVariable(startInfo.EnvironmentVariables, "DNX_APPBASE", DeploymentParameters.ApplicationPath); +#elif DNXCORE50 + SetEnvironmentVariable(startInfo.Environment, "PATH", ChosenRuntimePath + ";" + startInfo.Environment["PATH"]); + SetEnvironmentVariable(startInfo.Environment, "DNX_APPBASE", DeploymentParameters.ApplicationPath); +#endif + + _hostProcess = Process.Start(startInfo); + _hostProcess.EnableRaisingEvents = true; + var hostExitTokenSource = new CancellationTokenSource(); + _hostProcess.Exited += (sender, e) => + { + TriggerHostShutdown(hostExitTokenSource); + }; + + if (_hostProcess.HasExited) + { + Logger.LogError("Host process {processName} exited with code {exitCode} or failed to start.", startInfo.FileName, _hostProcess.ExitCode); + throw new Exception("Failed to start host"); + } + + Logger.LogInformation("Started iisexpress. Process Id : {processId}", _hostProcess.Id); + return hostExitTokenSource.Token; + } + + private void CopyAspNetLoader() + { + var libraryManager = (ILibraryManager)CallContextServiceLocator.Locator.ServiceProvider.GetService(typeof(ILibraryManager)); + var interopLibrary = libraryManager.GetLibraryInformation("Microsoft.AspNet.Loader.IIS.Interop"); + + if (interopLibrary == null) + { + throw new Exception( + string.Format("Include Microsoft.AspNet.Server.IIS package in your project.json to deploy in {0}.", + ServerType.IISExpress)); + } + + var aspNetLoaderSrcPath = Path.Combine(interopLibrary.Path, "tools", "AspNet.Loader.dll"); + var aspNetLoaderDestPath = Path.Combine(DeploymentParameters.ApplicationPath, "wwwroot", "bin", "AspNet.Loader.dll"); + + // Create bin directory if it does not exist. + Directory.CreateDirectory(new DirectoryInfo(aspNetLoaderDestPath).Parent.FullName); + + if (!File.Exists(aspNetLoaderDestPath)) + { + try + { + File.Copy(aspNetLoaderSrcPath, aspNetLoaderDestPath); + } + catch (IOException) + { + // Ignore file already exists exception. Sometimes multiple tests might try + // doing the same and one of them wins. + } + } + } + + private string GetIISExpressPath() + { + // Get path to program files + var iisExpressPath = Path.Combine(Environment.GetEnvironmentVariable("ProgramFiles(x86)"), "IIS Express", "iisexpress.exe"); + + // Get path to 64 bit of IIS Express + if (DeploymentParameters.RuntimeArchitecture == RuntimeArchitecture.x64) + { + iisExpressPath = Path.Combine(Environment.GetEnvironmentVariable("ProgramFiles"), "IIS Express", "iisexpress.exe"); + + // If process is 32 bit, the path points to x86. Replace path to point to x64 + iisExpressPath = IntPtr.Size == 8 ? iisExpressPath : iisExpressPath.Replace(" (x86)", ""); + } + + if (!File.Exists(iisExpressPath)) + { + throw new Exception("Unable to find IISExpress on the machine"); + } + + return iisExpressPath; + } + + public override void Dispose() + { + ShutDownIfAnyHostProcess(_hostProcess); + + if (!string.IsNullOrWhiteSpace(DeploymentParameters.ApplicationHostConfigLocation) + && File.Exists(DeploymentParameters.ApplicationHostConfigLocation)) + { + // Delete the temp applicationHostConfig that we created. + try + { + File.Delete(DeploymentParameters.ApplicationHostConfigLocation); + } + catch (Exception exception) + { + // Ignore delete failures - just write a log. + Logger.LogWarning("Failed to delete '{config}'. Exception : {exception}", DeploymentParameters.ApplicationHostConfigLocation, exception.Message); + } + } + + if (DeploymentParameters.PublishApplicationBeforeDeployment) + { + CleanPublishedOutput(); + } + + InvokeUserApplicationCleanup(); + + StopTimer(); + } + } +} \ No newline at end of file diff --git a/src/Microsoft.AspNet.Server.Testing/Deployers/MonoDeployer.cs b/src/Microsoft.AspNet.Server.Testing/Deployers/MonoDeployer.cs new file mode 100644 index 0000000000..12f099596f --- /dev/null +++ b/src/Microsoft.AspNet.Server.Testing/Deployers/MonoDeployer.cs @@ -0,0 +1,111 @@ +// 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 System; +using System.Diagnostics; +using System.IO; +using System.Linq; +using System.Threading; +using Microsoft.Framework.Logging; + +namespace Microsoft.AspNet.Server.Testing +{ + /// + /// Deployer for Kestrel on Mono. + /// + public class MonoDeployer : ApplicationDeployer + { + private Process _hostProcess; + + public MonoDeployer(DeploymentParameters deploymentParameters, ILogger logger) + : base(deploymentParameters, logger) + { + } + + public override DeploymentResult Deploy() + { + // Start timer + StartTimer(); + + var path = Environment.GetEnvironmentVariable("PATH"); + var runtimeBin = path.Split(new char[] { ':' }, StringSplitOptions.RemoveEmptyEntries). + Where(c => c.Contains("dnx-mono")).FirstOrDefault(); + + if (string.IsNullOrWhiteSpace(runtimeBin)) + { + throw new Exception("Runtime not detected on the machine."); + } + + if (DeploymentParameters.PublishApplicationBeforeDeployment) + { + // We use full path to runtime to pack. + DeploymentParameters.DnxRuntime = new DirectoryInfo(runtimeBin).Parent.FullName; + DnuPublish(); + } + + // Launch the host process. + var hostExitToken = StartMonoHost(); + + return new DeploymentResult + { + WebRootLocation = DeploymentParameters.ApplicationPath, + DeploymentParameters = DeploymentParameters, + ApplicationBaseUri = DeploymentParameters.ApplicationBaseUriHint, + HostShutdownToken = hostExitToken + }; + } + + private CancellationToken StartMonoHost() + { + if (DeploymentParameters.ServerType != ServerType.Kestrel) + { + throw new InvalidOperationException("kestrel is the only valid ServerType for Mono"); + } + + Logger.LogInformation("Executing command: dnx \"{appPath}\" kestrel --server.urls {url}", + DeploymentParameters.ApplicationPath, DeploymentParameters.ApplicationBaseUriHint); + + var startInfo = new ProcessStartInfo + { + FileName = "dnx", + Arguments = string.Format("\"{0}\" kestrel --server.urls {1}", DeploymentParameters.ApplicationPath, DeploymentParameters.ApplicationBaseUriHint), + UseShellExecute = false, + CreateNoWindow = true, + RedirectStandardInput = true + }; + + _hostProcess = Process.Start(startInfo); + _hostProcess.EnableRaisingEvents = true; + var hostExitTokenSource = new CancellationTokenSource(); + _hostProcess.Exited += (sender, e) => + { + Logger.LogError("Host process {processName} exited with code {exitCode}.", startInfo.FileName, _hostProcess.ExitCode); + TriggerHostShutdown(hostExitTokenSource); + }; + + Logger.LogInformation("Started {0}. Process Id : {1}", _hostProcess.MainModule.FileName, _hostProcess.Id); + + if (_hostProcess.HasExited) + { + Logger.LogError("Host process {processName} exited with code {exitCode} or failed to start.", startInfo.FileName, _hostProcess.ExitCode); + throw new Exception("Failed to start host"); + } + + return hostExitTokenSource.Token; + } + + public override void Dispose() + { + ShutDownIfAnyHostProcess(_hostProcess); + + if (DeploymentParameters.PublishApplicationBeforeDeployment) + { + CleanPublishedOutput(); + } + + InvokeUserApplicationCleanup(); + + StopTimer(); + } + } +} \ No newline at end of file diff --git a/src/Microsoft.AspNet.Server.Testing/Deployers/SelfHostDeployer.cs b/src/Microsoft.AspNet.Server.Testing/Deployers/SelfHostDeployer.cs new file mode 100644 index 0000000000..12252c8829 --- /dev/null +++ b/src/Microsoft.AspNet.Server.Testing/Deployers/SelfHostDeployer.cs @@ -0,0 +1,95 @@ +// 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 System; +using System.Diagnostics; +using System.IO; +using System.Threading; +using Microsoft.Framework.Logging; + +namespace Microsoft.AspNet.Server.Testing +{ + /// + /// Deployer for WebListener and Kestrel. + /// + public class SelfHostDeployer : ApplicationDeployer + { + private Process _hostProcess; + + public SelfHostDeployer(DeploymentParameters deploymentParameters, ILogger logger) + : base(deploymentParameters, logger) + { + } + + public override DeploymentResult Deploy() + { + // Start timer + StartTimer(); + + DeploymentParameters.DnxRuntime = PopulateChosenRuntimeInformation(); + + if (DeploymentParameters.PublishApplicationBeforeDeployment) + { + DnuPublish(); + } + + // Launch the host process. + var hostExitToken = StartSelfHost(); + + return new DeploymentResult + { + WebRootLocation = DeploymentParameters.ApplicationPath, + DeploymentParameters = DeploymentParameters, + ApplicationBaseUri = DeploymentParameters.ApplicationBaseUriHint, + HostShutdownToken = hostExitToken + }; + } + + private CancellationToken StartSelfHost() + { + var commandName = DeploymentParameters.ServerType == ServerType.WebListener ? "web" : "kestrel"; + Logger.LogInformation("Executing dnx.exe {appPath} {command} --server.urls {url}", DeploymentParameters.ApplicationPath, commandName, DeploymentParameters.ApplicationBaseUriHint); + + var startInfo = new ProcessStartInfo + { + FileName = Path.Combine(ChosenRuntimePath, "dnx.exe"), + Arguments = string.Format("\"{0}\" {1} --server.urls {2}", DeploymentParameters.ApplicationPath, commandName, DeploymentParameters.ApplicationBaseUriHint), + UseShellExecute = false, + CreateNoWindow = true + }; + + AddEnvironmentVariablesToProcess(startInfo); + + _hostProcess = Process.Start(startInfo); + _hostProcess.EnableRaisingEvents = true; + var hostExitTokenSource = new CancellationTokenSource(); + _hostProcess.Exited += (sender, e) => + { + TriggerHostShutdown(hostExitTokenSource); + }; + + if (_hostProcess.HasExited) + { + Logger.LogError("Host process {processName} exited with code {exitCode} or failed to start.", startInfo.FileName, _hostProcess.ExitCode); + throw new Exception("Failed to start host"); + } + + Logger.LogInformation("Started {fileName}. Process Id : {processId}", startInfo.FileName, _hostProcess.Id); + return hostExitTokenSource.Token; + } + + public override void Dispose() + { + ShutDownIfAnyHostProcess(_hostProcess); + + if (DeploymentParameters.PublishApplicationBeforeDeployment) + { + CleanPublishedOutput(); + } + + InvokeUserApplicationCleanup(); + + StopTimer(); + } + } +} \ No newline at end of file diff --git a/src/Microsoft.AspNet.Server.Testing/Microsoft.AspNet.Server.Testing.xproj b/src/Microsoft.AspNet.Server.Testing/Microsoft.AspNet.Server.Testing.xproj new file mode 100644 index 0000000000..6d890ba4ec --- /dev/null +++ b/src/Microsoft.AspNet.Server.Testing/Microsoft.AspNet.Server.Testing.xproj @@ -0,0 +1,20 @@ + + + + 14.0 + $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) + + + + 3da89347-6731-4366-80c4-548f24e8607b + + + + + + + + 2.0 + + + \ No newline at end of file diff --git a/src/Microsoft.AspNet.Server.Testing/project.json b/src/Microsoft.AspNet.Server.Testing/project.json new file mode 100644 index 0000000000..c4abcae964 --- /dev/null +++ b/src/Microsoft.AspNet.Server.Testing/project.json @@ -0,0 +1,31 @@ +{ + "version": "1.0.0-*", + "description": "ASP.NET 5 helpers to deploy applications to IIS Express, IIS, WebListener and Kestrel for testing.", + "dependencies": { + "Microsoft.AspNet.Testing": "1.0.0-*", + "Microsoft.Framework.Logging.Interfaces": "1.0.0-*", + "Microsoft.Framework.Runtime.Interfaces": "1.0.0-*" + }, + "frameworks": { + "dnx451": { + "dependencies": { + "Microsoft.Web.Administration": "7.0.0" + }, + "frameworkAssemblies": { + "System.Net.Http": "", + "System.Xml": "" + } + }, + "dnxcore50": { + "dependencies": { + "System.Diagnostics.Process": "4.0.0-beta-*", + "System.IO.FileSystem": "4.0.0-*", + "System.Net.Http": "4.0.0-beta-*", + "System.Runtime.Extensions": "4.0.10-beta-*", + "System.Text.RegularExpressions": "4.0.10-beta-*", + "System.Threading": "4.0.10-beta-*", + "System.Threading.Thread": "4.0.0-*" + } + } + } +} \ No newline at end of file diff --git a/src/Microsoft.AspNet.Server.Testing/xunit/SkipIfCurrentRuntimeIsCoreClr.cs b/src/Microsoft.AspNet.Server.Testing/xunit/SkipIfCurrentRuntimeIsCoreClr.cs new file mode 100644 index 0000000000..7c1d5340aa --- /dev/null +++ b/src/Microsoft.AspNet.Server.Testing/xunit/SkipIfCurrentRuntimeIsCoreClr.cs @@ -0,0 +1,32 @@ +// 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 System; +using System.Diagnostics; +using Microsoft.AspNet.Testing.xunit; + +namespace Microsoft.AspNet.Server.Testing +{ + /// + /// Skips a test if the DNX used to run the test is CoreClr. + /// + [AttributeUsage(AttributeTargets.Method, AllowMultiple = false)] + public class SkipIfCurrentRuntimeIsCoreClrAttribute : Attribute, ITestCondition + { + public bool IsMet + { + get + { + return !Process.GetCurrentProcess().ProcessName.ToLower().Contains("coreclr"); + } + } + + public string SkipReason + { + get + { + return "Cannot run these test variations using CoreCLR DNX as helpers are not available on CoreCLR."; + } + } + } +} diff --git a/src/Microsoft.AspNet.Server.Testing/xunit/SkipIfIISNativeVariationsNotEnabledAttribute.cs b/src/Microsoft.AspNet.Server.Testing/xunit/SkipIfIISNativeVariationsNotEnabledAttribute.cs new file mode 100644 index 0000000000..541fa684bc --- /dev/null +++ b/src/Microsoft.AspNet.Server.Testing/xunit/SkipIfIISNativeVariationsNotEnabledAttribute.cs @@ -0,0 +1,33 @@ +// 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 System; +using Microsoft.AspNet.Testing.xunit; + +namespace Microsoft.AspNet.Server.Testing +{ + /// + /// Skip test if IIS native module is not enabled. To enable setup native module + /// and set environment variable IIS_NATIVE_VARIATIONS_ENABLED=true for the test process. + /// + [AttributeUsage(AttributeTargets.Method, AllowMultiple = false)] + public class SkipIfIISNativeVariationsNotEnabledAttribute : Attribute, ITestCondition + { + public bool IsMet + { + get + { + return Environment.GetEnvironmentVariable("IIS_NATIVE_VARIATIONS_ENABLED") == "true"; + } + } + + public string SkipReason + { + get + { + return "Skipping Native module test since native module variations are not enabled. " + + "To run the test, setup the native module and set the environment variable IIS_NATIVE_VARIATIONS_ENABLED=true."; + } + } + } +} \ No newline at end of file diff --git a/src/Microsoft.AspNet.Server.Testing/xunit/SkipIfIISVariationsNotEnabledAttribute.cs b/src/Microsoft.AspNet.Server.Testing/xunit/SkipIfIISVariationsNotEnabledAttribute.cs new file mode 100644 index 0000000000..dbfcbc5014 --- /dev/null +++ b/src/Microsoft.AspNet.Server.Testing/xunit/SkipIfIISVariationsNotEnabledAttribute.cs @@ -0,0 +1,33 @@ +// 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 System; +using Microsoft.AspNet.Testing.xunit; + +namespace Microsoft.AspNet.Server.Testing +{ + /// + /// Skip test if IIS variations are not enabled. To enable set environment variable + /// IIS_VARIATIONS_ENABLED=true for the test process. + /// + [AttributeUsage(AttributeTargets.Method, AllowMultiple = false)] + public class SkipIfIISVariationsNotEnabledAttribute : Attribute, ITestCondition + { + public bool IsMet + { + get + { + return Environment.GetEnvironmentVariable("IIS_VARIATIONS_ENABLED") == "true"; + } + } + + public string SkipReason + { + get + { + return "Skipping IIS variation of tests. " + + "To run the IIS variations, setup IIS and set the environment variable IIS_VARIATIONS_ENABLED=true."; + } + } + } +} \ No newline at end of file diff --git a/src/Microsoft.AspNet.Server.Testing/xunit/SkipOn32BitOSAttribute.cs b/src/Microsoft.AspNet.Server.Testing/xunit/SkipOn32BitOSAttribute.cs new file mode 100644 index 0000000000..37be266e59 --- /dev/null +++ b/src/Microsoft.AspNet.Server.Testing/xunit/SkipOn32BitOSAttribute.cs @@ -0,0 +1,33 @@ +// 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 System; +using System.IO; +using Microsoft.AspNet.Testing.xunit; + +namespace Microsoft.AspNet.Server.Testing +{ + /// + /// Skips a 64 bit test if the current Windows OS is 32-bit. + /// + [AttributeUsage(AttributeTargets.Method, AllowMultiple = false)] + public class SkipOn32BitOSAttribute : Attribute, ITestCondition + { + public bool IsMet + { + get + { + // Directory found only on 64-bit OS. + return Directory.Exists(Path.Combine(Environment.GetEnvironmentVariable("SystemRoot"), "SysWOW64")); + } + } + + public string SkipReason + { + get + { + return "Skipping the x64 test since Windows is 32-bit"; + } + } + } +} \ No newline at end of file From cd878d57c1fc750299cf3fdb392a2d0e1f65f9c7 Mon Sep 17 00:00:00 2001 From: Praburaj Date: Fri, 17 Apr 2015 18:41:19 -0700 Subject: [PATCH 262/987] Removing some terms to clear the policheck. --- .../Deployers/ApplicationDeployer.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Microsoft.AspNet.Server.Testing/Deployers/ApplicationDeployer.cs b/src/Microsoft.AspNet.Server.Testing/Deployers/ApplicationDeployer.cs index c974840a22..a5505c169c 100644 --- a/src/Microsoft.AspNet.Server.Testing/Deployers/ApplicationDeployer.cs +++ b/src/Microsoft.AspNet.Server.Testing/Deployers/ApplicationDeployer.cs @@ -12,7 +12,7 @@ using Microsoft.Framework.Logging; namespace Microsoft.AspNet.Server.Testing { /// - /// Abstract base class of all deplolyers with a back bone implementation of some of the common helpers. + /// Abstract base class of all deployers with implementation of some of the common helpers. /// public abstract class ApplicationDeployer : IApplicationDeployer { From df6f59a1d1f8e7e9ed30989fe5e7affb7b421a59 Mon Sep 17 00:00:00 2001 From: Praburaj Date: Mon, 20 Apr 2015 10:17:18 -0700 Subject: [PATCH 263/987] Logging the dnx and dnu paths while running selfhost or dnu publish. --- .../Deployers/ApplicationDeployer.cs | 10 ++++++++-- .../Deployers/SelfHostDeployer.cs | 7 +++++-- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Testing/Deployers/ApplicationDeployer.cs b/src/Microsoft.AspNet.Server.Testing/Deployers/ApplicationDeployer.cs index a5505c169c..27c1ff131c 100644 --- a/src/Microsoft.AspNet.Server.Testing/Deployers/ApplicationDeployer.cs +++ b/src/Microsoft.AspNet.Server.Testing/Deployers/ApplicationDeployer.cs @@ -78,11 +78,12 @@ namespace Microsoft.AspNet.Server.Testing DeploymentParameters.DnxRuntime, DeploymentParameters.PublishWithNoSource ? "--no-source" : string.Empty); - Logger.LogInformation("Executing command dnu {args}", parameters); + var dnuPath = Path.Combine(ChosenRuntimePath, "dnu.cmd"); + Logger.LogInformation("Executing command {dnu} {args}", dnuPath, parameters); var startInfo = new ProcessStartInfo { - FileName = Path.Combine(ChosenRuntimePath, "dnu.cmd"), + FileName = dnuPath, Arguments = parameters, UseShellExecute = false, CreateNoWindow = true @@ -91,6 +92,11 @@ namespace Microsoft.AspNet.Server.Testing var hostProcess = Process.Start(startInfo); hostProcess.WaitForExit(60 * 1000); + if (hostProcess.ExitCode != 0) + { + throw new Exception("dnu publish exited with exit code : {0}"); + } + DeploymentParameters.ApplicationPath = (DeploymentParameters.ServerType == ServerType.IISExpress || DeploymentParameters.ServerType == ServerType.IISNativeModule || diff --git a/src/Microsoft.AspNet.Server.Testing/Deployers/SelfHostDeployer.cs b/src/Microsoft.AspNet.Server.Testing/Deployers/SelfHostDeployer.cs index 12252c8829..246e0ee3a6 100644 --- a/src/Microsoft.AspNet.Server.Testing/Deployers/SelfHostDeployer.cs +++ b/src/Microsoft.AspNet.Server.Testing/Deployers/SelfHostDeployer.cs @@ -48,11 +48,14 @@ namespace Microsoft.AspNet.Server.Testing private CancellationToken StartSelfHost() { var commandName = DeploymentParameters.ServerType == ServerType.WebListener ? "web" : "kestrel"; - Logger.LogInformation("Executing dnx.exe {appPath} {command} --server.urls {url}", DeploymentParameters.ApplicationPath, commandName, DeploymentParameters.ApplicationBaseUriHint); + var dnxPath = Path.Combine(ChosenRuntimePath, "dnx.exe"); + Logger.LogInformation("Executing {dnxexe} {appPath} {command} --server.urls {url}", + dnxPath, DeploymentParameters.ApplicationPath, + commandName, DeploymentParameters.ApplicationBaseUriHint); var startInfo = new ProcessStartInfo { - FileName = Path.Combine(ChosenRuntimePath, "dnx.exe"), + FileName = dnxPath, Arguments = string.Format("\"{0}\" {1} --server.urls {2}", DeploymentParameters.ApplicationPath, commandName, DeploymentParameters.ApplicationBaseUriHint), UseShellExecute = false, CreateNoWindow = true From 0ab04fd319934f39ee922fd70ed1e991bb8a3a23 Mon Sep 17 00:00:00 2001 From: Praburaj Date: Mon, 20 Apr 2015 10:25:53 -0700 Subject: [PATCH 264/987] Setting exit code in exception message. --- .../Deployers/ApplicationDeployer.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Microsoft.AspNet.Server.Testing/Deployers/ApplicationDeployer.cs b/src/Microsoft.AspNet.Server.Testing/Deployers/ApplicationDeployer.cs index 27c1ff131c..94c3d4a0c7 100644 --- a/src/Microsoft.AspNet.Server.Testing/Deployers/ApplicationDeployer.cs +++ b/src/Microsoft.AspNet.Server.Testing/Deployers/ApplicationDeployer.cs @@ -94,7 +94,7 @@ namespace Microsoft.AspNet.Server.Testing if (hostProcess.ExitCode != 0) { - throw new Exception("dnu publish exited with exit code : {0}"); + throw new Exception(string.Format("dnu publish exited with exit code : {0}", hostProcess.ExitCode)); } DeploymentParameters.ApplicationPath = From 0e9f876d4e890ec1a43c621409371d473b25e7ca Mon Sep 17 00:00:00 2001 From: Praburaj Date: Mon, 20 Apr 2015 11:11:00 -0700 Subject: [PATCH 265/987] Removing timeout for dnu publish Sometimes on slower machines that it takes more than this time especially when -no-source is turned on. --- .../Deployers/ApplicationDeployer.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Microsoft.AspNet.Server.Testing/Deployers/ApplicationDeployer.cs b/src/Microsoft.AspNet.Server.Testing/Deployers/ApplicationDeployer.cs index 94c3d4a0c7..409c5b6887 100644 --- a/src/Microsoft.AspNet.Server.Testing/Deployers/ApplicationDeployer.cs +++ b/src/Microsoft.AspNet.Server.Testing/Deployers/ApplicationDeployer.cs @@ -90,7 +90,7 @@ namespace Microsoft.AspNet.Server.Testing }; var hostProcess = Process.Start(startInfo); - hostProcess.WaitForExit(60 * 1000); + hostProcess.WaitForExit(); if (hostProcess.ExitCode != 0) { From 78e9ef27825e96f946a19f6fbc6cf7fc89cddfdf Mon Sep 17 00:00:00 2001 From: Praburaj Date: Mon, 20 Apr 2015 13:51:00 -0700 Subject: [PATCH 266/987] Add more logging while starting dnx.exe or dnu.cmd --- .../Deployers/ApplicationDeployer.cs | 2 +- .../Deployers/SelfHostDeployer.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Testing/Deployers/ApplicationDeployer.cs b/src/Microsoft.AspNet.Server.Testing/Deployers/ApplicationDeployer.cs index 409c5b6887..e562df8492 100644 --- a/src/Microsoft.AspNet.Server.Testing/Deployers/ApplicationDeployer.cs +++ b/src/Microsoft.AspNet.Server.Testing/Deployers/ApplicationDeployer.cs @@ -86,7 +86,7 @@ namespace Microsoft.AspNet.Server.Testing FileName = dnuPath, Arguments = parameters, UseShellExecute = false, - CreateNoWindow = true + CreateNoWindow = false }; var hostProcess = Process.Start(startInfo); diff --git a/src/Microsoft.AspNet.Server.Testing/Deployers/SelfHostDeployer.cs b/src/Microsoft.AspNet.Server.Testing/Deployers/SelfHostDeployer.cs index 246e0ee3a6..5e971664f0 100644 --- a/src/Microsoft.AspNet.Server.Testing/Deployers/SelfHostDeployer.cs +++ b/src/Microsoft.AspNet.Server.Testing/Deployers/SelfHostDeployer.cs @@ -58,7 +58,7 @@ namespace Microsoft.AspNet.Server.Testing FileName = dnxPath, Arguments = string.Format("\"{0}\" {1} --server.urls {2}", DeploymentParameters.ApplicationPath, commandName, DeploymentParameters.ApplicationBaseUriHint), UseShellExecute = false, - CreateNoWindow = true + CreateNoWindow = false }; AddEnvironmentVariablesToProcess(startInfo); From f3a4cf0ea7500a4ab84840a2aecdfe2d2a338c93 Mon Sep 17 00:00:00 2001 From: Praburaj Date: Mon, 20 Apr 2015 16:00:47 -0700 Subject: [PATCH 267/987] Fixing the CreateNoWindow=false issue on selfhost When CreateNoWindow is set to false, I see the selfhost process exiting immediately after start due to https://github.com/aspnet/Hosting/issues/140. To fix this I'm manually redirecting the stderror and stdoutput streams so test runs will have necessary logs. --- .../Deployers/SelfHostDeployer.cs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/Microsoft.AspNet.Server.Testing/Deployers/SelfHostDeployer.cs b/src/Microsoft.AspNet.Server.Testing/Deployers/SelfHostDeployer.cs index 5e971664f0..fe27167442 100644 --- a/src/Microsoft.AspNet.Server.Testing/Deployers/SelfHostDeployer.cs +++ b/src/Microsoft.AspNet.Server.Testing/Deployers/SelfHostDeployer.cs @@ -58,12 +58,19 @@ namespace Microsoft.AspNet.Server.Testing FileName = dnxPath, Arguments = string.Format("\"{0}\" {1} --server.urls {2}", DeploymentParameters.ApplicationPath, commandName, DeploymentParameters.ApplicationBaseUriHint), UseShellExecute = false, - CreateNoWindow = false + // https://github.com/aspnet/Hosting/issues/140 causing host process to exit when this is made false. + CreateNoWindow = true, + RedirectStandardError = true, + RedirectStandardOutput = true }; AddEnvironmentVariablesToProcess(startInfo); _hostProcess = Process.Start(startInfo); + _hostProcess.BeginErrorReadLine(); + _hostProcess.BeginOutputReadLine(); + _hostProcess.ErrorDataReceived += (sender, dataArgs) => { Logger.LogError(dataArgs.Data); }; + _hostProcess.OutputDataReceived += (sender, dataArgs) => { Logger.LogInformation(dataArgs.Data); }; _hostProcess.EnableRaisingEvents = true; var hostExitTokenSource = new CancellationTokenSource(); _hostProcess.Exited += (sender, e) => From f92b1f36e1a082322ac816708b2103378578ef87 Mon Sep 17 00:00:00 2001 From: Praburaj Date: Mon, 20 Apr 2015 16:19:56 -0700 Subject: [PATCH 268/987] Redirecting output for all process starts to see correlation in logs. --- .../Deployers/ApplicationDeployer.cs | 11 +++++++++-- .../Deployers/IISExpressDeployer.cs | 11 +++++++++-- .../Deployers/SelfHostDeployer.cs | 8 ++++---- 3 files changed, 22 insertions(+), 8 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Testing/Deployers/ApplicationDeployer.cs b/src/Microsoft.AspNet.Server.Testing/Deployers/ApplicationDeployer.cs index e562df8492..e3f1531052 100644 --- a/src/Microsoft.AspNet.Server.Testing/Deployers/ApplicationDeployer.cs +++ b/src/Microsoft.AspNet.Server.Testing/Deployers/ApplicationDeployer.cs @@ -86,10 +86,17 @@ namespace Microsoft.AspNet.Server.Testing FileName = dnuPath, Arguments = parameters, UseShellExecute = false, - CreateNoWindow = false + CreateNoWindow = true, + RedirectStandardError = true, + RedirectStandardOutput = true }; - var hostProcess = Process.Start(startInfo); + var hostProcess = new Process() { StartInfo = startInfo }; + hostProcess.ErrorDataReceived += (sender, dataArgs) => { Logger.LogError(dataArgs.Data); }; + hostProcess.OutputDataReceived += (sender, dataArgs) => { Logger.LogInformation(dataArgs.Data); }; + hostProcess.Start(); + hostProcess.BeginErrorReadLine(); + hostProcess.BeginOutputReadLine(); hostProcess.WaitForExit(); if (hostProcess.ExitCode != 0) diff --git a/src/Microsoft.AspNet.Server.Testing/Deployers/IISExpressDeployer.cs b/src/Microsoft.AspNet.Server.Testing/Deployers/IISExpressDeployer.cs index 30dc94bfdc..25cf0e7012 100644 --- a/src/Microsoft.AspNet.Server.Testing/Deployers/IISExpressDeployer.cs +++ b/src/Microsoft.AspNet.Server.Testing/Deployers/IISExpressDeployer.cs @@ -90,7 +90,9 @@ namespace Microsoft.AspNet.Server.Testing FileName = iisExpressPath, Arguments = parameters, UseShellExecute = false, - CreateNoWindow = false + CreateNoWindow = true, + RedirectStandardError = true, + RedirectStandardOutput = true }; AddEnvironmentVariablesToProcess(startInfo); @@ -104,13 +106,18 @@ namespace Microsoft.AspNet.Server.Testing SetEnvironmentVariable(startInfo.Environment, "DNX_APPBASE", DeploymentParameters.ApplicationPath); #endif - _hostProcess = Process.Start(startInfo); + _hostProcess = new Process() { StartInfo = startInfo }; + _hostProcess.ErrorDataReceived += (sender, dataArgs) => { Logger.LogError(dataArgs.Data); }; + _hostProcess.OutputDataReceived += (sender, dataArgs) => { Logger.LogInformation(dataArgs.Data); }; _hostProcess.EnableRaisingEvents = true; var hostExitTokenSource = new CancellationTokenSource(); _hostProcess.Exited += (sender, e) => { TriggerHostShutdown(hostExitTokenSource); }; + _hostProcess.Start(); + _hostProcess.BeginErrorReadLine(); + _hostProcess.BeginOutputReadLine(); if (_hostProcess.HasExited) { diff --git a/src/Microsoft.AspNet.Server.Testing/Deployers/SelfHostDeployer.cs b/src/Microsoft.AspNet.Server.Testing/Deployers/SelfHostDeployer.cs index fe27167442..9663bc9ed6 100644 --- a/src/Microsoft.AspNet.Server.Testing/Deployers/SelfHostDeployer.cs +++ b/src/Microsoft.AspNet.Server.Testing/Deployers/SelfHostDeployer.cs @@ -58,7 +58,6 @@ namespace Microsoft.AspNet.Server.Testing FileName = dnxPath, Arguments = string.Format("\"{0}\" {1} --server.urls {2}", DeploymentParameters.ApplicationPath, commandName, DeploymentParameters.ApplicationBaseUriHint), UseShellExecute = false, - // https://github.com/aspnet/Hosting/issues/140 causing host process to exit when this is made false. CreateNoWindow = true, RedirectStandardError = true, RedirectStandardOutput = true @@ -66,9 +65,7 @@ namespace Microsoft.AspNet.Server.Testing AddEnvironmentVariablesToProcess(startInfo); - _hostProcess = Process.Start(startInfo); - _hostProcess.BeginErrorReadLine(); - _hostProcess.BeginOutputReadLine(); + _hostProcess = new Process() { StartInfo = startInfo }; _hostProcess.ErrorDataReceived += (sender, dataArgs) => { Logger.LogError(dataArgs.Data); }; _hostProcess.OutputDataReceived += (sender, dataArgs) => { Logger.LogInformation(dataArgs.Data); }; _hostProcess.EnableRaisingEvents = true; @@ -77,6 +74,9 @@ namespace Microsoft.AspNet.Server.Testing { TriggerHostShutdown(hostExitTokenSource); }; + _hostProcess.Start(); + _hostProcess.BeginErrorReadLine(); + _hostProcess.BeginOutputReadLine(); if (_hostProcess.HasExited) { From 1a4dc9488adbfe6b954eb1387c11df2c9e898731 Mon Sep 17 00:00:00 2001 From: Praburaj Date: Mon, 20 Apr 2015 16:48:37 -0700 Subject: [PATCH 269/987] Trying to redirect the stdinput as well to see if this succeeds on CI --- .../Deployers/SelfHostDeployer.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Microsoft.AspNet.Server.Testing/Deployers/SelfHostDeployer.cs b/src/Microsoft.AspNet.Server.Testing/Deployers/SelfHostDeployer.cs index 9663bc9ed6..3d366241b5 100644 --- a/src/Microsoft.AspNet.Server.Testing/Deployers/SelfHostDeployer.cs +++ b/src/Microsoft.AspNet.Server.Testing/Deployers/SelfHostDeployer.cs @@ -60,7 +60,9 @@ namespace Microsoft.AspNet.Server.Testing UseShellExecute = false, CreateNoWindow = true, RedirectStandardError = true, - RedirectStandardOutput = true + RedirectStandardOutput = true, + // Trying a work around for https://github.com/aspnet/Hosting/issues/140. + RedirectStandardInput = true }; AddEnvironmentVariablesToProcess(startInfo); From 5fac18b4184e0eb2effe519242271bf4cdc3cea5 Mon Sep 17 00:00:00 2001 From: Chris Ross Date: Fri, 17 Apr 2015 12:18:50 -0700 Subject: [PATCH 270/987] HttpAbstractions#265 - Remove IApplicationBuilder.Server setter. --- .../Builder/ApplicationBuilderFactory.cs | 4 +-- .../Builder/IApplicationBuilderFactory.cs | 2 +- src/Microsoft.AspNet.Hosting/HostingEngine.cs | 25 +++++++++---------- 3 files changed, 15 insertions(+), 16 deletions(-) diff --git a/src/Microsoft.AspNet.Hosting/Builder/ApplicationBuilderFactory.cs b/src/Microsoft.AspNet.Hosting/Builder/ApplicationBuilderFactory.cs index 7bf1f59c23..acefa86bc7 100644 --- a/src/Microsoft.AspNet.Hosting/Builder/ApplicationBuilderFactory.cs +++ b/src/Microsoft.AspNet.Hosting/Builder/ApplicationBuilderFactory.cs @@ -15,9 +15,9 @@ namespace Microsoft.AspNet.Hosting.Builder _serviceProvider = serviceProvider; } - public IApplicationBuilder CreateBuilder() + public IApplicationBuilder CreateBuilder(object server) { - return new ApplicationBuilder(_serviceProvider); + return new ApplicationBuilder(_serviceProvider, server); } } } diff --git a/src/Microsoft.AspNet.Hosting/Builder/IApplicationBuilderFactory.cs b/src/Microsoft.AspNet.Hosting/Builder/IApplicationBuilderFactory.cs index 45194717bc..c866b2d79d 100644 --- a/src/Microsoft.AspNet.Hosting/Builder/IApplicationBuilderFactory.cs +++ b/src/Microsoft.AspNet.Hosting/Builder/IApplicationBuilderFactory.cs @@ -7,6 +7,6 @@ namespace Microsoft.AspNet.Hosting.Builder { public interface IApplicationBuilderFactory { - IApplicationBuilder CreateBuilder(); + IApplicationBuilder CreateBuilder(object server); } } \ No newline at end of file diff --git a/src/Microsoft.AspNet.Hosting/HostingEngine.cs b/src/Microsoft.AspNet.Hosting/HostingEngine.cs index 0f6826737c..4369057f46 100644 --- a/src/Microsoft.AspNet.Hosting/HostingEngine.cs +++ b/src/Microsoft.AspNet.Hosting/HostingEngine.cs @@ -51,8 +51,8 @@ namespace Microsoft.AspNet.Hosting public virtual IDisposable Start() { EnsureApplicationServices(); - EnsureBuilder(); EnsureServer(); + EnsureBuilder(); var applicationDelegate = BuildApplicationDelegate(); @@ -105,17 +105,6 @@ namespace Microsoft.AspNet.Hosting } } - private void EnsureBuilder() - { - if (_builderFactory == null) - { - _builderFactory = _applicationServices.GetRequiredService(); - } - - _builder = _builderFactory.CreateBuilder(); - _builder.ApplicationServices = _applicationServices; - } - private void EnsureServer() { if (_serverFactory == null) @@ -130,7 +119,17 @@ namespace Microsoft.AspNet.Hosting } _serverInstance = _serverFactory.Initialize(_config); - _builder.Server = _serverInstance; + } + + private void EnsureBuilder() + { + if (_builderFactory == null) + { + _builderFactory = _applicationServices.GetRequiredService(); + } + + _builder = _builderFactory.CreateBuilder(_serverInstance); + _builder.ApplicationServices = _applicationServices; } private RequestDelegate BuildApplicationDelegate() From d270525fde695ff0efed1a38c369402e92956bc0 Mon Sep 17 00:00:00 2001 From: Kiran Challa Date: Wed, 25 Mar 2015 11:08:58 -0700 Subject: [PATCH 271/987] Create a logging scope having request id --- .../DefaultRequestIdentifierFeature.cs | 18 +++ src/Microsoft.AspNet.Hosting/HostingEngine.cs | 37 +++-- .../HostingEngineTests.cs | 134 ++++++++++++++++++ .../project.json | 1 + 4 files changed, 182 insertions(+), 8 deletions(-) create mode 100644 src/Microsoft.AspNet.Hosting/DefaultRequestIdentifierFeature.cs diff --git a/src/Microsoft.AspNet.Hosting/DefaultRequestIdentifierFeature.cs b/src/Microsoft.AspNet.Hosting/DefaultRequestIdentifierFeature.cs new file mode 100644 index 0000000000..6baca0975d --- /dev/null +++ b/src/Microsoft.AspNet.Hosting/DefaultRequestIdentifierFeature.cs @@ -0,0 +1,18 @@ +// 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 System; +using Microsoft.AspNet.Http; + +namespace Microsoft.AspNet.Hosting +{ + public class DefaultRequestIdentifierFeature : IRequestIdentifierFeature + { + public DefaultRequestIdentifierFeature() + { + TraceIdentifier = Guid.NewGuid(); + } + + public Guid TraceIdentifier { get; } + } +} diff --git a/src/Microsoft.AspNet.Hosting/HostingEngine.cs b/src/Microsoft.AspNet.Hosting/HostingEngine.cs index 4369057f46..4889150d04 100644 --- a/src/Microsoft.AspNet.Hosting/HostingEngine.cs +++ b/src/Microsoft.AspNet.Hosting/HostingEngine.cs @@ -6,11 +6,14 @@ using System.Collections.Generic; using System.Linq; using System.Threading; using Microsoft.AspNet.Builder; +using Microsoft.AspNet.FeatureModel; using Microsoft.AspNet.Hosting.Builder; using Microsoft.AspNet.Hosting.Server; using Microsoft.AspNet.Hosting.Startup; +using Microsoft.AspNet.Http; using Microsoft.Framework.ConfigurationModel; using Microsoft.Framework.DependencyInjection; +using Microsoft.Framework.Logging; namespace Microsoft.AspNet.Hosting { @@ -24,7 +27,7 @@ namespace Microsoft.AspNet.Hosting // Start/ApplicationServices block use methods private bool _useDisabled; - + private IApplicationBuilderFactory _builderFactory; private IApplicationBuilder _builder; private IServiceProvider _applicationServices; @@ -56,14 +59,20 @@ namespace Microsoft.AspNet.Hosting var applicationDelegate = BuildApplicationDelegate(); - var _contextFactory = _applicationServices.GetRequiredService(); - var _contextAccessor = _applicationServices.GetRequiredService(); + var logger = _applicationServices.GetRequiredService>(); + var contextFactory = _applicationServices.GetRequiredService(); + var contextAccessor = _applicationServices.GetRequiredService(); var server = _serverFactory.Start(_serverInstance, - features => + async features => { - var httpContext = _contextFactory.CreateHttpContext(features); - _contextAccessor.HttpContext = httpContext; - return applicationDelegate(httpContext); + var httpContext = contextFactory.CreateHttpContext(features); + var requestIdentifier = GetRequestIdentifier(httpContext); + + using (logger.BeginScope("Request Id: {RequestId}", requestIdentifier)) + { + contextAccessor.HttpContext = httpContext; + await applicationDelegate(httpContext); + } }); return new Disposable(() => @@ -163,6 +172,18 @@ namespace Microsoft.AspNet.Hosting } } + private Guid GetRequestIdentifier(HttpContext httpContext) + { + var requestIdentifierFeature = httpContext.GetFeature(); + if (requestIdentifierFeature == null) + { + requestIdentifierFeature = new DefaultRequestIdentifierFeature(); + httpContext.SetFeature(requestIdentifierFeature); + } + + return requestIdentifierFeature.TraceIdentifier; + } + // Consider cutting public IHostingEngine UseEnvironment(string environment) { @@ -207,7 +228,7 @@ namespace Microsoft.AspNet.Hosting public IHostingEngine UseStartup(Action configureApp, Action configureServices) { CheckUseAllowed(); - _startup = new StartupMethods(configureApp, + _startup = new StartupMethods(configureApp, services => { if (configureServices != null) { diff --git a/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs b/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs index 01de9f14ed..07d946e490 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs @@ -7,12 +7,16 @@ using System.IO; using System.Threading.Tasks; using Microsoft.AspNet.Builder; using Microsoft.AspNet.FeatureModel; +using Microsoft.AspNet.Hosting.Builder; using Microsoft.AspNet.Hosting.Server; using Microsoft.AspNet.Hosting.Startup; +using Microsoft.AspNet.Http; using Microsoft.AspNet.Testing.xunit; using Microsoft.Framework.ConfigurationModel; using Microsoft.Framework.DependencyInjection; +using Microsoft.Framework.Logging; using Microsoft.Framework.OptionsModel; +using Moq; using Xunit; namespace Microsoft.AspNet.Hosting @@ -150,6 +154,115 @@ namespace Microsoft.AspNet.Hosting RunMapPath(virtualPath, expectedSuffix); } + [Fact] + public void HostingEngine_CreatesDefaultRequestIdentifierFeature_IfNotPresent() + { + // Arrange + HttpContext httpContext = null; + var requestDelegate = new RequestDelegate(innerHttpContext => + { + httpContext = innerHttpContext; + return Task.FromResult(0); + }); + var featuresSupportedByHost = new FeatureCollection(); + var hostingEngine = CreateHostingEngine(featuresSupportedByHost, requestDelegate); + + // Act + var disposable = hostingEngine.Start(); + + // Assert + Assert.NotNull(httpContext); + Assert.IsType(httpContext.GetFeature()); + } + + [Fact] + public void Hosting_CreatesDefaultRequestIdentifierFeature_IfNotPresent_ForImmutableFeatureCollection() + { + // Arrange + HttpContext httpContext = null; + var requestDelegate = new RequestDelegate(innerHttpContext => + { + httpContext = innerHttpContext; + return Task.FromResult(0); + }); + var featuresSupportedByHost = new Mock(); + featuresSupportedByHost + .Setup(fc => fc.Add(It.IsAny(), It.IsAny())) + .Throws(new NotImplementedException()); + featuresSupportedByHost + .Setup(fc => fc.Add(new KeyValuePair(It.IsAny(), It.IsAny()))) + .Throws(new NotImplementedException()); + var hostingEngine = CreateHostingEngine(featuresSupportedByHost.Object, requestDelegate); + + // Act + var disposable = hostingEngine.Start(); + + // Assert + Assert.NotNull(httpContext); + Assert.IsType(httpContext.GetFeature()); + } + + [Fact] + public void HostingEngine_DoesNot_CreateDefaultRequestIdentifierFeature_IfPresent() + { + // Arrange + HttpContext httpContext = null; + var requestDelegate = new RequestDelegate(innerHttpContext => + { + httpContext = innerHttpContext; + return Task.FromResult(0); + }); + var featuresSupportedByHost = new FeatureCollection(); + var requestIdentifierFeature = new Mock().Object; + featuresSupportedByHost.Add(typeof(IRequestIdentifierFeature), requestIdentifierFeature); + var hostingEngine = CreateHostingEngine(featuresSupportedByHost, requestDelegate); + + // Act + var disposable = hostingEngine.Start(); + + // Assert + Assert.NotNull(httpContext); + Assert.Same(requestIdentifierFeature, httpContext.GetFeature()); + } + + private IHostingEngine CreateHostingEngine( + IFeatureCollection featuresSupportedByHost, + RequestDelegate requestDelegate) + { + var applicationBuilder = new Mock(); + applicationBuilder.Setup(appBuilder => appBuilder.Build()).Returns(requestDelegate); + var applicationBuilderFactory = new Mock(); + applicationBuilderFactory + .Setup(abf => abf.CreateBuilder(It.IsAny())) + .Returns(applicationBuilder.Object); + + var serviceCollection = new ServiceCollection(); + serviceCollection.Add( + new ServiceDescriptor(typeof(IApplicationBuilderFactory), applicationBuilderFactory.Object)); + serviceCollection.Add( + new ServiceDescriptor(typeof(ILogger), new Mock>().Object)); + serviceCollection.Add( + new ServiceDescriptor(typeof(IHttpContextFactory), new HttpContextFactory())); + serviceCollection.Add( + new ServiceDescriptor(typeof(IHttpContextAccessor), new Mock().Object)); + + var startupLoader = new Mock(); + var startupMethods = new StartupMethods( + (appBuilder) => { }, + (configureServices) => configureServices.BuildServiceProvider()); + startupLoader.Setup(sl => sl.Load(It.IsAny(), It.IsAny(), It.IsAny>())) + .Returns(startupMethods); + + var hostingEngine = new HostingEngine( + serviceCollection, + startupLoader.Object, + new Mock().Object, + new Mock().Object, + "TestAppName"); + + return hostingEngine.UseServer(new TestServerFactory(featuresSupportedByHost)); + } + private void RunMapPath(string virtualPath, string expectedSuffix) { var engine = WebHost.CreateEngine().UseServer(this); @@ -207,5 +320,26 @@ namespace Microsoft.AspNet.Hosting throw new NotImplementedException(); } } + + private class TestServerFactory : IServerFactory + { + private readonly IFeatureCollection _featuresSupportedByThisHost; + + public TestServerFactory(IFeatureCollection featuresSupportedByThisHost) + { + _featuresSupportedByThisHost = featuresSupportedByThisHost; + } + + public IServerInformation Initialize(IConfiguration configuration) + { + return null; + } + + public IDisposable Start(IServerInformation serverInformation, Func application) + { + application(_featuresSupportedByThisHost).Wait(); + return null; + } + } } } diff --git a/test/Microsoft.AspNet.Hosting.Tests/project.json b/test/Microsoft.AspNet.Hosting.Tests/project.json index 0d307555cb..de8dbc8b81 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/project.json +++ b/test/Microsoft.AspNet.Hosting.Tests/project.json @@ -5,6 +5,7 @@ "Microsoft.AspNet.Testing": "1.0.0-*", "Microsoft.Framework.OptionsModel": "1.0.0-*", "Microsoft.Framework.Runtime.Interfaces": "1.0.0-*", + "Moq": "4.2.1312.1622", "xunit.runner.aspnet": "2.0.0-aspnet-*" }, "frameworks": { From 1248c7a76b7067fe655011505f90d06dc49fa74b Mon Sep 17 00:00:00 2001 From: Praburaj Date: Tue, 21 Apr 2015 11:35:14 -0700 Subject: [PATCH 272/987] Assigning application pool runtime version to 4.0.30319 explicitly I'm noticing that leaving it to an empty value defaults to 4.0 runtime on Win8.1 and above. But on downlevel OSes this defaults to v2.0 app pool resulting in errors. Always assigning the app pool version explicitly. --- .../Deployers/IISDeployer.cs | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Testing/Deployers/IISDeployer.cs b/src/Microsoft.AspNet.Server.Testing/Deployers/IISDeployer.cs index bdc5ac70c6..45749a82ba 100644 --- a/src/Microsoft.AspNet.Server.Testing/Deployers/IISDeployer.cs +++ b/src/Microsoft.AspNet.Server.Testing/Deployers/IISDeployer.cs @@ -117,8 +117,9 @@ namespace Microsoft.AspNet.Server.Testing private class IISApplication { - private const string WEBSITE_NAME = "ASPNETTESTRUNS"; - private const string NATIVE_MODULE_MANAGED_RUNTIME_VERSION = "vCoreFX"; + private const string WebSiteName = "ASPNETTESTRUNS"; + private const string NativeModuleManagedRuntimeVersion = "vCoreFX"; + private const string Dotnet45RuntimeVersion = "v4.0.30319"; private readonly ServerManager _serverManager = new ServerManager(); private readonly DeploymentParameters _deploymentParameters; @@ -139,7 +140,7 @@ namespace Microsoft.AspNet.Server.Testing return Path.Combine( Environment.GetEnvironmentVariable("SystemDrive") + @"\", "inetpub", - WEBSITE_NAME); + WebSiteName); } } @@ -162,10 +163,10 @@ namespace Microsoft.AspNet.Server.Testing { get { - _website = _serverManager.Sites.Where(s => s.Name == WEBSITE_NAME).FirstOrDefault(); + _website = _serverManager.Sites.Where(s => s.Name == WebSiteName).FirstOrDefault(); if (_website == null) { - _website = _serverManager.Sites.Add(WEBSITE_NAME, WebSiteRootFolder, Port); + _website = _serverManager.Sites.Add(WebSiteName, WebSiteRootFolder, Port); } return _website; @@ -175,11 +176,10 @@ namespace Microsoft.AspNet.Server.Testing private ApplicationPool CreateAppPool(string appPoolName) { var applicationPool = _serverManager.ApplicationPools.Add(appPoolName); - if (_deploymentParameters.ServerType == ServerType.IISNativeModule) - { - // Not assigning a runtime version will choose v4.0 default. - applicationPool.ManagedRuntimeVersion = NATIVE_MODULE_MANAGED_RUNTIME_VERSION; - } + applicationPool.ManagedRuntimeVersion = + _deploymentParameters.ServerType == ServerType.IISNativeModule ? + NativeModuleManagedRuntimeVersion : + Dotnet45RuntimeVersion; applicationPool.Enable32BitAppOnWin64 = (_deploymentParameters.RuntimeArchitecture == RuntimeArchitecture.x86); _logger.LogInformation("Created {bit} application pool '{name}' with runtime version {runtime}.", From 663bf4f0f95bb09832182d83e914c05f29eb2900 Mon Sep 17 00:00:00 2001 From: Chris Ross Date: Thu, 23 Apr 2015 11:59:17 -0700 Subject: [PATCH 273/987] Handle FileProviders package rename. --- src/Microsoft.AspNet.Hosting/project.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Microsoft.AspNet.Hosting/project.json b/src/Microsoft.AspNet.Hosting/project.json index 8253c2503b..68028eeede 100644 --- a/src/Microsoft.AspNet.Hosting/project.json +++ b/src/Microsoft.AspNet.Hosting/project.json @@ -3,7 +3,7 @@ "description": "ASP.NET 5 core hosting infrastructure and startup logic for web applications.", "compilationOptions": { "warningsAsErrors": "true" }, "dependencies": { - "Microsoft.AspNet.FileProviders": "1.0.0-*", + "Microsoft.AspNet.FileProviders.Physical": "1.0.0-*", "Microsoft.AspNet.Hosting.Interfaces": "1.0.0-*", "Microsoft.AspNet.Hosting.Server.Interfaces": "1.0.0-*", "Microsoft.AspNet.Http": "1.0.0-*", From 234bbf82f2329e1ce2092962264ba5d4567d115b Mon Sep 17 00:00:00 2001 From: Hao Kung Date: Thu, 23 Apr 2015 23:51:29 -0700 Subject: [PATCH 274/987] Hosting API Review changes - Introduce WebHostBuilder --- src/Microsoft.AspNet.Hosting/HostingEngine.cs | 257 ------------------ .../HostingFactory.cs | 35 --- .../IHostingEngine.cs | 32 --- .../IHostingFactory.cs | 12 - .../Internal/HostingEngine.cs | 184 +++++++++++++ .../Internal/IHostingEngine.cs | 15 + ...RootHostingServiceCollectionInitializer.cs | 66 ----- src/Microsoft.AspNet.Hosting/Program.cs | 20 +- .../Startup/IStartupLoader.cs | 7 +- .../Startup/StartupLoader.cs | 16 +- src/Microsoft.AspNet.Hosting/WebHost.cs | 63 ----- .../WebHostBuilder.cs | 189 +++++++++++++ src/Microsoft.AspNet.Hosting/project.json | 1 + src/Microsoft.AspNet.TestHost/TestServer.cs | 86 ++---- .../TestServerBuilder.cs | 126 --------- .../HostingEngineTests.cs | 185 +++++++------ .../StartupManagerTests.cs | 39 ++- .../TestServerTests.cs | 60 +--- 18 files changed, 566 insertions(+), 827 deletions(-) delete mode 100644 src/Microsoft.AspNet.Hosting/HostingEngine.cs delete mode 100644 src/Microsoft.AspNet.Hosting/HostingFactory.cs delete mode 100644 src/Microsoft.AspNet.Hosting/IHostingEngine.cs delete mode 100644 src/Microsoft.AspNet.Hosting/IHostingFactory.cs create mode 100644 src/Microsoft.AspNet.Hosting/Internal/HostingEngine.cs create mode 100644 src/Microsoft.AspNet.Hosting/Internal/IHostingEngine.cs delete mode 100644 src/Microsoft.AspNet.Hosting/Internal/RootHostingServiceCollectionInitializer.cs delete mode 100644 src/Microsoft.AspNet.Hosting/WebHost.cs create mode 100644 src/Microsoft.AspNet.Hosting/WebHostBuilder.cs delete mode 100644 src/Microsoft.AspNet.TestHost/TestServerBuilder.cs diff --git a/src/Microsoft.AspNet.Hosting/HostingEngine.cs b/src/Microsoft.AspNet.Hosting/HostingEngine.cs deleted file mode 100644 index 4889150d04..0000000000 --- a/src/Microsoft.AspNet.Hosting/HostingEngine.cs +++ /dev/null @@ -1,257 +0,0 @@ -// 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 System; -using System.Collections.Generic; -using System.Linq; -using System.Threading; -using Microsoft.AspNet.Builder; -using Microsoft.AspNet.FeatureModel; -using Microsoft.AspNet.Hosting.Builder; -using Microsoft.AspNet.Hosting.Server; -using Microsoft.AspNet.Hosting.Startup; -using Microsoft.AspNet.Http; -using Microsoft.Framework.ConfigurationModel; -using Microsoft.Framework.DependencyInjection; -using Microsoft.Framework.Logging; - -namespace Microsoft.AspNet.Hosting -{ - public class HostingEngine : IHostingEngine - { - private readonly IServiceCollection _applicationServiceCollection; - private readonly IStartupLoader _startupLoader; - private readonly ApplicationLifetime _applicationLifetime; - private readonly IHostingEnvironment _hostingEnvironment; - private readonly IConfiguration _config; - - // Start/ApplicationServices block use methods - private bool _useDisabled; - - private IApplicationBuilderFactory _builderFactory; - private IApplicationBuilder _builder; - private IServiceProvider _applicationServices; - - // Only one of these should be set - private string _startupAssemblyName; - private StartupMethods _startup; - - // Only one of these should be set - private string _serverFactoryLocation; - private IServerFactory _serverFactory; - private IServerInformation _serverInstance; - - public HostingEngine(IServiceCollection appServices, IStartupLoader startupLoader, IConfiguration config, IHostingEnvironment hostingEnv, string appName) - { - _config = config ?? new Configuration(); - _applicationServiceCollection = appServices; - _startupLoader = startupLoader; - _startupAssemblyName = appName; - _applicationLifetime = new ApplicationLifetime(); - _hostingEnvironment = hostingEnv; - } - - public virtual IDisposable Start() - { - EnsureApplicationServices(); - EnsureServer(); - EnsureBuilder(); - - var applicationDelegate = BuildApplicationDelegate(); - - var logger = _applicationServices.GetRequiredService>(); - var contextFactory = _applicationServices.GetRequiredService(); - var contextAccessor = _applicationServices.GetRequiredService(); - var server = _serverFactory.Start(_serverInstance, - async features => - { - var httpContext = contextFactory.CreateHttpContext(features); - var requestIdentifier = GetRequestIdentifier(httpContext); - - using (logger.BeginScope("Request Id: {RequestId}", requestIdentifier)) - { - contextAccessor.HttpContext = httpContext; - await applicationDelegate(httpContext); - } - }); - - return new Disposable(() => - { - _applicationLifetime.NotifyStopping(); - server.Dispose(); - _applicationLifetime.NotifyStopped(); - }); - } - - private void EnsureApplicationServices() - { - _useDisabled = true; - EnsureStartup(); - - _applicationServiceCollection.AddInstance(_applicationLifetime); - - _applicationServices = _startup.ConfigureServicesDelegate(_applicationServiceCollection); - } - - private void EnsureStartup() - { - if (_startup != null) - { - return; - } - - var diagnosticMessages = new List(); - _startup = _startupLoader.Load( - _startupAssemblyName, - _hostingEnvironment.EnvironmentName, - diagnosticMessages); - - if (_startup == null) - { - throw new ArgumentException( - diagnosticMessages.Aggregate("Failed to find a startup entry point for the web application.", (a, b) => a + "\r\n" + b), - _startupAssemblyName); - } - } - - private void EnsureServer() - { - if (_serverFactory == null) - { - // Blow up if we don't have a server set at this point - if (_serverFactoryLocation == null) - { - throw new InvalidOperationException("UseStartup() is required for Start()"); - } - - _serverFactory = _applicationServices.GetRequiredService().LoadServerFactory(_serverFactoryLocation); - } - - _serverInstance = _serverFactory.Initialize(_config); - } - - private void EnsureBuilder() - { - if (_builderFactory == null) - { - _builderFactory = _applicationServices.GetRequiredService(); - } - - _builder = _builderFactory.CreateBuilder(_serverInstance); - _builder.ApplicationServices = _applicationServices; - } - - private RequestDelegate BuildApplicationDelegate() - { - var startupFilters = _applicationServices.GetService>(); - var configure = _startup.ConfigureDelegate; - foreach (var filter in startupFilters) - { - configure = filter.Configure(_builder, configure); - } - - configure(_builder); - - return _builder.Build(); - } - - public IServiceProvider ApplicationServices - { - get - { - EnsureApplicationServices(); - return _applicationServices; - } - } - - private void CheckUseAllowed() - { - if (_useDisabled) - { - throw new InvalidOperationException("HostingEngine has already been started."); - } - } - - private Guid GetRequestIdentifier(HttpContext httpContext) - { - var requestIdentifierFeature = httpContext.GetFeature(); - if (requestIdentifierFeature == null) - { - requestIdentifierFeature = new DefaultRequestIdentifierFeature(); - httpContext.SetFeature(requestIdentifierFeature); - } - - return requestIdentifierFeature.TraceIdentifier; - } - - // Consider cutting - public IHostingEngine UseEnvironment(string environment) - { - CheckUseAllowed(); - _hostingEnvironment.EnvironmentName = environment; - return this; - } - - public IHostingEngine UseServer(string assemblyName) - { - CheckUseAllowed(); - _serverFactoryLocation = assemblyName; - return this; - } - - public IHostingEngine UseServer(IServerFactory factory) - { - CheckUseAllowed(); - _serverFactory = factory; - return this; - } - - public IHostingEngine UseStartup(string startupAssemblyName) - { - CheckUseAllowed(); - _startupAssemblyName = startupAssemblyName; - return this; - } - - public IHostingEngine UseStartup(Action configureApp) - { - return UseStartup(configureApp, configureServices: null); - } - - public IHostingEngine UseStartup(Action configureApp, ConfigureServicesDelegate configureServices) - { - CheckUseAllowed(); - _startup = new StartupMethods(configureApp, configureServices); - return this; - } - - public IHostingEngine UseStartup(Action configureApp, Action configureServices) - { - CheckUseAllowed(); - _startup = new StartupMethods(configureApp, - services => { - if (configureServices != null) - { - configureServices(services); - } - return services.BuildServiceProvider(); - }); - return this; - } - - private class Disposable : IDisposable - { - private Action _dispose; - - public Disposable(Action dispose) - { - _dispose = dispose; - } - - public void Dispose() - { - Interlocked.Exchange(ref _dispose, () => { }).Invoke(); - } - } - } -} \ No newline at end of file diff --git a/src/Microsoft.AspNet.Hosting/HostingFactory.cs b/src/Microsoft.AspNet.Hosting/HostingFactory.cs deleted file mode 100644 index 1b77dc7e59..0000000000 --- a/src/Microsoft.AspNet.Hosting/HostingFactory.cs +++ /dev/null @@ -1,35 +0,0 @@ -// 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.Hosting.Internal; -using Microsoft.AspNet.Hosting.Startup; -using Microsoft.Framework.ConfigurationModel; -using Microsoft.Framework.Runtime; - -namespace Microsoft.AspNet.Hosting -{ - public class HostingFactory : IHostingFactory - { - public const string EnvironmentKey = "ASPNET_ENV"; - - private readonly RootHostingServiceCollectionInitializer _serviceInitializer; - private readonly IStartupLoader _startupLoader; - private readonly IApplicationEnvironment _applicationEnvironment; - private readonly IHostingEnvironment _hostingEnvironment; - - public HostingFactory(RootHostingServiceCollectionInitializer initializer, IStartupLoader startupLoader, IApplicationEnvironment appEnv, IHostingEnvironment hostingEnv) - { - _serviceInitializer = initializer; - _startupLoader = startupLoader; - _applicationEnvironment = appEnv; - _hostingEnvironment = hostingEnv; - } - - public IHostingEngine Create(IConfiguration config) - { - _hostingEnvironment.Initialize(_applicationEnvironment.ApplicationBasePath, config?[EnvironmentKey]); - - return new HostingEngine(_serviceInitializer.Build(), _startupLoader, config, _hostingEnvironment, _applicationEnvironment.ApplicationName); - } - } -} \ No newline at end of file diff --git a/src/Microsoft.AspNet.Hosting/IHostingEngine.cs b/src/Microsoft.AspNet.Hosting/IHostingEngine.cs deleted file mode 100644 index dbd6577b05..0000000000 --- a/src/Microsoft.AspNet.Hosting/IHostingEngine.cs +++ /dev/null @@ -1,32 +0,0 @@ -// 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 System; -using Microsoft.AspNet.Builder; -using Microsoft.AspNet.Hosting.Server; -using Microsoft.AspNet.Hosting.Startup; -using Microsoft.Framework.DependencyInjection; - -namespace Microsoft.AspNet.Hosting -{ - public interface IHostingEngine - { - IDisposable Start(); - - // Accessing this will block Use methods - IServiceProvider ApplicationServices { get; } - - // Use methods blow up after any of the above methods are called - IHostingEngine UseEnvironment(string environment); - - // Mutually exclusive - IHostingEngine UseServer(string assemblyName); - IHostingEngine UseServer(IServerFactory factory); - - // Mutually exclusive - IHostingEngine UseStartup(string startupAssemblyName); - IHostingEngine UseStartup(Action configureApp); - IHostingEngine UseStartup(Action configureApp, ConfigureServicesDelegate configureServices); - IHostingEngine UseStartup(Action configureApp, Action configureServices); - } -} \ No newline at end of file diff --git a/src/Microsoft.AspNet.Hosting/IHostingFactory.cs b/src/Microsoft.AspNet.Hosting/IHostingFactory.cs deleted file mode 100644 index f44b02c1db..0000000000 --- a/src/Microsoft.AspNet.Hosting/IHostingFactory.cs +++ /dev/null @@ -1,12 +0,0 @@ -// 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.Framework.ConfigurationModel; - -namespace Microsoft.AspNet.Hosting -{ - public interface IHostingFactory - { - IHostingEngine Create(IConfiguration config); - } -} \ No newline at end of file diff --git a/src/Microsoft.AspNet.Hosting/Internal/HostingEngine.cs b/src/Microsoft.AspNet.Hosting/Internal/HostingEngine.cs new file mode 100644 index 0000000000..86bbee3936 --- /dev/null +++ b/src/Microsoft.AspNet.Hosting/Internal/HostingEngine.cs @@ -0,0 +1,184 @@ +// 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 System; +using System.Collections.Generic; +using System.Linq; +using System.Threading; +using Microsoft.AspNet.Builder; +using Microsoft.AspNet.Hosting.Builder; +using Microsoft.AspNet.Hosting.Server; +using Microsoft.AspNet.Hosting.Startup; +using Microsoft.AspNet.Http; +using Microsoft.Framework.ConfigurationModel; +using Microsoft.Framework.DependencyInjection; +using Microsoft.Framework.Internal; +using Microsoft.Framework.Logging; + +namespace Microsoft.AspNet.Hosting.Internal +{ + public class HostingEngine : IHostingEngine + { + private readonly IServiceCollection _applicationServiceCollection; + private readonly IStartupLoader _startupLoader; + private readonly ApplicationLifetime _applicationLifetime; + private readonly IConfiguration _config; + + private IServiceProvider _applicationServices; + + // Only one of these should be set + internal string StartupAssemblyName { get; set; } + internal StartupMethods Startup { get; set; } + internal Type StartupType { get; set; } + + // Only one of these should be set + internal IServerFactory ServerFactory { get; set; } + internal string ServerFactoryLocation { get; set; } + private IServerInformation _serverInstance; + + public HostingEngine( + [NotNull] IServiceCollection appServices, + [NotNull] IStartupLoader startupLoader, + [NotNull] IConfiguration config) + { + _config = config; + _applicationServiceCollection = appServices; + _startupLoader = startupLoader; + _applicationLifetime = new ApplicationLifetime(); + } + + public IServiceProvider ApplicationServices + { + get + { + EnsureApplicationServices(); + return _applicationServices; + } + } + + public virtual IDisposable Start() + { + EnsureApplicationServices(); + + var application = BuildApplication(); + + var logger = _applicationServices.GetRequiredService>(); + var contextFactory = _applicationServices.GetRequiredService(); + var contextAccessor = _applicationServices.GetRequiredService(); + var server = ServerFactory.Start(_serverInstance, + async features => + { + var httpContext = contextFactory.CreateHttpContext(features); + var requestIdentifier = GetRequestIdentifier(httpContext); + + using (logger.BeginScope("Request Id: {RequestId}", requestIdentifier)) + { + contextAccessor.HttpContext = httpContext; + await application(httpContext); + } + }); + + return new Disposable(() => + { + _applicationLifetime.NotifyStopping(); + server.Dispose(); + _applicationLifetime.NotifyStopped(); + }); + } + + private void EnsureApplicationServices() + { + EnsureStartup(); + + _applicationServiceCollection.AddInstance(_applicationLifetime); + + _applicationServices = Startup.ConfigureServicesDelegate(_applicationServiceCollection); + } + + private void EnsureStartup() + { + if (Startup != null) + { + return; + } + + if (StartupType == null) + { + var diagnosticTypeMessages = new List(); + StartupType = _startupLoader.FindStartupType(StartupAssemblyName, diagnosticTypeMessages); + if (StartupType == null) + { + throw new ArgumentException( + diagnosticTypeMessages.Aggregate("Failed to find a startup type for the web application.", (a, b) => a + "\r\n" + b), + StartupAssemblyName); + } + } + + var diagnosticMessages = new List(); + Startup = _startupLoader.LoadMethods(StartupType, diagnosticMessages); + if (Startup == null) + { + throw new ArgumentException( + diagnosticMessages.Aggregate("Failed to find a startup entry point for the web application.", (a, b) => a + "\r\n" + b), + StartupAssemblyName); + } + } + + private RequestDelegate BuildApplication() + { + if (ServerFactory == null) + { + // Blow up if we don't have a server set at this point + if (ServerFactoryLocation == null) + { + throw new InvalidOperationException("IHostingBuilder.UseServer() is required for " + nameof(Start) + "()"); + } + + ServerFactory = _applicationServices.GetRequiredService().LoadServerFactory(ServerFactoryLocation); + } + + _serverInstance = ServerFactory.Initialize(_config); + var builderFactory = _applicationServices.GetRequiredService(); + var builder = builderFactory.CreateBuilder(_serverInstance); + builder.ApplicationServices = _applicationServices; + + var startupFilters = _applicationServices.GetService>(); + var configure = Startup.ConfigureDelegate; + foreach (var filter in startupFilters) + { + configure = filter.Configure(builder, configure); + } + + configure(builder); + + return builder.Build(); + } + + private Guid GetRequestIdentifier(HttpContext httpContext) + { + var requestIdentifierFeature = httpContext.GetFeature(); + if (requestIdentifierFeature == null) + { + requestIdentifierFeature = new DefaultRequestIdentifierFeature(); + httpContext.SetFeature(requestIdentifierFeature); + } + + return requestIdentifierFeature.TraceIdentifier; + } + + private class Disposable : IDisposable + { + private Action _dispose; + + public Disposable(Action dispose) + { + _dispose = dispose; + } + + public void Dispose() + { + Interlocked.Exchange(ref _dispose, () => { }).Invoke(); + } + } + } +} \ No newline at end of file diff --git a/src/Microsoft.AspNet.Hosting/Internal/IHostingEngine.cs b/src/Microsoft.AspNet.Hosting/Internal/IHostingEngine.cs new file mode 100644 index 0000000000..f79031eb0f --- /dev/null +++ b/src/Microsoft.AspNet.Hosting/Internal/IHostingEngine.cs @@ -0,0 +1,15 @@ +// 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 System; + +namespace Microsoft.AspNet.Hosting.Internal +{ + public interface IHostingEngine + { + IDisposable Start(); + + // Accessing this will block Use methods + IServiceProvider ApplicationServices { get; } + } +} \ No newline at end of file diff --git a/src/Microsoft.AspNet.Hosting/Internal/RootHostingServiceCollectionInitializer.cs b/src/Microsoft.AspNet.Hosting/Internal/RootHostingServiceCollectionInitializer.cs deleted file mode 100644 index 3e9a9babec..0000000000 --- a/src/Microsoft.AspNet.Hosting/Internal/RootHostingServiceCollectionInitializer.cs +++ /dev/null @@ -1,66 +0,0 @@ -// 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 System; -using Microsoft.AspNet.Hosting.Builder; -using Microsoft.AspNet.Hosting.Internal; -using Microsoft.AspNet.Hosting.Server; -using Microsoft.AspNet.Hosting.Startup; -using Microsoft.Framework.DependencyInjection; -using Microsoft.Framework.Logging; -using Microsoft.Framework.Runtime; -using Microsoft.Framework.Runtime.Infrastructure; - -namespace Microsoft.AspNet.Hosting.Internal -{ - public class RootHostingServiceCollectionInitializer - { - private readonly IServiceProvider _fallbackServices; - private readonly Action _configureServices; - private readonly IHostingEnvironment _hostingEnvironment; - private readonly ILoggerFactory _loggerFactory; - - public RootHostingServiceCollectionInitializer(IServiceProvider fallbackServices, Action configureServices) - { - _fallbackServices = fallbackServices; - _configureServices = configureServices; - _hostingEnvironment = new HostingEnvironment(); - _loggerFactory = new LoggerFactory(); - } - - public IServiceCollection Build() - { - var services = new ServiceCollection(); - - // Import from manifest - var manifest = _fallbackServices.GetRequiredService(); - foreach (var service in manifest.Services) - { - services.AddTransient(service, sp => _fallbackServices.GetService(service)); - } - - services.AddInstance(_hostingEnvironment); - services.AddInstance(this); - services.AddInstance(_loggerFactory); - - services.AddTransient(); - services.AddTransient(); - - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddSingleton(); - services.AddLogging(); - - // Conjure up a RequestServices - services.AddTransient(); - - if (_configureServices != null) - { - _configureServices(services); - } - - return services; - } - } -} \ No newline at end of file diff --git a/src/Microsoft.AspNet.Hosting/Program.cs b/src/Microsoft.AspNet.Hosting/Program.cs index 6c4a24ae1c..541eec0f0d 100644 --- a/src/Microsoft.AspNet.Hosting/Program.cs +++ b/src/Microsoft.AspNet.Hosting/Program.cs @@ -5,6 +5,7 @@ using System; using System.IO; using System.Threading; using System.Threading.Tasks; +using Microsoft.AspNet.Hosting.Internal; using Microsoft.Framework.ConfigurationModel; using Microsoft.Framework.DependencyInjection; using Microsoft.Framework.Logging; @@ -33,21 +34,10 @@ namespace Microsoft.AspNet.Hosting config.AddEnvironmentVariables(); config.AddCommandLine(args); - var engine = WebHost.CreateEngine(_serviceProvider, config); - var server = config.Get("server"); - if (server != null) - { - engine.UseServer(server); - } - var startup = config.Get("app"); - if (startup != null) - { - engine.UseStartup(startup); - } - - var serverShutdown = engine.Start(); - var loggerFactory = engine.ApplicationServices.GetRequiredService(); - var appShutdownService = engine.ApplicationServices.GetRequiredService(); + var host = new WebHostBuilder(_serviceProvider).Build(); + var serverShutdown = host.Start(); + var loggerFactory = host.ApplicationServices.GetRequiredService(); + var appShutdownService = host.ApplicationServices.GetRequiredService(); var shutdownHandle = new ManualResetEvent(false); appShutdownService.ShutdownRequested.Register(() => diff --git a/src/Microsoft.AspNet.Hosting/Startup/IStartupLoader.cs b/src/Microsoft.AspNet.Hosting/Startup/IStartupLoader.cs index cab29b61ce..6ba16f4e08 100644 --- a/src/Microsoft.AspNet.Hosting/Startup/IStartupLoader.cs +++ b/src/Microsoft.AspNet.Hosting/Startup/IStartupLoader.cs @@ -8,9 +8,8 @@ namespace Microsoft.AspNet.Hosting.Startup { public interface IStartupLoader { - StartupMethods Load( - string startupAssemblyName, - string environmentName, - IList diagnosticMessages); + Type FindStartupType(string startupAssemblyName, IList diagnosticMessages); + + StartupMethods LoadMethods(Type startupType, IList diagnosticMessages); } } diff --git a/src/Microsoft.AspNet.Hosting/Startup/StartupLoader.cs b/src/Microsoft.AspNet.Hosting/Startup/StartupLoader.cs index 6ebc09f04e..2b95b72ed7 100644 --- a/src/Microsoft.AspNet.Hosting/Startup/StartupLoader.cs +++ b/src/Microsoft.AspNet.Hosting/Startup/StartupLoader.cs @@ -13,17 +13,19 @@ namespace Microsoft.AspNet.Hosting.Startup public class StartupLoader : IStartupLoader { private readonly IServiceProvider _services; + private readonly IHostingEnvironment _hostingEnv; - public StartupLoader(IServiceProvider services) + public StartupLoader(IServiceProvider services, IHostingEnvironment hostingEnv) { _services = services; + _hostingEnv = hostingEnv; } - public StartupMethods Load( + public StartupMethods LoadMethods( Type startupType, - string environmentName, IList diagnosticMessages) { + var environmentName = _hostingEnv.EnvironmentName; var configureMethod = FindConfigureDelegate(startupType, environmentName); var servicesMethod = FindConfigureServicesDelegate(startupType, environmentName); @@ -36,11 +38,9 @@ namespace Microsoft.AspNet.Hosting.Startup return new StartupMethods(configureMethod.Build(instance), servicesMethod?.Build(instance)); } - public StartupMethods Load( - string startupAssemblyName, - string environmentName, - IList diagnosticMessages) + public Type FindStartupType(string startupAssemblyName, IList diagnosticMessages) { + var environmentName = _hostingEnv.EnvironmentName; if (string.IsNullOrEmpty(startupAssemblyName)) { throw new ArgumentException("Value cannot be null or empty.", nameof(startupAssemblyName)); @@ -85,7 +85,7 @@ namespace Microsoft.AspNet.Hosting.Startup startupAssemblyName)); } - return Load(type, environmentName, diagnosticMessages); + return type; } private static ConfigureBuilder FindConfigureDelegate(Type startupType, string environmentName) diff --git a/src/Microsoft.AspNet.Hosting/WebHost.cs b/src/Microsoft.AspNet.Hosting/WebHost.cs deleted file mode 100644 index c1d331e0c4..0000000000 --- a/src/Microsoft.AspNet.Hosting/WebHost.cs +++ /dev/null @@ -1,63 +0,0 @@ -// 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 System; -using Microsoft.AspNet.Hosting.Internal; -using Microsoft.Framework.ConfigurationModel; -using Microsoft.Framework.DependencyInjection; -using Microsoft.Framework.Runtime.Infrastructure; - -namespace Microsoft.AspNet.Hosting -{ - public static class WebHost - { - public static IHostingEngine CreateEngine() - { - return CreateEngine(new Configuration()); - } - - public static IHostingEngine CreateEngine(Action configureServices) - { - return CreateEngine(new Configuration(), configureServices); - } - - public static IHostingEngine CreateEngine(IConfiguration config) - { - return CreateEngine(config, configureServices: null); - } - - public static IHostingEngine CreateEngine(IConfiguration config, Action configureServices) - { - return CreateEngine(fallbackServices: null, config: config, configureServices: configureServices); - } - - public static IHostingEngine CreateEngine(IServiceProvider fallbackServices, IConfiguration config) - { - return CreateEngine(fallbackServices, config, configureServices: null); - } - - public static IHostingEngine CreateEngine(IServiceProvider fallbackServices, IConfiguration config, Action configureServices) - { - return CreateFactory(fallbackServices, configureServices).Create(config); - } - - public static IHostingFactory CreateFactory() - { - return CreateFactory(fallbackServices: null, configureServices: null); - } - - public static IHostingFactory CreateFactory(Action configureServices) - { - return CreateFactory(fallbackServices: null, configureServices: configureServices); - } - - public static IHostingFactory CreateFactory(IServiceProvider fallbackServices, Action configureServices) - { - fallbackServices = fallbackServices ?? CallContextServiceLocator.Locator.ServiceProvider; - return new RootHostingServiceCollectionInitializer(fallbackServices, configureServices) - .Build() - .BuildServiceProvider() - .GetRequiredService(); - } - } -} \ No newline at end of file diff --git a/src/Microsoft.AspNet.Hosting/WebHostBuilder.cs b/src/Microsoft.AspNet.Hosting/WebHostBuilder.cs new file mode 100644 index 0000000000..09e70f2650 --- /dev/null +++ b/src/Microsoft.AspNet.Hosting/WebHostBuilder.cs @@ -0,0 +1,189 @@ +// 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 System; +using Microsoft.AspNet.Builder; +using Microsoft.AspNet.Hosting.Builder; +using Microsoft.AspNet.Hosting.Internal; +using Microsoft.AspNet.Hosting.Server; +using Microsoft.AspNet.Hosting.Startup; +using Microsoft.Framework.ConfigurationModel; +using Microsoft.Framework.DependencyInjection; +using Microsoft.Framework.Internal; +using Microsoft.Framework.Logging; +using Microsoft.Framework.Runtime; + +namespace Microsoft.AspNet.Hosting +{ + public class WebHostBuilder + { + public const string OldEnvironmentKey = "ASPNET_ENV"; + public const string EnvironmentKey = "Hosting:Environment"; + + public const string OldApplicationKey = "app"; + public const string ApplicationKey = "Hosting:Application"; + + public const string OldServerKey = "server"; + public const string ServerKey = "Hosting:Server"; + + private readonly IServiceProvider _services; + private readonly IHostingEnvironment _hostingEnvironment; + private readonly ILoggerFactory _loggerFactory; + private readonly IConfiguration _config; + + private Action _configureServices; + + // Only one of these should be set + private StartupMethods _startup; + private Type _startupType; + private string _startupAssemblyName; + + // Only one of these should be set + private string _serverFactoryLocation; + private IServerFactory _serverFactory; + + public WebHostBuilder([NotNull] IServiceProvider services) : this(services, config: new Configuration()) { } + + public WebHostBuilder([NotNull] IServiceProvider services, [NotNull] IConfiguration config) + { + _hostingEnvironment = new HostingEnvironment(); + _loggerFactory = new LoggerFactory(); + _services = services; + _config = config; + } + + private IServiceCollection BuildHostingServices() + { + var services = new ServiceCollection(); + + // Import from manifest + var manifest = _services.GetService(); + if (manifest != null) + { + foreach (var service in manifest.Services) + { + services.AddTransient(service, sp => _services.GetService(service)); + } + } + + services.AddInstance(_hostingEnvironment); + services.AddInstance(_loggerFactory); + + services.AddTransient(); + + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddSingleton(); + services.AddLogging(); + + // Conjure up a RequestServices + services.AddTransient(); + + if (_configureServices != null) + { + _configureServices(services); + } + + return services; + } + + public IHostingEngine Build() + { + var hostingServices = BuildHostingServices(); + + var hostingContainer = hostingServices.BuildServiceProvider(); + + var appEnvironment = hostingContainer.GetRequiredService(); + var startupLoader = hostingContainer.GetRequiredService(); + + _hostingEnvironment.Initialize(appEnvironment.ApplicationBasePath, _config?[EnvironmentKey] ?? _config?[OldEnvironmentKey]); + + var engine = new HostingEngine(hostingServices, startupLoader, _config); + + // Only one of these should be set, but they are used in priority + engine.ServerFactory = _serverFactory; + engine.ServerFactoryLocation = _config.Get(ServerKey) ?? _config.Get(OldServerKey) ?? _serverFactoryLocation; + + // Only one of these should be set, but they are used in priority + engine.Startup = _startup; + engine.StartupType = _startupType; + engine.StartupAssemblyName = _config.Get(ApplicationKey) ?? _config.Get(OldApplicationKey) ?? appEnvironment.ApplicationName; + + return engine; + } + + public WebHostBuilder UseServices(Action configureServices) + { + _configureServices = configureServices; + return this; + } + + public WebHostBuilder UseEnvironment([NotNull] string environment) + { + _hostingEnvironment.EnvironmentName = environment; + return this; + } + + public WebHostBuilder UseServer([NotNull] string assemblyName) + { + _serverFactoryLocation = assemblyName; + return this; + } + + public WebHostBuilder UseServer(IServerFactory factory) + { + _serverFactory = factory; + return this; + } + + public WebHostBuilder UseStartup([NotNull] string startupAssemblyName) + { + if (startupAssemblyName == null) + { + throw new ArgumentNullException(nameof(startupAssemblyName)); + } + _startupAssemblyName = startupAssemblyName; + return this; + } + + public WebHostBuilder UseStartup([NotNull] Type startupType) + { + if (startupType == null) + { + throw new ArgumentNullException(nameof(startupType)); + } + _startupType = startupType; + return this; + } + + public WebHostBuilder UseStartup() where TStartup : class + { + return UseStartup(typeof(TStartup)); + } + + public WebHostBuilder UseStartup([NotNull] Action configureApp) + { + return UseStartup(configureApp, configureServices: null); + } + + public WebHostBuilder UseStartup([NotNull] Action configureApp, ConfigureServicesDelegate configureServices) + { + _startup = new StartupMethods(configureApp, configureServices); + return this; + } + + public WebHostBuilder UseStartup([NotNull] Action configureApp, Action configureServices) + { + _startup = new StartupMethods(configureApp, + services => { + if (configureServices != null) + { + configureServices(services); + } + return services.BuildServiceProvider(); + }); + return this; + } + } +} \ No newline at end of file diff --git a/src/Microsoft.AspNet.Hosting/project.json b/src/Microsoft.AspNet.Hosting/project.json index 68028eeede..25eda4017f 100644 --- a/src/Microsoft.AspNet.Hosting/project.json +++ b/src/Microsoft.AspNet.Hosting/project.json @@ -12,6 +12,7 @@ "Microsoft.Framework.DependencyInjection": "1.0.0-*", "Microsoft.Framework.Logging": "1.0.0-*", "Microsoft.Framework.Runtime.Interfaces": "1.0.0-*", + "Microsoft.Framework.NotNullAttribute.Internal": { "type": "build", "version": "1.0.0-*" }, "Newtonsoft.Json": "6.0.6" }, "frameworks": { diff --git a/src/Microsoft.AspNet.TestHost/TestServer.cs b/src/Microsoft.AspNet.TestHost/TestServer.cs index f290092609..d5bf3e52a6 100644 --- a/src/Microsoft.AspNet.TestHost/TestServer.cs +++ b/src/Microsoft.AspNet.TestHost/TestServer.cs @@ -12,6 +12,7 @@ using Microsoft.AspNet.Hosting.Startup; using Microsoft.AspNet.Http; using Microsoft.Framework.ConfigurationModel; using Microsoft.Framework.DependencyInjection; +using Microsoft.Framework.Runtime.Infrastructure; namespace Microsoft.AspNet.TestHost { @@ -24,101 +25,66 @@ namespace Microsoft.AspNet.TestHost private IDisposable _appInstance; private bool _disposed = false; - public TestServer(IHostingEngine engine) + public TestServer(WebHostBuilder builder) { - _appInstance = engine.UseServer(this).Start(); + _appInstance = builder.UseServer(this).Build().Start(); } public Uri BaseAddress { get; set; } = new Uri("http://localhost/"); public static TestServer Create() { - return Create(fallbackServices: null, config: null, configureApp: null, configureServices: null); + return Create(services: null, config: null, configureApp: null, configureServices: null); } public static TestServer Create(Action configureApp) { - return Create(fallbackServices: null, config: null, configureApp: configureApp, configureServices: null); + return Create(services: null, config: null, configureApp: configureApp, configureServices: null); } public static TestServer Create(Action configureApp, Action configureServices) { - return Create(fallbackServices: null, config: null, configureApp: configureApp, configureServices: configureServices); + return Create(services: null, config: null, configureApp: configureApp, configureServices: configureServices); } - public static TestServer Create(IServiceProvider fallbackServices, Action configureApp, ConfigureServicesDelegate configureServices) + public static TestServer Create(IServiceProvider services, Action configureApp, ConfigureServicesDelegate configureServices) { - return CreateBuilder(fallbackServices, config: null, configureApp: configureApp, configureServices: configureServices).Build(); + return new TestServer(CreateBuilder(services, config: null, configureApp: configureApp, configureServices: configureServices)); } - public static TestServer Create(IServiceProvider fallbackServices, IConfiguration config, Action configureApp, Action configureServices) + public static TestServer Create(IServiceProvider services, IConfiguration config, Action configureApp, Action configureServices) { - return CreateBuilder(fallbackServices, config, configureApp, configureServices).Build(); + return new TestServer(CreateBuilder(services, config, configureApp, configureServices)); } - public static TestServer Create() where TStartup : class + public static WebHostBuilder CreateBuilder(IServiceProvider services, IConfiguration config, Action configureApp, Action configureServices) { - return Create(fallbackServices: null, config: null, configureApp: null, configureServices: null); - } - - public static TestServer Create(Action configureApp) where TStartup : class - { - return Create(fallbackServices: null, config: null, configureApp: configureApp, configureServices: null); - } - - public static TestServer Create(Action configureApp, Action configureServices) where TStartup : class - { - return Create(fallbackServices: null, config: null, configureApp: configureApp, configureServices: configureServices); - } - - public static TestServer Create(IServiceProvider fallbackServices, IConfiguration config, Action configureApp, Action configureServices) where TStartup : class - { - var builder = CreateBuilder(fallbackServices, config, configureApp, configureServices); - builder.StartupType = typeof(TStartup); - return builder.Build(); - } - - public static TestServerBuilder CreateBuilder() where TStartup : class - { - var builder = CreateBuilder(fallbackServices: null, config: null, configureApp: null, configureServices: null); - builder.StartupType = typeof(TStartup); - return builder; - } - - public static TestServerBuilder CreateBuilder(IServiceProvider fallbackServices, IConfiguration config, Action configureApp, Action configureServices) where TStartup : class - { - var builder = CreateBuilder(fallbackServices, config, configureApp, configureServices); - builder.StartupType = typeof(TStartup); - return builder; - } - - public static TestServerBuilder CreateBuilder(IServiceProvider fallbackServices, IConfiguration config, Action configureApp, Action configureServices) - { - return CreateBuilder(fallbackServices, config, configureApp, - services => + return CreateBuilder(services, config, configureApp, + s => { if (configureServices != null) { - configureServices(services); + configureServices(s); } - return services.BuildServiceProvider(); + return s.BuildServiceProvider(); }); } - public static TestServerBuilder CreateBuilder(IServiceProvider fallbackServices, IConfiguration config) + public static WebHostBuilder CreateBuilder(IServiceProvider services, IConfiguration config, Action configureApp, ConfigureServicesDelegate configureServices) { - return new TestServerBuilder - { - FallbackServices = fallbackServices, - Config = config - }; + return CreateBuilder(services, config).UseStartup(configureApp, configureServices); } - public static TestServerBuilder CreateBuilder(IServiceProvider fallbackServices, IConfiguration config, Action configureApp, ConfigureServicesDelegate configureServices) + public static WebHostBuilder CreateBuilder(IServiceProvider services, IConfiguration config) { - var builder = CreateBuilder(fallbackServices, config); - builder.Startup = new StartupMethods(configureApp, configureServices); - return builder; + return new WebHostBuilder( + services ?? CallContextServiceLocator.Locator.ServiceProvider, + config ?? new Configuration()); + } + + public static WebHostBuilder CreateBuilder() + { + return CreateBuilder(services: null, config: null); } public HttpMessageHandler CreateHandler() diff --git a/src/Microsoft.AspNet.TestHost/TestServerBuilder.cs b/src/Microsoft.AspNet.TestHost/TestServerBuilder.cs deleted file mode 100644 index 74425f89f5..0000000000 --- a/src/Microsoft.AspNet.TestHost/TestServerBuilder.cs +++ /dev/null @@ -1,126 +0,0 @@ -// 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 System; -using System.Collections.Generic; -using System.Runtime.Versioning; -using Microsoft.AspNet.Hosting; -using Microsoft.AspNet.Hosting.Startup; -using Microsoft.Framework.ConfigurationModel; -using Microsoft.Framework.DependencyInjection; -using Microsoft.Framework.Runtime; -using Microsoft.Framework.Runtime.Infrastructure; - -namespace Microsoft.AspNet.TestHost -{ - public class TestServerBuilder - { - public IServiceProvider FallbackServices { get; set; } - public string Environment { get; set; } - public string ApplicationName { get; set; } - public string ApplicationBasePath { get; set; } - - public Type StartupType { get; set; } - public string StartupAssemblyName { get; set; } - public IConfiguration Config { get; set; } - - public IServiceCollection AdditionalServices { get; } = new ServiceCollection(); - - public StartupMethods Startup { get; set; } - - public TestServer Build() - { - var fallbackServices = FallbackServices ?? CallContextServiceLocator.Locator.ServiceProvider; - var config = Config ?? new Configuration(); - if (Environment != null) - { - config[HostingFactory.EnvironmentKey] = Environment; - } - if (ApplicationName != null || ApplicationBasePath != null) - { - var appEnv = new TestApplicationEnvironment(fallbackServices.GetRequiredService()); - appEnv.ApplicationBasePath = ApplicationBasePath; - appEnv.ApplicationName = ApplicationName; - AdditionalServices.AddInstance(appEnv); - } - - var engine = WebHost.CreateEngine(fallbackServices, - config, - services => services.Add(AdditionalServices)); - if (StartupType != null) - { - Startup = new StartupLoader(fallbackServices).Load(StartupType, Environment, new List()); - } - if (Startup != null) - { - engine.UseStartup(Startup.ConfigureDelegate, Startup.ConfigureServicesDelegate); - } - else if (StartupAssemblyName != null) - { - engine.UseStartup(StartupAssemblyName); - } - - return new TestServer(engine); - } - - private class TestApplicationEnvironment : IApplicationEnvironment - { - private readonly IApplicationEnvironment _appEnv; - private string _appName; - private string _appBasePath; - - public TestApplicationEnvironment(IApplicationEnvironment appEnv) - { - _appEnv = appEnv; - } - - public string ApplicationBasePath - { - get - { - return _appBasePath ?? _appEnv.ApplicationBasePath; - } - set - { - _appBasePath = value; - } - } - - public string ApplicationName - { - get - { - return _appName ?? _appEnv.ApplicationName; - } - set - { - _appName = value; - } - } - - public string Configuration - { - get - { - return _appEnv.Configuration; - } - } - - public FrameworkName RuntimeFramework - { - get - { - return _appEnv.RuntimeFramework; - } - } - - public string Version - { - get - { - throw new NotImplementedException(); - } - } - } - } -} \ No newline at end of file diff --git a/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs b/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs index 07d946e490..dca50c4e0f 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs @@ -8,6 +8,7 @@ using System.Threading.Tasks; using Microsoft.AspNet.Builder; using Microsoft.AspNet.FeatureModel; using Microsoft.AspNet.Hosting.Builder; +using Microsoft.AspNet.Hosting.Internal; using Microsoft.AspNet.Hosting.Server; using Microsoft.AspNet.Hosting.Startup; using Microsoft.AspNet.Http; @@ -16,6 +17,7 @@ using Microsoft.Framework.ConfigurationModel; using Microsoft.Framework.DependencyInjection; using Microsoft.Framework.Logging; using Microsoft.Framework.OptionsModel; +using Microsoft.Framework.Runtime.Infrastructure; using Moq; using Xunit; @@ -24,19 +26,58 @@ namespace Microsoft.AspNet.Hosting public class HostingEngineTests : IServerFactory { private readonly IList _startInstances = new List(); + private IFeatureCollection _featuresSupportedByThisHost = new FeatureCollection(); [Fact] public void HostingEngineThrowsWithNoServer() { - Assert.Throws(() => WebHost.CreateEngine().Start()); + var ex = Assert.Throws(() => CreateBuilder().Build().Start()); + Assert.True(ex.Message.Contains("UseServer()")); + } + + [Fact] + public void UseStartupThrowsWithNull() + { + Assert.Throws(() => CreateBuilder().UseStartup((string)null)); + } + + [Fact] + public void CanStartWithOldServerConfig() + { + var vals = new Dictionary + { + { "server", "Microsoft.AspNet.Hosting.Tests" } + }; + + var config = new Configuration() + .Add(new MemoryConfigurationSource(vals)); + var host = CreateBuilder(config).Build(); + host.Start(); + Assert.NotNull(host.ApplicationServices.GetRequiredService()); + } + + [Fact] + public void CanStartWithServerConfig() + { + var vals = new Dictionary + { + { "Hosting:Server", "Microsoft.AspNet.Hosting.Tests" } + }; + + var config = new Configuration() + .Add(new MemoryConfigurationSource(vals)); + var host = CreateBuilder(config).Build(); + host.Start(); + Assert.NotNull(host.ApplicationServices.GetRequiredService()); } [Fact] public void HostingEngineCanBeStarted() { - var engine = WebHost.CreateEngine() + var engine = CreateBuilder() .UseServer(this) .UseStartup("Microsoft.AspNet.Hosting.Tests") + .Build() .Start(); Assert.NotNull(engine); @@ -51,10 +92,11 @@ namespace Microsoft.AspNet.Hosting [Fact] public void HostingEngineInjectsHostingEnvironment() { - var engine = WebHost.CreateEngine() + var engine = CreateBuilder() .UseServer(this) .UseStartup("Microsoft.AspNet.Hosting.Tests") - .UseEnvironment("WithHostingEnvironment"); + .UseEnvironment("WithHostingEnvironment") + .Build(); using (var server = engine.Start()) { @@ -63,20 +105,13 @@ namespace Microsoft.AspNet.Hosting } } - [Fact] - public void CanReplaceHostingFactory() - { - var factory = WebHost.CreateFactory(services => services.AddTransient()); - - Assert.NotNull(factory as TestEngineFactory); - } - [Fact] public void CanReplaceStartupLoader() { - var engine = WebHost.CreateEngine(services => services.AddTransient()) + var engine = CreateBuilder().UseServices(services => services.AddTransient()) .UseServer(this) - .UseStartup("Microsoft.AspNet.Hosting.Tests"); + .UseStartup("Microsoft.AspNet.Hosting.Tests") + .Build(); Assert.Throws(() => engine.Start()); } @@ -84,20 +119,20 @@ namespace Microsoft.AspNet.Hosting [Fact] public void CanCreateApplicationServicesWithAddedServices() { - var engineStart = WebHost.CreateEngine(services => services.AddOptions()); - Assert.NotNull(engineStart.ApplicationServices.GetRequiredService>()); + var host = CreateBuilder().UseServices(services => services.AddOptions()).Build(); + Assert.NotNull(host.ApplicationServices.GetRequiredService>()); } [Fact] public void EnvDefaultsToDevelopmentIfNoConfig() { - var engine = WebHost.CreateEngine(new Configuration()); + var engine = CreateBuilder().Build(); var env = engine.ApplicationServices.GetRequiredService(); Assert.Equal("Development", env.EnvironmentName); } [Fact] - public void EnvDefaultsToDevelopmentConfigValueIfSpecified() + public void EnvDefaultsToDevelopmentConfigValueIfSpecifiedWithOldKey() { var vals = new Dictionary { @@ -107,7 +142,23 @@ namespace Microsoft.AspNet.Hosting var config = new Configuration() .Add(new MemoryConfigurationSource(vals)); - var engine = WebHost.CreateEngine(config); + var engine = CreateBuilder(config).Build(); + var env = engine.ApplicationServices.GetRequiredService(); + Assert.Equal("Staging", env.EnvironmentName); + } + + [Fact] + public void EnvDefaultsToDevelopmentConfigValueIfSpecified() + { + var vals = new Dictionary + { + { "Hosting:Environment", "Staging" } + }; + + var config = new Configuration() + .Add(new MemoryConfigurationSource(vals)); + + var engine = CreateBuilder(config).Build(); var env = engine.ApplicationServices.GetRequiredService(); Assert.Equal("Staging", env.EnvironmentName); } @@ -115,7 +166,7 @@ namespace Microsoft.AspNet.Hosting [Fact] public void WebRootCanBeResolvedFromTheProjectJson() { - var engine = WebHost.CreateEngine().UseServer(this); + var engine = CreateBuilder().UseServer(this).Build(); var env = engine.ApplicationServices.GetRequiredService(); Assert.Equal(Path.GetFullPath("testroot"), env.WebRootPath); Assert.True(env.WebRootFileProvider.GetFileInfo("TextFile.txt").Exists); @@ -124,8 +175,7 @@ namespace Microsoft.AspNet.Hosting [Fact] public void IsEnvironment_Extension_Is_Case_Insensitive() { - var engine = WebHost.CreateEngine().UseServer(this); - + var engine = CreateBuilder().UseServer(this).Build(); using (engine.Start()) { var env = engine.ApplicationServices.GetRequiredService(); @@ -164,8 +214,7 @@ namespace Microsoft.AspNet.Hosting httpContext = innerHttpContext; return Task.FromResult(0); }); - var featuresSupportedByHost = new FeatureCollection(); - var hostingEngine = CreateHostingEngine(featuresSupportedByHost, requestDelegate); + var hostingEngine = CreateHostingEngine(requestDelegate); // Act var disposable = hostingEngine.Start(); @@ -192,7 +241,9 @@ namespace Microsoft.AspNet.Hosting featuresSupportedByHost .Setup(fc => fc.Add(new KeyValuePair(It.IsAny(), It.IsAny()))) .Throws(new NotImplementedException()); - var hostingEngine = CreateHostingEngine(featuresSupportedByHost.Object, requestDelegate); + _featuresSupportedByThisHost = featuresSupportedByHost.Object; + + var hostingEngine = CreateHostingEngine(requestDelegate); // Act var disposable = hostingEngine.Start(); @@ -212,10 +263,9 @@ namespace Microsoft.AspNet.Hosting httpContext = innerHttpContext; return Task.FromResult(0); }); - var featuresSupportedByHost = new FeatureCollection(); var requestIdentifierFeature = new Mock().Object; - featuresSupportedByHost.Add(typeof(IRequestIdentifierFeature), requestIdentifierFeature); - var hostingEngine = CreateHostingEngine(featuresSupportedByHost, requestDelegate); + _featuresSupportedByThisHost.Add(typeof(IRequestIdentifierFeature), requestIdentifierFeature); + var hostingEngine = CreateHostingEngine(requestDelegate); // Act var disposable = hostingEngine.Start(); @@ -225,9 +275,7 @@ namespace Microsoft.AspNet.Hosting Assert.Same(requestIdentifierFeature, httpContext.GetFeature()); } - private IHostingEngine CreateHostingEngine( - IFeatureCollection featuresSupportedByHost, - RequestDelegate requestDelegate) + private IHostingEngine CreateHostingEngine(RequestDelegate requestDelegate) { var applicationBuilder = new Mock(); applicationBuilder.Setup(appBuilder => appBuilder.Build()).Returns(requestDelegate); @@ -236,36 +284,25 @@ namespace Microsoft.AspNet.Hosting .Setup(abf => abf.CreateBuilder(It.IsAny())) .Returns(applicationBuilder.Object); - var serviceCollection = new ServiceCollection(); - serviceCollection.Add( - new ServiceDescriptor(typeof(IApplicationBuilderFactory), applicationBuilderFactory.Object)); - serviceCollection.Add( - new ServiceDescriptor(typeof(ILogger), new Mock>().Object)); - serviceCollection.Add( - new ServiceDescriptor(typeof(IHttpContextFactory), new HttpContextFactory())); - serviceCollection.Add( - new ServiceDescriptor(typeof(IHttpContextAccessor), new Mock().Object)); - - var startupLoader = new Mock(); - var startupMethods = new StartupMethods( - (appBuilder) => { }, - (configureServices) => configureServices.BuildServiceProvider()); - startupLoader.Setup(sl => sl.Load(It.IsAny(), It.IsAny(), It.IsAny>())) - .Returns(startupMethods); - - var hostingEngine = new HostingEngine( - serviceCollection, - startupLoader.Object, - new Mock().Object, - new Mock().Object, - "TestAppName"); - - return hostingEngine.UseServer(new TestServerFactory(featuresSupportedByHost)); + var host = CreateBuilder() + .UseServer(this) + .UseServices(s => + { + s.AddInstance(applicationBuilderFactory.Object); + s.AddInstance(new Mock>().Object); + s.AddSingleton(); + s.AddInstance(new Mock().Object); + s.AddInstance(new Mock().Object); + }) + .UseStartup( + appBuilder => { }, + configureServices => configureServices.BuildServiceProvider()); + return host.Build(); } private void RunMapPath(string virtualPath, string expectedSuffix) { - var engine = WebHost.CreateEngine().UseServer(this); + var engine = CreateBuilder().UseServer(this).Build(); using (engine.Start()) { @@ -276,6 +313,11 @@ namespace Microsoft.AspNet.Hosting } } + private WebHostBuilder CreateBuilder(IConfiguration config = null) + { + return new WebHostBuilder(CallContextServiceLocator.Locator.ServiceProvider, config ?? new Configuration()); + } + public IServerInformation Initialize(IConfiguration configuration) { return null; @@ -285,6 +327,7 @@ namespace Microsoft.AspNet.Hosting { var startInstance = new StartInstance(application); _startInstances.Add(startInstance); + application(_featuresSupportedByThisHost); return startInstance; } @@ -307,39 +350,15 @@ namespace Microsoft.AspNet.Hosting private class TestLoader : IStartupLoader { - public StartupMethods Load(string startupAssemblyName, string environmentName, IList diagnosticMessages) + public Type FindStartupType(string startupAssemblyName, IList diagnosticMessages) { throw new NotImplementedException(); } - } - private class TestEngineFactory : IHostingFactory - { - public IHostingEngine Create(IConfiguration config) + public StartupMethods LoadMethods(Type startupType, IList diagnosticMessages) { throw new NotImplementedException(); } } - - private class TestServerFactory : IServerFactory - { - private readonly IFeatureCollection _featuresSupportedByThisHost; - - public TestServerFactory(IFeatureCollection featuresSupportedByThisHost) - { - _featuresSupportedByThisHost = featuresSupportedByThisHost; - } - - public IServerInformation Initialize(IConfiguration configuration) - { - return null; - } - - public IDisposable Start(IServerInformation serverInformation, Func application) - { - application(_featuresSupportedByThisHost).Wait(); - return null; - } - } } } diff --git a/test/Microsoft.AspNet.Hosting.Tests/StartupManagerTests.cs b/test/Microsoft.AspNet.Hosting.Tests/StartupManagerTests.cs index cce2931e22..ca803c6831 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/StartupManagerTests.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/StartupManagerTests.cs @@ -3,7 +3,6 @@ using System; using System.Collections.Generic; -using System.Diagnostics; using System.Reflection; using Microsoft.AspNet.Builder; using Microsoft.AspNet.Hosting.Fakes; @@ -26,7 +25,10 @@ namespace Microsoft.AspNet.Hosting.Tests var services = serviceCollection.BuildServiceProvider(); var diagnosticMessages = new List(); - var startup = new StartupLoader(services).Load("Microsoft.AspNet.Hosting.Tests", "WithServices", diagnosticMessages); + var hostingEnv = new HostingEnvironment { EnvironmentName = "WithServices" }; + var loader = new StartupLoader(services, hostingEnv); + var type = loader.FindStartupType("Microsoft.AspNet.Hosting.Tests", diagnosticMessages); + var startup = loader.LoadMethods(type, diagnosticMessages); var app = new ApplicationBuilder(services); app.ApplicationServices = startup.ConfigureServicesDelegate(serviceCollection); @@ -47,9 +49,12 @@ namespace Microsoft.AspNet.Hosting.Tests public void StartupClassAddsConfigureServicesToApplicationServices(string environment) { var services = new ServiceCollection().BuildServiceProvider(); - var diagnosticMesssages = new List(); - var startup = new StartupLoader(services).Load("Microsoft.AspNet.Hosting.Tests", environment ?? "", diagnosticMesssages); + var diagnosticMessages = new List(); + var hostingEnv = new HostingEnvironment { EnvironmentName = environment }; + var loader = new StartupLoader(services, hostingEnv); + var type = loader.FindStartupType("Microsoft.AspNet.Hosting.Tests", diagnosticMessages); + var startup = loader.LoadMethods(type, diagnosticMessages); var app = new ApplicationBuilder(services); app.ApplicationServices = startup.ConfigureServicesDelegate(new ServiceCollection()); @@ -67,9 +72,13 @@ namespace Microsoft.AspNet.Hosting.Tests var serviceCollection = new ServiceCollection(); serviceCollection.AddInstance(this); var services = serviceCollection.BuildServiceProvider(); - var diagnosticMessages = new List(); - var ex = Assert.Throws(() => new StartupLoader(services).Load("Microsoft.AspNet.Hosting.Tests", "Boom", diagnosticMessages)); + var diagnosticMessages = new List(); + var hostingEnv = new HostingEnvironment { EnvironmentName = "Boom" }; + var loader = new StartupLoader(services, hostingEnv); + var type = loader.FindStartupType("Microsoft.AspNet.Hosting.Tests", diagnosticMessages); + + var ex = Assert.Throws(() => loader.LoadMethods(type, diagnosticMessages)); Assert.Equal("A method named 'ConfigureBoom' or 'Configure' in the type 'Microsoft.AspNet.Hosting.Fakes.StartupBoom' could not be found.", ex.Message); } @@ -80,7 +89,10 @@ namespace Microsoft.AspNet.Hosting.Tests var services = serviceCollection.BuildServiceProvider(); var diagnosticMessages = new List(); - var startup = new StartupLoader(services).Load("Microsoft.AspNet.Hosting.Tests", "WithNullConfigureServices", diagnosticMessages); + var hostingEnv = new HostingEnvironment { EnvironmentName = "WithNullConfigureServices" }; + var loader = new StartupLoader(services, hostingEnv); + var type = loader.FindStartupType("Microsoft.AspNet.Hosting.Tests", diagnosticMessages); + var startup = loader.LoadMethods(type, diagnosticMessages); var app = new ApplicationBuilder(services); app.ApplicationServices = startup.ConfigureServicesDelegate(new ServiceCollection()); @@ -96,7 +108,10 @@ namespace Microsoft.AspNet.Hosting.Tests var services = serviceCollection.BuildServiceProvider(); var diagnosticMessages = new List(); - var startup = new StartupLoader(services).Load("Microsoft.AspNet.Hosting.Tests", "WithConfigureServices", diagnosticMessages); + var hostingEnv = new HostingEnvironment { EnvironmentName = "WithConfigureServices" }; + var loader = new StartupLoader(services, hostingEnv); + var type = loader.FindStartupType("Microsoft.AspNet.Hosting.Tests", diagnosticMessages); + var startup = loader.LoadMethods(type, diagnosticMessages); var app = new ApplicationBuilder(services); app.ApplicationServices = startup.ConfigureServicesDelegate(serviceCollection); @@ -113,7 +128,9 @@ namespace Microsoft.AspNet.Hosting.Tests var services = serviceCollection.BuildServiceProvider(); var diagnosticMessages = new List(); - var startup = new StartupLoader(services).Load(typeof(TestStartup), "", diagnosticMessages); + var hostingEnv = new HostingEnvironment(); + var loader = new StartupLoader(services, hostingEnv); + var startup = loader.LoadMethods(typeof(TestStartup), diagnosticMessages); var app = new ApplicationBuilder(services); app.ApplicationServices = startup.ConfigureServicesDelegate(serviceCollection); @@ -130,7 +147,9 @@ namespace Microsoft.AspNet.Hosting.Tests var services = serviceCollection.BuildServiceProvider(); var diagnosticMessages = new List(); - var startup = new StartupLoader(services).Load(typeof(TestStartup), "No", diagnosticMessages); + var hostingEnv = new HostingEnvironment { EnvironmentName = "No" }; + var loader = new StartupLoader(services, hostingEnv); + var startup = loader.LoadMethods(typeof(TestStartup), diagnosticMessages); var app = new ApplicationBuilder(services); app.ApplicationServices = startup.ConfigureServicesDelegate(serviceCollection); diff --git a/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs b/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs index 72f7277990..fcbd153e8a 100644 --- a/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs +++ b/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs @@ -2,20 +2,16 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using System.Diagnostics; using System.IO; using System.Net; using System.Net.Http; -using System.Runtime.Versioning; using System.Threading.Tasks; using Microsoft.AspNet.Builder; using Microsoft.AspNet.Hosting; -using Microsoft.AspNet.Hosting.Startup; using Microsoft.AspNet.Http; using Microsoft.Framework.ConfigurationModel; using Microsoft.Framework.DependencyInjection; using Microsoft.Framework.Logging; -using Microsoft.Framework.Runtime; using Microsoft.Framework.Runtime.Infrastructure; using Xunit; @@ -56,54 +52,6 @@ namespace Microsoft.AspNet.TestHost Assert.Equal("RequestServices:True", result); } - [Fact] - public async Task CanChangeApplicationName() - { - var fallbackServices = CallContextServiceLocator.Locator.ServiceProvider; - var appName = "gobblegobble"; - - var builder = TestServer.CreateBuilder(fallbackServices, new Configuration(), - app => - { - app.Run(context => - { - var appEnv = app.ApplicationServices.GetRequiredService(); - return context.Response.WriteAsync("AppName:" + appEnv.ApplicationName); - }); - }, - configureServices: null); - - builder.ApplicationName = appName; - var server = builder.Build(); - - string result = await server.CreateClient().GetStringAsync("/path"); - Assert.Equal("AppName:" + appName, result); - } - - [Fact] - public async Task CanChangeAppPath() - { - var fallbackServices = CallContextServiceLocator.Locator.ServiceProvider; - var appPath = "."; - - var builder = TestServer.CreateBuilder(fallbackServices, new Configuration(), - app => - { - app.Run(context => - { - var env = app.ApplicationServices.GetRequiredService(); - return context.Response.WriteAsync("AppPath:" + env.ApplicationBasePath); - }); - }, - configureServices: null); - - builder.ApplicationBasePath = appPath; - var server = builder.Build(); - - string result = await server.CreateClient().GetStringAsync("/path"); - Assert.Equal("AppPath:" + appPath, result); - } - [Fact] public async Task CanAccessLogger() { @@ -242,7 +190,7 @@ namespace Microsoft.AspNet.TestHost [Fact] public async Task CanCreateViaStartupType() { - TestServer server = TestServer.Create(); + TestServer server = new TestServer(TestServer.CreateBuilder().UseStartup()); HttpResponseMessage result = await server.CreateClient().GetAsync("/"); Assert.Equal(HttpStatusCode.OK, result.StatusCode); Assert.Equal("FoundService:True", await result.Content.ReadAsStringAsync()); @@ -251,9 +199,9 @@ namespace Microsoft.AspNet.TestHost [Fact] public async Task CanCreateViaStartupTypeAndSpecifyEnv() { - var builder = TestServer.CreateBuilder(); - builder.Environment = "Foo"; - var server = builder.Build(); + TestServer server = new TestServer(TestServer.CreateBuilder() + .UseStartup() + .UseEnvironment("Foo")); HttpResponseMessage result = await server.CreateClient().GetAsync("/"); Assert.Equal(HttpStatusCode.OK, result.StatusCode); Assert.Equal("FoundFoo:False", await result.Content.ReadAsStringAsync()); From 5093c06b2a6aa3360989fe6e7e61ea69a1f616fb Mon Sep 17 00:00:00 2001 From: Hao Kung Date: Fri, 24 Apr 2015 00:10:36 -0700 Subject: [PATCH 275/987] Fix program main to actually use config --- src/Microsoft.AspNet.Hosting/Program.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Microsoft.AspNet.Hosting/Program.cs b/src/Microsoft.AspNet.Hosting/Program.cs index 541eec0f0d..d1282d9e1a 100644 --- a/src/Microsoft.AspNet.Hosting/Program.cs +++ b/src/Microsoft.AspNet.Hosting/Program.cs @@ -34,7 +34,7 @@ namespace Microsoft.AspNet.Hosting config.AddEnvironmentVariables(); config.AddCommandLine(args); - var host = new WebHostBuilder(_serviceProvider).Build(); + var host = new WebHostBuilder(_serviceProvider, config).Build(); var serverShutdown = host.Start(); var loggerFactory = host.ApplicationServices.GetRequiredService(); var appShutdownService = host.ApplicationServices.GetRequiredService(); From b98af101f9226b4d3f817640f86058cd3a2d8085 Mon Sep 17 00:00:00 2001 From: Troy Dai Date: Fri, 24 Apr 2015 13:57:10 -0700 Subject: [PATCH 276/987] React to OperatingSystems change --- test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs b/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs index dca50c4e0f..5260f6c345 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs @@ -197,7 +197,7 @@ namespace Microsoft.AspNet.Hosting } [ConditionalTheory] - [OSSkipCondition(OperatingSystems.Unix | OperatingSystems.MacOSX)] + [OSSkipCondition(OperatingSystems.Linux | OperatingSystems.MacOSX)] [InlineData(@"sub/sub2\sub3\", @"sub/sub2/sub3/")] public void MapPath_Windows_Facts(string virtualPath, string expectedSuffix) { From f48801cdf704fb60d395d5cc18ca2014958752a1 Mon Sep 17 00:00:00 2001 From: Chris R Date: Wed, 29 Apr 2015 15:28:38 -0700 Subject: [PATCH 277/987] React to Http.Core rename. --- src/Microsoft.AspNet.Hosting.Interfaces/project.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Microsoft.AspNet.Hosting.Interfaces/project.json b/src/Microsoft.AspNet.Hosting.Interfaces/project.json index fa914dfcab..448c0c48a3 100644 --- a/src/Microsoft.AspNet.Hosting.Interfaces/project.json +++ b/src/Microsoft.AspNet.Hosting.Interfaces/project.json @@ -2,7 +2,7 @@ "version": "1.0.0-*", "description": "ASP.NET 5 Hosting interfaces.", "dependencies": { - "Microsoft.AspNet.Http.Core": "1.0.0-*", + "Microsoft.AspNet.Http.Abstractions": "1.0.0-*", "Microsoft.AspNet.FileProviders.Interfaces": "1.0.0-*", "Microsoft.Framework.NotNullAttribute.Internal": { "type": "build", "version": "1.0.0-*" } }, From ec7a4351ded97ec484fcbf273bab05e0ad12954c Mon Sep 17 00:00:00 2001 From: Brennan Date: Wed, 29 Apr 2015 16:54:12 -0700 Subject: [PATCH 278/987] Interfaces->Abstractions --- Hosting.sln | 4 ++-- .../HostingEnvironmentExtensions.cs | 0 .../IApplicationLifetime.cs | 0 .../IHostingEnvironment.cs | 0 .../IHttpContextAccessor.cs | 0 .../Microsoft.AspNet.Hosting.Abstractions.xproj} | 0 .../Properties/AssemblyInfo.cs | 0 .../project.json | 2 +- .../IServerFactory.cs | 0 .../IServerInformation.cs | 0 .../Microsoft.AspNet.Hosting.Server.Abstractions.xproj} | 0 .../project.json | 0 src/Microsoft.AspNet.Hosting/project.json | 4 ++-- 13 files changed, 5 insertions(+), 5 deletions(-) rename src/{Microsoft.AspNet.Hosting.Interfaces => Microsoft.AspNet.Hosting.Abstractions}/HostingEnvironmentExtensions.cs (100%) rename src/{Microsoft.AspNet.Hosting.Interfaces => Microsoft.AspNet.Hosting.Abstractions}/IApplicationLifetime.cs (100%) rename src/{Microsoft.AspNet.Hosting.Interfaces => Microsoft.AspNet.Hosting.Abstractions}/IHostingEnvironment.cs (100%) rename src/{Microsoft.AspNet.Hosting.Interfaces => Microsoft.AspNet.Hosting.Abstractions}/IHttpContextAccessor.cs (100%) rename src/{Microsoft.AspNet.Hosting.Interfaces/Microsoft.AspNet.Hosting.Interfaces.xproj => Microsoft.AspNet.Hosting.Abstractions/Microsoft.AspNet.Hosting.Abstractions.xproj} (100%) rename src/{Microsoft.AspNet.Hosting.Interfaces => Microsoft.AspNet.Hosting.Abstractions}/Properties/AssemblyInfo.cs (100%) rename src/{Microsoft.AspNet.Hosting.Interfaces => Microsoft.AspNet.Hosting.Abstractions}/project.json (86%) rename src/{Microsoft.AspNet.Hosting.Server.Interfaces => Microsoft.AspNet.Hosting.Server.Abstractions}/IServerFactory.cs (100%) rename src/{Microsoft.AspNet.Hosting.Server.Interfaces => Microsoft.AspNet.Hosting.Server.Abstractions}/IServerInformation.cs (100%) rename src/{Microsoft.AspNet.Hosting.Server.Interfaces/Microsoft.AspNet.Hosting.Server.Interfaces.xproj => Microsoft.AspNet.Hosting.Server.Abstractions/Microsoft.AspNet.Hosting.Server.Abstractions.xproj} (100%) rename src/{Microsoft.AspNet.Hosting.Server.Interfaces => Microsoft.AspNet.Hosting.Server.Abstractions}/project.json (100%) diff --git a/Hosting.sln b/Hosting.sln index b7b4361fe4..0c93390a49 100644 --- a/Hosting.sln +++ b/Hosting.sln @@ -20,9 +20,9 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution global.json = global.json EndProjectSection EndProject -Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNet.Hosting.Interfaces", "src\Microsoft.AspNet.Hosting.Interfaces\Microsoft.AspNet.Hosting.Interfaces.xproj", "{BB780FBB-7842-4759-8DE7-96FA2E5571C1}" +Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNet.Hosting.Abstractions", "src\Microsoft.AspNet.Hosting.Abstractions\Microsoft.AspNet.Hosting.Abstractions.xproj", "{BB780FBB-7842-4759-8DE7-96FA2E5571C1}" EndProject -Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNet.Hosting.Server.Interfaces", "src\Microsoft.AspNet.Hosting.Server.Interfaces\Microsoft.AspNet.Hosting.Server.Interfaces.xproj", "{FDBBA081-5248-4FC0-9E08-B46BEF3FA438}" +Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNet.Hosting.Server.Abstractions", "src\Microsoft.AspNet.Hosting.Server.Abstractions\Microsoft.AspNet.Hosting.Server.Abstractions.xproj", "{FDBBA081-5248-4FC0-9E08-B46BEF3FA438}" EndProject Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNet.Server.Testing", "src\Microsoft.AspNet.Server.Testing\Microsoft.AspNet.Server.Testing.xproj", "{3DA89347-6731-4366-80C4-548F24E8607B}" EndProject diff --git a/src/Microsoft.AspNet.Hosting.Interfaces/HostingEnvironmentExtensions.cs b/src/Microsoft.AspNet.Hosting.Abstractions/HostingEnvironmentExtensions.cs similarity index 100% rename from src/Microsoft.AspNet.Hosting.Interfaces/HostingEnvironmentExtensions.cs rename to src/Microsoft.AspNet.Hosting.Abstractions/HostingEnvironmentExtensions.cs diff --git a/src/Microsoft.AspNet.Hosting.Interfaces/IApplicationLifetime.cs b/src/Microsoft.AspNet.Hosting.Abstractions/IApplicationLifetime.cs similarity index 100% rename from src/Microsoft.AspNet.Hosting.Interfaces/IApplicationLifetime.cs rename to src/Microsoft.AspNet.Hosting.Abstractions/IApplicationLifetime.cs diff --git a/src/Microsoft.AspNet.Hosting.Interfaces/IHostingEnvironment.cs b/src/Microsoft.AspNet.Hosting.Abstractions/IHostingEnvironment.cs similarity index 100% rename from src/Microsoft.AspNet.Hosting.Interfaces/IHostingEnvironment.cs rename to src/Microsoft.AspNet.Hosting.Abstractions/IHostingEnvironment.cs diff --git a/src/Microsoft.AspNet.Hosting.Interfaces/IHttpContextAccessor.cs b/src/Microsoft.AspNet.Hosting.Abstractions/IHttpContextAccessor.cs similarity index 100% rename from src/Microsoft.AspNet.Hosting.Interfaces/IHttpContextAccessor.cs rename to src/Microsoft.AspNet.Hosting.Abstractions/IHttpContextAccessor.cs diff --git a/src/Microsoft.AspNet.Hosting.Interfaces/Microsoft.AspNet.Hosting.Interfaces.xproj b/src/Microsoft.AspNet.Hosting.Abstractions/Microsoft.AspNet.Hosting.Abstractions.xproj similarity index 100% rename from src/Microsoft.AspNet.Hosting.Interfaces/Microsoft.AspNet.Hosting.Interfaces.xproj rename to src/Microsoft.AspNet.Hosting.Abstractions/Microsoft.AspNet.Hosting.Abstractions.xproj diff --git a/src/Microsoft.AspNet.Hosting.Interfaces/Properties/AssemblyInfo.cs b/src/Microsoft.AspNet.Hosting.Abstractions/Properties/AssemblyInfo.cs similarity index 100% rename from src/Microsoft.AspNet.Hosting.Interfaces/Properties/AssemblyInfo.cs rename to src/Microsoft.AspNet.Hosting.Abstractions/Properties/AssemblyInfo.cs diff --git a/src/Microsoft.AspNet.Hosting.Interfaces/project.json b/src/Microsoft.AspNet.Hosting.Abstractions/project.json similarity index 86% rename from src/Microsoft.AspNet.Hosting.Interfaces/project.json rename to src/Microsoft.AspNet.Hosting.Abstractions/project.json index 448c0c48a3..5d61d5a330 100644 --- a/src/Microsoft.AspNet.Hosting.Interfaces/project.json +++ b/src/Microsoft.AspNet.Hosting.Abstractions/project.json @@ -1,6 +1,6 @@ { "version": "1.0.0-*", - "description": "ASP.NET 5 Hosting interfaces.", + "description": "ASP.NET 5 Hosting abstractions.", "dependencies": { "Microsoft.AspNet.Http.Abstractions": "1.0.0-*", "Microsoft.AspNet.FileProviders.Interfaces": "1.0.0-*", diff --git a/src/Microsoft.AspNet.Hosting.Server.Interfaces/IServerFactory.cs b/src/Microsoft.AspNet.Hosting.Server.Abstractions/IServerFactory.cs similarity index 100% rename from src/Microsoft.AspNet.Hosting.Server.Interfaces/IServerFactory.cs rename to src/Microsoft.AspNet.Hosting.Server.Abstractions/IServerFactory.cs diff --git a/src/Microsoft.AspNet.Hosting.Server.Interfaces/IServerInformation.cs b/src/Microsoft.AspNet.Hosting.Server.Abstractions/IServerInformation.cs similarity index 100% rename from src/Microsoft.AspNet.Hosting.Server.Interfaces/IServerInformation.cs rename to src/Microsoft.AspNet.Hosting.Server.Abstractions/IServerInformation.cs diff --git a/src/Microsoft.AspNet.Hosting.Server.Interfaces/Microsoft.AspNet.Hosting.Server.Interfaces.xproj b/src/Microsoft.AspNet.Hosting.Server.Abstractions/Microsoft.AspNet.Hosting.Server.Abstractions.xproj similarity index 100% rename from src/Microsoft.AspNet.Hosting.Server.Interfaces/Microsoft.AspNet.Hosting.Server.Interfaces.xproj rename to src/Microsoft.AspNet.Hosting.Server.Abstractions/Microsoft.AspNet.Hosting.Server.Abstractions.xproj diff --git a/src/Microsoft.AspNet.Hosting.Server.Interfaces/project.json b/src/Microsoft.AspNet.Hosting.Server.Abstractions/project.json similarity index 100% rename from src/Microsoft.AspNet.Hosting.Server.Interfaces/project.json rename to src/Microsoft.AspNet.Hosting.Server.Abstractions/project.json diff --git a/src/Microsoft.AspNet.Hosting/project.json b/src/Microsoft.AspNet.Hosting/project.json index 25eda4017f..89f0bf59dd 100644 --- a/src/Microsoft.AspNet.Hosting/project.json +++ b/src/Microsoft.AspNet.Hosting/project.json @@ -4,8 +4,8 @@ "compilationOptions": { "warningsAsErrors": "true" }, "dependencies": { "Microsoft.AspNet.FileProviders.Physical": "1.0.0-*", - "Microsoft.AspNet.Hosting.Interfaces": "1.0.0-*", - "Microsoft.AspNet.Hosting.Server.Interfaces": "1.0.0-*", + "Microsoft.AspNet.Hosting.Abstractions": "1.0.0-*", + "Microsoft.AspNet.Hosting.Server.Abstractions": "1.0.0-*", "Microsoft.AspNet.Http": "1.0.0-*", "Microsoft.AspNet.Http.Extensions": "1.0.0-*", "Microsoft.Framework.ConfigurationModel": "1.0.0-*", From 4308522de7ab7fe1f4428a3ccad4186ccf13ad11 Mon Sep 17 00:00:00 2001 From: Brennan Date: Wed, 29 Apr 2015 18:52:51 -0700 Subject: [PATCH 279/987] Reacting to interface name changes --- src/Microsoft.AspNet.Hosting.Abstractions/project.json | 2 +- src/Microsoft.AspNet.Hosting.Server.Abstractions/project.json | 2 +- src/Microsoft.AspNet.Hosting/project.json | 2 +- src/Microsoft.AspNet.Server.Testing/project.json | 4 ++-- test/Microsoft.AspNet.Hosting.Tests/project.json | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Microsoft.AspNet.Hosting.Abstractions/project.json b/src/Microsoft.AspNet.Hosting.Abstractions/project.json index 5d61d5a330..bfb6a183f1 100644 --- a/src/Microsoft.AspNet.Hosting.Abstractions/project.json +++ b/src/Microsoft.AspNet.Hosting.Abstractions/project.json @@ -3,7 +3,7 @@ "description": "ASP.NET 5 Hosting abstractions.", "dependencies": { "Microsoft.AspNet.Http.Abstractions": "1.0.0-*", - "Microsoft.AspNet.FileProviders.Interfaces": "1.0.0-*", + "Microsoft.AspNet.FileProviders.Abstractions": "1.0.0-*", "Microsoft.Framework.NotNullAttribute.Internal": { "type": "build", "version": "1.0.0-*" } }, "frameworks": { diff --git a/src/Microsoft.AspNet.Hosting.Server.Abstractions/project.json b/src/Microsoft.AspNet.Hosting.Server.Abstractions/project.json index fd590e5417..ecc01a5efb 100644 --- a/src/Microsoft.AspNet.Hosting.Server.Abstractions/project.json +++ b/src/Microsoft.AspNet.Hosting.Server.Abstractions/project.json @@ -2,7 +2,7 @@ "version": "1.0.0-*", "dependencies": { "Microsoft.AspNet.FeatureModel": "1.0.0-*", - "Microsoft.Framework.ConfigurationModel.Interfaces": "1.0.0-*" + "Microsoft.Framework.ConfigurationModel.Abstractions": "1.0.0-*" }, "frameworks": { diff --git a/src/Microsoft.AspNet.Hosting/project.json b/src/Microsoft.AspNet.Hosting/project.json index 89f0bf59dd..2450ba27c8 100644 --- a/src/Microsoft.AspNet.Hosting/project.json +++ b/src/Microsoft.AspNet.Hosting/project.json @@ -11,7 +11,7 @@ "Microsoft.Framework.ConfigurationModel": "1.0.0-*", "Microsoft.Framework.DependencyInjection": "1.0.0-*", "Microsoft.Framework.Logging": "1.0.0-*", - "Microsoft.Framework.Runtime.Interfaces": "1.0.0-*", + "Microsoft.Framework.Runtime.Abstractions": "1.0.0-*", "Microsoft.Framework.NotNullAttribute.Internal": { "type": "build", "version": "1.0.0-*" }, "Newtonsoft.Json": "6.0.6" }, diff --git a/src/Microsoft.AspNet.Server.Testing/project.json b/src/Microsoft.AspNet.Server.Testing/project.json index c4abcae964..ffebc4d56b 100644 --- a/src/Microsoft.AspNet.Server.Testing/project.json +++ b/src/Microsoft.AspNet.Server.Testing/project.json @@ -3,8 +3,8 @@ "description": "ASP.NET 5 helpers to deploy applications to IIS Express, IIS, WebListener and Kestrel for testing.", "dependencies": { "Microsoft.AspNet.Testing": "1.0.0-*", - "Microsoft.Framework.Logging.Interfaces": "1.0.0-*", - "Microsoft.Framework.Runtime.Interfaces": "1.0.0-*" + "Microsoft.Framework.Logging.Abstractions": "1.0.0-*", + "Microsoft.Framework.Runtime.Abstractions": "1.0.0-*" }, "frameworks": { "dnx451": { diff --git a/test/Microsoft.AspNet.Hosting.Tests/project.json b/test/Microsoft.AspNet.Hosting.Tests/project.json index de8dbc8b81..3465647dff 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/project.json +++ b/test/Microsoft.AspNet.Hosting.Tests/project.json @@ -4,7 +4,7 @@ "Microsoft.AspNet.Owin": "1.0.0-*", "Microsoft.AspNet.Testing": "1.0.0-*", "Microsoft.Framework.OptionsModel": "1.0.0-*", - "Microsoft.Framework.Runtime.Interfaces": "1.0.0-*", + "Microsoft.Framework.Runtime.Abstractions": "1.0.0-*", "Moq": "4.2.1312.1622", "xunit.runner.aspnet": "2.0.0-aspnet-*" }, From 2a90b46be98a14813ea8801ab3dcc55abe2c28af Mon Sep 17 00:00:00 2001 From: Brennan Date: Wed, 29 Apr 2015 23:44:24 -0700 Subject: [PATCH 280/987] Revert "Reacting to interface name changes" This reverts commit 4308522de7ab7fe1f4428a3ccad4186ccf13ad11. --- src/Microsoft.AspNet.Hosting.Abstractions/project.json | 2 +- src/Microsoft.AspNet.Hosting.Server.Abstractions/project.json | 2 +- src/Microsoft.AspNet.Hosting/project.json | 2 +- src/Microsoft.AspNet.Server.Testing/project.json | 4 ++-- test/Microsoft.AspNet.Hosting.Tests/project.json | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Microsoft.AspNet.Hosting.Abstractions/project.json b/src/Microsoft.AspNet.Hosting.Abstractions/project.json index bfb6a183f1..5d61d5a330 100644 --- a/src/Microsoft.AspNet.Hosting.Abstractions/project.json +++ b/src/Microsoft.AspNet.Hosting.Abstractions/project.json @@ -3,7 +3,7 @@ "description": "ASP.NET 5 Hosting abstractions.", "dependencies": { "Microsoft.AspNet.Http.Abstractions": "1.0.0-*", - "Microsoft.AspNet.FileProviders.Abstractions": "1.0.0-*", + "Microsoft.AspNet.FileProviders.Interfaces": "1.0.0-*", "Microsoft.Framework.NotNullAttribute.Internal": { "type": "build", "version": "1.0.0-*" } }, "frameworks": { diff --git a/src/Microsoft.AspNet.Hosting.Server.Abstractions/project.json b/src/Microsoft.AspNet.Hosting.Server.Abstractions/project.json index ecc01a5efb..fd590e5417 100644 --- a/src/Microsoft.AspNet.Hosting.Server.Abstractions/project.json +++ b/src/Microsoft.AspNet.Hosting.Server.Abstractions/project.json @@ -2,7 +2,7 @@ "version": "1.0.0-*", "dependencies": { "Microsoft.AspNet.FeatureModel": "1.0.0-*", - "Microsoft.Framework.ConfigurationModel.Abstractions": "1.0.0-*" + "Microsoft.Framework.ConfigurationModel.Interfaces": "1.0.0-*" }, "frameworks": { diff --git a/src/Microsoft.AspNet.Hosting/project.json b/src/Microsoft.AspNet.Hosting/project.json index 2450ba27c8..89f0bf59dd 100644 --- a/src/Microsoft.AspNet.Hosting/project.json +++ b/src/Microsoft.AspNet.Hosting/project.json @@ -11,7 +11,7 @@ "Microsoft.Framework.ConfigurationModel": "1.0.0-*", "Microsoft.Framework.DependencyInjection": "1.0.0-*", "Microsoft.Framework.Logging": "1.0.0-*", - "Microsoft.Framework.Runtime.Abstractions": "1.0.0-*", + "Microsoft.Framework.Runtime.Interfaces": "1.0.0-*", "Microsoft.Framework.NotNullAttribute.Internal": { "type": "build", "version": "1.0.0-*" }, "Newtonsoft.Json": "6.0.6" }, diff --git a/src/Microsoft.AspNet.Server.Testing/project.json b/src/Microsoft.AspNet.Server.Testing/project.json index ffebc4d56b..c4abcae964 100644 --- a/src/Microsoft.AspNet.Server.Testing/project.json +++ b/src/Microsoft.AspNet.Server.Testing/project.json @@ -3,8 +3,8 @@ "description": "ASP.NET 5 helpers to deploy applications to IIS Express, IIS, WebListener and Kestrel for testing.", "dependencies": { "Microsoft.AspNet.Testing": "1.0.0-*", - "Microsoft.Framework.Logging.Abstractions": "1.0.0-*", - "Microsoft.Framework.Runtime.Abstractions": "1.0.0-*" + "Microsoft.Framework.Logging.Interfaces": "1.0.0-*", + "Microsoft.Framework.Runtime.Interfaces": "1.0.0-*" }, "frameworks": { "dnx451": { diff --git a/test/Microsoft.AspNet.Hosting.Tests/project.json b/test/Microsoft.AspNet.Hosting.Tests/project.json index 3465647dff..de8dbc8b81 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/project.json +++ b/test/Microsoft.AspNet.Hosting.Tests/project.json @@ -4,7 +4,7 @@ "Microsoft.AspNet.Owin": "1.0.0-*", "Microsoft.AspNet.Testing": "1.0.0-*", "Microsoft.Framework.OptionsModel": "1.0.0-*", - "Microsoft.Framework.Runtime.Abstractions": "1.0.0-*", + "Microsoft.Framework.Runtime.Interfaces": "1.0.0-*", "Moq": "4.2.1312.1622", "xunit.runner.aspnet": "2.0.0-aspnet-*" }, From 306cf6221d449d9455c24bb8f92976d64461b0e3 Mon Sep 17 00:00:00 2001 From: Brennan Date: Wed, 29 Apr 2015 23:44:27 -0700 Subject: [PATCH 281/987] Revert "Interfaces->Abstractions" This reverts commit ec7a4351ded97ec484fcbf273bab05e0ad12954c. --- Hosting.sln | 4 ++-- .../HostingEnvironmentExtensions.cs | 0 .../IApplicationLifetime.cs | 0 .../IHostingEnvironment.cs | 0 .../IHttpContextAccessor.cs | 0 .../Microsoft.AspNet.Hosting.Interfaces.xproj} | 0 .../Properties/AssemblyInfo.cs | 0 .../project.json | 2 +- .../IServerFactory.cs | 0 .../IServerInformation.cs | 0 .../Microsoft.AspNet.Hosting.Server.Interfaces.xproj} | 0 .../project.json | 0 src/Microsoft.AspNet.Hosting/project.json | 4 ++-- 13 files changed, 5 insertions(+), 5 deletions(-) rename src/{Microsoft.AspNet.Hosting.Abstractions => Microsoft.AspNet.Hosting.Interfaces}/HostingEnvironmentExtensions.cs (100%) rename src/{Microsoft.AspNet.Hosting.Abstractions => Microsoft.AspNet.Hosting.Interfaces}/IApplicationLifetime.cs (100%) rename src/{Microsoft.AspNet.Hosting.Abstractions => Microsoft.AspNet.Hosting.Interfaces}/IHostingEnvironment.cs (100%) rename src/{Microsoft.AspNet.Hosting.Abstractions => Microsoft.AspNet.Hosting.Interfaces}/IHttpContextAccessor.cs (100%) rename src/{Microsoft.AspNet.Hosting.Abstractions/Microsoft.AspNet.Hosting.Abstractions.xproj => Microsoft.AspNet.Hosting.Interfaces/Microsoft.AspNet.Hosting.Interfaces.xproj} (100%) rename src/{Microsoft.AspNet.Hosting.Abstractions => Microsoft.AspNet.Hosting.Interfaces}/Properties/AssemblyInfo.cs (100%) rename src/{Microsoft.AspNet.Hosting.Abstractions => Microsoft.AspNet.Hosting.Interfaces}/project.json (86%) rename src/{Microsoft.AspNet.Hosting.Server.Abstractions => Microsoft.AspNet.Hosting.Server.Interfaces}/IServerFactory.cs (100%) rename src/{Microsoft.AspNet.Hosting.Server.Abstractions => Microsoft.AspNet.Hosting.Server.Interfaces}/IServerInformation.cs (100%) rename src/{Microsoft.AspNet.Hosting.Server.Abstractions/Microsoft.AspNet.Hosting.Server.Abstractions.xproj => Microsoft.AspNet.Hosting.Server.Interfaces/Microsoft.AspNet.Hosting.Server.Interfaces.xproj} (100%) rename src/{Microsoft.AspNet.Hosting.Server.Abstractions => Microsoft.AspNet.Hosting.Server.Interfaces}/project.json (100%) diff --git a/Hosting.sln b/Hosting.sln index 0c93390a49..b7b4361fe4 100644 --- a/Hosting.sln +++ b/Hosting.sln @@ -20,9 +20,9 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution global.json = global.json EndProjectSection EndProject -Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNet.Hosting.Abstractions", "src\Microsoft.AspNet.Hosting.Abstractions\Microsoft.AspNet.Hosting.Abstractions.xproj", "{BB780FBB-7842-4759-8DE7-96FA2E5571C1}" +Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNet.Hosting.Interfaces", "src\Microsoft.AspNet.Hosting.Interfaces\Microsoft.AspNet.Hosting.Interfaces.xproj", "{BB780FBB-7842-4759-8DE7-96FA2E5571C1}" EndProject -Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNet.Hosting.Server.Abstractions", "src\Microsoft.AspNet.Hosting.Server.Abstractions\Microsoft.AspNet.Hosting.Server.Abstractions.xproj", "{FDBBA081-5248-4FC0-9E08-B46BEF3FA438}" +Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNet.Hosting.Server.Interfaces", "src\Microsoft.AspNet.Hosting.Server.Interfaces\Microsoft.AspNet.Hosting.Server.Interfaces.xproj", "{FDBBA081-5248-4FC0-9E08-B46BEF3FA438}" EndProject Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNet.Server.Testing", "src\Microsoft.AspNet.Server.Testing\Microsoft.AspNet.Server.Testing.xproj", "{3DA89347-6731-4366-80C4-548F24E8607B}" EndProject diff --git a/src/Microsoft.AspNet.Hosting.Abstractions/HostingEnvironmentExtensions.cs b/src/Microsoft.AspNet.Hosting.Interfaces/HostingEnvironmentExtensions.cs similarity index 100% rename from src/Microsoft.AspNet.Hosting.Abstractions/HostingEnvironmentExtensions.cs rename to src/Microsoft.AspNet.Hosting.Interfaces/HostingEnvironmentExtensions.cs diff --git a/src/Microsoft.AspNet.Hosting.Abstractions/IApplicationLifetime.cs b/src/Microsoft.AspNet.Hosting.Interfaces/IApplicationLifetime.cs similarity index 100% rename from src/Microsoft.AspNet.Hosting.Abstractions/IApplicationLifetime.cs rename to src/Microsoft.AspNet.Hosting.Interfaces/IApplicationLifetime.cs diff --git a/src/Microsoft.AspNet.Hosting.Abstractions/IHostingEnvironment.cs b/src/Microsoft.AspNet.Hosting.Interfaces/IHostingEnvironment.cs similarity index 100% rename from src/Microsoft.AspNet.Hosting.Abstractions/IHostingEnvironment.cs rename to src/Microsoft.AspNet.Hosting.Interfaces/IHostingEnvironment.cs diff --git a/src/Microsoft.AspNet.Hosting.Abstractions/IHttpContextAccessor.cs b/src/Microsoft.AspNet.Hosting.Interfaces/IHttpContextAccessor.cs similarity index 100% rename from src/Microsoft.AspNet.Hosting.Abstractions/IHttpContextAccessor.cs rename to src/Microsoft.AspNet.Hosting.Interfaces/IHttpContextAccessor.cs diff --git a/src/Microsoft.AspNet.Hosting.Abstractions/Microsoft.AspNet.Hosting.Abstractions.xproj b/src/Microsoft.AspNet.Hosting.Interfaces/Microsoft.AspNet.Hosting.Interfaces.xproj similarity index 100% rename from src/Microsoft.AspNet.Hosting.Abstractions/Microsoft.AspNet.Hosting.Abstractions.xproj rename to src/Microsoft.AspNet.Hosting.Interfaces/Microsoft.AspNet.Hosting.Interfaces.xproj diff --git a/src/Microsoft.AspNet.Hosting.Abstractions/Properties/AssemblyInfo.cs b/src/Microsoft.AspNet.Hosting.Interfaces/Properties/AssemblyInfo.cs similarity index 100% rename from src/Microsoft.AspNet.Hosting.Abstractions/Properties/AssemblyInfo.cs rename to src/Microsoft.AspNet.Hosting.Interfaces/Properties/AssemblyInfo.cs diff --git a/src/Microsoft.AspNet.Hosting.Abstractions/project.json b/src/Microsoft.AspNet.Hosting.Interfaces/project.json similarity index 86% rename from src/Microsoft.AspNet.Hosting.Abstractions/project.json rename to src/Microsoft.AspNet.Hosting.Interfaces/project.json index 5d61d5a330..448c0c48a3 100644 --- a/src/Microsoft.AspNet.Hosting.Abstractions/project.json +++ b/src/Microsoft.AspNet.Hosting.Interfaces/project.json @@ -1,6 +1,6 @@ { "version": "1.0.0-*", - "description": "ASP.NET 5 Hosting abstractions.", + "description": "ASP.NET 5 Hosting interfaces.", "dependencies": { "Microsoft.AspNet.Http.Abstractions": "1.0.0-*", "Microsoft.AspNet.FileProviders.Interfaces": "1.0.0-*", diff --git a/src/Microsoft.AspNet.Hosting.Server.Abstractions/IServerFactory.cs b/src/Microsoft.AspNet.Hosting.Server.Interfaces/IServerFactory.cs similarity index 100% rename from src/Microsoft.AspNet.Hosting.Server.Abstractions/IServerFactory.cs rename to src/Microsoft.AspNet.Hosting.Server.Interfaces/IServerFactory.cs diff --git a/src/Microsoft.AspNet.Hosting.Server.Abstractions/IServerInformation.cs b/src/Microsoft.AspNet.Hosting.Server.Interfaces/IServerInformation.cs similarity index 100% rename from src/Microsoft.AspNet.Hosting.Server.Abstractions/IServerInformation.cs rename to src/Microsoft.AspNet.Hosting.Server.Interfaces/IServerInformation.cs diff --git a/src/Microsoft.AspNet.Hosting.Server.Abstractions/Microsoft.AspNet.Hosting.Server.Abstractions.xproj b/src/Microsoft.AspNet.Hosting.Server.Interfaces/Microsoft.AspNet.Hosting.Server.Interfaces.xproj similarity index 100% rename from src/Microsoft.AspNet.Hosting.Server.Abstractions/Microsoft.AspNet.Hosting.Server.Abstractions.xproj rename to src/Microsoft.AspNet.Hosting.Server.Interfaces/Microsoft.AspNet.Hosting.Server.Interfaces.xproj diff --git a/src/Microsoft.AspNet.Hosting.Server.Abstractions/project.json b/src/Microsoft.AspNet.Hosting.Server.Interfaces/project.json similarity index 100% rename from src/Microsoft.AspNet.Hosting.Server.Abstractions/project.json rename to src/Microsoft.AspNet.Hosting.Server.Interfaces/project.json diff --git a/src/Microsoft.AspNet.Hosting/project.json b/src/Microsoft.AspNet.Hosting/project.json index 89f0bf59dd..25eda4017f 100644 --- a/src/Microsoft.AspNet.Hosting/project.json +++ b/src/Microsoft.AspNet.Hosting/project.json @@ -4,8 +4,8 @@ "compilationOptions": { "warningsAsErrors": "true" }, "dependencies": { "Microsoft.AspNet.FileProviders.Physical": "1.0.0-*", - "Microsoft.AspNet.Hosting.Abstractions": "1.0.0-*", - "Microsoft.AspNet.Hosting.Server.Abstractions": "1.0.0-*", + "Microsoft.AspNet.Hosting.Interfaces": "1.0.0-*", + "Microsoft.AspNet.Hosting.Server.Interfaces": "1.0.0-*", "Microsoft.AspNet.Http": "1.0.0-*", "Microsoft.AspNet.Http.Extensions": "1.0.0-*", "Microsoft.Framework.ConfigurationModel": "1.0.0-*", From a8f794bbb39d123f59d9ce3d41839d3c8b10f852 Mon Sep 17 00:00:00 2001 From: Brennan Date: Wed, 29 Apr 2015 23:47:40 -0700 Subject: [PATCH 282/987] Revert "Revert "Interfaces->Abstractions"" This reverts commit 306cf6221d449d9455c24bb8f92976d64461b0e3. --- Hosting.sln | 4 ++-- .../HostingEnvironmentExtensions.cs | 0 .../IApplicationLifetime.cs | 0 .../IHostingEnvironment.cs | 0 .../IHttpContextAccessor.cs | 0 .../Microsoft.AspNet.Hosting.Abstractions.xproj} | 0 .../Properties/AssemblyInfo.cs | 0 .../project.json | 2 +- .../IServerFactory.cs | 0 .../IServerInformation.cs | 0 .../Microsoft.AspNet.Hosting.Server.Abstractions.xproj} | 0 .../project.json | 0 src/Microsoft.AspNet.Hosting/project.json | 4 ++-- 13 files changed, 5 insertions(+), 5 deletions(-) rename src/{Microsoft.AspNet.Hosting.Interfaces => Microsoft.AspNet.Hosting.Abstractions}/HostingEnvironmentExtensions.cs (100%) rename src/{Microsoft.AspNet.Hosting.Interfaces => Microsoft.AspNet.Hosting.Abstractions}/IApplicationLifetime.cs (100%) rename src/{Microsoft.AspNet.Hosting.Interfaces => Microsoft.AspNet.Hosting.Abstractions}/IHostingEnvironment.cs (100%) rename src/{Microsoft.AspNet.Hosting.Interfaces => Microsoft.AspNet.Hosting.Abstractions}/IHttpContextAccessor.cs (100%) rename src/{Microsoft.AspNet.Hosting.Interfaces/Microsoft.AspNet.Hosting.Interfaces.xproj => Microsoft.AspNet.Hosting.Abstractions/Microsoft.AspNet.Hosting.Abstractions.xproj} (100%) rename src/{Microsoft.AspNet.Hosting.Interfaces => Microsoft.AspNet.Hosting.Abstractions}/Properties/AssemblyInfo.cs (100%) rename src/{Microsoft.AspNet.Hosting.Interfaces => Microsoft.AspNet.Hosting.Abstractions}/project.json (86%) rename src/{Microsoft.AspNet.Hosting.Server.Interfaces => Microsoft.AspNet.Hosting.Server.Abstractions}/IServerFactory.cs (100%) rename src/{Microsoft.AspNet.Hosting.Server.Interfaces => Microsoft.AspNet.Hosting.Server.Abstractions}/IServerInformation.cs (100%) rename src/{Microsoft.AspNet.Hosting.Server.Interfaces/Microsoft.AspNet.Hosting.Server.Interfaces.xproj => Microsoft.AspNet.Hosting.Server.Abstractions/Microsoft.AspNet.Hosting.Server.Abstractions.xproj} (100%) rename src/{Microsoft.AspNet.Hosting.Server.Interfaces => Microsoft.AspNet.Hosting.Server.Abstractions}/project.json (100%) diff --git a/Hosting.sln b/Hosting.sln index b7b4361fe4..0c93390a49 100644 --- a/Hosting.sln +++ b/Hosting.sln @@ -20,9 +20,9 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution global.json = global.json EndProjectSection EndProject -Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNet.Hosting.Interfaces", "src\Microsoft.AspNet.Hosting.Interfaces\Microsoft.AspNet.Hosting.Interfaces.xproj", "{BB780FBB-7842-4759-8DE7-96FA2E5571C1}" +Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNet.Hosting.Abstractions", "src\Microsoft.AspNet.Hosting.Abstractions\Microsoft.AspNet.Hosting.Abstractions.xproj", "{BB780FBB-7842-4759-8DE7-96FA2E5571C1}" EndProject -Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNet.Hosting.Server.Interfaces", "src\Microsoft.AspNet.Hosting.Server.Interfaces\Microsoft.AspNet.Hosting.Server.Interfaces.xproj", "{FDBBA081-5248-4FC0-9E08-B46BEF3FA438}" +Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNet.Hosting.Server.Abstractions", "src\Microsoft.AspNet.Hosting.Server.Abstractions\Microsoft.AspNet.Hosting.Server.Abstractions.xproj", "{FDBBA081-5248-4FC0-9E08-B46BEF3FA438}" EndProject Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNet.Server.Testing", "src\Microsoft.AspNet.Server.Testing\Microsoft.AspNet.Server.Testing.xproj", "{3DA89347-6731-4366-80C4-548F24E8607B}" EndProject diff --git a/src/Microsoft.AspNet.Hosting.Interfaces/HostingEnvironmentExtensions.cs b/src/Microsoft.AspNet.Hosting.Abstractions/HostingEnvironmentExtensions.cs similarity index 100% rename from src/Microsoft.AspNet.Hosting.Interfaces/HostingEnvironmentExtensions.cs rename to src/Microsoft.AspNet.Hosting.Abstractions/HostingEnvironmentExtensions.cs diff --git a/src/Microsoft.AspNet.Hosting.Interfaces/IApplicationLifetime.cs b/src/Microsoft.AspNet.Hosting.Abstractions/IApplicationLifetime.cs similarity index 100% rename from src/Microsoft.AspNet.Hosting.Interfaces/IApplicationLifetime.cs rename to src/Microsoft.AspNet.Hosting.Abstractions/IApplicationLifetime.cs diff --git a/src/Microsoft.AspNet.Hosting.Interfaces/IHostingEnvironment.cs b/src/Microsoft.AspNet.Hosting.Abstractions/IHostingEnvironment.cs similarity index 100% rename from src/Microsoft.AspNet.Hosting.Interfaces/IHostingEnvironment.cs rename to src/Microsoft.AspNet.Hosting.Abstractions/IHostingEnvironment.cs diff --git a/src/Microsoft.AspNet.Hosting.Interfaces/IHttpContextAccessor.cs b/src/Microsoft.AspNet.Hosting.Abstractions/IHttpContextAccessor.cs similarity index 100% rename from src/Microsoft.AspNet.Hosting.Interfaces/IHttpContextAccessor.cs rename to src/Microsoft.AspNet.Hosting.Abstractions/IHttpContextAccessor.cs diff --git a/src/Microsoft.AspNet.Hosting.Interfaces/Microsoft.AspNet.Hosting.Interfaces.xproj b/src/Microsoft.AspNet.Hosting.Abstractions/Microsoft.AspNet.Hosting.Abstractions.xproj similarity index 100% rename from src/Microsoft.AspNet.Hosting.Interfaces/Microsoft.AspNet.Hosting.Interfaces.xproj rename to src/Microsoft.AspNet.Hosting.Abstractions/Microsoft.AspNet.Hosting.Abstractions.xproj diff --git a/src/Microsoft.AspNet.Hosting.Interfaces/Properties/AssemblyInfo.cs b/src/Microsoft.AspNet.Hosting.Abstractions/Properties/AssemblyInfo.cs similarity index 100% rename from src/Microsoft.AspNet.Hosting.Interfaces/Properties/AssemblyInfo.cs rename to src/Microsoft.AspNet.Hosting.Abstractions/Properties/AssemblyInfo.cs diff --git a/src/Microsoft.AspNet.Hosting.Interfaces/project.json b/src/Microsoft.AspNet.Hosting.Abstractions/project.json similarity index 86% rename from src/Microsoft.AspNet.Hosting.Interfaces/project.json rename to src/Microsoft.AspNet.Hosting.Abstractions/project.json index 448c0c48a3..5d61d5a330 100644 --- a/src/Microsoft.AspNet.Hosting.Interfaces/project.json +++ b/src/Microsoft.AspNet.Hosting.Abstractions/project.json @@ -1,6 +1,6 @@ { "version": "1.0.0-*", - "description": "ASP.NET 5 Hosting interfaces.", + "description": "ASP.NET 5 Hosting abstractions.", "dependencies": { "Microsoft.AspNet.Http.Abstractions": "1.0.0-*", "Microsoft.AspNet.FileProviders.Interfaces": "1.0.0-*", diff --git a/src/Microsoft.AspNet.Hosting.Server.Interfaces/IServerFactory.cs b/src/Microsoft.AspNet.Hosting.Server.Abstractions/IServerFactory.cs similarity index 100% rename from src/Microsoft.AspNet.Hosting.Server.Interfaces/IServerFactory.cs rename to src/Microsoft.AspNet.Hosting.Server.Abstractions/IServerFactory.cs diff --git a/src/Microsoft.AspNet.Hosting.Server.Interfaces/IServerInformation.cs b/src/Microsoft.AspNet.Hosting.Server.Abstractions/IServerInformation.cs similarity index 100% rename from src/Microsoft.AspNet.Hosting.Server.Interfaces/IServerInformation.cs rename to src/Microsoft.AspNet.Hosting.Server.Abstractions/IServerInformation.cs diff --git a/src/Microsoft.AspNet.Hosting.Server.Interfaces/Microsoft.AspNet.Hosting.Server.Interfaces.xproj b/src/Microsoft.AspNet.Hosting.Server.Abstractions/Microsoft.AspNet.Hosting.Server.Abstractions.xproj similarity index 100% rename from src/Microsoft.AspNet.Hosting.Server.Interfaces/Microsoft.AspNet.Hosting.Server.Interfaces.xproj rename to src/Microsoft.AspNet.Hosting.Server.Abstractions/Microsoft.AspNet.Hosting.Server.Abstractions.xproj diff --git a/src/Microsoft.AspNet.Hosting.Server.Interfaces/project.json b/src/Microsoft.AspNet.Hosting.Server.Abstractions/project.json similarity index 100% rename from src/Microsoft.AspNet.Hosting.Server.Interfaces/project.json rename to src/Microsoft.AspNet.Hosting.Server.Abstractions/project.json diff --git a/src/Microsoft.AspNet.Hosting/project.json b/src/Microsoft.AspNet.Hosting/project.json index 25eda4017f..89f0bf59dd 100644 --- a/src/Microsoft.AspNet.Hosting/project.json +++ b/src/Microsoft.AspNet.Hosting/project.json @@ -4,8 +4,8 @@ "compilationOptions": { "warningsAsErrors": "true" }, "dependencies": { "Microsoft.AspNet.FileProviders.Physical": "1.0.0-*", - "Microsoft.AspNet.Hosting.Interfaces": "1.0.0-*", - "Microsoft.AspNet.Hosting.Server.Interfaces": "1.0.0-*", + "Microsoft.AspNet.Hosting.Abstractions": "1.0.0-*", + "Microsoft.AspNet.Hosting.Server.Abstractions": "1.0.0-*", "Microsoft.AspNet.Http": "1.0.0-*", "Microsoft.AspNet.Http.Extensions": "1.0.0-*", "Microsoft.Framework.ConfigurationModel": "1.0.0-*", From 23592666e29bb81fd5002b86ddc287d45e3b5a9c Mon Sep 17 00:00:00 2001 From: Brennan Date: Wed, 29 Apr 2015 23:48:21 -0700 Subject: [PATCH 283/987] Revert "Revert "Reacting to interface name changes"" This reverts commit 2a90b46be98a14813ea8801ab3dcc55abe2c28af. --- src/Microsoft.AspNet.Hosting.Abstractions/project.json | 2 +- src/Microsoft.AspNet.Hosting.Server.Abstractions/project.json | 2 +- src/Microsoft.AspNet.Hosting/project.json | 2 +- src/Microsoft.AspNet.Server.Testing/project.json | 4 ++-- test/Microsoft.AspNet.Hosting.Tests/project.json | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Microsoft.AspNet.Hosting.Abstractions/project.json b/src/Microsoft.AspNet.Hosting.Abstractions/project.json index 5d61d5a330..bfb6a183f1 100644 --- a/src/Microsoft.AspNet.Hosting.Abstractions/project.json +++ b/src/Microsoft.AspNet.Hosting.Abstractions/project.json @@ -3,7 +3,7 @@ "description": "ASP.NET 5 Hosting abstractions.", "dependencies": { "Microsoft.AspNet.Http.Abstractions": "1.0.0-*", - "Microsoft.AspNet.FileProviders.Interfaces": "1.0.0-*", + "Microsoft.AspNet.FileProviders.Abstractions": "1.0.0-*", "Microsoft.Framework.NotNullAttribute.Internal": { "type": "build", "version": "1.0.0-*" } }, "frameworks": { diff --git a/src/Microsoft.AspNet.Hosting.Server.Abstractions/project.json b/src/Microsoft.AspNet.Hosting.Server.Abstractions/project.json index fd590e5417..ecc01a5efb 100644 --- a/src/Microsoft.AspNet.Hosting.Server.Abstractions/project.json +++ b/src/Microsoft.AspNet.Hosting.Server.Abstractions/project.json @@ -2,7 +2,7 @@ "version": "1.0.0-*", "dependencies": { "Microsoft.AspNet.FeatureModel": "1.0.0-*", - "Microsoft.Framework.ConfigurationModel.Interfaces": "1.0.0-*" + "Microsoft.Framework.ConfigurationModel.Abstractions": "1.0.0-*" }, "frameworks": { diff --git a/src/Microsoft.AspNet.Hosting/project.json b/src/Microsoft.AspNet.Hosting/project.json index 89f0bf59dd..2450ba27c8 100644 --- a/src/Microsoft.AspNet.Hosting/project.json +++ b/src/Microsoft.AspNet.Hosting/project.json @@ -11,7 +11,7 @@ "Microsoft.Framework.ConfigurationModel": "1.0.0-*", "Microsoft.Framework.DependencyInjection": "1.0.0-*", "Microsoft.Framework.Logging": "1.0.0-*", - "Microsoft.Framework.Runtime.Interfaces": "1.0.0-*", + "Microsoft.Framework.Runtime.Abstractions": "1.0.0-*", "Microsoft.Framework.NotNullAttribute.Internal": { "type": "build", "version": "1.0.0-*" }, "Newtonsoft.Json": "6.0.6" }, diff --git a/src/Microsoft.AspNet.Server.Testing/project.json b/src/Microsoft.AspNet.Server.Testing/project.json index c4abcae964..ffebc4d56b 100644 --- a/src/Microsoft.AspNet.Server.Testing/project.json +++ b/src/Microsoft.AspNet.Server.Testing/project.json @@ -3,8 +3,8 @@ "description": "ASP.NET 5 helpers to deploy applications to IIS Express, IIS, WebListener and Kestrel for testing.", "dependencies": { "Microsoft.AspNet.Testing": "1.0.0-*", - "Microsoft.Framework.Logging.Interfaces": "1.0.0-*", - "Microsoft.Framework.Runtime.Interfaces": "1.0.0-*" + "Microsoft.Framework.Logging.Abstractions": "1.0.0-*", + "Microsoft.Framework.Runtime.Abstractions": "1.0.0-*" }, "frameworks": { "dnx451": { diff --git a/test/Microsoft.AspNet.Hosting.Tests/project.json b/test/Microsoft.AspNet.Hosting.Tests/project.json index de8dbc8b81..3465647dff 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/project.json +++ b/test/Microsoft.AspNet.Hosting.Tests/project.json @@ -4,7 +4,7 @@ "Microsoft.AspNet.Owin": "1.0.0-*", "Microsoft.AspNet.Testing": "1.0.0-*", "Microsoft.Framework.OptionsModel": "1.0.0-*", - "Microsoft.Framework.Runtime.Interfaces": "1.0.0-*", + "Microsoft.Framework.Runtime.Abstractions": "1.0.0-*", "Moq": "4.2.1312.1622", "xunit.runner.aspnet": "2.0.0-aspnet-*" }, From 2c602d6396697270f82d6aa04a74245b40252a21 Mon Sep 17 00:00:00 2001 From: Brennan Date: Wed, 29 Apr 2015 23:50:17 -0700 Subject: [PATCH 284/987] Only revert runtime.abstractions --- src/Microsoft.AspNet.Hosting/project.json | 2 +- src/Microsoft.AspNet.Server.Testing/project.json | 2 +- test/Microsoft.AspNet.Hosting.Tests/project.json | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Microsoft.AspNet.Hosting/project.json b/src/Microsoft.AspNet.Hosting/project.json index 2450ba27c8..89f0bf59dd 100644 --- a/src/Microsoft.AspNet.Hosting/project.json +++ b/src/Microsoft.AspNet.Hosting/project.json @@ -11,7 +11,7 @@ "Microsoft.Framework.ConfigurationModel": "1.0.0-*", "Microsoft.Framework.DependencyInjection": "1.0.0-*", "Microsoft.Framework.Logging": "1.0.0-*", - "Microsoft.Framework.Runtime.Abstractions": "1.0.0-*", + "Microsoft.Framework.Runtime.Interfaces": "1.0.0-*", "Microsoft.Framework.NotNullAttribute.Internal": { "type": "build", "version": "1.0.0-*" }, "Newtonsoft.Json": "6.0.6" }, diff --git a/src/Microsoft.AspNet.Server.Testing/project.json b/src/Microsoft.AspNet.Server.Testing/project.json index ffebc4d56b..c9913e24b2 100644 --- a/src/Microsoft.AspNet.Server.Testing/project.json +++ b/src/Microsoft.AspNet.Server.Testing/project.json @@ -4,7 +4,7 @@ "dependencies": { "Microsoft.AspNet.Testing": "1.0.0-*", "Microsoft.Framework.Logging.Abstractions": "1.0.0-*", - "Microsoft.Framework.Runtime.Abstractions": "1.0.0-*" + "Microsoft.Framework.Runtime.Interfaces": "1.0.0-*" }, "frameworks": { "dnx451": { diff --git a/test/Microsoft.AspNet.Hosting.Tests/project.json b/test/Microsoft.AspNet.Hosting.Tests/project.json index 3465647dff..de8dbc8b81 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/project.json +++ b/test/Microsoft.AspNet.Hosting.Tests/project.json @@ -4,7 +4,7 @@ "Microsoft.AspNet.Owin": "1.0.0-*", "Microsoft.AspNet.Testing": "1.0.0-*", "Microsoft.Framework.OptionsModel": "1.0.0-*", - "Microsoft.Framework.Runtime.Abstractions": "1.0.0-*", + "Microsoft.Framework.Runtime.Interfaces": "1.0.0-*", "Moq": "4.2.1312.1622", "xunit.runner.aspnet": "2.0.0-aspnet-*" }, From c4d8b51f99f87a7e352a8e06be40d41749ddf574 Mon Sep 17 00:00:00 2001 From: Brennan Date: Fri, 1 May 2015 11:05:40 -0700 Subject: [PATCH 285/987] React to DNX package renames --- src/Microsoft.AspNet.Hosting/project.json | 2 +- src/Microsoft.AspNet.Server.Testing/project.json | 2 +- test/Microsoft.AspNet.Hosting.Tests/project.json | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Microsoft.AspNet.Hosting/project.json b/src/Microsoft.AspNet.Hosting/project.json index 89f0bf59dd..2450ba27c8 100644 --- a/src/Microsoft.AspNet.Hosting/project.json +++ b/src/Microsoft.AspNet.Hosting/project.json @@ -11,7 +11,7 @@ "Microsoft.Framework.ConfigurationModel": "1.0.0-*", "Microsoft.Framework.DependencyInjection": "1.0.0-*", "Microsoft.Framework.Logging": "1.0.0-*", - "Microsoft.Framework.Runtime.Interfaces": "1.0.0-*", + "Microsoft.Framework.Runtime.Abstractions": "1.0.0-*", "Microsoft.Framework.NotNullAttribute.Internal": { "type": "build", "version": "1.0.0-*" }, "Newtonsoft.Json": "6.0.6" }, diff --git a/src/Microsoft.AspNet.Server.Testing/project.json b/src/Microsoft.AspNet.Server.Testing/project.json index c9913e24b2..ffebc4d56b 100644 --- a/src/Microsoft.AspNet.Server.Testing/project.json +++ b/src/Microsoft.AspNet.Server.Testing/project.json @@ -4,7 +4,7 @@ "dependencies": { "Microsoft.AspNet.Testing": "1.0.0-*", "Microsoft.Framework.Logging.Abstractions": "1.0.0-*", - "Microsoft.Framework.Runtime.Interfaces": "1.0.0-*" + "Microsoft.Framework.Runtime.Abstractions": "1.0.0-*" }, "frameworks": { "dnx451": { diff --git a/test/Microsoft.AspNet.Hosting.Tests/project.json b/test/Microsoft.AspNet.Hosting.Tests/project.json index de8dbc8b81..3465647dff 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/project.json +++ b/test/Microsoft.AspNet.Hosting.Tests/project.json @@ -4,7 +4,7 @@ "Microsoft.AspNet.Owin": "1.0.0-*", "Microsoft.AspNet.Testing": "1.0.0-*", "Microsoft.Framework.OptionsModel": "1.0.0-*", - "Microsoft.Framework.Runtime.Interfaces": "1.0.0-*", + "Microsoft.Framework.Runtime.Abstractions": "1.0.0-*", "Moq": "4.2.1312.1622", "xunit.runner.aspnet": "2.0.0-aspnet-*" }, From 65b21712ef26090c2c3b3b8818f61fe2193e0ed9 Mon Sep 17 00:00:00 2001 From: "N. Taylor Mullen" Date: Fri, 1 May 2015 13:51:42 -0700 Subject: [PATCH 286/987] Update LICENSE.txt and license header on files. --- LICENSE.txt | 2 +- .../HostingEnvironmentExtensions.cs | 2 +- .../IApplicationLifetime.cs | 2 +- .../IHostingEnvironment.cs | 2 +- .../IHttpContextAccessor.cs | 2 +- .../Properties/AssemblyInfo.cs | 2 +- .../IServerFactory.cs | 2 +- .../IServerInformation.cs | 2 +- src/Microsoft.AspNet.Hosting/ApplicationLifetime.cs | 2 +- .../Builder/ApplicationBuilderFactory.cs | 2 +- src/Microsoft.AspNet.Hosting/Builder/HttpContextFactory.cs | 2 +- .../Builder/IApplicationBuilderFactory.cs | 2 +- src/Microsoft.AspNet.Hosting/Builder/IHttpContextFactory.cs | 2 +- src/Microsoft.AspNet.Hosting/DefaultRequestIdentifierFeature.cs | 2 +- src/Microsoft.AspNet.Hosting/HostingEnvironment.cs | 2 +- src/Microsoft.AspNet.Hosting/HostingEnvironmentExtensions.cs | 2 +- src/Microsoft.AspNet.Hosting/HttpContextAccessor.cs | 2 +- .../Internal/AutoRequestServicesStartupFilter.cs | 2 +- src/Microsoft.AspNet.Hosting/Internal/HostingEngine.cs | 2 +- src/Microsoft.AspNet.Hosting/Internal/HostingUtilities.cs | 2 +- src/Microsoft.AspNet.Hosting/Internal/IHostingEngine.cs | 2 +- .../Internal/RequestServicesContainer.cs | 2 +- .../Internal/RequestServicesContainerMiddleware.cs | 2 +- src/Microsoft.AspNet.Hosting/PlatformHelper.cs | 2 +- src/Microsoft.AspNet.Hosting/Program.cs | 2 +- src/Microsoft.AspNet.Hosting/Properties/AssemblyInfo.cs | 2 +- src/Microsoft.AspNet.Hosting/Server/IServerLoader.cs | 2 +- src/Microsoft.AspNet.Hosting/Server/ServerLoader.cs | 2 +- src/Microsoft.AspNet.Hosting/Startup/ConfigureDelegate.cs | 2 +- .../Startup/ConfigureServicesDelegate.cs | 2 +- src/Microsoft.AspNet.Hosting/Startup/IStartupFilter.cs | 2 +- src/Microsoft.AspNet.Hosting/Startup/IStartupLoader.cs | 2 +- src/Microsoft.AspNet.Hosting/Startup/StartupLoader.cs | 2 +- src/Microsoft.AspNet.Hosting/Startup/StartupMethods.cs | 2 +- src/Microsoft.AspNet.Hosting/WebHostBuilder.cs | 2 +- .../Common/DeploymentParameters.cs | 2 +- src/Microsoft.AspNet.Server.Testing/Common/DeploymentResult.cs | 2 +- .../Common/DotnetArchitecture.cs | 2 +- src/Microsoft.AspNet.Server.Testing/Common/DotnetFlavor.cs | 2 +- src/Microsoft.AspNet.Server.Testing/Common/RetryHelper.cs | 2 +- src/Microsoft.AspNet.Server.Testing/Common/ServerType.cs | 2 +- .../Deployers/ApplicationDeployer.cs | 2 +- .../Deployers/ApplicationDeployerFactory.cs | 2 +- .../Deployers/IApplicationDeployer.cs | 2 +- src/Microsoft.AspNet.Server.Testing/Deployers/IISDeployer.cs | 2 +- .../Deployers/IISExpressDeployer.cs | 2 +- src/Microsoft.AspNet.Server.Testing/Deployers/MonoDeployer.cs | 2 +- .../Deployers/SelfHostDeployer.cs | 2 +- .../xunit/SkipIfCurrentRuntimeIsCoreClr.cs | 2 +- .../xunit/SkipIfIISNativeVariationsNotEnabledAttribute.cs | 2 +- .../xunit/SkipIfIISVariationsNotEnabledAttribute.cs | 2 +- .../xunit/SkipOn32BitOSAttribute.cs | 2 +- src/Microsoft.AspNet.TestHost/ClientHandler.cs | 2 +- src/Microsoft.AspNet.TestHost/Properties/AssemblyInfo.cs | 2 +- src/Microsoft.AspNet.TestHost/RequestBuilder.cs | 2 +- src/Microsoft.AspNet.TestHost/RequestFeature.cs | 2 +- src/Microsoft.AspNet.TestHost/ResponseFeature.cs | 2 +- src/Microsoft.AspNet.TestHost/ResponseStream.cs | 2 +- src/Microsoft.AspNet.TestHost/TestServer.cs | 2 +- test/Microsoft.AspNet.Hosting.Tests/Fakes/FakeOptions.cs | 2 +- test/Microsoft.AspNet.Hosting.Tests/Fakes/FakeService.cs | 2 +- test/Microsoft.AspNet.Hosting.Tests/Fakes/IFactoryService.cs | 2 +- test/Microsoft.AspNet.Hosting.Tests/Fakes/IFakeEveryService.cs | 2 +- test/Microsoft.AspNet.Hosting.Tests/Fakes/IFakeScopedService.cs | 2 +- test/Microsoft.AspNet.Hosting.Tests/Fakes/IFakeService.cs | 2 +- .../Fakes/IFakeServiceInstance.cs | 2 +- .../Fakes/IFakeSingletonService.cs | 2 +- .../Fakes/IFakeStartupCallback.cs | 2 +- .../Microsoft.AspNet.Hosting.Tests/Fakes/INonexistentService.cs | 2 +- test/Microsoft.AspNet.Hosting.Tests/Fakes/Startup.cs | 2 +- test/Microsoft.AspNet.Hosting.Tests/Fakes/StartupBase.cs | 2 +- test/Microsoft.AspNet.Hosting.Tests/Fakes/StartupBoom.cs | 2 +- test/Microsoft.AspNet.Hosting.Tests/Fakes/StartupNoServices.cs | 2 +- .../Fakes/StartupWithConfigureServicesNotResolved.cs | 2 +- .../Microsoft.AspNet.Hosting.Tests/Fakes/StartupWithServices.cs | 2 +- test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs | 2 +- test/Microsoft.AspNet.Hosting.Tests/HostingUtilitiesTests.cs | 2 +- test/Microsoft.AspNet.Hosting.Tests/HttpContextFactoryFacts.cs | 2 +- test/Microsoft.AspNet.Hosting.Tests/StartupManagerTests.cs | 2 +- test/Microsoft.AspNet.TestHost.Tests/ClientHandlerTests.cs | 2 +- test/Microsoft.AspNet.TestHost.Tests/Properties/AssemblyInfo.cs | 2 +- test/Microsoft.AspNet.TestHost.Tests/RequestBuilderTests.cs | 2 +- test/Microsoft.AspNet.TestHost.Tests/ResponseFeatureTests.cs | 2 +- test/Microsoft.AspNet.TestHost.Tests/TestClientTests.cs | 2 +- test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs | 2 +- 85 files changed, 85 insertions(+), 85 deletions(-) diff --git a/LICENSE.txt b/LICENSE.txt index d85a1524ad..0bdc1962b6 100644 --- a/LICENSE.txt +++ b/LICENSE.txt @@ -1,4 +1,4 @@ -Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. +Copyright (c) .NET Foundation. All rights reserved. Licensed under the Apache License, Version 2.0 (the "License"); you may not use these files except in compliance with the License. You may obtain a copy of the diff --git a/src/Microsoft.AspNet.Hosting.Abstractions/HostingEnvironmentExtensions.cs b/src/Microsoft.AspNet.Hosting.Abstractions/HostingEnvironmentExtensions.cs index 9e9b5fd2ce..c0838231fc 100644 --- a/src/Microsoft.AspNet.Hosting.Abstractions/HostingEnvironmentExtensions.cs +++ b/src/Microsoft.AspNet.Hosting.Abstractions/HostingEnvironmentExtensions.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. +// 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; diff --git a/src/Microsoft.AspNet.Hosting.Abstractions/IApplicationLifetime.cs b/src/Microsoft.AspNet.Hosting.Abstractions/IApplicationLifetime.cs index 755a415103..c229eb6e67 100644 --- a/src/Microsoft.AspNet.Hosting.Abstractions/IApplicationLifetime.cs +++ b/src/Microsoft.AspNet.Hosting.Abstractions/IApplicationLifetime.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. +// 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.Threading; diff --git a/src/Microsoft.AspNet.Hosting.Abstractions/IHostingEnvironment.cs b/src/Microsoft.AspNet.Hosting.Abstractions/IHostingEnvironment.cs index da774985c4..b57ae9a6af 100644 --- a/src/Microsoft.AspNet.Hosting.Abstractions/IHostingEnvironment.cs +++ b/src/Microsoft.AspNet.Hosting.Abstractions/IHostingEnvironment.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. +// 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.FileProviders; diff --git a/src/Microsoft.AspNet.Hosting.Abstractions/IHttpContextAccessor.cs b/src/Microsoft.AspNet.Hosting.Abstractions/IHttpContextAccessor.cs index 8b1719880b..eab12b1344 100644 --- a/src/Microsoft.AspNet.Hosting.Abstractions/IHttpContextAccessor.cs +++ b/src/Microsoft.AspNet.Hosting.Abstractions/IHttpContextAccessor.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. +// 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; diff --git a/src/Microsoft.AspNet.Hosting.Abstractions/Properties/AssemblyInfo.cs b/src/Microsoft.AspNet.Hosting.Abstractions/Properties/AssemblyInfo.cs index f5c6f4a83a..025a94598c 100644 --- a/src/Microsoft.AspNet.Hosting.Abstractions/Properties/AssemblyInfo.cs +++ b/src/Microsoft.AspNet.Hosting.Abstractions/Properties/AssemblyInfo.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. +// 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.Reflection; diff --git a/src/Microsoft.AspNet.Hosting.Server.Abstractions/IServerFactory.cs b/src/Microsoft.AspNet.Hosting.Server.Abstractions/IServerFactory.cs index fe46b8fc69..a4b5c17d32 100644 --- a/src/Microsoft.AspNet.Hosting.Server.Abstractions/IServerFactory.cs +++ b/src/Microsoft.AspNet.Hosting.Server.Abstractions/IServerFactory.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. +// 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; diff --git a/src/Microsoft.AspNet.Hosting.Server.Abstractions/IServerInformation.cs b/src/Microsoft.AspNet.Hosting.Server.Abstractions/IServerInformation.cs index c30e0d00e3..2e3af1e7a2 100644 --- a/src/Microsoft.AspNet.Hosting.Server.Abstractions/IServerInformation.cs +++ b/src/Microsoft.AspNet.Hosting.Server.Abstractions/IServerInformation.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. +// 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. namespace Microsoft.AspNet.Hosting.Server diff --git a/src/Microsoft.AspNet.Hosting/ApplicationLifetime.cs b/src/Microsoft.AspNet.Hosting/ApplicationLifetime.cs index a8bb03860b..eb6dc364b9 100644 --- a/src/Microsoft.AspNet.Hosting/ApplicationLifetime.cs +++ b/src/Microsoft.AspNet.Hosting/ApplicationLifetime.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. +// 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; diff --git a/src/Microsoft.AspNet.Hosting/Builder/ApplicationBuilderFactory.cs b/src/Microsoft.AspNet.Hosting/Builder/ApplicationBuilderFactory.cs index acefa86bc7..f1198a9ef0 100644 --- a/src/Microsoft.AspNet.Hosting/Builder/ApplicationBuilderFactory.cs +++ b/src/Microsoft.AspNet.Hosting/Builder/ApplicationBuilderFactory.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. +// 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; diff --git a/src/Microsoft.AspNet.Hosting/Builder/HttpContextFactory.cs b/src/Microsoft.AspNet.Hosting/Builder/HttpContextFactory.cs index f8411eee1a..0b8af5f0ea 100644 --- a/src/Microsoft.AspNet.Hosting/Builder/HttpContextFactory.cs +++ b/src/Microsoft.AspNet.Hosting/Builder/HttpContextFactory.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. +// 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.FeatureModel; diff --git a/src/Microsoft.AspNet.Hosting/Builder/IApplicationBuilderFactory.cs b/src/Microsoft.AspNet.Hosting/Builder/IApplicationBuilderFactory.cs index c866b2d79d..ddcf5807a5 100644 --- a/src/Microsoft.AspNet.Hosting/Builder/IApplicationBuilderFactory.cs +++ b/src/Microsoft.AspNet.Hosting/Builder/IApplicationBuilderFactory.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. +// 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.Builder; diff --git a/src/Microsoft.AspNet.Hosting/Builder/IHttpContextFactory.cs b/src/Microsoft.AspNet.Hosting/Builder/IHttpContextFactory.cs index ba3e7a36dc..128dfc4fa1 100644 --- a/src/Microsoft.AspNet.Hosting/Builder/IHttpContextFactory.cs +++ b/src/Microsoft.AspNet.Hosting/Builder/IHttpContextFactory.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. +// 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.FeatureModel; diff --git a/src/Microsoft.AspNet.Hosting/DefaultRequestIdentifierFeature.cs b/src/Microsoft.AspNet.Hosting/DefaultRequestIdentifierFeature.cs index 6baca0975d..6593cf957e 100644 --- a/src/Microsoft.AspNet.Hosting/DefaultRequestIdentifierFeature.cs +++ b/src/Microsoft.AspNet.Hosting/DefaultRequestIdentifierFeature.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. +// 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; diff --git a/src/Microsoft.AspNet.Hosting/HostingEnvironment.cs b/src/Microsoft.AspNet.Hosting/HostingEnvironment.cs index dac9b27d89..8060d32659 100644 --- a/src/Microsoft.AspNet.Hosting/HostingEnvironment.cs +++ b/src/Microsoft.AspNet.Hosting/HostingEnvironment.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. +// 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.FileProviders; diff --git a/src/Microsoft.AspNet.Hosting/HostingEnvironmentExtensions.cs b/src/Microsoft.AspNet.Hosting/HostingEnvironmentExtensions.cs index cd18889034..a6cd1d5abf 100644 --- a/src/Microsoft.AspNet.Hosting/HostingEnvironmentExtensions.cs +++ b/src/Microsoft.AspNet.Hosting/HostingEnvironmentExtensions.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. +// 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.FileProviders; diff --git a/src/Microsoft.AspNet.Hosting/HttpContextAccessor.cs b/src/Microsoft.AspNet.Hosting/HttpContextAccessor.cs index 5b1e0ef9e1..f649d95016 100644 --- a/src/Microsoft.AspNet.Hosting/HttpContextAccessor.cs +++ b/src/Microsoft.AspNet.Hosting/HttpContextAccessor.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. +// 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; diff --git a/src/Microsoft.AspNet.Hosting/Internal/AutoRequestServicesStartupFilter.cs b/src/Microsoft.AspNet.Hosting/Internal/AutoRequestServicesStartupFilter.cs index 0d28da169c..205440b5fe 100644 --- a/src/Microsoft.AspNet.Hosting/Internal/AutoRequestServicesStartupFilter.cs +++ b/src/Microsoft.AspNet.Hosting/Internal/AutoRequestServicesStartupFilter.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. +// 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; diff --git a/src/Microsoft.AspNet.Hosting/Internal/HostingEngine.cs b/src/Microsoft.AspNet.Hosting/Internal/HostingEngine.cs index 86bbee3936..9a14754a40 100644 --- a/src/Microsoft.AspNet.Hosting/Internal/HostingEngine.cs +++ b/src/Microsoft.AspNet.Hosting/Internal/HostingEngine.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. +// 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; diff --git a/src/Microsoft.AspNet.Hosting/Internal/HostingUtilities.cs b/src/Microsoft.AspNet.Hosting/Internal/HostingUtilities.cs index 7b48d72b8f..cec8d4d762 100644 --- a/src/Microsoft.AspNet.Hosting/Internal/HostingUtilities.cs +++ b/src/Microsoft.AspNet.Hosting/Internal/HostingUtilities.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. +// 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; diff --git a/src/Microsoft.AspNet.Hosting/Internal/IHostingEngine.cs b/src/Microsoft.AspNet.Hosting/Internal/IHostingEngine.cs index f79031eb0f..d0a3818867 100644 --- a/src/Microsoft.AspNet.Hosting/Internal/IHostingEngine.cs +++ b/src/Microsoft.AspNet.Hosting/Internal/IHostingEngine.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. +// 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; diff --git a/src/Microsoft.AspNet.Hosting/Internal/RequestServicesContainer.cs b/src/Microsoft.AspNet.Hosting/Internal/RequestServicesContainer.cs index 716c2ed3be..74e6df0fe2 100644 --- a/src/Microsoft.AspNet.Hosting/Internal/RequestServicesContainer.cs +++ b/src/Microsoft.AspNet.Hosting/Internal/RequestServicesContainer.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. +// 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; diff --git a/src/Microsoft.AspNet.Hosting/Internal/RequestServicesContainerMiddleware.cs b/src/Microsoft.AspNet.Hosting/Internal/RequestServicesContainerMiddleware.cs index 8ffd9f7a06..0a0d169dcb 100644 --- a/src/Microsoft.AspNet.Hosting/Internal/RequestServicesContainerMiddleware.cs +++ b/src/Microsoft.AspNet.Hosting/Internal/RequestServicesContainerMiddleware.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. +// 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; diff --git a/src/Microsoft.AspNet.Hosting/PlatformHelper.cs b/src/Microsoft.AspNet.Hosting/PlatformHelper.cs index 1309a18786..fbe16751c1 100644 --- a/src/Microsoft.AspNet.Hosting/PlatformHelper.cs +++ b/src/Microsoft.AspNet.Hosting/PlatformHelper.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. +// 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; diff --git a/src/Microsoft.AspNet.Hosting/Program.cs b/src/Microsoft.AspNet.Hosting/Program.cs index d1282d9e1a..11718b64b5 100644 --- a/src/Microsoft.AspNet.Hosting/Program.cs +++ b/src/Microsoft.AspNet.Hosting/Program.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. +// 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; diff --git a/src/Microsoft.AspNet.Hosting/Properties/AssemblyInfo.cs b/src/Microsoft.AspNet.Hosting/Properties/AssemblyInfo.cs index f5c6f4a83a..025a94598c 100644 --- a/src/Microsoft.AspNet.Hosting/Properties/AssemblyInfo.cs +++ b/src/Microsoft.AspNet.Hosting/Properties/AssemblyInfo.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. +// 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.Reflection; diff --git a/src/Microsoft.AspNet.Hosting/Server/IServerLoader.cs b/src/Microsoft.AspNet.Hosting/Server/IServerLoader.cs index f0b91fcf8f..abf67b4263 100644 --- a/src/Microsoft.AspNet.Hosting/Server/IServerLoader.cs +++ b/src/Microsoft.AspNet.Hosting/Server/IServerLoader.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. +// 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. namespace Microsoft.AspNet.Hosting.Server diff --git a/src/Microsoft.AspNet.Hosting/Server/ServerLoader.cs b/src/Microsoft.AspNet.Hosting/Server/ServerLoader.cs index fd7c9a41ea..7a06dfa70f 100644 --- a/src/Microsoft.AspNet.Hosting/Server/ServerLoader.cs +++ b/src/Microsoft.AspNet.Hosting/Server/ServerLoader.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. +// 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; diff --git a/src/Microsoft.AspNet.Hosting/Startup/ConfigureDelegate.cs b/src/Microsoft.AspNet.Hosting/Startup/ConfigureDelegate.cs index 415302a961..3275f056d9 100644 --- a/src/Microsoft.AspNet.Hosting/Startup/ConfigureDelegate.cs +++ b/src/Microsoft.AspNet.Hosting/Startup/ConfigureDelegate.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. +// 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; diff --git a/src/Microsoft.AspNet.Hosting/Startup/ConfigureServicesDelegate.cs b/src/Microsoft.AspNet.Hosting/Startup/ConfigureServicesDelegate.cs index c55eee4c6f..d500ccea06 100644 --- a/src/Microsoft.AspNet.Hosting/Startup/ConfigureServicesDelegate.cs +++ b/src/Microsoft.AspNet.Hosting/Startup/ConfigureServicesDelegate.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. +// 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; diff --git a/src/Microsoft.AspNet.Hosting/Startup/IStartupFilter.cs b/src/Microsoft.AspNet.Hosting/Startup/IStartupFilter.cs index 943c8aed32..437a841e89 100644 --- a/src/Microsoft.AspNet.Hosting/Startup/IStartupFilter.cs +++ b/src/Microsoft.AspNet.Hosting/Startup/IStartupFilter.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. +// 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; diff --git a/src/Microsoft.AspNet.Hosting/Startup/IStartupLoader.cs b/src/Microsoft.AspNet.Hosting/Startup/IStartupLoader.cs index 6ba16f4e08..ee1db50c8e 100644 --- a/src/Microsoft.AspNet.Hosting/Startup/IStartupLoader.cs +++ b/src/Microsoft.AspNet.Hosting/Startup/IStartupLoader.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. +// 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; diff --git a/src/Microsoft.AspNet.Hosting/Startup/StartupLoader.cs b/src/Microsoft.AspNet.Hosting/Startup/StartupLoader.cs index 2b95b72ed7..383d0d8357 100644 --- a/src/Microsoft.AspNet.Hosting/Startup/StartupLoader.cs +++ b/src/Microsoft.AspNet.Hosting/Startup/StartupLoader.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. +// 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; diff --git a/src/Microsoft.AspNet.Hosting/Startup/StartupMethods.cs b/src/Microsoft.AspNet.Hosting/Startup/StartupMethods.cs index 4644b5a55e..c213a681d3 100644 --- a/src/Microsoft.AspNet.Hosting/Startup/StartupMethods.cs +++ b/src/Microsoft.AspNet.Hosting/Startup/StartupMethods.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. +// 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; diff --git a/src/Microsoft.AspNet.Hosting/WebHostBuilder.cs b/src/Microsoft.AspNet.Hosting/WebHostBuilder.cs index 09e70f2650..256f615597 100644 --- a/src/Microsoft.AspNet.Hosting/WebHostBuilder.cs +++ b/src/Microsoft.AspNet.Hosting/WebHostBuilder.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. +// 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; diff --git a/src/Microsoft.AspNet.Server.Testing/Common/DeploymentParameters.cs b/src/Microsoft.AspNet.Server.Testing/Common/DeploymentParameters.cs index 39278112b2..aa1a0d87a7 100644 --- a/src/Microsoft.AspNet.Server.Testing/Common/DeploymentParameters.cs +++ b/src/Microsoft.AspNet.Server.Testing/Common/DeploymentParameters.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. +// 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; diff --git a/src/Microsoft.AspNet.Server.Testing/Common/DeploymentResult.cs b/src/Microsoft.AspNet.Server.Testing/Common/DeploymentResult.cs index 6a2c1a69d4..8266234522 100644 --- a/src/Microsoft.AspNet.Server.Testing/Common/DeploymentResult.cs +++ b/src/Microsoft.AspNet.Server.Testing/Common/DeploymentResult.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. +// 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.Threading; diff --git a/src/Microsoft.AspNet.Server.Testing/Common/DotnetArchitecture.cs b/src/Microsoft.AspNet.Server.Testing/Common/DotnetArchitecture.cs index 11b1a3d5e3..483a4569bb 100644 --- a/src/Microsoft.AspNet.Server.Testing/Common/DotnetArchitecture.cs +++ b/src/Microsoft.AspNet.Server.Testing/Common/DotnetArchitecture.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. +// 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. namespace Microsoft.AspNet.Server.Testing diff --git a/src/Microsoft.AspNet.Server.Testing/Common/DotnetFlavor.cs b/src/Microsoft.AspNet.Server.Testing/Common/DotnetFlavor.cs index 99913581b7..5b67b5d24c 100644 --- a/src/Microsoft.AspNet.Server.Testing/Common/DotnetFlavor.cs +++ b/src/Microsoft.AspNet.Server.Testing/Common/DotnetFlavor.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. +// 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. namespace Microsoft.AspNet.Server.Testing diff --git a/src/Microsoft.AspNet.Server.Testing/Common/RetryHelper.cs b/src/Microsoft.AspNet.Server.Testing/Common/RetryHelper.cs index 1c6e6949dd..ae2cedd6e7 100644 --- a/src/Microsoft.AspNet.Server.Testing/Common/RetryHelper.cs +++ b/src/Microsoft.AspNet.Server.Testing/Common/RetryHelper.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. +// 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; diff --git a/src/Microsoft.AspNet.Server.Testing/Common/ServerType.cs b/src/Microsoft.AspNet.Server.Testing/Common/ServerType.cs index 9756b1496b..3d17cb23bd 100644 --- a/src/Microsoft.AspNet.Server.Testing/Common/ServerType.cs +++ b/src/Microsoft.AspNet.Server.Testing/Common/ServerType.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. +// 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. namespace Microsoft.AspNet.Server.Testing diff --git a/src/Microsoft.AspNet.Server.Testing/Deployers/ApplicationDeployer.cs b/src/Microsoft.AspNet.Server.Testing/Deployers/ApplicationDeployer.cs index e3f1531052..55893b7aec 100644 --- a/src/Microsoft.AspNet.Server.Testing/Deployers/ApplicationDeployer.cs +++ b/src/Microsoft.AspNet.Server.Testing/Deployers/ApplicationDeployer.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. +// 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; diff --git a/src/Microsoft.AspNet.Server.Testing/Deployers/ApplicationDeployerFactory.cs b/src/Microsoft.AspNet.Server.Testing/Deployers/ApplicationDeployerFactory.cs index 5308609815..6422d3f507 100644 --- a/src/Microsoft.AspNet.Server.Testing/Deployers/ApplicationDeployerFactory.cs +++ b/src/Microsoft.AspNet.Server.Testing/Deployers/ApplicationDeployerFactory.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. +// 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; diff --git a/src/Microsoft.AspNet.Server.Testing/Deployers/IApplicationDeployer.cs b/src/Microsoft.AspNet.Server.Testing/Deployers/IApplicationDeployer.cs index c027632ccd..85467bccb1 100644 --- a/src/Microsoft.AspNet.Server.Testing/Deployers/IApplicationDeployer.cs +++ b/src/Microsoft.AspNet.Server.Testing/Deployers/IApplicationDeployer.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. +// 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; diff --git a/src/Microsoft.AspNet.Server.Testing/Deployers/IISDeployer.cs b/src/Microsoft.AspNet.Server.Testing/Deployers/IISDeployer.cs index 45749a82ba..b7290b9f9c 100644 --- a/src/Microsoft.AspNet.Server.Testing/Deployers/IISDeployer.cs +++ b/src/Microsoft.AspNet.Server.Testing/Deployers/IISDeployer.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. +// 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. #if DNX451 diff --git a/src/Microsoft.AspNet.Server.Testing/Deployers/IISExpressDeployer.cs b/src/Microsoft.AspNet.Server.Testing/Deployers/IISExpressDeployer.cs index 25cf0e7012..5c63d28982 100644 --- a/src/Microsoft.AspNet.Server.Testing/Deployers/IISExpressDeployer.cs +++ b/src/Microsoft.AspNet.Server.Testing/Deployers/IISExpressDeployer.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. +// 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; diff --git a/src/Microsoft.AspNet.Server.Testing/Deployers/MonoDeployer.cs b/src/Microsoft.AspNet.Server.Testing/Deployers/MonoDeployer.cs index 12f099596f..df44e88ecd 100644 --- a/src/Microsoft.AspNet.Server.Testing/Deployers/MonoDeployer.cs +++ b/src/Microsoft.AspNet.Server.Testing/Deployers/MonoDeployer.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. +// 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; diff --git a/src/Microsoft.AspNet.Server.Testing/Deployers/SelfHostDeployer.cs b/src/Microsoft.AspNet.Server.Testing/Deployers/SelfHostDeployer.cs index 3d366241b5..e0121bdfd4 100644 --- a/src/Microsoft.AspNet.Server.Testing/Deployers/SelfHostDeployer.cs +++ b/src/Microsoft.AspNet.Server.Testing/Deployers/SelfHostDeployer.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. +// 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; diff --git a/src/Microsoft.AspNet.Server.Testing/xunit/SkipIfCurrentRuntimeIsCoreClr.cs b/src/Microsoft.AspNet.Server.Testing/xunit/SkipIfCurrentRuntimeIsCoreClr.cs index 7c1d5340aa..3afee2f2fa 100644 --- a/src/Microsoft.AspNet.Server.Testing/xunit/SkipIfCurrentRuntimeIsCoreClr.cs +++ b/src/Microsoft.AspNet.Server.Testing/xunit/SkipIfCurrentRuntimeIsCoreClr.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. +// 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; diff --git a/src/Microsoft.AspNet.Server.Testing/xunit/SkipIfIISNativeVariationsNotEnabledAttribute.cs b/src/Microsoft.AspNet.Server.Testing/xunit/SkipIfIISNativeVariationsNotEnabledAttribute.cs index 541fa684bc..b3c13646ce 100644 --- a/src/Microsoft.AspNet.Server.Testing/xunit/SkipIfIISNativeVariationsNotEnabledAttribute.cs +++ b/src/Microsoft.AspNet.Server.Testing/xunit/SkipIfIISNativeVariationsNotEnabledAttribute.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. +// 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; diff --git a/src/Microsoft.AspNet.Server.Testing/xunit/SkipIfIISVariationsNotEnabledAttribute.cs b/src/Microsoft.AspNet.Server.Testing/xunit/SkipIfIISVariationsNotEnabledAttribute.cs index dbfcbc5014..a6d26fe3b6 100644 --- a/src/Microsoft.AspNet.Server.Testing/xunit/SkipIfIISVariationsNotEnabledAttribute.cs +++ b/src/Microsoft.AspNet.Server.Testing/xunit/SkipIfIISVariationsNotEnabledAttribute.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. +// 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; diff --git a/src/Microsoft.AspNet.Server.Testing/xunit/SkipOn32BitOSAttribute.cs b/src/Microsoft.AspNet.Server.Testing/xunit/SkipOn32BitOSAttribute.cs index 37be266e59..a04349bcc2 100644 --- a/src/Microsoft.AspNet.Server.Testing/xunit/SkipOn32BitOSAttribute.cs +++ b/src/Microsoft.AspNet.Server.Testing/xunit/SkipOn32BitOSAttribute.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. +// 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; diff --git a/src/Microsoft.AspNet.TestHost/ClientHandler.cs b/src/Microsoft.AspNet.TestHost/ClientHandler.cs index 75a954296c..78afb19a28 100644 --- a/src/Microsoft.AspNet.TestHost/ClientHandler.cs +++ b/src/Microsoft.AspNet.TestHost/ClientHandler.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. +// 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; diff --git a/src/Microsoft.AspNet.TestHost/Properties/AssemblyInfo.cs b/src/Microsoft.AspNet.TestHost/Properties/AssemblyInfo.cs index 23c410c805..d052161863 100644 --- a/src/Microsoft.AspNet.TestHost/Properties/AssemblyInfo.cs +++ b/src/Microsoft.AspNet.TestHost/Properties/AssemblyInfo.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Open Technologies, Inc. +// Copyright (c) .NET Foundation. // All Rights Reserved // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/src/Microsoft.AspNet.TestHost/RequestBuilder.cs b/src/Microsoft.AspNet.TestHost/RequestBuilder.cs index 57422b4b33..77344da496 100644 --- a/src/Microsoft.AspNet.TestHost/RequestBuilder.cs +++ b/src/Microsoft.AspNet.TestHost/RequestBuilder.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. +// 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; diff --git a/src/Microsoft.AspNet.TestHost/RequestFeature.cs b/src/Microsoft.AspNet.TestHost/RequestFeature.cs index 3c043c6e98..61fb442632 100644 --- a/src/Microsoft.AspNet.TestHost/RequestFeature.cs +++ b/src/Microsoft.AspNet.TestHost/RequestFeature.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. +// 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; diff --git a/src/Microsoft.AspNet.TestHost/ResponseFeature.cs b/src/Microsoft.AspNet.TestHost/ResponseFeature.cs index b8bf81dcba..3b43f42e6f 100644 --- a/src/Microsoft.AspNet.TestHost/ResponseFeature.cs +++ b/src/Microsoft.AspNet.TestHost/ResponseFeature.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. +// 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; diff --git a/src/Microsoft.AspNet.TestHost/ResponseStream.cs b/src/Microsoft.AspNet.TestHost/ResponseStream.cs index a3b555bd70..5946117ab2 100644 --- a/src/Microsoft.AspNet.TestHost/ResponseStream.cs +++ b/src/Microsoft.AspNet.TestHost/ResponseStream.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. +// 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; diff --git a/src/Microsoft.AspNet.TestHost/TestServer.cs b/src/Microsoft.AspNet.TestHost/TestServer.cs index d5bf3e52a6..772c934260 100644 --- a/src/Microsoft.AspNet.TestHost/TestServer.cs +++ b/src/Microsoft.AspNet.TestHost/TestServer.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. +// 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; diff --git a/test/Microsoft.AspNet.Hosting.Tests/Fakes/FakeOptions.cs b/test/Microsoft.AspNet.Hosting.Tests/Fakes/FakeOptions.cs index a955ed377e..d18fdd9e42 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/Fakes/FakeOptions.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/Fakes/FakeOptions.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. +// 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. namespace Microsoft.AspNet.Hosting.Fakes diff --git a/test/Microsoft.AspNet.Hosting.Tests/Fakes/FakeService.cs b/test/Microsoft.AspNet.Hosting.Tests/Fakes/FakeService.cs index 75e8b53216..75176f8928 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/Fakes/FakeService.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/Fakes/FakeService.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. +// 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. namespace Microsoft.AspNet.Hosting.Fakes diff --git a/test/Microsoft.AspNet.Hosting.Tests/Fakes/IFactoryService.cs b/test/Microsoft.AspNet.Hosting.Tests/Fakes/IFactoryService.cs index e67809bb83..c0a60c9364 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/Fakes/IFactoryService.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/Fakes/IFactoryService.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. +// 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. namespace Microsoft.AspNet.Hosting.Fakes diff --git a/test/Microsoft.AspNet.Hosting.Tests/Fakes/IFakeEveryService.cs b/test/Microsoft.AspNet.Hosting.Tests/Fakes/IFakeEveryService.cs index 6e279051e2..da9f00507f 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/Fakes/IFakeEveryService.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/Fakes/IFakeEveryService.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. +// 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. namespace Microsoft.AspNet.Hosting.Fakes diff --git a/test/Microsoft.AspNet.Hosting.Tests/Fakes/IFakeScopedService.cs b/test/Microsoft.AspNet.Hosting.Tests/Fakes/IFakeScopedService.cs index 0e5ca63193..f5586003a6 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/Fakes/IFakeScopedService.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/Fakes/IFakeScopedService.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. +// 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. namespace Microsoft.AspNet.Hosting.Fakes diff --git a/test/Microsoft.AspNet.Hosting.Tests/Fakes/IFakeService.cs b/test/Microsoft.AspNet.Hosting.Tests/Fakes/IFakeService.cs index 22e1837513..dc08bcbe64 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/Fakes/IFakeService.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/Fakes/IFakeService.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. +// 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. namespace Microsoft.AspNet.Hosting.Fakes diff --git a/test/Microsoft.AspNet.Hosting.Tests/Fakes/IFakeServiceInstance.cs b/test/Microsoft.AspNet.Hosting.Tests/Fakes/IFakeServiceInstance.cs index e9d8bc0f47..6dd1313072 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/Fakes/IFakeServiceInstance.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/Fakes/IFakeServiceInstance.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. +// 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. namespace Microsoft.AspNet.Hosting.Fakes diff --git a/test/Microsoft.AspNet.Hosting.Tests/Fakes/IFakeSingletonService.cs b/test/Microsoft.AspNet.Hosting.Tests/Fakes/IFakeSingletonService.cs index 844ad72395..aca376a3fa 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/Fakes/IFakeSingletonService.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/Fakes/IFakeSingletonService.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. +// 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. namespace Microsoft.AspNet.Hosting.Fakes diff --git a/test/Microsoft.AspNet.Hosting.Tests/Fakes/IFakeStartupCallback.cs b/test/Microsoft.AspNet.Hosting.Tests/Fakes/IFakeStartupCallback.cs index 5a5ca0341b..e804deee82 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/Fakes/IFakeStartupCallback.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/Fakes/IFakeStartupCallback.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. +// 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. namespace Microsoft.AspNet.Hosting.Fakes diff --git a/test/Microsoft.AspNet.Hosting.Tests/Fakes/INonexistentService.cs b/test/Microsoft.AspNet.Hosting.Tests/Fakes/INonexistentService.cs index 0e64d75641..d71be552c2 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/Fakes/INonexistentService.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/Fakes/INonexistentService.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. +// 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. namespace Microsoft.AspNet.Hosting.Fakes diff --git a/test/Microsoft.AspNet.Hosting.Tests/Fakes/Startup.cs b/test/Microsoft.AspNet.Hosting.Tests/Fakes/Startup.cs index 8f61d7e4c3..09a4a3360f 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/Fakes/Startup.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/Fakes/Startup.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. +// 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.Builder; diff --git a/test/Microsoft.AspNet.Hosting.Tests/Fakes/StartupBase.cs b/test/Microsoft.AspNet.Hosting.Tests/Fakes/StartupBase.cs index e9daa9584d..d2f27bdf40 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/Fakes/StartupBase.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/Fakes/StartupBase.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. +// 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.Framework.DependencyInjection; diff --git a/test/Microsoft.AspNet.Hosting.Tests/Fakes/StartupBoom.cs b/test/Microsoft.AspNet.Hosting.Tests/Fakes/StartupBoom.cs index 6fb647a489..cfef8b9060 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/Fakes/StartupBoom.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/Fakes/StartupBoom.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. +// 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. namespace Microsoft.AspNet.Hosting.Fakes diff --git a/test/Microsoft.AspNet.Hosting.Tests/Fakes/StartupNoServices.cs b/test/Microsoft.AspNet.Hosting.Tests/Fakes/StartupNoServices.cs index 16e73e3d9c..e32663d293 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/Fakes/StartupNoServices.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/Fakes/StartupNoServices.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. +// 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.Builder; diff --git a/test/Microsoft.AspNet.Hosting.Tests/Fakes/StartupWithConfigureServicesNotResolved.cs b/test/Microsoft.AspNet.Hosting.Tests/Fakes/StartupWithConfigureServicesNotResolved.cs index 8679e62093..fda5c8af5f 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/Fakes/StartupWithConfigureServicesNotResolved.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/Fakes/StartupWithConfigureServicesNotResolved.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. +// 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.Builder; diff --git a/test/Microsoft.AspNet.Hosting.Tests/Fakes/StartupWithServices.cs b/test/Microsoft.AspNet.Hosting.Tests/Fakes/StartupWithServices.cs index c7d4050481..f24e3babfd 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/Fakes/StartupWithServices.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/Fakes/StartupWithServices.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. +// 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.Builder; diff --git a/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs b/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs index 5260f6c345..3f8492b13f 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. +// 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; diff --git a/test/Microsoft.AspNet.Hosting.Tests/HostingUtilitiesTests.cs b/test/Microsoft.AspNet.Hosting.Tests/HostingUtilitiesTests.cs index 06cf95333b..86de386a1e 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/HostingUtilitiesTests.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/HostingUtilitiesTests.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. +// 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.Hosting.Internal; diff --git a/test/Microsoft.AspNet.Hosting.Tests/HttpContextFactoryFacts.cs b/test/Microsoft.AspNet.Hosting.Tests/HttpContextFactoryFacts.cs index b6ab156902..2188bfbb7c 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/HttpContextFactoryFacts.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/HttpContextFactoryFacts.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. +// 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.Collections.Generic; diff --git a/test/Microsoft.AspNet.Hosting.Tests/StartupManagerTests.cs b/test/Microsoft.AspNet.Hosting.Tests/StartupManagerTests.cs index ca803c6831..15fe74ab56 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/StartupManagerTests.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/StartupManagerTests.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. +// 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; diff --git a/test/Microsoft.AspNet.TestHost.Tests/ClientHandlerTests.cs b/test/Microsoft.AspNet.TestHost.Tests/ClientHandlerTests.cs index f8772ee570..b8f3ecb73a 100644 --- a/test/Microsoft.AspNet.TestHost.Tests/ClientHandlerTests.cs +++ b/test/Microsoft.AspNet.TestHost.Tests/ClientHandlerTests.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. +// 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; diff --git a/test/Microsoft.AspNet.TestHost.Tests/Properties/AssemblyInfo.cs b/test/Microsoft.AspNet.TestHost.Tests/Properties/AssemblyInfo.cs index 64d1e18c97..8129ea73eb 100644 --- a/test/Microsoft.AspNet.TestHost.Tests/Properties/AssemblyInfo.cs +++ b/test/Microsoft.AspNet.TestHost.Tests/Properties/AssemblyInfo.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Open Technologies, Inc. +// Copyright (c) .NET Foundation. // All Rights Reserved // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/test/Microsoft.AspNet.TestHost.Tests/RequestBuilderTests.cs b/test/Microsoft.AspNet.TestHost.Tests/RequestBuilderTests.cs index 6a005fd0dc..11e3965a6e 100644 --- a/test/Microsoft.AspNet.TestHost.Tests/RequestBuilderTests.cs +++ b/test/Microsoft.AspNet.TestHost.Tests/RequestBuilderTests.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. +// 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 Xunit; diff --git a/test/Microsoft.AspNet.TestHost.Tests/ResponseFeatureTests.cs b/test/Microsoft.AspNet.TestHost.Tests/ResponseFeatureTests.cs index 2564ee7112..f2c32ef0ca 100644 --- a/test/Microsoft.AspNet.TestHost.Tests/ResponseFeatureTests.cs +++ b/test/Microsoft.AspNet.TestHost.Tests/ResponseFeatureTests.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. +// 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 Xunit; diff --git a/test/Microsoft.AspNet.TestHost.Tests/TestClientTests.cs b/test/Microsoft.AspNet.TestHost.Tests/TestClientTests.cs index c710d01da1..b77a681862 100644 --- a/test/Microsoft.AspNet.TestHost.Tests/TestClientTests.cs +++ b/test/Microsoft.AspNet.TestHost.Tests/TestClientTests.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. +// 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.IO; diff --git a/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs b/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs index fcbd153e8a..be52e9b9cd 100644 --- a/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs +++ b/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. +// 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; From ef9dde7d7c669cc74cd12da16c710c51ce793be8 Mon Sep 17 00:00:00 2001 From: Troy Dai Date: Thu, 7 May 2015 09:37:39 -0700 Subject: [PATCH 287/987] React to common package name change --- src/Microsoft.AspNet.Hosting.Abstractions/project.json | 2 +- src/Microsoft.AspNet.Hosting/project.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Microsoft.AspNet.Hosting.Abstractions/project.json b/src/Microsoft.AspNet.Hosting.Abstractions/project.json index bfb6a183f1..adca748265 100644 --- a/src/Microsoft.AspNet.Hosting.Abstractions/project.json +++ b/src/Microsoft.AspNet.Hosting.Abstractions/project.json @@ -4,7 +4,7 @@ "dependencies": { "Microsoft.AspNet.Http.Abstractions": "1.0.0-*", "Microsoft.AspNet.FileProviders.Abstractions": "1.0.0-*", - "Microsoft.Framework.NotNullAttribute.Internal": { "type": "build", "version": "1.0.0-*" } + "Microsoft.Framework.NotNullAttribute.Sources": { "type": "build", "version": "1.0.0-*" } }, "frameworks": { "dnx451": {}, diff --git a/src/Microsoft.AspNet.Hosting/project.json b/src/Microsoft.AspNet.Hosting/project.json index 2450ba27c8..a84b1bc227 100644 --- a/src/Microsoft.AspNet.Hosting/project.json +++ b/src/Microsoft.AspNet.Hosting/project.json @@ -12,7 +12,7 @@ "Microsoft.Framework.DependencyInjection": "1.0.0-*", "Microsoft.Framework.Logging": "1.0.0-*", "Microsoft.Framework.Runtime.Abstractions": "1.0.0-*", - "Microsoft.Framework.NotNullAttribute.Internal": { "type": "build", "version": "1.0.0-*" }, + "Microsoft.Framework.NotNullAttribute.Sources": { "type": "build", "version": "1.0.0-*" }, "Newtonsoft.Json": "6.0.6" }, "frameworks": { From 018b4c24263ec70fd200a84ae7d0106576c78606 Mon Sep 17 00:00:00 2001 From: Hisham Abdullah Bin Ateya Date: Thu, 7 May 2015 16:15:17 +0300 Subject: [PATCH 288/987] Using 'nameof' operator instead of magic strings --- src/Microsoft.AspNet.Hosting/Server/ServerLoader.cs | 2 +- .../Common/DeploymentParameters.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Microsoft.AspNet.Hosting/Server/ServerLoader.cs b/src/Microsoft.AspNet.Hosting/Server/ServerLoader.cs index 7a06dfa70f..0327ae6a31 100644 --- a/src/Microsoft.AspNet.Hosting/Server/ServerLoader.cs +++ b/src/Microsoft.AspNet.Hosting/Server/ServerLoader.cs @@ -22,7 +22,7 @@ namespace Microsoft.AspNet.Hosting.Server { if (string.IsNullOrEmpty(serverFactoryIdentifier)) { - throw new ArgumentException(string.Empty, "serverFactoryIdentifier"); + throw new ArgumentException(string.Empty, nameof(serverFactoryIdentifier)); } var nameParts = HostingUtilities.SplitTypeName(serverFactoryIdentifier); diff --git a/src/Microsoft.AspNet.Server.Testing/Common/DeploymentParameters.cs b/src/Microsoft.AspNet.Server.Testing/Common/DeploymentParameters.cs index aa1a0d87a7..86d29d9b2b 100644 --- a/src/Microsoft.AspNet.Server.Testing/Common/DeploymentParameters.cs +++ b/src/Microsoft.AspNet.Server.Testing/Common/DeploymentParameters.cs @@ -27,7 +27,7 @@ namespace Microsoft.AspNet.Server.Testing { if (string.IsNullOrEmpty(applicationPath)) { - throw new ArgumentException("Value cannot be null.", "applicationPath"); + throw new ArgumentException("Value cannot be null.", nameof(applicationPath)); } if (!Directory.Exists(applicationPath)) From 4852bf0c528fb84ba50602ad52dd64342b35eb6f Mon Sep 17 00:00:00 2001 From: Hisham Abdullah Bin Ateya Date: Thu, 7 May 2015 16:19:38 +0300 Subject: [PATCH 289/987] Using [NotNull] --- src/Microsoft.AspNet.TestHost/ClientHandler.cs | 15 +++------------ src/Microsoft.AspNet.TestHost/RequestBuilder.cs | 15 +++------------ src/Microsoft.AspNet.TestHost/ResponseStream.cs | 7 ++----- src/Microsoft.AspNet.TestHost/project.json | 3 ++- 4 files changed, 10 insertions(+), 30 deletions(-) diff --git a/src/Microsoft.AspNet.TestHost/ClientHandler.cs b/src/Microsoft.AspNet.TestHost/ClientHandler.cs index 78afb19a28..add6bf48be 100644 --- a/src/Microsoft.AspNet.TestHost/ClientHandler.cs +++ b/src/Microsoft.AspNet.TestHost/ClientHandler.cs @@ -12,6 +12,7 @@ using System.Threading; using System.Threading.Tasks; using Microsoft.AspNet.FeatureModel; using Microsoft.AspNet.Http; +using Microsoft.Framework.Internal; namespace Microsoft.AspNet.TestHost { @@ -28,13 +29,8 @@ namespace Microsoft.AspNet.TestHost /// Create a new handler. /// /// The pipeline entry point. - public ClientHandler(Func next, PathString pathBase) + public ClientHandler([NotNull] Func next, PathString pathBase) { - if (next == null) - { - throw new ArgumentNullException("next"); - } - _next = next; // PathString.StartsWithSegments that we use below requires the base path to not end in a slash. @@ -53,14 +49,9 @@ namespace Microsoft.AspNet.TestHost /// /// protected override async Task SendAsync( - HttpRequestMessage request, + [NotNull] HttpRequestMessage request, CancellationToken cancellationToken) { - if (request == null) - { - throw new ArgumentNullException("request"); - } - var state = new RequestState(request, _pathBase, cancellationToken); var requestContent = request.Content ?? new StreamContent(Stream.Null); var body = await requestContent.ReadAsStreamAsync(); diff --git a/src/Microsoft.AspNet.TestHost/RequestBuilder.cs b/src/Microsoft.AspNet.TestHost/RequestBuilder.cs index 77344da496..3de390f63a 100644 --- a/src/Microsoft.AspNet.TestHost/RequestBuilder.cs +++ b/src/Microsoft.AspNet.TestHost/RequestBuilder.cs @@ -7,6 +7,7 @@ using System.Globalization; using System.IO; using System.Net.Http; using System.Threading.Tasks; +using Microsoft.Framework.Internal; namespace Microsoft.AspNet.TestHost { @@ -26,13 +27,8 @@ namespace Microsoft.AspNet.TestHost /// /// [SuppressMessage("Microsoft.Usage", "CA2234:PassSystemUriObjectsInsteadOfStrings", Justification = "Not a full URI")] - public RequestBuilder(TestServer server, string path) + public RequestBuilder([NotNull] TestServer server, string path) { - if (server == null) - { - throw new ArgumentNullException("server"); - } - _server = server; _req = new HttpRequestMessage(HttpMethod.Get, path); } @@ -42,13 +38,8 @@ namespace Microsoft.AspNet.TestHost /// /// /// - public RequestBuilder And(Action configure) + public RequestBuilder And([NotNull] Action configure) { - if (configure == null) - { - throw new ArgumentNullException("configure"); - } - configure(_req); return this; } diff --git a/src/Microsoft.AspNet.TestHost/ResponseStream.cs b/src/Microsoft.AspNet.TestHost/ResponseStream.cs index 5946117ab2..42a8a419c5 100644 --- a/src/Microsoft.AspNet.TestHost/ResponseStream.cs +++ b/src/Microsoft.AspNet.TestHost/ResponseStream.cs @@ -8,6 +8,7 @@ using System.Diagnostics.Contracts; using System.IO; using System.Threading; using System.Threading.Tasks; +using Microsoft.Framework.Internal; namespace Microsoft.AspNet.TestHost { @@ -28,12 +29,8 @@ namespace Microsoft.AspNet.TestHost private Action _onFirstWrite; private bool _firstWrite; - internal ResponseStream(Action onFirstWrite) + internal ResponseStream([NotNull] Action onFirstWrite) { - if (onFirstWrite == null) - { - throw new ArgumentNullException("onFirstWrite"); - } _onFirstWrite = onFirstWrite; _firstWrite = true; diff --git a/src/Microsoft.AspNet.TestHost/project.json b/src/Microsoft.AspNet.TestHost/project.json index 28acab776a..c32b8f617b 100644 --- a/src/Microsoft.AspNet.TestHost/project.json +++ b/src/Microsoft.AspNet.TestHost/project.json @@ -2,7 +2,8 @@ "version": "1.0.0-*", "description": "ASP.NET 5 web server for writing and running tests.", "dependencies": { - "Microsoft.AspNet.Hosting": "1.0.0-*" + "Microsoft.AspNet.Hosting": "1.0.0-*", + "Microsoft.Framework.NotNullAttribute.Internal": { "version": "1.0.0-*", "type": "build" } }, "frameworks": { "dnx451": { From ad93dd74b63316945bd55e4731c9e7ad6cc932c7 Mon Sep 17 00:00:00 2001 From: Chris R Date: Thu, 7 May 2015 13:26:53 -0700 Subject: [PATCH 290/987] React to Http namespace changes. --- .../Builder/ApplicationBuilderFactory.cs | 1 + src/Microsoft.AspNet.Hosting/Builder/HttpContextFactory.cs | 1 + src/Microsoft.AspNet.Hosting/DefaultRequestIdentifierFeature.cs | 2 +- src/Microsoft.AspNet.Hosting/Internal/HostingEngine.cs | 1 + src/Microsoft.AspNet.TestHost/ClientHandler.cs | 2 ++ src/Microsoft.AspNet.TestHost/RequestFeature.cs | 2 +- src/Microsoft.AspNet.TestHost/ResponseFeature.cs | 2 +- test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs | 1 + test/Microsoft.AspNet.Hosting.Tests/StartupManagerTests.cs | 1 + test/Microsoft.AspNet.TestHost.Tests/ClientHandlerTests.cs | 2 ++ 10 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/Microsoft.AspNet.Hosting/Builder/ApplicationBuilderFactory.cs b/src/Microsoft.AspNet.Hosting/Builder/ApplicationBuilderFactory.cs index f1198a9ef0..a5b00f5fbf 100644 --- a/src/Microsoft.AspNet.Hosting/Builder/ApplicationBuilderFactory.cs +++ b/src/Microsoft.AspNet.Hosting/Builder/ApplicationBuilderFactory.cs @@ -3,6 +3,7 @@ using System; using Microsoft.AspNet.Builder; +using Microsoft.AspNet.Builder.Internal; namespace Microsoft.AspNet.Hosting.Builder { diff --git a/src/Microsoft.AspNet.Hosting/Builder/HttpContextFactory.cs b/src/Microsoft.AspNet.Hosting/Builder/HttpContextFactory.cs index 0b8af5f0ea..88ea3a3472 100644 --- a/src/Microsoft.AspNet.Hosting/Builder/HttpContextFactory.cs +++ b/src/Microsoft.AspNet.Hosting/Builder/HttpContextFactory.cs @@ -3,6 +3,7 @@ using Microsoft.AspNet.FeatureModel; using Microsoft.AspNet.Http; +using Microsoft.AspNet.Http.Internal; namespace Microsoft.AspNet.Hosting.Builder { diff --git a/src/Microsoft.AspNet.Hosting/DefaultRequestIdentifierFeature.cs b/src/Microsoft.AspNet.Hosting/DefaultRequestIdentifierFeature.cs index 6593cf957e..07d1f11442 100644 --- a/src/Microsoft.AspNet.Hosting/DefaultRequestIdentifierFeature.cs +++ b/src/Microsoft.AspNet.Hosting/DefaultRequestIdentifierFeature.cs @@ -2,7 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using Microsoft.AspNet.Http; +using Microsoft.AspNet.Http.Features; namespace Microsoft.AspNet.Hosting { diff --git a/src/Microsoft.AspNet.Hosting/Internal/HostingEngine.cs b/src/Microsoft.AspNet.Hosting/Internal/HostingEngine.cs index 9a14754a40..56659edc73 100644 --- a/src/Microsoft.AspNet.Hosting/Internal/HostingEngine.cs +++ b/src/Microsoft.AspNet.Hosting/Internal/HostingEngine.cs @@ -10,6 +10,7 @@ using Microsoft.AspNet.Hosting.Builder; using Microsoft.AspNet.Hosting.Server; using Microsoft.AspNet.Hosting.Startup; using Microsoft.AspNet.Http; +using Microsoft.AspNet.Http.Features; using Microsoft.Framework.ConfigurationModel; using Microsoft.Framework.DependencyInjection; using Microsoft.Framework.Internal; diff --git a/src/Microsoft.AspNet.TestHost/ClientHandler.cs b/src/Microsoft.AspNet.TestHost/ClientHandler.cs index add6bf48be..f5b501af7e 100644 --- a/src/Microsoft.AspNet.TestHost/ClientHandler.cs +++ b/src/Microsoft.AspNet.TestHost/ClientHandler.cs @@ -12,6 +12,8 @@ using System.Threading; using System.Threading.Tasks; using Microsoft.AspNet.FeatureModel; using Microsoft.AspNet.Http; +using Microsoft.AspNet.Http.Features; +using Microsoft.AspNet.Http.Internal; using Microsoft.Framework.Internal; namespace Microsoft.AspNet.TestHost diff --git a/src/Microsoft.AspNet.TestHost/RequestFeature.cs b/src/Microsoft.AspNet.TestHost/RequestFeature.cs index 61fb442632..eebdd28372 100644 --- a/src/Microsoft.AspNet.TestHost/RequestFeature.cs +++ b/src/Microsoft.AspNet.TestHost/RequestFeature.cs @@ -4,7 +4,7 @@ using System; using System.Collections.Generic; using System.IO; -using Microsoft.AspNet.Http; +using Microsoft.AspNet.Http.Features; namespace Microsoft.AspNet.TestHost { diff --git a/src/Microsoft.AspNet.TestHost/ResponseFeature.cs b/src/Microsoft.AspNet.TestHost/ResponseFeature.cs index 3b43f42e6f..b582e028a9 100644 --- a/src/Microsoft.AspNet.TestHost/ResponseFeature.cs +++ b/src/Microsoft.AspNet.TestHost/ResponseFeature.cs @@ -4,7 +4,7 @@ using System; using System.Collections.Generic; using System.IO; -using Microsoft.AspNet.Http; +using Microsoft.AspNet.Http.Features; namespace Microsoft.AspNet.TestHost { diff --git a/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs b/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs index 3f8492b13f..d776c1d481 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs @@ -12,6 +12,7 @@ using Microsoft.AspNet.Hosting.Internal; using Microsoft.AspNet.Hosting.Server; using Microsoft.AspNet.Hosting.Startup; using Microsoft.AspNet.Http; +using Microsoft.AspNet.Http.Features; using Microsoft.AspNet.Testing.xunit; using Microsoft.Framework.ConfigurationModel; using Microsoft.Framework.DependencyInjection; diff --git a/test/Microsoft.AspNet.Hosting.Tests/StartupManagerTests.cs b/test/Microsoft.AspNet.Hosting.Tests/StartupManagerTests.cs index 15fe74ab56..013f202f03 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/StartupManagerTests.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/StartupManagerTests.cs @@ -5,6 +5,7 @@ using System; using System.Collections.Generic; using System.Reflection; using Microsoft.AspNet.Builder; +using Microsoft.AspNet.Builder.Internal; using Microsoft.AspNet.Hosting.Fakes; using Microsoft.AspNet.Hosting.Startup; using Microsoft.Framework.DependencyInjection; diff --git a/test/Microsoft.AspNet.TestHost.Tests/ClientHandlerTests.cs b/test/Microsoft.AspNet.TestHost.Tests/ClientHandlerTests.cs index b8f3ecb73a..779afc7a87 100644 --- a/test/Microsoft.AspNet.TestHost.Tests/ClientHandlerTests.cs +++ b/test/Microsoft.AspNet.TestHost.Tests/ClientHandlerTests.cs @@ -9,6 +9,8 @@ using System.Threading; using System.Threading.Tasks; using Microsoft.AspNet.FeatureModel; using Microsoft.AspNet.Http; +using Microsoft.AspNet.Http.Features; +using Microsoft.AspNet.Http.Internal; using Xunit; namespace Microsoft.AspNet.TestHost From 4de328069ade71b40051f6f3147bc8aa01aa4502 Mon Sep 17 00:00:00 2001 From: Kai Ruhnau Date: Fri, 8 May 2015 12:54:34 +0200 Subject: [PATCH 291/987] Add an ApplicationStarted event --- .../IApplicationLifetime.cs | 8 +++++- .../ApplicationLifetime.cs | 27 ++++++++++++++++++- .../Internal/HostingEngine.cs | 4 ++- .../HostingEngineTests.cs | 15 +++++++++++ 4 files changed, 51 insertions(+), 3 deletions(-) diff --git a/src/Microsoft.AspNet.Hosting.Abstractions/IApplicationLifetime.cs b/src/Microsoft.AspNet.Hosting.Abstractions/IApplicationLifetime.cs index c229eb6e67..536e24c165 100644 --- a/src/Microsoft.AspNet.Hosting.Abstractions/IApplicationLifetime.cs +++ b/src/Microsoft.AspNet.Hosting.Abstractions/IApplicationLifetime.cs @@ -10,6 +10,12 @@ namespace Microsoft.AspNet.Hosting /// public interface IApplicationLifetime { + /// + /// Triggered when the application host has fully started and is about to wait + /// for a graceful shutdown. + /// + CancellationToken ApplicationStarted { get; } + /// /// Triggered when the application host is performing a graceful shutdown. /// Request may still be in flight. Shutdown will block until this event completes. @@ -25,4 +31,4 @@ namespace Microsoft.AspNet.Hosting /// CancellationToken ApplicationStopped { get; } } -} \ No newline at end of file +} diff --git a/src/Microsoft.AspNet.Hosting/ApplicationLifetime.cs b/src/Microsoft.AspNet.Hosting/ApplicationLifetime.cs index eb6dc364b9..ced615c889 100644 --- a/src/Microsoft.AspNet.Hosting/ApplicationLifetime.cs +++ b/src/Microsoft.AspNet.Hosting/ApplicationLifetime.cs @@ -11,9 +11,19 @@ namespace Microsoft.AspNet.Hosting /// public class ApplicationLifetime : IApplicationLifetime { + private readonly CancellationTokenSource _startedSource = new CancellationTokenSource(); private readonly CancellationTokenSource _stoppingSource = new CancellationTokenSource(); private readonly CancellationTokenSource _stoppedSource = new CancellationTokenSource(); + /// + /// Triggered when the application host has fully started and is about to wait + /// for a graceful shutdown. + /// + public CancellationToken ApplicationStarted + { + get { return _startedSource.Token; } + } + /// /// Triggered when the application host is performing a graceful shutdown. /// Request may still be in flight. Shutdown will block until this event completes. @@ -35,6 +45,21 @@ namespace Microsoft.AspNet.Hosting get { return _stoppedSource.Token; } } + /// + /// Signals the ApplicationStarted event and blocks until it completes. + /// + public void NotifyStarted() + { + try + { + _startedSource.Cancel(throwOnFirstException: false); + } + catch (Exception) + { + // TODO: LOG + } + } + /// /// Signals the ApplicationStopping event and blocks until it completes. /// @@ -65,4 +90,4 @@ namespace Microsoft.AspNet.Hosting } } } -} \ No newline at end of file +} diff --git a/src/Microsoft.AspNet.Hosting/Internal/HostingEngine.cs b/src/Microsoft.AspNet.Hosting/Internal/HostingEngine.cs index 56659edc73..48a0069b92 100644 --- a/src/Microsoft.AspNet.Hosting/Internal/HostingEngine.cs +++ b/src/Microsoft.AspNet.Hosting/Internal/HostingEngine.cs @@ -79,6 +79,8 @@ namespace Microsoft.AspNet.Hosting.Internal } }); + _applicationLifetime.NotifyStarted(); + return new Disposable(() => { _applicationLifetime.NotifyStopping(); @@ -182,4 +184,4 @@ namespace Microsoft.AspNet.Hosting.Internal } } } -} \ No newline at end of file +} diff --git a/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs b/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs index d776c1d481..6c613adcf7 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs @@ -90,6 +90,21 @@ namespace Microsoft.AspNet.Hosting Assert.Equal(1, _startInstances[0].DisposeCalls); } + [Fact] + public void HostingEngineNotifiesApplicationStarted() + { + var host = CreateBuilder() + .UseServer(this) + .Build(); + var applicationLifetime = host.ApplicationServices.GetRequiredService(); + + Assert.False(applicationLifetime.ApplicationStarted.IsCancellationRequested); + using (host.Start()) + { + Assert.True(applicationLifetime.ApplicationStarted.IsCancellationRequested); + } + } + [Fact] public void HostingEngineInjectsHostingEnvironment() { From 1354d66fb6dbaa732e18c66daf40a6fda20b7b90 Mon Sep 17 00:00:00 2001 From: Hao Kung Date: Mon, 11 May 2015 15:08:40 -0700 Subject: [PATCH 292/987] Ensure ConfigureServices is only called once --- .../Internal/HostingEngine.cs | 11 ++++--- .../HostingEngineTests.cs | 32 +++++++++++++++++++ 2 files changed, 38 insertions(+), 5 deletions(-) diff --git a/src/Microsoft.AspNet.Hosting/Internal/HostingEngine.cs b/src/Microsoft.AspNet.Hosting/Internal/HostingEngine.cs index 48a0069b92..924d336e1d 100644 --- a/src/Microsoft.AspNet.Hosting/Internal/HostingEngine.cs +++ b/src/Microsoft.AspNet.Hosting/Internal/HostingEngine.cs @@ -91,11 +91,12 @@ namespace Microsoft.AspNet.Hosting.Internal private void EnsureApplicationServices() { - EnsureStartup(); - - _applicationServiceCollection.AddInstance(_applicationLifetime); - - _applicationServices = Startup.ConfigureServicesDelegate(_applicationServiceCollection); + if (_applicationServices == null) + { + EnsureStartup(); + _applicationServiceCollection.AddInstance(_applicationLifetime); + _applicationServices = Startup.ConfigureServicesDelegate(_applicationServiceCollection); + } } private void EnsureStartup() diff --git a/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs b/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs index 6c613adcf7..6ad8ab0b87 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs @@ -291,6 +291,38 @@ namespace Microsoft.AspNet.Hosting Assert.Same(requestIdentifierFeature, httpContext.GetFeature()); } + [Fact] + public void HostingEngine_InvokesConfigureMethodsOnlyOnce() + { + var engine = CreateBuilder() + .UseServer(this) + .UseStartup() + .Build(); + using (engine.Start()) + { + var services = engine.ApplicationServices; + var services2 = engine.ApplicationServices; + Assert.Equal(1, CountStartup.ConfigureCount); + Assert.Equal(1, CountStartup.ConfigureServicesCount); + } + } + + public class CountStartup + { + public static int ConfigureServicesCount; + public static int ConfigureCount; + + public void ConfigureServices(IServiceCollection services) + { + ConfigureServicesCount++; + } + + public void Configure(IApplicationBuilder app) + { + ConfigureCount++; + } + } + private IHostingEngine CreateHostingEngine(RequestDelegate requestDelegate) { var applicationBuilder = new Mock(); From 95b1997c14bb6fb7e2e68dd156f4feee3d139fec Mon Sep 17 00:00:00 2001 From: Kai Ruhnau Date: Thu, 7 May 2015 11:25:57 +0200 Subject: [PATCH 293/987] Simplify Hosting's shutdown handling. Don't require a TTY on Unix. --- src/Microsoft.AspNet.Hosting/Program.cs | 34 ++++--------------------- 1 file changed, 5 insertions(+), 29 deletions(-) diff --git a/src/Microsoft.AspNet.Hosting/Program.cs b/src/Microsoft.AspNet.Hosting/Program.cs index 11718b64b5..55117e0081 100644 --- a/src/Microsoft.AspNet.Hosting/Program.cs +++ b/src/Microsoft.AspNet.Hosting/Program.cs @@ -3,12 +3,9 @@ using System; using System.IO; -using System.Threading; -using System.Threading.Tasks; using Microsoft.AspNet.Hosting.Internal; using Microsoft.Framework.ConfigurationModel; using Microsoft.Framework.DependencyInjection; -using Microsoft.Framework.Logging; using Microsoft.Framework.Runtime; namespace Microsoft.AspNet.Hosting @@ -35,33 +32,12 @@ namespace Microsoft.AspNet.Hosting config.AddCommandLine(args); var host = new WebHostBuilder(_serviceProvider, config).Build(); - var serverShutdown = host.Start(); - var loggerFactory = host.ApplicationServices.GetRequiredService(); - var appShutdownService = host.ApplicationServices.GetRequiredService(); - var shutdownHandle = new ManualResetEvent(false); - - appShutdownService.ShutdownRequested.Register(() => + using (host.Start()) { - try - { - serverShutdown.Dispose(); - } - catch (Exception ex) - { - var logger = loggerFactory.CreateLogger(); - logger.LogError("Dispose threw an exception.", ex); - } - shutdownHandle.Set(); - }); - - var ignored = Task.Run(() => - { - Console.WriteLine("Started"); - Console.ReadLine(); - appShutdownService.RequestShutdown(); - }); - - shutdownHandle.WaitOne(); + var appShutdownService = host.ApplicationServices.GetRequiredService(); + Console.CancelKeyPress += delegate { appShutdownService.RequestShutdown(); }; + appShutdownService.ShutdownRequested.WaitHandle.WaitOne(); + } } } } From c390d47317c8d0bdac35b1a22d4c180ea79791bb Mon Sep 17 00:00:00 2001 From: Glenn Condron Date: Wed, 25 Mar 2015 21:22:50 -0700 Subject: [PATCH 294/987] Add IsDevelopment and IsProduction extension methods --- .../HostingEnvironmentExtensions.cs | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/Microsoft.AspNet.Hosting.Abstractions/HostingEnvironmentExtensions.cs b/src/Microsoft.AspNet.Hosting.Abstractions/HostingEnvironmentExtensions.cs index c0838231fc..d0baeb570f 100644 --- a/src/Microsoft.AspNet.Hosting.Abstractions/HostingEnvironmentExtensions.cs +++ b/src/Microsoft.AspNet.Hosting.Abstractions/HostingEnvironmentExtensions.cs @@ -9,6 +9,29 @@ namespace Microsoft.AspNet.Hosting { public static class HostingEnvironmentExtensions { + private const string DevelopmentEnvironmentName = "Development"; + private const string ProductionEnvironmentName = "Production"; + + /// + /// Checks if the current hosting environment name is development. + /// + /// An instance of service. + /// True if the environment name is Development, otherwise false. + public static bool IsDevelopment([NotNull]this IHostingEnvironment hostingEnvironment) + { + return hostingEnvironment.IsEnvironment(DevelopmentEnvironmentName); + } + + /// + /// Checks if the current hosting environment name is Production. + /// + /// An instance of service. + /// True if the environment name is Production, otherwise false. + public static bool IsProduction([NotNull]this IHostingEnvironment hostingEnvironment) + { + return hostingEnvironment.IsEnvironment(ProductionEnvironmentName); + } + /// /// Compares the current hosting environment name against the specified value. /// From a4a37b2f0fda69e15f9fc2975895ba3f8574905a Mon Sep 17 00:00:00 2001 From: Eilon Lipton Date: Tue, 12 May 2015 11:49:57 -0700 Subject: [PATCH 295/987] Update Home master -> Home dev --- CONTRIBUTING.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index eac4268e4c..64ff041d5c 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,4 +1,4 @@ Contributing ====== -Information on contributing to this repo is in the [Contributing Guide](https://github.com/aspnet/Home/blob/master/CONTRIBUTING.md) in the Home repo. +Information on contributing to this repo is in the [Contributing Guide](https://github.com/aspnet/Home/blob/dev/CONTRIBUTING.md) in the Home repo. From 8c58f7ac1ad54e9b31e7eeae2cddaf881775ec94 Mon Sep 17 00:00:00 2001 From: David Fowler Date: Tue, 12 May 2015 18:32:53 -0700 Subject: [PATCH 296/987] Print started --- src/Microsoft.AspNet.Hosting/Program.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Microsoft.AspNet.Hosting/Program.cs b/src/Microsoft.AspNet.Hosting/Program.cs index 55117e0081..495d1380b0 100644 --- a/src/Microsoft.AspNet.Hosting/Program.cs +++ b/src/Microsoft.AspNet.Hosting/Program.cs @@ -34,6 +34,7 @@ namespace Microsoft.AspNet.Hosting var host = new WebHostBuilder(_serviceProvider, config).Build(); using (host.Start()) { + Console.WriteLine("Started"); var appShutdownService = host.ApplicationServices.GetRequiredService(); Console.CancelKeyPress += delegate { appShutdownService.RequestShutdown(); }; appShutdownService.ShutdownRequested.WaitHandle.WaitOne(); From 89e60921f8c8165cefe1264ae915c201a94b3f71 Mon Sep 17 00:00:00 2001 From: Chris R Date: Fri, 15 May 2015 10:39:32 -0700 Subject: [PATCH 297/987] React to CoreClr dependency changes. --- src/Microsoft.AspNet.Server.Testing/project.json | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Microsoft.AspNet.Server.Testing/project.json b/src/Microsoft.AspNet.Server.Testing/project.json index ffebc4d56b..e4538164a4 100644 --- a/src/Microsoft.AspNet.Server.Testing/project.json +++ b/src/Microsoft.AspNet.Server.Testing/project.json @@ -21,6 +21,7 @@ "System.Diagnostics.Process": "4.0.0-beta-*", "System.IO.FileSystem": "4.0.0-*", "System.Net.Http": "4.0.0-beta-*", + "System.Net.Primitives": "4.0.10-beta-*", "System.Runtime.Extensions": "4.0.10-beta-*", "System.Text.RegularExpressions": "4.0.10-beta-*", "System.Threading": "4.0.10-beta-*", From 5b851c49a337e49001ed2351253ab0f52b696040 Mon Sep 17 00:00:00 2001 From: Hao Kung Date: Fri, 15 May 2015 13:46:58 -0700 Subject: [PATCH 298/987] Throw when ConfigureServices has wrong signature --- .../Internal/HostingUtilities.cs | 2 +- .../Internal/RequestServicesContainer.cs | 1 - src/Microsoft.AspNet.Hosting/Program.cs | 2 ++ .../Server/ServerLoader.cs | 4 +-- .../Startup/ConfigureDelegate.cs | 5 +-- .../Startup/ConfigureServicesDelegate.cs | 33 ++++++++++--------- .../Fakes/Startup.cs | 2 +- .../HostingEngineTests.cs | 17 ++++++++++ 8 files changed, 42 insertions(+), 24 deletions(-) diff --git a/src/Microsoft.AspNet.Hosting/Internal/HostingUtilities.cs b/src/Microsoft.AspNet.Hosting/Internal/HostingUtilities.cs index cec8d4d762..9d868fe532 100644 --- a/src/Microsoft.AspNet.Hosting/Internal/HostingUtilities.cs +++ b/src/Microsoft.AspNet.Hosting/Internal/HostingUtilities.cs @@ -13,7 +13,7 @@ namespace Microsoft.AspNet.Hosting.Internal internal static Tuple SplitTypeName(string identifier) { string typeName = null; - string assemblyName = identifier.Trim(); + var assemblyName = identifier.Trim(); var parts = identifier.Split(new[] { ',' }, 2); if (parts.Length == 2) { diff --git a/src/Microsoft.AspNet.Hosting/Internal/RequestServicesContainer.cs b/src/Microsoft.AspNet.Hosting/Internal/RequestServicesContainer.cs index 74e6df0fe2..a4ab07d546 100644 --- a/src/Microsoft.AspNet.Hosting/Internal/RequestServicesContainer.cs +++ b/src/Microsoft.AspNet.Hosting/Internal/RequestServicesContainer.cs @@ -39,7 +39,6 @@ namespace Microsoft.AspNet.Hosting.Internal private IServiceProvider PriorRequestServices { get; set; } private IServiceScope Scope { get; set; } - // CONSIDER: this could be an extension method on HttpContext instead public static RequestServicesContainer EnsureRequestServices(HttpContext httpContext, IServiceProvider services) { diff --git a/src/Microsoft.AspNet.Hosting/Program.cs b/src/Microsoft.AspNet.Hosting/Program.cs index 495d1380b0..8e40a30f0e 100644 --- a/src/Microsoft.AspNet.Hosting/Program.cs +++ b/src/Microsoft.AspNet.Hosting/Program.cs @@ -3,6 +3,8 @@ using System; using System.IO; +using System.Threading; +using System.Threading.Tasks; using Microsoft.AspNet.Hosting.Internal; using Microsoft.Framework.ConfigurationModel; using Microsoft.Framework.DependencyInjection; diff --git a/src/Microsoft.AspNet.Hosting/Server/ServerLoader.cs b/src/Microsoft.AspNet.Hosting/Server/ServerLoader.cs index 0327ae6a31..51cdecfe36 100644 --- a/src/Microsoft.AspNet.Hosting/Server/ServerLoader.cs +++ b/src/Microsoft.AspNet.Hosting/Server/ServerLoader.cs @@ -26,8 +26,8 @@ namespace Microsoft.AspNet.Hosting.Server } var nameParts = HostingUtilities.SplitTypeName(serverFactoryIdentifier); - string typeName = nameParts.Item1; - string assemblyName = nameParts.Item2; + var typeName = nameParts.Item1; + var assemblyName = nameParts.Item2; var assembly = Assembly.Load(new AssemblyName(assemblyName)); if (assembly == null) diff --git a/src/Microsoft.AspNet.Hosting/Startup/ConfigureDelegate.cs b/src/Microsoft.AspNet.Hosting/Startup/ConfigureDelegate.cs index 3275f056d9..50f2b22005 100644 --- a/src/Microsoft.AspNet.Hosting/Startup/ConfigureDelegate.cs +++ b/src/Microsoft.AspNet.Hosting/Startup/ConfigureDelegate.cs @@ -20,10 +20,7 @@ namespace Microsoft.AspNet.Hosting.Startup public MethodInfo MethodInfo { get; } - public Action Build(object instance) - { - return builder => Invoke(instance, builder); - } + public Action Build(object instance) => builder => Invoke(instance, builder); private void Invoke(object instance, IApplicationBuilder builder) { diff --git a/src/Microsoft.AspNet.Hosting/Startup/ConfigureServicesDelegate.cs b/src/Microsoft.AspNet.Hosting/Startup/ConfigureServicesDelegate.cs index d500ccea06..0935c7a69d 100644 --- a/src/Microsoft.AspNet.Hosting/Startup/ConfigureServicesDelegate.cs +++ b/src/Microsoft.AspNet.Hosting/Startup/ConfigureServicesDelegate.cs @@ -2,8 +2,10 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.Linq; using System.Reflection; using Microsoft.Framework.DependencyInjection; +using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Hosting.Startup { @@ -11,32 +13,33 @@ namespace Microsoft.AspNet.Hosting.Startup public class ConfigureServicesBuilder { - public ConfigureServicesBuilder(MethodInfo configureServices) + public ConfigureServicesBuilder([NotNull] MethodInfo configureServices) { + // Only support IServiceCollection parameters + var parameters = configureServices.GetParameters(); + if (parameters.Length > 1 || + parameters.Any(p => p.ParameterType != typeof(IServiceCollection))) + { + throw new InvalidOperationException("ConfigureServices can take at most a single IServiceCollection parameter."); + } + MethodInfo = configureServices; } public MethodInfo MethodInfo { get; } - public ConfigureServicesDelegate Build(object instance) - { - return services => Invoke(instance, services); - } + public ConfigureServicesDelegate Build(object instance) => services => Invoke(instance, services); - private IServiceProvider Invoke(object instance, IServiceCollection exportServices) + private IServiceProvider Invoke(object instance, [NotNull] IServiceCollection exportServices) { - var parameterInfos = MethodInfo.GetParameters(); - var parameters = new object[parameterInfos.Length]; - for (var index = 0; index != parameterInfos.Length; ++index) + var parameters = new object[MethodInfo.GetParameters().Length]; + + // Ctor ensures we have at most one IServiceCollection parameter + if (parameters.Length > 0) { - var parameterInfo = parameterInfos[index]; - if (exportServices != null && parameterInfo.ParameterType == typeof(IServiceCollection)) - { - parameters[index] = exportServices; - } + parameters[0] = exportServices; } - // REVIEW: We null ref if exportServices is null, cuz it should not be null return MethodInfo.Invoke(instance, parameters) as IServiceProvider ?? exportServices.BuildServiceProvider(); } } diff --git a/test/Microsoft.AspNet.Hosting.Tests/Fakes/Startup.cs b/test/Microsoft.AspNet.Hosting.Tests/Fakes/Startup.cs index 09a4a3360f..87950f61dc 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/Fakes/Startup.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/Fakes/Startup.cs @@ -82,7 +82,7 @@ namespace Microsoft.AspNet.Hosting.Fakes return services.BuildServiceProvider(); } - public IServiceProvider ConfigureProviderArgsServices(IApplicationBuilder me) + public IServiceProvider ConfigureProviderArgsServices() { var services = new ServiceCollection().AddOptions(); services.Configure(o => diff --git a/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs b/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs index 6ad8ab0b87..2234fcaa5d 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs @@ -323,6 +323,23 @@ namespace Microsoft.AspNet.Hosting } } + [Fact] + public void HostingEngine_ThrowsForBadConfigureServiceSignature() + { + var engine = CreateBuilder() + .UseServer(this) + .UseStartup() + .Build(); + var ex = Assert.Throws(() => engine.Start()); + Assert.True(ex.Message.Contains("ConfigureServices")); + } + + public class BadConfigureServicesStartup + { + public void ConfigureServices(IServiceCollection services, int gunk) { } + public void Configure(IApplicationBuilder app) { } + } + private IHostingEngine CreateHostingEngine(RequestDelegate requestDelegate) { var applicationBuilder = new Mock(); From 0e87d989d77a9b831f6926a8c809f05dabfafebd Mon Sep 17 00:00:00 2001 From: Chris R Date: Fri, 15 May 2015 11:59:13 -0700 Subject: [PATCH 299/987] #272 Make HostingEnvironment default to Production. --- src/Microsoft.AspNet.Hosting/HostingEnvironment.cs | 2 +- .../HostingEngineTests.cs | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/Microsoft.AspNet.Hosting/HostingEnvironment.cs b/src/Microsoft.AspNet.Hosting/HostingEnvironment.cs index 8060d32659..323f0c0270 100644 --- a/src/Microsoft.AspNet.Hosting/HostingEnvironment.cs +++ b/src/Microsoft.AspNet.Hosting/HostingEnvironment.cs @@ -8,7 +8,7 @@ namespace Microsoft.AspNet.Hosting { public class HostingEnvironment : IHostingEnvironment { - internal const string DefaultEnvironmentName = "Development"; + internal const string DefaultEnvironmentName = "Production"; public string EnvironmentName { get; set; } = DefaultEnvironmentName; diff --git a/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs b/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs index 2234fcaa5d..95204108b5 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs @@ -140,15 +140,15 @@ namespace Microsoft.AspNet.Hosting } [Fact] - public void EnvDefaultsToDevelopmentIfNoConfig() + public void EnvDefaultsToProductionIfNoConfig() { var engine = CreateBuilder().Build(); var env = engine.ApplicationServices.GetRequiredService(); - Assert.Equal("Development", env.EnvironmentName); + Assert.Equal("Production", env.EnvironmentName); } [Fact] - public void EnvDefaultsToDevelopmentConfigValueIfSpecifiedWithOldKey() + public void EnvDefaultsToConfigValueIfSpecifiedWithOldKey() { var vals = new Dictionary { @@ -164,7 +164,7 @@ namespace Microsoft.AspNet.Hosting } [Fact] - public void EnvDefaultsToDevelopmentConfigValueIfSpecified() + public void EnvDefaultsToConfigValueIfSpecified() { var vals = new Dictionary { @@ -195,8 +195,8 @@ namespace Microsoft.AspNet.Hosting using (engine.Start()) { var env = engine.ApplicationServices.GetRequiredService(); - Assert.True(env.IsEnvironment("Development")); - Assert.True(env.IsEnvironment("developMent")); + Assert.True(env.IsEnvironment("Production")); + Assert.True(env.IsEnvironment("producTion")); } } From 3124cdd641eef683c5d33c44c94cc4eb995df877 Mon Sep 17 00:00:00 2001 From: David Fowler Date: Sun, 17 May 2015 10:19:03 -0700 Subject: [PATCH 300/987] Remove ConfigureServicesDelegate - Removed the delegate type as it's not used anywhere in user code - Also removed platform helper --- .../PlatformHelper.cs | 20 ------------------- .../Startup/ConfigureServicesDelegate.cs | 4 +--- .../Startup/StartupMethods.cs | 13 ++++++------ .../WebHostBuilder.cs | 2 +- 4 files changed, 9 insertions(+), 30 deletions(-) delete mode 100644 src/Microsoft.AspNet.Hosting/PlatformHelper.cs diff --git a/src/Microsoft.AspNet.Hosting/PlatformHelper.cs b/src/Microsoft.AspNet.Hosting/PlatformHelper.cs deleted file mode 100644 index fbe16751c1..0000000000 --- a/src/Microsoft.AspNet.Hosting/PlatformHelper.cs +++ /dev/null @@ -1,20 +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; - -namespace Microsoft.AspNet.Hosting -{ - internal static class PlatformHelper - { - private static Lazy _isMono = new Lazy(() => Type.GetType("Mono.Runtime") != null); - - public static bool IsMono - { - get - { - return _isMono.Value; - } - } - } -} \ No newline at end of file diff --git a/src/Microsoft.AspNet.Hosting/Startup/ConfigureServicesDelegate.cs b/src/Microsoft.AspNet.Hosting/Startup/ConfigureServicesDelegate.cs index 0935c7a69d..977cb07238 100644 --- a/src/Microsoft.AspNet.Hosting/Startup/ConfigureServicesDelegate.cs +++ b/src/Microsoft.AspNet.Hosting/Startup/ConfigureServicesDelegate.cs @@ -9,8 +9,6 @@ using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Hosting.Startup { - public delegate IServiceProvider ConfigureServicesDelegate(IServiceCollection services); - public class ConfigureServicesBuilder { public ConfigureServicesBuilder([NotNull] MethodInfo configureServices) @@ -28,7 +26,7 @@ namespace Microsoft.AspNet.Hosting.Startup public MethodInfo MethodInfo { get; } - public ConfigureServicesDelegate Build(object instance) => services => Invoke(instance, services); + public Func Build(object instance) => services => Invoke(instance, services); private IServiceProvider Invoke(object instance, [NotNull] IServiceCollection exportServices) { diff --git a/src/Microsoft.AspNet.Hosting/Startup/StartupMethods.cs b/src/Microsoft.AspNet.Hosting/Startup/StartupMethods.cs index c213a681d3..e8b61efdab 100644 --- a/src/Microsoft.AspNet.Hosting/Startup/StartupMethods.cs +++ b/src/Microsoft.AspNet.Hosting/Startup/StartupMethods.cs @@ -9,19 +9,20 @@ namespace Microsoft.AspNet.Hosting.Startup { public class StartupMethods { - internal static ConfigureServicesDelegate DefaultBuildServiceProvider = s => s.BuildServiceProvider(); + internal static Func DefaultBuildServiceProvider = s => s.BuildServiceProvider(); - public StartupMethods(Action configure) - : this(configure, configureServices: null) { } + public StartupMethods(Action configure) + : this(configure, configureServices: null) + { + } - // TODO: switch to ConfigureDelegate eventually - public StartupMethods(Action configure, ConfigureServicesDelegate configureServices) + public StartupMethods(Action configure, Func configureServices) { ConfigureDelegate = configure; ConfigureServicesDelegate = configureServices ?? DefaultBuildServiceProvider; } - public ConfigureServicesDelegate ConfigureServicesDelegate { get; } + public Func ConfigureServicesDelegate { get; } public Action ConfigureDelegate { get; } } diff --git a/src/Microsoft.AspNet.Hosting/WebHostBuilder.cs b/src/Microsoft.AspNet.Hosting/WebHostBuilder.cs index 256f615597..06ae275e29 100644 --- a/src/Microsoft.AspNet.Hosting/WebHostBuilder.cs +++ b/src/Microsoft.AspNet.Hosting/WebHostBuilder.cs @@ -167,7 +167,7 @@ namespace Microsoft.AspNet.Hosting return UseStartup(configureApp, configureServices: null); } - public WebHostBuilder UseStartup([NotNull] Action configureApp, ConfigureServicesDelegate configureServices) + public WebHostBuilder UseStartup([NotNull] Action configureApp, Func configureServices) { _startup = new StartupMethods(configureApp, configureServices); return this; From ac1e0aeee34a59f617a9bd53f3ef6a8ca2f87cb4 Mon Sep 17 00:00:00 2001 From: David Fowler Date: Sun, 17 May 2015 10:25:42 -0700 Subject: [PATCH 301/987] Fixed remaining refs --- src/Microsoft.AspNet.TestHost/TestServer.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Microsoft.AspNet.TestHost/TestServer.cs b/src/Microsoft.AspNet.TestHost/TestServer.cs index 772c934260..c91d7b896e 100644 --- a/src/Microsoft.AspNet.TestHost/TestServer.cs +++ b/src/Microsoft.AspNet.TestHost/TestServer.cs @@ -47,7 +47,7 @@ namespace Microsoft.AspNet.TestHost return Create(services: null, config: null, configureApp: configureApp, configureServices: configureServices); } - public static TestServer Create(IServiceProvider services, Action configureApp, ConfigureServicesDelegate configureServices) + public static TestServer Create(IServiceProvider services, Action configureApp, Func configureServices) { return new TestServer(CreateBuilder(services, config: null, configureApp: configureApp, configureServices: configureServices)); } @@ -70,7 +70,7 @@ namespace Microsoft.AspNet.TestHost }); } - public static WebHostBuilder CreateBuilder(IServiceProvider services, IConfiguration config, Action configureApp, ConfigureServicesDelegate configureServices) + public static WebHostBuilder CreateBuilder(IServiceProvider services, IConfiguration config, Action configureApp, Func configureServices) { return CreateBuilder(services, config).UseStartup(configureApp, configureServices); } From 1566f7206368c1493754ab1e4fd4229f80c951eb Mon Sep 17 00:00:00 2001 From: Troy Dai Date: Wed, 20 May 2015 12:24:38 -0700 Subject: [PATCH 302/987] Update TestHost's dependencies --- src/Microsoft.AspNet.TestHost/project.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Microsoft.AspNet.TestHost/project.json b/src/Microsoft.AspNet.TestHost/project.json index c32b8f617b..b6fc16fd22 100644 --- a/src/Microsoft.AspNet.TestHost/project.json +++ b/src/Microsoft.AspNet.TestHost/project.json @@ -3,7 +3,7 @@ "description": "ASP.NET 5 web server for writing and running tests.", "dependencies": { "Microsoft.AspNet.Hosting": "1.0.0-*", - "Microsoft.Framework.NotNullAttribute.Internal": { "version": "1.0.0-*", "type": "build" } + "Microsoft.Framework.NotNullAttribute.Sources": { "version": "1.0.0-*", "type": "build" } }, "frameworks": { "dnx451": { From b75a855b98b7d1e2385ba9695eabdaeab06c138a Mon Sep 17 00:00:00 2001 From: Kirthi Krishnamraju Date: Wed, 20 May 2015 14:54:33 -0700 Subject: [PATCH 303/987] React to aspnet/Congifuration #195,#198 --- .../IServerFactory.cs | 2 +- .../project.json | 2 +- .../Internal/HostingEngine.cs | 2 +- src/Microsoft.AspNet.Hosting/Program.cs | 4 ++-- src/Microsoft.AspNet.Hosting/WebHostBuilder.cs | 4 ++-- src/Microsoft.AspNet.Hosting/project.json | 5 ++++- src/Microsoft.AspNet.TestHost/TestServer.cs | 4 ++-- .../HostingEngineTests.cs | 14 ++++++++------ .../TestServerTests.cs | 7 +++++-- 9 files changed, 26 insertions(+), 18 deletions(-) diff --git a/src/Microsoft.AspNet.Hosting.Server.Abstractions/IServerFactory.cs b/src/Microsoft.AspNet.Hosting.Server.Abstractions/IServerFactory.cs index a4b5c17d32..be933ea8f7 100644 --- a/src/Microsoft.AspNet.Hosting.Server.Abstractions/IServerFactory.cs +++ b/src/Microsoft.AspNet.Hosting.Server.Abstractions/IServerFactory.cs @@ -4,7 +4,7 @@ using System; using System.Threading.Tasks; using Microsoft.AspNet.FeatureModel; -using Microsoft.Framework.ConfigurationModel; +using Microsoft.Framework.Configuration; namespace Microsoft.AspNet.Hosting.Server { diff --git a/src/Microsoft.AspNet.Hosting.Server.Abstractions/project.json b/src/Microsoft.AspNet.Hosting.Server.Abstractions/project.json index ecc01a5efb..f368b88e76 100644 --- a/src/Microsoft.AspNet.Hosting.Server.Abstractions/project.json +++ b/src/Microsoft.AspNet.Hosting.Server.Abstractions/project.json @@ -2,7 +2,7 @@ "version": "1.0.0-*", "dependencies": { "Microsoft.AspNet.FeatureModel": "1.0.0-*", - "Microsoft.Framework.ConfigurationModel.Abstractions": "1.0.0-*" + "Microsoft.Framework.Configuration.Abstractions": "1.0.0-*" }, "frameworks": { diff --git a/src/Microsoft.AspNet.Hosting/Internal/HostingEngine.cs b/src/Microsoft.AspNet.Hosting/Internal/HostingEngine.cs index 924d336e1d..fd70f5840f 100644 --- a/src/Microsoft.AspNet.Hosting/Internal/HostingEngine.cs +++ b/src/Microsoft.AspNet.Hosting/Internal/HostingEngine.cs @@ -11,7 +11,7 @@ using Microsoft.AspNet.Hosting.Server; using Microsoft.AspNet.Hosting.Startup; using Microsoft.AspNet.Http; using Microsoft.AspNet.Http.Features; -using Microsoft.Framework.ConfigurationModel; +using Microsoft.Framework.Configuration; using Microsoft.Framework.DependencyInjection; using Microsoft.Framework.Internal; using Microsoft.Framework.Logging; diff --git a/src/Microsoft.AspNet.Hosting/Program.cs b/src/Microsoft.AspNet.Hosting/Program.cs index 8e40a30f0e..e9e7ca522b 100644 --- a/src/Microsoft.AspNet.Hosting/Program.cs +++ b/src/Microsoft.AspNet.Hosting/Program.cs @@ -6,7 +6,7 @@ using System.IO; using System.Threading; using System.Threading.Tasks; using Microsoft.AspNet.Hosting.Internal; -using Microsoft.Framework.ConfigurationModel; +using Microsoft.Framework.Configuration; using Microsoft.Framework.DependencyInjection; using Microsoft.Framework.Runtime; @@ -25,7 +25,7 @@ namespace Microsoft.AspNet.Hosting public void Main(string[] args) { - var config = new Configuration(); + var config = new ConfigurationSection(); if (File.Exists(HostingIniFile)) { config.AddIniFile(HostingIniFile); diff --git a/src/Microsoft.AspNet.Hosting/WebHostBuilder.cs b/src/Microsoft.AspNet.Hosting/WebHostBuilder.cs index 06ae275e29..7e204b3b96 100644 --- a/src/Microsoft.AspNet.Hosting/WebHostBuilder.cs +++ b/src/Microsoft.AspNet.Hosting/WebHostBuilder.cs @@ -7,7 +7,7 @@ using Microsoft.AspNet.Hosting.Builder; using Microsoft.AspNet.Hosting.Internal; using Microsoft.AspNet.Hosting.Server; using Microsoft.AspNet.Hosting.Startup; -using Microsoft.Framework.ConfigurationModel; +using Microsoft.Framework.Configuration; using Microsoft.Framework.DependencyInjection; using Microsoft.Framework.Internal; using Microsoft.Framework.Logging; @@ -42,7 +42,7 @@ namespace Microsoft.AspNet.Hosting private string _serverFactoryLocation; private IServerFactory _serverFactory; - public WebHostBuilder([NotNull] IServiceProvider services) : this(services, config: new Configuration()) { } + public WebHostBuilder([NotNull] IServiceProvider services) : this(services, config: new ConfigurationSection()) { } public WebHostBuilder([NotNull] IServiceProvider services, [NotNull] IConfiguration config) { diff --git a/src/Microsoft.AspNet.Hosting/project.json b/src/Microsoft.AspNet.Hosting/project.json index a84b1bc227..cafb35b26d 100644 --- a/src/Microsoft.AspNet.Hosting/project.json +++ b/src/Microsoft.AspNet.Hosting/project.json @@ -8,7 +8,10 @@ "Microsoft.AspNet.Hosting.Server.Abstractions": "1.0.0-*", "Microsoft.AspNet.Http": "1.0.0-*", "Microsoft.AspNet.Http.Extensions": "1.0.0-*", - "Microsoft.Framework.ConfigurationModel": "1.0.0-*", + "Microsoft.Framework.Configuration": "1.0.0-*", + "Microsoft.Framework.Configuration.CommandLine": "1.0.0-*", + "Microsoft.Framework.Configuration.EnvironmentVariables": "1.0.0-*", + "Microsoft.Framework.Configuration.Ini": "1.0.0-*", "Microsoft.Framework.DependencyInjection": "1.0.0-*", "Microsoft.Framework.Logging": "1.0.0-*", "Microsoft.Framework.Runtime.Abstractions": "1.0.0-*", diff --git a/src/Microsoft.AspNet.TestHost/TestServer.cs b/src/Microsoft.AspNet.TestHost/TestServer.cs index c91d7b896e..4bc34a517c 100644 --- a/src/Microsoft.AspNet.TestHost/TestServer.cs +++ b/src/Microsoft.AspNet.TestHost/TestServer.cs @@ -10,7 +10,7 @@ using Microsoft.AspNet.Hosting; using Microsoft.AspNet.Hosting.Server; using Microsoft.AspNet.Hosting.Startup; using Microsoft.AspNet.Http; -using Microsoft.Framework.ConfigurationModel; +using Microsoft.Framework.Configuration; using Microsoft.Framework.DependencyInjection; using Microsoft.Framework.Runtime.Infrastructure; @@ -79,7 +79,7 @@ namespace Microsoft.AspNet.TestHost { return new WebHostBuilder( services ?? CallContextServiceLocator.Locator.ServiceProvider, - config ?? new Configuration()); + config ?? new ConfigurationSection()); } public static WebHostBuilder CreateBuilder() diff --git a/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs b/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs index 95204108b5..268a91a7d3 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs @@ -14,7 +14,7 @@ using Microsoft.AspNet.Hosting.Startup; using Microsoft.AspNet.Http; using Microsoft.AspNet.Http.Features; using Microsoft.AspNet.Testing.xunit; -using Microsoft.Framework.ConfigurationModel; +using Microsoft.Framework.Configuration; using Microsoft.Framework.DependencyInjection; using Microsoft.Framework.Logging; using Microsoft.Framework.OptionsModel; @@ -50,7 +50,7 @@ namespace Microsoft.AspNet.Hosting { "server", "Microsoft.AspNet.Hosting.Tests" } }; - var config = new Configuration() + var config = new ConfigurationSection() .Add(new MemoryConfigurationSource(vals)); var host = CreateBuilder(config).Build(); host.Start(); @@ -65,7 +65,7 @@ namespace Microsoft.AspNet.Hosting { "Hosting:Server", "Microsoft.AspNet.Hosting.Tests" } }; - var config = new Configuration() + var config = new ConfigurationSection() .Add(new MemoryConfigurationSource(vals)); var host = CreateBuilder(config).Build(); host.Start(); @@ -155,7 +155,7 @@ namespace Microsoft.AspNet.Hosting { "ASPNET_ENV", "Staging" } }; - var config = new Configuration() + var config = new ConfigurationSection() .Add(new MemoryConfigurationSource(vals)); var engine = CreateBuilder(config).Build(); @@ -171,7 +171,7 @@ namespace Microsoft.AspNet.Hosting { "Hosting:Environment", "Staging" } }; - var config = new Configuration() + var config = new ConfigurationSection() .Add(new MemoryConfigurationSource(vals)); var engine = CreateBuilder(config).Build(); @@ -380,7 +380,9 @@ namespace Microsoft.AspNet.Hosting private WebHostBuilder CreateBuilder(IConfiguration config = null) { - return new WebHostBuilder(CallContextServiceLocator.Locator.ServiceProvider, config ?? new Configuration()); + return new WebHostBuilder( + CallContextServiceLocator.Locator.ServiceProvider, + config ?? new ConfigurationSection()); } public IServerInformation Initialize(IConfiguration configuration) diff --git a/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs b/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs index be52e9b9cd..e65c0130e7 100644 --- a/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs +++ b/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs @@ -9,7 +9,7 @@ using System.Threading.Tasks; using Microsoft.AspNet.Builder; using Microsoft.AspNet.Hosting; using Microsoft.AspNet.Http; -using Microsoft.Framework.ConfigurationModel; +using Microsoft.Framework.Configuration; using Microsoft.Framework.DependencyInjection; using Microsoft.Framework.Logging; using Microsoft.Framework.Runtime.Infrastructure; @@ -34,7 +34,10 @@ namespace Microsoft.AspNet.TestHost var services = new ServiceCollection().BuildServiceProvider(); // Act & Assert - Assert.Throws(() => TestServer.Create(services, new Configuration(), new Startup().Configure, configureServices: null)); + Assert.Throws( + () => TestServer.Create( + services, + new ConfigurationSection(), new Startup().Configure, configureServices: null)); } [Fact] From 21681761490266ce9b8b519f841abeb97ac46b38 Mon Sep 17 00:00:00 2001 From: Chris R Date: Wed, 20 May 2015 16:10:58 -0700 Subject: [PATCH 304/987] #276 #277 Fix ini loading, read location from command line. --- src/Microsoft.AspNet.Hosting/Program.cs | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/Microsoft.AspNet.Hosting/Program.cs b/src/Microsoft.AspNet.Hosting/Program.cs index e9e7ca522b..eb9e2eccbf 100644 --- a/src/Microsoft.AspNet.Hosting/Program.cs +++ b/src/Microsoft.AspNet.Hosting/Program.cs @@ -2,10 +2,6 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using System.IO; -using System.Threading; -using System.Threading.Tasks; -using Microsoft.AspNet.Hosting.Internal; using Microsoft.Framework.Configuration; using Microsoft.Framework.DependencyInjection; using Microsoft.Framework.Runtime; @@ -15,6 +11,7 @@ namespace Microsoft.AspNet.Hosting public class Program { private const string HostingIniFile = "Microsoft.AspNet.Hosting.ini"; + private const string ConfigFileKey = "config"; private readonly IServiceProvider _serviceProvider; @@ -25,11 +22,13 @@ namespace Microsoft.AspNet.Hosting public void Main(string[] args) { - var config = new ConfigurationSection(); - if (File.Exists(HostingIniFile)) - { - config.AddIniFile(HostingIniFile); - } + // Allow the location of the ini file to be specfied via a --config command line arg + var tempConfig = new ConfigurationSection().AddCommandLine(args); + var configFilePath = tempConfig[ConfigFileKey] ?? HostingIniFile; + + var appBasePath = _serviceProvider.GetRequiredService().ApplicationBasePath; + var config = new ConfigurationSection(appBasePath); + config.AddIniFile(configFilePath, optional: true); config.AddEnvironmentVariables(); config.AddCommandLine(args); From 4289542996bc60adfbfd7053355ab11e94f3b392 Mon Sep 17 00:00:00 2001 From: Kirthi Krishnamraju Date: Fri, 22 May 2015 04:58:56 -0700 Subject: [PATCH 305/987] React to aspnet/Configuration #194 --- src/Microsoft.AspNet.Hosting/Program.cs | 12 +++++++----- src/Microsoft.AspNet.Hosting/WebHostBuilder.cs | 3 ++- src/Microsoft.AspNet.TestHost/TestServer.cs | 2 +- .../HostingEngineTests.cs | 14 +++++++++----- .../TestServerTests.cs | 2 +- 5 files changed, 20 insertions(+), 13 deletions(-) diff --git a/src/Microsoft.AspNet.Hosting/Program.cs b/src/Microsoft.AspNet.Hosting/Program.cs index eb9e2eccbf..6004d8e50f 100644 --- a/src/Microsoft.AspNet.Hosting/Program.cs +++ b/src/Microsoft.AspNet.Hosting/Program.cs @@ -23,14 +23,16 @@ namespace Microsoft.AspNet.Hosting public void Main(string[] args) { // Allow the location of the ini file to be specfied via a --config command line arg - var tempConfig = new ConfigurationSection().AddCommandLine(args); + var tempBuilder = new ConfigurationBuilder().AddCommandLine(args); + var tempConfig = tempBuilder.Build(); var configFilePath = tempConfig[ConfigFileKey] ?? HostingIniFile; var appBasePath = _serviceProvider.GetRequiredService().ApplicationBasePath; - var config = new ConfigurationSection(appBasePath); - config.AddIniFile(configFilePath, optional: true); - config.AddEnvironmentVariables(); - config.AddCommandLine(args); + var builder = new ConfigurationBuilder(appBasePath); + builder.AddIniFile(configFilePath, optional: true); + builder.AddEnvironmentVariables(); + builder.AddCommandLine(args); + var config = builder.Build(); var host = new WebHostBuilder(_serviceProvider, config).Build(); using (host.Start()) diff --git a/src/Microsoft.AspNet.Hosting/WebHostBuilder.cs b/src/Microsoft.AspNet.Hosting/WebHostBuilder.cs index 7e204b3b96..4ae42e9c46 100644 --- a/src/Microsoft.AspNet.Hosting/WebHostBuilder.cs +++ b/src/Microsoft.AspNet.Hosting/WebHostBuilder.cs @@ -42,7 +42,8 @@ namespace Microsoft.AspNet.Hosting private string _serverFactoryLocation; private IServerFactory _serverFactory; - public WebHostBuilder([NotNull] IServiceProvider services) : this(services, config: new ConfigurationSection()) { } + public WebHostBuilder([NotNull] IServiceProvider services) + : this(services, config: new ConfigurationBuilder().Build()) { } public WebHostBuilder([NotNull] IServiceProvider services, [NotNull] IConfiguration config) { diff --git a/src/Microsoft.AspNet.TestHost/TestServer.cs b/src/Microsoft.AspNet.TestHost/TestServer.cs index 4bc34a517c..3dfacf4b59 100644 --- a/src/Microsoft.AspNet.TestHost/TestServer.cs +++ b/src/Microsoft.AspNet.TestHost/TestServer.cs @@ -79,7 +79,7 @@ namespace Microsoft.AspNet.TestHost { return new WebHostBuilder( services ?? CallContextServiceLocator.Locator.ServiceProvider, - config ?? new ConfigurationSection()); + config ?? new ConfigurationBuilder().Build()); } public static WebHostBuilder CreateBuilder() diff --git a/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs b/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs index 268a91a7d3..8c16801d1d 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs @@ -50,8 +50,9 @@ namespace Microsoft.AspNet.Hosting { "server", "Microsoft.AspNet.Hosting.Tests" } }; - var config = new ConfigurationSection() + var builder = new ConfigurationBuilder() .Add(new MemoryConfigurationSource(vals)); + var config = builder.Build(); var host = CreateBuilder(config).Build(); host.Start(); Assert.NotNull(host.ApplicationServices.GetRequiredService()); @@ -65,8 +66,9 @@ namespace Microsoft.AspNet.Hosting { "Hosting:Server", "Microsoft.AspNet.Hosting.Tests" } }; - var config = new ConfigurationSection() + var builder = new ConfigurationBuilder() .Add(new MemoryConfigurationSource(vals)); + var config = builder.Build(); var host = CreateBuilder(config).Build(); host.Start(); Assert.NotNull(host.ApplicationServices.GetRequiredService()); @@ -155,8 +157,9 @@ namespace Microsoft.AspNet.Hosting { "ASPNET_ENV", "Staging" } }; - var config = new ConfigurationSection() + var builder = new ConfigurationBuilder() .Add(new MemoryConfigurationSource(vals)); + var config = builder.Build(); var engine = CreateBuilder(config).Build(); var env = engine.ApplicationServices.GetRequiredService(); @@ -171,8 +174,9 @@ namespace Microsoft.AspNet.Hosting { "Hosting:Environment", "Staging" } }; - var config = new ConfigurationSection() + var builder = new ConfigurationBuilder() .Add(new MemoryConfigurationSource(vals)); + var config = builder.Build(); var engine = CreateBuilder(config).Build(); var env = engine.ApplicationServices.GetRequiredService(); @@ -382,7 +386,7 @@ namespace Microsoft.AspNet.Hosting { return new WebHostBuilder( CallContextServiceLocator.Locator.ServiceProvider, - config ?? new ConfigurationSection()); + config ?? new ConfigurationBuilder().Build()); } public IServerInformation Initialize(IConfiguration configuration) diff --git a/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs b/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs index e65c0130e7..23ae59567b 100644 --- a/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs +++ b/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs @@ -37,7 +37,7 @@ namespace Microsoft.AspNet.TestHost Assert.Throws( () => TestServer.Create( services, - new ConfigurationSection(), new Startup().Configure, configureServices: null)); + new ConfigurationBuilder().Build(), new Startup().Configure, configureServices: null)); } [Fact] From a80b5b4f3d0c0c281bbe22ff406135d036198b35 Mon Sep 17 00:00:00 2001 From: Kai Ruhnau Date: Fri, 22 May 2015 23:48:37 +0200 Subject: [PATCH 306/987] Disabled two tests failing on Mono --- test/Microsoft.AspNet.TestHost.Tests/ClientHandlerTests.cs | 4 +++- test/Microsoft.AspNet.TestHost.Tests/RequestBuilderTests.cs | 5 ++++- test/Microsoft.AspNet.TestHost.Tests/project.json | 1 + 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/test/Microsoft.AspNet.TestHost.Tests/ClientHandlerTests.cs b/test/Microsoft.AspNet.TestHost.Tests/ClientHandlerTests.cs index 779afc7a87..e80ad3dc27 100644 --- a/test/Microsoft.AspNet.TestHost.Tests/ClientHandlerTests.cs +++ b/test/Microsoft.AspNet.TestHost.Tests/ClientHandlerTests.cs @@ -11,6 +11,7 @@ using Microsoft.AspNet.FeatureModel; using Microsoft.AspNet.Http; using Microsoft.AspNet.Http.Features; using Microsoft.AspNet.Http.Internal; +using Microsoft.AspNet.Testing.xunit; using Xunit; namespace Microsoft.AspNet.TestHost @@ -222,7 +223,8 @@ namespace Microsoft.AspNet.TestHost HttpCompletionOption.ResponseHeadersRead)); } - [Fact] + [ConditionalFact] + [FrameworkSkipCondition(RuntimeFrameworks.Mono)] public async Task ExceptionAfterFirstWriteIsReported() { ManualResetEvent block = new ManualResetEvent(false); diff --git a/test/Microsoft.AspNet.TestHost.Tests/RequestBuilderTests.cs b/test/Microsoft.AspNet.TestHost.Tests/RequestBuilderTests.cs index 11e3965a6e..bcc4c79707 100644 --- a/test/Microsoft.AspNet.TestHost.Tests/RequestBuilderTests.cs +++ b/test/Microsoft.AspNet.TestHost.Tests/RequestBuilderTests.cs @@ -1,13 +1,16 @@ // 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.Testing.xunit; using Xunit; namespace Microsoft.AspNet.TestHost { public class RequestBuilderTests { - [Fact] + // c.f. https://github.com/mono/mono/pull/1832 + [ConditionalFact] + [FrameworkSkipCondition(RuntimeFrameworks.Mono)] public void AddRequestHeader() { var server = TestServer.Create(app => { }); diff --git a/test/Microsoft.AspNet.TestHost.Tests/project.json b/test/Microsoft.AspNet.TestHost.Tests/project.json index 968dba2a54..b203628aa6 100644 --- a/test/Microsoft.AspNet.TestHost.Tests/project.json +++ b/test/Microsoft.AspNet.TestHost.Tests/project.json @@ -1,5 +1,6 @@ { "dependencies": { + "Microsoft.AspNet.Testing": "1.0.0-*", "Microsoft.AspNet.TestHost": "1.0.0-*", "xunit.runner.aspnet": "2.0.0-aspnet-*" }, From cb0cde61aa5d4f45dfb68c7b7e516586479d0a0d Mon Sep 17 00:00:00 2001 From: Pranav K Date: Wed, 27 May 2015 16:24:27 -0700 Subject: [PATCH 307/987] Updating to release NuGet.config --- NuGet.Config | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/NuGet.Config b/NuGet.Config index da57d47267..0e74a4912d 100644 --- a/NuGet.Config +++ b/NuGet.Config @@ -1,7 +1,8 @@  - + + - \ No newline at end of file + From 568c8b6bc4c029ba6e3260e3f92e050585753f90 Mon Sep 17 00:00:00 2001 From: Kiran Challa Date: Thu, 28 May 2015 16:16:46 -0700 Subject: [PATCH 308/987] Fix build break. --- .../Deployers/ApplicationDeployer.cs | 4 ++-- .../Deployers/IISExpressDeployer.cs | 4 ++-- .../Deployers/SelfHostDeployer.cs | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Testing/Deployers/ApplicationDeployer.cs b/src/Microsoft.AspNet.Server.Testing/Deployers/ApplicationDeployer.cs index 55893b7aec..6dd076e1a1 100644 --- a/src/Microsoft.AspNet.Server.Testing/Deployers/ApplicationDeployer.cs +++ b/src/Microsoft.AspNet.Server.Testing/Deployers/ApplicationDeployer.cs @@ -92,8 +92,8 @@ namespace Microsoft.AspNet.Server.Testing }; var hostProcess = new Process() { StartInfo = startInfo }; - hostProcess.ErrorDataReceived += (sender, dataArgs) => { Logger.LogError(dataArgs.Data); }; - hostProcess.OutputDataReceived += (sender, dataArgs) => { Logger.LogInformation(dataArgs.Data); }; + hostProcess.ErrorDataReceived += (sender, dataArgs) => { Logger.LogError(dataArgs.Data ?? string.Empty); }; + hostProcess.OutputDataReceived += (sender, dataArgs) => { Logger.LogInformation(dataArgs.Data ?? string.Empty); }; hostProcess.Start(); hostProcess.BeginErrorReadLine(); hostProcess.BeginOutputReadLine(); diff --git a/src/Microsoft.AspNet.Server.Testing/Deployers/IISExpressDeployer.cs b/src/Microsoft.AspNet.Server.Testing/Deployers/IISExpressDeployer.cs index 5c63d28982..5dbf924e5a 100644 --- a/src/Microsoft.AspNet.Server.Testing/Deployers/IISExpressDeployer.cs +++ b/src/Microsoft.AspNet.Server.Testing/Deployers/IISExpressDeployer.cs @@ -107,8 +107,8 @@ namespace Microsoft.AspNet.Server.Testing #endif _hostProcess = new Process() { StartInfo = startInfo }; - _hostProcess.ErrorDataReceived += (sender, dataArgs) => { Logger.LogError(dataArgs.Data); }; - _hostProcess.OutputDataReceived += (sender, dataArgs) => { Logger.LogInformation(dataArgs.Data); }; + _hostProcess.ErrorDataReceived += (sender, dataArgs) => { Logger.LogError(dataArgs.Data ?? string.Empty); }; + _hostProcess.OutputDataReceived += (sender, dataArgs) => { Logger.LogInformation(dataArgs.Data ?? string.Empty); }; _hostProcess.EnableRaisingEvents = true; var hostExitTokenSource = new CancellationTokenSource(); _hostProcess.Exited += (sender, e) => diff --git a/src/Microsoft.AspNet.Server.Testing/Deployers/SelfHostDeployer.cs b/src/Microsoft.AspNet.Server.Testing/Deployers/SelfHostDeployer.cs index e0121bdfd4..e23ae53cef 100644 --- a/src/Microsoft.AspNet.Server.Testing/Deployers/SelfHostDeployer.cs +++ b/src/Microsoft.AspNet.Server.Testing/Deployers/SelfHostDeployer.cs @@ -68,8 +68,8 @@ namespace Microsoft.AspNet.Server.Testing AddEnvironmentVariablesToProcess(startInfo); _hostProcess = new Process() { StartInfo = startInfo }; - _hostProcess.ErrorDataReceived += (sender, dataArgs) => { Logger.LogError(dataArgs.Data); }; - _hostProcess.OutputDataReceived += (sender, dataArgs) => { Logger.LogInformation(dataArgs.Data); }; + _hostProcess.ErrorDataReceived += (sender, dataArgs) => { Logger.LogError(dataArgs.Data ?? string.Empty); }; + _hostProcess.OutputDataReceived += (sender, dataArgs) => { Logger.LogInformation(dataArgs.Data ?? string.Empty); }; _hostProcess.EnableRaisingEvents = true; var hostExitTokenSource = new CancellationTokenSource(); _hostProcess.Exited += (sender, e) => From 62e534977386ebb02bfc351ec4a6bbea9ea7f635 Mon Sep 17 00:00:00 2001 From: Brice Lambson Date: Thu, 28 May 2015 14:29:17 -0700 Subject: [PATCH 309/987] Make webHostBuilder.UseStartup(startupAssemblyName) work --- .../Properties/AssemblyInfo.cs | 4 ++- .../WebHostBuilder.cs | 13 ++++--- .../WebHostBuilderTests.cs | 34 +++++++++++++++++++ 3 files changed, 45 insertions(+), 6 deletions(-) create mode 100644 test/Microsoft.AspNet.Hosting.Tests/WebHostBuilderTests.cs diff --git a/src/Microsoft.AspNet.Hosting/Properties/AssemblyInfo.cs b/src/Microsoft.AspNet.Hosting/Properties/AssemblyInfo.cs index 025a94598c..6145905b3a 100644 --- a/src/Microsoft.AspNet.Hosting/Properties/AssemblyInfo.cs +++ b/src/Microsoft.AspNet.Hosting/Properties/AssemblyInfo.cs @@ -2,5 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Reflection; +using System.Runtime.CompilerServices; -[assembly: AssemblyMetadata("Serviceable", "True")] \ No newline at end of file +[assembly: AssemblyMetadata("Serviceable", "True")] +[assembly: InternalsVisibleTo("Microsoft.AspNet.Hosting.Tests")] diff --git a/src/Microsoft.AspNet.Hosting/WebHostBuilder.cs b/src/Microsoft.AspNet.Hosting/WebHostBuilder.cs index 4ae42e9c46..052f4740c1 100644 --- a/src/Microsoft.AspNet.Hosting/WebHostBuilder.cs +++ b/src/Microsoft.AspNet.Hosting/WebHostBuilder.cs @@ -42,8 +42,10 @@ namespace Microsoft.AspNet.Hosting private string _serverFactoryLocation; private IServerFactory _serverFactory; - public WebHostBuilder([NotNull] IServiceProvider services) - : this(services, config: new ConfigurationBuilder().Build()) { } + public WebHostBuilder([NotNull] IServiceProvider services) + : this(services, config: new ConfigurationBuilder().Build()) + { + } public WebHostBuilder([NotNull] IServiceProvider services, [NotNull] IConfiguration config) { @@ -109,7 +111,7 @@ namespace Microsoft.AspNet.Hosting // Only one of these should be set, but they are used in priority engine.Startup = _startup; engine.StartupType = _startupType; - engine.StartupAssemblyName = _config.Get(ApplicationKey) ?? _config.Get(OldApplicationKey) ?? appEnvironment.ApplicationName; + engine.StartupAssemblyName = _startupAssemblyName ?? _config.Get(ApplicationKey) ?? _config.Get(OldApplicationKey) ?? appEnvironment.ApplicationName; return engine; } @@ -177,7 +179,8 @@ namespace Microsoft.AspNet.Hosting public WebHostBuilder UseStartup([NotNull] Action configureApp, Action configureServices) { _startup = new StartupMethods(configureApp, - services => { + services => + { if (configureServices != null) { configureServices(services); @@ -187,4 +190,4 @@ namespace Microsoft.AspNet.Hosting return this; } } -} \ No newline at end of file +} diff --git a/test/Microsoft.AspNet.Hosting.Tests/WebHostBuilderTests.cs b/test/Microsoft.AspNet.Hosting.Tests/WebHostBuilderTests.cs new file mode 100644 index 0000000000..94cf636d9c --- /dev/null +++ b/test/Microsoft.AspNet.Hosting.Tests/WebHostBuilderTests.cs @@ -0,0 +1,34 @@ +// 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.Hosting.Internal; +using Microsoft.Framework.Runtime.Infrastructure; +using Xunit; + +namespace Microsoft.AspNet.Hosting +{ + public class WebHostBuilderTests + { + [Fact] + public void Build_uses_application_for_startup_assembly_by_default() + { + var builder = CreateWebHostBuilder(); + + var engine = (HostingEngine)builder.Build(); + + Assert.Equal("Microsoft.AspNet.Hosting.Tests", engine.StartupAssemblyName); + } + + [Fact] + public void Build_honors_UseStartup_with_string() + { + var builder = CreateWebHostBuilder(); + + var engine = (HostingEngine)builder.UseStartup("MyStartupAssembly").Build(); + + Assert.Equal("MyStartupAssembly", engine.StartupAssemblyName); + } + + private WebHostBuilder CreateWebHostBuilder() => new WebHostBuilder(CallContextServiceLocator.Locator.ServiceProvider); + } +} From c2b638d85bfb253df3e8e711f19b7d8e45017de1 Mon Sep 17 00:00:00 2001 From: Chris R Date: Fri, 12 Jun 2015 14:38:03 -0700 Subject: [PATCH 310/987] React to OnSendingHeaders rename. --- src/Microsoft.AspNet.TestHost/ResponseFeature.cs | 14 +++++++------- .../ResponseFeatureTests.cs | 4 ++-- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/Microsoft.AspNet.TestHost/ResponseFeature.cs b/src/Microsoft.AspNet.TestHost/ResponseFeature.cs index b582e028a9..7ae2111959 100644 --- a/src/Microsoft.AspNet.TestHost/ResponseFeature.cs +++ b/src/Microsoft.AspNet.TestHost/ResponseFeature.cs @@ -10,7 +10,7 @@ namespace Microsoft.AspNet.TestHost { internal class ResponseFeature : IHttpResponseFeature { - private Action _sendingHeaders = () => { }; + private Action _responseStarting = () => { }; private Action _responseCompleted = () => { }; public ResponseFeature() @@ -31,12 +31,12 @@ namespace Microsoft.AspNet.TestHost public Stream Body { get; set; } - public bool HeadersSent { get; set; } + public bool HasStarted { get; set; } - public void OnSendingHeaders(Action callback, object state) + public void OnResponseStarting(Action callback, object state) { - var prior = _sendingHeaders; - _sendingHeaders = () => + var prior = _responseStarting; + _responseStarting = () => { callback(state); prior(); @@ -55,8 +55,8 @@ namespace Microsoft.AspNet.TestHost public void FireOnSendingHeaders() { - _sendingHeaders(); - HeadersSent = true; + _responseStarting(); + HasStarted = true; } public void FireOnResponseCompleted() diff --git a/test/Microsoft.AspNet.TestHost.Tests/ResponseFeatureTests.cs b/test/Microsoft.AspNet.TestHost.Tests/ResponseFeatureTests.cs index f2c32ef0ca..c3e4b85021 100644 --- a/test/Microsoft.AspNet.TestHost.Tests/ResponseFeatureTests.cs +++ b/test/Microsoft.AspNet.TestHost.Tests/ResponseFeatureTests.cs @@ -15,11 +15,11 @@ namespace Microsoft.AspNet.TestHost // Assert Assert.Equal(200, responseInformation.StatusCode); - Assert.False(responseInformation.HeadersSent); + Assert.False(responseInformation.HasStarted); responseInformation.FireOnSendingHeaders(); - Assert.True(responseInformation.HeadersSent); + Assert.True(responseInformation.HasStarted); } } } \ No newline at end of file From 736e6bee2ba5ab5ed5d8da49f68d698e4f077369 Mon Sep 17 00:00:00 2001 From: Chris R Date: Mon, 15 Jun 2015 11:11:08 -0700 Subject: [PATCH 311/987] #233 Create the wwwroot directory if it doesn't exist. --- src/Microsoft.AspNet.Hosting/HostingEnvironmentExtensions.cs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/Microsoft.AspNet.Hosting/HostingEnvironmentExtensions.cs b/src/Microsoft.AspNet.Hosting/HostingEnvironmentExtensions.cs index a6cd1d5abf..98a839afdc 100644 --- a/src/Microsoft.AspNet.Hosting/HostingEnvironmentExtensions.cs +++ b/src/Microsoft.AspNet.Hosting/HostingEnvironmentExtensions.cs @@ -1,6 +1,7 @@ // 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.IO; using Microsoft.AspNet.FileProviders; using Microsoft.AspNet.Hosting.Internal; @@ -11,6 +12,10 @@ namespace Microsoft.AspNet.Hosting public static void Initialize(this IHostingEnvironment hostingEnvironment, string applicationBasePath, string environmentName) { hostingEnvironment.WebRootPath = HostingUtilities.GetWebRoot(applicationBasePath); + if (!Directory.Exists(hostingEnvironment.WebRootPath)) + { + Directory.CreateDirectory(hostingEnvironment.WebRootPath); + } hostingEnvironment.WebRootFileProvider = new PhysicalFileProvider(hostingEnvironment.WebRootPath); hostingEnvironment.EnvironmentName = environmentName ?? hostingEnvironment.EnvironmentName; } From 2c43b350b41ada2358269312bfe20c9d0764c25a Mon Sep 17 00:00:00 2001 From: Chris R Date: Thu, 18 Jun 2015 15:38:58 -0700 Subject: [PATCH 312/987] React to IRequestIdentifierFeature refactor. --- .../DefaultRequestIdentifierFeature.cs | 18 ------------------ .../Internal/HostingEngine.cs | 10 +++++++--- .../HostingEngineTests.cs | 11 ++++++----- 3 files changed, 13 insertions(+), 26 deletions(-) delete mode 100644 src/Microsoft.AspNet.Hosting/DefaultRequestIdentifierFeature.cs diff --git a/src/Microsoft.AspNet.Hosting/DefaultRequestIdentifierFeature.cs b/src/Microsoft.AspNet.Hosting/DefaultRequestIdentifierFeature.cs deleted file mode 100644 index 07d1f11442..0000000000 --- a/src/Microsoft.AspNet.Hosting/DefaultRequestIdentifierFeature.cs +++ /dev/null @@ -1,18 +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; -using Microsoft.AspNet.Http.Features; - -namespace Microsoft.AspNet.Hosting -{ - public class DefaultRequestIdentifierFeature : IRequestIdentifierFeature - { - public DefaultRequestIdentifierFeature() - { - TraceIdentifier = Guid.NewGuid(); - } - - public Guid TraceIdentifier { get; } - } -} diff --git a/src/Microsoft.AspNet.Hosting/Internal/HostingEngine.cs b/src/Microsoft.AspNet.Hosting/Internal/HostingEngine.cs index fd70f5840f..04b77d4113 100644 --- a/src/Microsoft.AspNet.Hosting/Internal/HostingEngine.cs +++ b/src/Microsoft.AspNet.Hosting/Internal/HostingEngine.cs @@ -11,6 +11,7 @@ using Microsoft.AspNet.Hosting.Server; using Microsoft.AspNet.Hosting.Startup; using Microsoft.AspNet.Http; using Microsoft.AspNet.Http.Features; +using Microsoft.AspNet.Http.Features.Internal; using Microsoft.Framework.Configuration; using Microsoft.Framework.DependencyInjection; using Microsoft.Framework.Internal; @@ -158,12 +159,15 @@ namespace Microsoft.AspNet.Hosting.Internal return builder.Build(); } - private Guid GetRequestIdentifier(HttpContext httpContext) + private string GetRequestIdentifier(HttpContext httpContext) { - var requestIdentifierFeature = httpContext.GetFeature(); + var requestIdentifierFeature = httpContext.GetFeature(); if (requestIdentifierFeature == null) { - requestIdentifierFeature = new DefaultRequestIdentifierFeature(); + requestIdentifierFeature = new HttpRequestIdentifierFeature() + { + TraceIdentifier = Guid.NewGuid().ToString() + }; httpContext.SetFeature(requestIdentifierFeature); } diff --git a/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs b/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs index 8c16801d1d..de7782c4dc 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs @@ -13,6 +13,7 @@ using Microsoft.AspNet.Hosting.Server; using Microsoft.AspNet.Hosting.Startup; using Microsoft.AspNet.Http; using Microsoft.AspNet.Http.Features; +using Microsoft.AspNet.Http.Features.Internal; using Microsoft.AspNet.Testing.xunit; using Microsoft.Framework.Configuration; using Microsoft.Framework.DependencyInjection; @@ -241,7 +242,7 @@ namespace Microsoft.AspNet.Hosting // Assert Assert.NotNull(httpContext); - Assert.IsType(httpContext.GetFeature()); + Assert.IsType(httpContext.GetFeature()); } [Fact] @@ -270,7 +271,7 @@ namespace Microsoft.AspNet.Hosting // Assert Assert.NotNull(httpContext); - Assert.IsType(httpContext.GetFeature()); + Assert.IsType(httpContext.GetFeature()); } [Fact] @@ -283,8 +284,8 @@ namespace Microsoft.AspNet.Hosting httpContext = innerHttpContext; return Task.FromResult(0); }); - var requestIdentifierFeature = new Mock().Object; - _featuresSupportedByThisHost.Add(typeof(IRequestIdentifierFeature), requestIdentifierFeature); + var requestIdentifierFeature = new Mock().Object; + _featuresSupportedByThisHost.Add(typeof(IHttpRequestIdentifierFeature), requestIdentifierFeature); var hostingEngine = CreateHostingEngine(requestDelegate); // Act @@ -292,7 +293,7 @@ namespace Microsoft.AspNet.Hosting // Assert Assert.NotNull(httpContext); - Assert.Same(requestIdentifierFeature, httpContext.GetFeature()); + Assert.Same(requestIdentifierFeature, httpContext.GetFeature()); } [Fact] From 98f8bf6fd380df2992cb822fae0088fe9c0882b8 Mon Sep 17 00:00:00 2001 From: Chris R Date: Fri, 19 Jun 2015 15:04:42 -0700 Subject: [PATCH 313/987] #296 Keep the process alive long enough to shutdown gracefully. --- src/Microsoft.AspNet.Hosting/Program.cs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/Microsoft.AspNet.Hosting/Program.cs b/src/Microsoft.AspNet.Hosting/Program.cs index 6004d8e50f..2ef0635d6f 100644 --- a/src/Microsoft.AspNet.Hosting/Program.cs +++ b/src/Microsoft.AspNet.Hosting/Program.cs @@ -22,7 +22,7 @@ namespace Microsoft.AspNet.Hosting public void Main(string[] args) { - // Allow the location of the ini file to be specfied via a --config command line arg + // Allow the location of the ini file to be specified via a --config command line arg var tempBuilder = new ConfigurationBuilder().AddCommandLine(args); var tempConfig = tempBuilder.Build(); var configFilePath = tempConfig[ConfigFileKey] ?? HostingIniFile; @@ -39,7 +39,12 @@ namespace Microsoft.AspNet.Hosting { Console.WriteLine("Started"); var appShutdownService = host.ApplicationServices.GetRequiredService(); - Console.CancelKeyPress += delegate { appShutdownService.RequestShutdown(); }; + Console.CancelKeyPress += (sender, eventArgs) => + { + appShutdownService.RequestShutdown(); + // Don't terminate the process immediately, wait for the Main thread to exit gracefully. + eventArgs.Cancel = true; + }; appShutdownService.ShutdownRequested.WaitHandle.WaitOne(); } } From 0013d44167dda56996d5f3c6cf0dfec64a01eed3 Mon Sep 17 00:00:00 2001 From: Doug Bunting Date: Tue, 23 Jun 2015 10:58:16 -0700 Subject: [PATCH 314/987] Change hardcoded `bash` shebang to `env` - aspnet/Home#695 - support various `bash` installation locations - in particular, enable building on FreeBSD --- build.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.sh b/build.sh index d81164353c..3ef874f9bd 100755 --- a/build.sh +++ b/build.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash if test `uname` = Darwin; then cachedir=~/Library/Caches/KBuild From ee8baab1ed725cbce97e8daccd5ee7dbacad51b5 Mon Sep 17 00:00:00 2001 From: Hao Kung Date: Tue, 23 Jun 2015 13:44:06 -0700 Subject: [PATCH 315/987] Nuke RequestServicesContainer (inline instead) --- .../Internal/RequestServicesContainer.cs | 114 ------------------ .../RequestServicesContainerMiddleware.cs | 33 ++++- .../HostingEngineTests.cs | 1 + .../TestServerTests.cs | 53 +++++++- 4 files changed, 82 insertions(+), 119 deletions(-) delete mode 100644 src/Microsoft.AspNet.Hosting/Internal/RequestServicesContainer.cs diff --git a/src/Microsoft.AspNet.Hosting/Internal/RequestServicesContainer.cs b/src/Microsoft.AspNet.Hosting/Internal/RequestServicesContainer.cs deleted file mode 100644 index a4ab07d546..0000000000 --- a/src/Microsoft.AspNet.Hosting/Internal/RequestServicesContainer.cs +++ /dev/null @@ -1,114 +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; -using Microsoft.AspNet.Http; -using Microsoft.Framework.DependencyInjection; - -namespace Microsoft.AspNet.Hosting.Internal -{ - public class RequestServicesContainer : IDisposable - { - public RequestServicesContainer( - HttpContext context, - IServiceScopeFactory scopeFactory, - IServiceProvider appServiceProvider) - { - if (scopeFactory == null) - { - throw new ArgumentNullException(nameof(scopeFactory)); - } - if (context == null) - { - throw new ArgumentNullException(nameof(context)); - } - - Context = context; - PriorAppServices = context.ApplicationServices; - PriorRequestServices = context.RequestServices; - - // Begin the scope - Scope = scopeFactory.CreateScope(); - - Context.ApplicationServices = appServiceProvider; - Context.RequestServices = Scope.ServiceProvider; - } - - private HttpContext Context { get; set; } - private IServiceProvider PriorAppServices { get; set; } - private IServiceProvider PriorRequestServices { get; set; } - private IServiceScope Scope { get; set; } - - // CONSIDER: this could be an extension method on HttpContext instead - public static RequestServicesContainer EnsureRequestServices(HttpContext httpContext, IServiceProvider services) - { - // All done if we already have a request services - if (httpContext.RequestServices != null) - { - return null; - } - - var serviceProvider = httpContext.ApplicationServices ?? services; - if (serviceProvider == null) - { - throw new InvalidOperationException("TODO: services and httpContext.ApplicationServices are both null!"); - } - - // Matches constructor of RequestContainer - var rootServiceProvider = serviceProvider.GetRequiredService(); - var rootServiceScopeFactory = serviceProvider.GetRequiredService(); - - // Pre Scope setup - var priorApplicationServices = serviceProvider; - var priorRequestServices = serviceProvider; - - var appServiceProvider = rootServiceProvider; - var appServiceScopeFactory = rootServiceScopeFactory; - - if (priorApplicationServices != null && - priorApplicationServices != appServiceProvider) - { - appServiceProvider = priorApplicationServices; - appServiceScopeFactory = priorApplicationServices.GetRequiredService(); - } - - // Creates the scope and does the service swaps - return new RequestServicesContainer(httpContext, appServiceScopeFactory, appServiceProvider); - } - -#region IDisposable Support - private bool disposedValue = false; // To detect redundant calls - - protected virtual void Dispose(bool disposing) - { - if (!disposedValue) - { - if (disposing) - { - Context.RequestServices = PriorRequestServices; - Context.ApplicationServices = PriorAppServices; - } - - if (Scope != null) - { - Scope.Dispose(); - Scope = null; - } - - Context = null; - PriorAppServices = null; - PriorRequestServices = null; - - disposedValue = true; - } - } - - // This code added to correctly implement the disposable pattern. - public void Dispose() - { - // Do not change this code. Put cleanup code in Dispose(bool disposing) above. - Dispose(true); - } -#endregion - } -} \ No newline at end of file diff --git a/src/Microsoft.AspNet.Hosting/Internal/RequestServicesContainerMiddleware.cs b/src/Microsoft.AspNet.Hosting/Internal/RequestServicesContainerMiddleware.cs index 0a0d169dcb..9c740ba7f1 100644 --- a/src/Microsoft.AspNet.Hosting/Internal/RequestServicesContainerMiddleware.cs +++ b/src/Microsoft.AspNet.Hosting/Internal/RequestServicesContainerMiddleware.cs @@ -5,6 +5,8 @@ using System; using System.Threading.Tasks; using Microsoft.AspNet.Builder; using Microsoft.AspNet.Http; +using Microsoft.Framework.DependencyInjection; +using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Hosting.Internal { @@ -13,18 +15,41 @@ namespace Microsoft.AspNet.Hosting.Internal private readonly RequestDelegate _next; private readonly IServiceProvider _services; - public RequestServicesContainerMiddleware(RequestDelegate next, IServiceProvider services) + public RequestServicesContainerMiddleware([NotNull] RequestDelegate next, [NotNull] IServiceProvider services) { _services = services; _next = next; } - public async Task Invoke(HttpContext httpContext) + public async Task Invoke([NotNull] HttpContext httpContext) { - using (var container = RequestServicesContainer.EnsureRequestServices(httpContext, _services)) + // All done if there request services is set + if (httpContext.RequestServices != null) { await _next.Invoke(httpContext); + return; + } + + var priorApplicationServices = httpContext.ApplicationServices; + var serviceProvider = priorApplicationServices ?? _services; + var scopeFactory = serviceProvider.GetRequiredService(); + + try + { + // Creates the scope and temporarily swap services + using (var scope = scopeFactory.CreateScope()) + { + httpContext.ApplicationServices = serviceProvider; + httpContext.RequestServices = scope.ServiceProvider; + + await _next.Invoke(httpContext); + } + } + finally + { + httpContext.RequestServices = null; + httpContext.ApplicationServices = priorApplicationServices; } } } -} +} \ No newline at end of file diff --git a/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs b/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs index de7782c4dc..b9f0d6a442 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs @@ -8,6 +8,7 @@ using System.Threading.Tasks; using Microsoft.AspNet.Builder; using Microsoft.AspNet.FeatureModel; using Microsoft.AspNet.Hosting.Builder; +using Microsoft.AspNet.Hosting.Fakes; using Microsoft.AspNet.Hosting.Internal; using Microsoft.AspNet.Hosting.Server; using Microsoft.AspNet.Hosting.Startup; diff --git a/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs b/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs index 23ae59567b..d1dbcb93e1 100644 --- a/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs +++ b/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs @@ -8,6 +8,7 @@ using System.Net.Http; using System.Threading.Tasks; using Microsoft.AspNet.Builder; using Microsoft.AspNet.Hosting; +using Microsoft.AspNet.Hosting.Startup; using Microsoft.AspNet.Http; using Microsoft.Framework.Configuration; using Microsoft.Framework.DependencyInjection; @@ -55,10 +56,60 @@ namespace Microsoft.AspNet.TestHost Assert.Equal("RequestServices:True", result); } + public class TestService { } + + public class TestRequestServiceMiddleware + { + private RequestDelegate _next; + + public TestRequestServiceMiddleware(RequestDelegate next) + { + _next = next; + } + + public Task Invoke(HttpContext httpContext) + { + var services = new ServiceCollection(); + services.AddTransient(); + httpContext.RequestServices = services.BuildServiceProvider(); + + return _next.Invoke(httpContext); + } + } + + public class RequestServicesFilter : IStartupFilter + { + public Action Configure(IApplicationBuilder app, Action next) + { + return builder => + { + app.UseMiddleware(); + next(builder); + }; + } + } + + [Fact] + public async Task ExistingRequestServicesWillNotBeReplaced() + { + var server = TestServer.Create(app => + { + app.Run(context => + { + var service = context.RequestServices.GetService(); + return context.Response.WriteAsync("Found:" + (service != null)); + }); + }, + services => services.AddTransient()); + string result = await server.CreateClient().GetStringAsync("/path"); + Assert.Equal("Found:True", result); + } + + [Fact] public async Task CanAccessLogger() { - TestServer server = TestServer.Create(app => + var server = TestServer.Create(app => { app.Run(context => { From 5621a2c2c7326fc285b9a148e37c3298d25cff68 Mon Sep 17 00:00:00 2001 From: Hao Kung Date: Thu, 25 Jun 2015 17:04:16 -0700 Subject: [PATCH 316/987] React to HttpChanges --- src/Microsoft.AspNet.TestHost/ResponseFeature.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Microsoft.AspNet.TestHost/ResponseFeature.cs b/src/Microsoft.AspNet.TestHost/ResponseFeature.cs index 7ae2111959..25d9b3260d 100644 --- a/src/Microsoft.AspNet.TestHost/ResponseFeature.cs +++ b/src/Microsoft.AspNet.TestHost/ResponseFeature.cs @@ -4,6 +4,7 @@ using System; using System.Collections.Generic; using System.IO; +using System.Threading.Tasks; using Microsoft.AspNet.Http.Features; namespace Microsoft.AspNet.TestHost @@ -33,7 +34,7 @@ namespace Microsoft.AspNet.TestHost public bool HasStarted { get; set; } - public void OnResponseStarting(Action callback, object state) + public void OnStarting(Func callback, object state) { var prior = _responseStarting; _responseStarting = () => @@ -43,7 +44,7 @@ namespace Microsoft.AspNet.TestHost }; } - public void OnResponseCompleted(Action callback, object state) + public void OnCompleted(Func callback, object state) { var prior = _responseCompleted; _responseCompleted = () => From bf6e293bfedcb921215f8c4273839912be205719 Mon Sep 17 00:00:00 2001 From: Hao Kung Date: Mon, 29 Jun 2015 11:39:06 -0700 Subject: [PATCH 317/987] Simplify server loader logic --- .../Internal/HostingUtilities.cs | 13 ----- .../Server/IServerLoader.cs | 2 +- .../Server/ServerLoader.cs | 52 ++++--------------- 3 files changed, 12 insertions(+), 55 deletions(-) diff --git a/src/Microsoft.AspNet.Hosting/Internal/HostingUtilities.cs b/src/Microsoft.AspNet.Hosting/Internal/HostingUtilities.cs index 9d868fe532..305888997d 100644 --- a/src/Microsoft.AspNet.Hosting/Internal/HostingUtilities.cs +++ b/src/Microsoft.AspNet.Hosting/Internal/HostingUtilities.cs @@ -10,19 +10,6 @@ namespace Microsoft.AspNet.Hosting.Internal { public static class HostingUtilities { - internal static Tuple SplitTypeName(string identifier) - { - string typeName = null; - var assemblyName = identifier.Trim(); - var parts = identifier.Split(new[] { ',' }, 2); - if (parts.Length == 2) - { - typeName = parts[0].Trim(); - assemblyName = parts[1].Trim(); - } - return new Tuple(typeName, assemblyName); - } - public static string GetWebRoot(string applicationBasePath) { var webroot = applicationBasePath; diff --git a/src/Microsoft.AspNet.Hosting/Server/IServerLoader.cs b/src/Microsoft.AspNet.Hosting/Server/IServerLoader.cs index abf67b4263..3902135cab 100644 --- a/src/Microsoft.AspNet.Hosting/Server/IServerLoader.cs +++ b/src/Microsoft.AspNet.Hosting/Server/IServerLoader.cs @@ -5,6 +5,6 @@ namespace Microsoft.AspNet.Hosting.Server { public interface IServerLoader { - IServerFactory LoadServerFactory(string serverName); + IServerFactory LoadServerFactory(string assemblyName); } } \ No newline at end of file diff --git a/src/Microsoft.AspNet.Hosting/Server/ServerLoader.cs b/src/Microsoft.AspNet.Hosting/Server/ServerLoader.cs index 51cdecfe36..367f7bea05 100644 --- a/src/Microsoft.AspNet.Hosting/Server/ServerLoader.cs +++ b/src/Microsoft.AspNet.Hosting/Server/ServerLoader.cs @@ -4,8 +4,8 @@ using System; using System.Linq; using System.Reflection; -using Microsoft.AspNet.Hosting.Internal; using Microsoft.Framework.DependencyInjection; +using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Hosting.Server { @@ -18,59 +18,29 @@ namespace Microsoft.AspNet.Hosting.Server _services = services; } - public IServerFactory LoadServerFactory(string serverFactoryIdentifier) + public IServerFactory LoadServerFactory([NotNull] string assemblyName) { - if (string.IsNullOrEmpty(serverFactoryIdentifier)) + if (string.IsNullOrEmpty(assemblyName)) { - throw new ArgumentException(string.Empty, nameof(serverFactoryIdentifier)); + throw new ArgumentException(string.Empty, nameof(assemblyName)); } - var nameParts = HostingUtilities.SplitTypeName(serverFactoryIdentifier); - var typeName = nameParts.Item1; - var assemblyName = nameParts.Item2; - var assembly = Assembly.Load(new AssemblyName(assemblyName)); if (assembly == null) { throw new Exception(string.Format("The assembly {0} failed to load.", assemblyName)); } - Type type = null; - Type interfaceInfo; - if (string.IsNullOrEmpty(typeName)) + var serverTypeInfo = assembly.DefinedTypes.Where( + t => t.ImplementedInterfaces.FirstOrDefault(interf => interf.Equals(typeof(IServerFactory))) != null) + .FirstOrDefault(); + + if (serverTypeInfo == null) { - foreach (var typeInfo in assembly.DefinedTypes) - { - interfaceInfo = typeInfo.ImplementedInterfaces.FirstOrDefault(interf => interf.Equals(typeof(IServerFactory))); - if (interfaceInfo != null) - { - type = typeInfo.AsType(); - } - } - - if (type == null) - { - throw new Exception(string.Format("The type {0} failed to load.", typeName ?? "")); - } - } - else - { - type = assembly.GetType(typeName); - - if (type == null) - { - throw new Exception(String.Format("The type {0} failed to load.", typeName ?? "")); - } - - interfaceInfo = type.GetTypeInfo().ImplementedInterfaces.FirstOrDefault(interf => interf.Equals(typeof(IServerFactory))); - - if (interfaceInfo == null) - { - throw new Exception(string.Format("The type '{0}' does not implement the '{1}' interface.", type, typeof(IServerFactory).FullName)); - } + throw new InvalidOperationException($"No server type found that implements IServerFactory in assembly: {assemblyName}."); } - return (IServerFactory)ActivatorUtilities.GetServiceOrCreateInstance(_services, type); + return (IServerFactory)ActivatorUtilities.GetServiceOrCreateInstance(_services, serverTypeInfo.AsType()); } } } \ No newline at end of file From 00b5cdc4a27a71c223e6b6cb63dff50a0bf2a71a Mon Sep 17 00:00:00 2001 From: Chris R Date: Wed, 1 Jul 2015 13:00:54 -0700 Subject: [PATCH 318/987] #212 Check for duplicate Configure or ConfigureServices methods. --- .../Startup/StartupLoader.cs | 19 +++++++++-- .../Fakes/StartupTwoConfigureServices.cs | 30 +++++++++++++++++ .../Fakes/StartupTwoConfigures.cs | 24 ++++++++++++++ .../StartupManagerTests.cs | 32 +++++++++++++++++++ 4 files changed, 103 insertions(+), 2 deletions(-) create mode 100644 test/Microsoft.AspNet.Hosting.Tests/Fakes/StartupTwoConfigureServices.cs create mode 100644 test/Microsoft.AspNet.Hosting.Tests/Fakes/StartupTwoConfigures.cs diff --git a/src/Microsoft.AspNet.Hosting/Startup/StartupLoader.cs b/src/Microsoft.AspNet.Hosting/Startup/StartupLoader.cs index 383d0d8357..28d716ffa4 100644 --- a/src/Microsoft.AspNet.Hosting/Startup/StartupLoader.cs +++ b/src/Microsoft.AspNet.Hosting/Startup/StartupLoader.cs @@ -105,8 +105,23 @@ namespace Microsoft.AspNet.Hosting.Startup { var methodNameWithEnv = string.Format(CultureInfo.InvariantCulture, methodName, environmentName); var methodNameWithNoEnv = string.Format(CultureInfo.InvariantCulture, methodName, ""); - var methodInfo = startupType.GetMethod(methodNameWithEnv, BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static) - ?? startupType.GetMethod(methodNameWithNoEnv, BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static); + + var methods = startupType.GetMethods(BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static); + var selectedMethods = methods.Where(method => method.Name.Equals(methodNameWithEnv)).ToList(); + if (selectedMethods.Count > 1) + { + throw new InvalidOperationException(string.Format("Having multiple overloads of method '{0}' is not supported.", methodNameWithEnv)); + } + if (selectedMethods.Count == 0) + { + selectedMethods = methods.Where(method => method.Name.Equals(methodNameWithNoEnv)).ToList(); + if (selectedMethods.Count > 1) + { + throw new InvalidOperationException(string.Format("Having multiple overloads of method '{0}' is not supported.", methodNameWithNoEnv)); + } + } + + var methodInfo = selectedMethods.FirstOrDefault(); if (methodInfo == null) { if (required) diff --git a/test/Microsoft.AspNet.Hosting.Tests/Fakes/StartupTwoConfigureServices.cs b/test/Microsoft.AspNet.Hosting.Tests/Fakes/StartupTwoConfigureServices.cs new file mode 100644 index 0000000000..0442c3785c --- /dev/null +++ b/test/Microsoft.AspNet.Hosting.Tests/Fakes/StartupTwoConfigureServices.cs @@ -0,0 +1,30 @@ +// 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.Builder; +using Microsoft.Framework.DependencyInjection; + +namespace Microsoft.AspNet.Hosting.Fakes +{ + public class StartupTwoConfigureServices + { + public StartupTwoConfigureServices() + { + } + + public void ConfigureServices(IServiceCollection services) + { + + } + + public void ConfigureServices(IServiceCollection services, object service) + { + + } + + public void Configure(IApplicationBuilder builder) + { + + } + } +} \ No newline at end of file diff --git a/test/Microsoft.AspNet.Hosting.Tests/Fakes/StartupTwoConfigures.cs b/test/Microsoft.AspNet.Hosting.Tests/Fakes/StartupTwoConfigures.cs new file mode 100644 index 0000000000..a97d679ac1 --- /dev/null +++ b/test/Microsoft.AspNet.Hosting.Tests/Fakes/StartupTwoConfigures.cs @@ -0,0 +1,24 @@ +// 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.Builder; + +namespace Microsoft.AspNet.Hosting.Fakes +{ + public class StartupTwoConfigures + { + public StartupTwoConfigures() + { + } + + public void Configure(IApplicationBuilder builder) + { + + } + + public void Configure(IApplicationBuilder builder, object service) + { + + } + } +} \ No newline at end of file diff --git a/test/Microsoft.AspNet.Hosting.Tests/StartupManagerTests.cs b/test/Microsoft.AspNet.Hosting.Tests/StartupManagerTests.cs index 013f202f03..9cc385ae40 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/StartupManagerTests.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/StartupManagerTests.cs @@ -83,6 +83,38 @@ namespace Microsoft.AspNet.Hosting.Tests Assert.Equal("A method named 'ConfigureBoom' or 'Configure' in the type 'Microsoft.AspNet.Hosting.Fakes.StartupBoom' could not be found.", ex.Message); } + [Fact] + public void StartupWithTwoConfiguresThrows() + { + var serviceCollection = new ServiceCollection(); + serviceCollection.AddInstance(this); + var services = serviceCollection.BuildServiceProvider(); + + var diagnosticMessages = new List(); + var hostingEnv = new HostingEnvironment { EnvironmentName = "TwoConfigures" }; + var loader = new StartupLoader(services, hostingEnv); + var type = loader.FindStartupType("Microsoft.AspNet.Hosting.Tests", diagnosticMessages); + + var ex = Assert.Throws(() => loader.LoadMethods(type, diagnosticMessages)); + Assert.Equal("Having multiple overloads of method 'Configure' is not supported.", ex.Message); + } + + [Fact] + public void StartupWithTwoConfigureServicesThrows() + { + var serviceCollection = new ServiceCollection(); + serviceCollection.AddInstance(this); + var services = serviceCollection.BuildServiceProvider(); + + var diagnosticMessages = new List(); + var hostingEnv = new HostingEnvironment { EnvironmentName = "TwoConfigureServices" }; + var loader = new StartupLoader(services, hostingEnv); + var type = loader.FindStartupType("Microsoft.AspNet.Hosting.Tests", diagnosticMessages); + + var ex = Assert.Throws(() => loader.LoadMethods(type, diagnosticMessages)); + Assert.Equal("Having multiple overloads of method 'ConfigureServices' is not supported.", ex.Message); + } + [Fact] public void StartupClassCanHandleConfigureServicesThatReturnsNull() { From 430c55440b3528427d934c074264ef8c8cbdf739 Mon Sep 17 00:00:00 2001 From: Victor Hurdugaci Date: Wed, 1 Jul 2015 19:59:11 -0700 Subject: [PATCH 319/987] Add repository information to project files --- src/Microsoft.AspNet.Hosting.Abstractions/project.json | 4 ++++ src/Microsoft.AspNet.Hosting.Server.Abstractions/project.json | 4 ++++ src/Microsoft.AspNet.Hosting/project.json | 4 ++++ src/Microsoft.AspNet.Server.Testing/project.json | 4 ++++ src/Microsoft.AspNet.TestHost/project.json | 4 ++++ 5 files changed, 20 insertions(+) diff --git a/src/Microsoft.AspNet.Hosting.Abstractions/project.json b/src/Microsoft.AspNet.Hosting.Abstractions/project.json index adca748265..6e143904ae 100644 --- a/src/Microsoft.AspNet.Hosting.Abstractions/project.json +++ b/src/Microsoft.AspNet.Hosting.Abstractions/project.json @@ -1,6 +1,10 @@ { "version": "1.0.0-*", "description": "ASP.NET 5 Hosting abstractions.", + "repository": { + "type": "git", + "url": "git://github.com/aspnet/hosting" + }, "dependencies": { "Microsoft.AspNet.Http.Abstractions": "1.0.0-*", "Microsoft.AspNet.FileProviders.Abstractions": "1.0.0-*", diff --git a/src/Microsoft.AspNet.Hosting.Server.Abstractions/project.json b/src/Microsoft.AspNet.Hosting.Server.Abstractions/project.json index f368b88e76..c9ea12da6a 100644 --- a/src/Microsoft.AspNet.Hosting.Server.Abstractions/project.json +++ b/src/Microsoft.AspNet.Hosting.Server.Abstractions/project.json @@ -1,5 +1,9 @@ { "version": "1.0.0-*", + "repository": { + "type": "git", + "url": "git://github.com/aspnet/hosting" + }, "dependencies": { "Microsoft.AspNet.FeatureModel": "1.0.0-*", "Microsoft.Framework.Configuration.Abstractions": "1.0.0-*" diff --git a/src/Microsoft.AspNet.Hosting/project.json b/src/Microsoft.AspNet.Hosting/project.json index cafb35b26d..8b202b7129 100644 --- a/src/Microsoft.AspNet.Hosting/project.json +++ b/src/Microsoft.AspNet.Hosting/project.json @@ -1,6 +1,10 @@ { "version": "1.0.0-*", "description": "ASP.NET 5 core hosting infrastructure and startup logic for web applications.", + "repository": { + "type": "git", + "url": "git://github.com/aspnet/hosting" + }, "compilationOptions": { "warningsAsErrors": "true" }, "dependencies": { "Microsoft.AspNet.FileProviders.Physical": "1.0.0-*", diff --git a/src/Microsoft.AspNet.Server.Testing/project.json b/src/Microsoft.AspNet.Server.Testing/project.json index e4538164a4..84b84fe211 100644 --- a/src/Microsoft.AspNet.Server.Testing/project.json +++ b/src/Microsoft.AspNet.Server.Testing/project.json @@ -1,6 +1,10 @@ { "version": "1.0.0-*", "description": "ASP.NET 5 helpers to deploy applications to IIS Express, IIS, WebListener and Kestrel for testing.", + "repository": { + "type": "git", + "url": "git://github.com/aspnet/hosting" + }, "dependencies": { "Microsoft.AspNet.Testing": "1.0.0-*", "Microsoft.Framework.Logging.Abstractions": "1.0.0-*", diff --git a/src/Microsoft.AspNet.TestHost/project.json b/src/Microsoft.AspNet.TestHost/project.json index b6fc16fd22..009a2aac6a 100644 --- a/src/Microsoft.AspNet.TestHost/project.json +++ b/src/Microsoft.AspNet.TestHost/project.json @@ -1,6 +1,10 @@ { "version": "1.0.0-*", "description": "ASP.NET 5 web server for writing and running tests.", + "repository": { + "type": "git", + "url": "git://github.com/aspnet/hosting" + }, "dependencies": { "Microsoft.AspNet.Hosting": "1.0.0-*", "Microsoft.Framework.NotNullAttribute.Sources": { "version": "1.0.0-*", "type": "build" } From ad5ab9e76cc213383ced06d27716938d03fdd29e Mon Sep 17 00:00:00 2001 From: Pranav K Date: Thu, 16 Jul 2015 08:57:24 -0700 Subject: [PATCH 320/987] Updating to release NuGet.config --- NuGet.Config | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/NuGet.Config b/NuGet.Config index da57d47267..0e74a4912d 100644 --- a/NuGet.Config +++ b/NuGet.Config @@ -1,7 +1,8 @@  - + + - \ No newline at end of file + From a8c755e6649db3bf4191dc8d96a8cddf2a148b22 Mon Sep 17 00:00:00 2001 From: Chris R Date: Fri, 17 Jul 2015 09:28:11 -0700 Subject: [PATCH 321/987] React to FeatureModel package change. --- .../IServerFactory.cs | 2 +- src/Microsoft.AspNet.Hosting.Server.Abstractions/project.json | 2 +- src/Microsoft.AspNet.Hosting/Builder/HttpContextFactory.cs | 2 +- src/Microsoft.AspNet.Hosting/Builder/IHttpContextFactory.cs | 2 +- src/Microsoft.AspNet.TestHost/ClientHandler.cs | 1 - src/Microsoft.AspNet.TestHost/TestServer.cs | 2 +- test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs | 2 -- test/Microsoft.AspNet.TestHost.Tests/ClientHandlerTests.cs | 1 - 8 files changed, 5 insertions(+), 9 deletions(-) diff --git a/src/Microsoft.AspNet.Hosting.Server.Abstractions/IServerFactory.cs b/src/Microsoft.AspNet.Hosting.Server.Abstractions/IServerFactory.cs index be933ea8f7..09c696b8c8 100644 --- a/src/Microsoft.AspNet.Hosting.Server.Abstractions/IServerFactory.cs +++ b/src/Microsoft.AspNet.Hosting.Server.Abstractions/IServerFactory.cs @@ -3,7 +3,7 @@ using System; using System.Threading.Tasks; -using Microsoft.AspNet.FeatureModel; +using Microsoft.AspNet.Http.Features; using Microsoft.Framework.Configuration; namespace Microsoft.AspNet.Hosting.Server diff --git a/src/Microsoft.AspNet.Hosting.Server.Abstractions/project.json b/src/Microsoft.AspNet.Hosting.Server.Abstractions/project.json index c9ea12da6a..07cab5d291 100644 --- a/src/Microsoft.AspNet.Hosting.Server.Abstractions/project.json +++ b/src/Microsoft.AspNet.Hosting.Server.Abstractions/project.json @@ -5,7 +5,7 @@ "url": "git://github.com/aspnet/hosting" }, "dependencies": { - "Microsoft.AspNet.FeatureModel": "1.0.0-*", + "Microsoft.AspNet.Http.Features": "1.0.0-*", "Microsoft.Framework.Configuration.Abstractions": "1.0.0-*" }, diff --git a/src/Microsoft.AspNet.Hosting/Builder/HttpContextFactory.cs b/src/Microsoft.AspNet.Hosting/Builder/HttpContextFactory.cs index 88ea3a3472..7fccad6854 100644 --- a/src/Microsoft.AspNet.Hosting/Builder/HttpContextFactory.cs +++ b/src/Microsoft.AspNet.Hosting/Builder/HttpContextFactory.cs @@ -1,8 +1,8 @@ // 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.FeatureModel; using Microsoft.AspNet.Http; +using Microsoft.AspNet.Http.Features; using Microsoft.AspNet.Http.Internal; namespace Microsoft.AspNet.Hosting.Builder diff --git a/src/Microsoft.AspNet.Hosting/Builder/IHttpContextFactory.cs b/src/Microsoft.AspNet.Hosting/Builder/IHttpContextFactory.cs index 128dfc4fa1..ed1d9f4cc3 100644 --- a/src/Microsoft.AspNet.Hosting/Builder/IHttpContextFactory.cs +++ b/src/Microsoft.AspNet.Hosting/Builder/IHttpContextFactory.cs @@ -1,8 +1,8 @@ // 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.FeatureModel; using Microsoft.AspNet.Http; +using Microsoft.AspNet.Http.Features; namespace Microsoft.AspNet.Hosting.Builder { diff --git a/src/Microsoft.AspNet.TestHost/ClientHandler.cs b/src/Microsoft.AspNet.TestHost/ClientHandler.cs index f5b501af7e..a5f61bd4f9 100644 --- a/src/Microsoft.AspNet.TestHost/ClientHandler.cs +++ b/src/Microsoft.AspNet.TestHost/ClientHandler.cs @@ -10,7 +10,6 @@ using System.Net; using System.Net.Http; using System.Threading; using System.Threading.Tasks; -using Microsoft.AspNet.FeatureModel; using Microsoft.AspNet.Http; using Microsoft.AspNet.Http.Features; using Microsoft.AspNet.Http.Internal; diff --git a/src/Microsoft.AspNet.TestHost/TestServer.cs b/src/Microsoft.AspNet.TestHost/TestServer.cs index 3dfacf4b59..9bacf1226c 100644 --- a/src/Microsoft.AspNet.TestHost/TestServer.cs +++ b/src/Microsoft.AspNet.TestHost/TestServer.cs @@ -5,11 +5,11 @@ 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.Hosting.Startup; using Microsoft.AspNet.Http; +using Microsoft.AspNet.Http.Features; using Microsoft.Framework.Configuration; using Microsoft.Framework.DependencyInjection; using Microsoft.Framework.Runtime.Infrastructure; diff --git a/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs b/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs index b9f0d6a442..213d57b460 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs @@ -6,9 +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.Builder; -using Microsoft.AspNet.Hosting.Fakes; using Microsoft.AspNet.Hosting.Internal; using Microsoft.AspNet.Hosting.Server; using Microsoft.AspNet.Hosting.Startup; diff --git a/test/Microsoft.AspNet.TestHost.Tests/ClientHandlerTests.cs b/test/Microsoft.AspNet.TestHost.Tests/ClientHandlerTests.cs index 779afc7a87..5ce037f2ba 100644 --- a/test/Microsoft.AspNet.TestHost.Tests/ClientHandlerTests.cs +++ b/test/Microsoft.AspNet.TestHost.Tests/ClientHandlerTests.cs @@ -7,7 +7,6 @@ using System.Linq; using System.Net.Http; using System.Threading; using System.Threading.Tasks; -using Microsoft.AspNet.FeatureModel; using Microsoft.AspNet.Http; using Microsoft.AspNet.Http.Features; using Microsoft.AspNet.Http.Internal; From 6b9093679e2a6b7c9dad61609230ccfa80fb0f8b Mon Sep 17 00:00:00 2001 From: Andrew Stanton-Nurse Date: Tue, 21 Jul 2015 14:56:53 -0700 Subject: [PATCH 322/987] react to DNX renames --- src/Microsoft.AspNet.Hosting/WebHostBuilder.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Microsoft.AspNet.Hosting/WebHostBuilder.cs b/src/Microsoft.AspNet.Hosting/WebHostBuilder.cs index 052f4740c1..b1786b336e 100644 --- a/src/Microsoft.AspNet.Hosting/WebHostBuilder.cs +++ b/src/Microsoft.AspNet.Hosting/WebHostBuilder.cs @@ -60,7 +60,7 @@ namespace Microsoft.AspNet.Hosting var services = new ServiceCollection(); // Import from manifest - var manifest = _services.GetService(); + var manifest = _services.GetService(); if (manifest != null) { foreach (var service in manifest.Services) From bc409abb7dc124b1dafe174fd46d4d022054fb64 Mon Sep 17 00:00:00 2001 From: Eilon Lipton Date: Wed, 22 Jul 2015 14:01:56 -0700 Subject: [PATCH 323/987] Update API usage from Configuration change Caused by https://github.com/aspnet/Configuration/commit/602ce3723f2db9440c09abd732ae59748d768d55 --- test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs b/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs index 213d57b460..6e19e004ad 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs @@ -51,7 +51,7 @@ namespace Microsoft.AspNet.Hosting }; var builder = new ConfigurationBuilder() - .Add(new MemoryConfigurationSource(vals)); + .AddInMemoryCollection(vals); var config = builder.Build(); var host = CreateBuilder(config).Build(); host.Start(); @@ -67,7 +67,7 @@ namespace Microsoft.AspNet.Hosting }; var builder = new ConfigurationBuilder() - .Add(new MemoryConfigurationSource(vals)); + .AddInMemoryCollection(vals); var config = builder.Build(); var host = CreateBuilder(config).Build(); host.Start(); @@ -158,7 +158,7 @@ namespace Microsoft.AspNet.Hosting }; var builder = new ConfigurationBuilder() - .Add(new MemoryConfigurationSource(vals)); + .AddInMemoryCollection(vals); var config = builder.Build(); var engine = CreateBuilder(config).Build(); @@ -175,7 +175,7 @@ namespace Microsoft.AspNet.Hosting }; var builder = new ConfigurationBuilder() - .Add(new MemoryConfigurationSource(vals)); + .AddInMemoryCollection(vals); var config = builder.Build(); var engine = CreateBuilder(config).Build(); From 72a41c78b9225ed2b697f4bfb810c80990408f56 Mon Sep 17 00:00:00 2001 From: moozzyk Date: Thu, 23 Jul 2015 13:40:28 -0700 Subject: [PATCH 324/987] Fixing dnx.exe arguments in deployer to fix server tests --- .gitignore | 1 + .../Deployers/MonoDeployer.cs | 7 ++++--- .../Deployers/SelfHostDeployer.cs | 7 +++---- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/.gitignore b/.gitignore index ac82da7568..58ebbb8fa3 100644 --- a/.gitignore +++ b/.gitignore @@ -25,3 +25,4 @@ nuget.exe *.ipch *.sln.ide project.lock.json +/.vs/ diff --git a/src/Microsoft.AspNet.Server.Testing/Deployers/MonoDeployer.cs b/src/Microsoft.AspNet.Server.Testing/Deployers/MonoDeployer.cs index df44e88ecd..4b8a17eb7a 100644 --- a/src/Microsoft.AspNet.Server.Testing/Deployers/MonoDeployer.cs +++ b/src/Microsoft.AspNet.Server.Testing/Deployers/MonoDeployer.cs @@ -62,13 +62,14 @@ namespace Microsoft.AspNet.Server.Testing throw new InvalidOperationException("kestrel is the only valid ServerType for Mono"); } - Logger.LogInformation("Executing command: dnx \"{appPath}\" kestrel --server.urls {url}", - DeploymentParameters.ApplicationPath, DeploymentParameters.ApplicationBaseUriHint); + var dnxArgs = $"--appbase \"{DeploymentParameters.ApplicationPath}\" Microsoft.Framework.ApplicationHost kestrel --server.urls {DeploymentParameters.ApplicationBaseUriHint}"; + + Logger.LogInformation("Executing command: dnx {dnxArgs}", dnxArgs); var startInfo = new ProcessStartInfo { FileName = "dnx", - Arguments = string.Format("\"{0}\" kestrel --server.urls {1}", DeploymentParameters.ApplicationPath, DeploymentParameters.ApplicationBaseUriHint), + Arguments = dnxArgs, UseShellExecute = false, CreateNoWindow = true, RedirectStandardInput = true diff --git a/src/Microsoft.AspNet.Server.Testing/Deployers/SelfHostDeployer.cs b/src/Microsoft.AspNet.Server.Testing/Deployers/SelfHostDeployer.cs index e23ae53cef..58c1c9420e 100644 --- a/src/Microsoft.AspNet.Server.Testing/Deployers/SelfHostDeployer.cs +++ b/src/Microsoft.AspNet.Server.Testing/Deployers/SelfHostDeployer.cs @@ -49,14 +49,13 @@ namespace Microsoft.AspNet.Server.Testing { var commandName = DeploymentParameters.ServerType == ServerType.WebListener ? "web" : "kestrel"; var dnxPath = Path.Combine(ChosenRuntimePath, "dnx.exe"); - Logger.LogInformation("Executing {dnxexe} {appPath} {command} --server.urls {url}", - dnxPath, DeploymentParameters.ApplicationPath, - commandName, DeploymentParameters.ApplicationBaseUriHint); + var dnxArgs = $"--appbase \"{DeploymentParameters.ApplicationPath}\" Microsoft.Framework.ApplicationHost {commandName} --server.urls {DeploymentParameters.ApplicationBaseUriHint}"; + Logger.LogInformation("Executing {dnxexe} {dnxArgs}", dnxPath, dnxArgs); var startInfo = new ProcessStartInfo { FileName = dnxPath, - Arguments = string.Format("\"{0}\" {1} --server.urls {2}", DeploymentParameters.ApplicationPath, commandName, DeploymentParameters.ApplicationBaseUriHint), + Arguments = dnxArgs, UseShellExecute = false, CreateNoWindow = true, RedirectStandardError = true, From dfe427d3b32478db198f356ee22507b50461060d Mon Sep 17 00:00:00 2001 From: Victor Hurdugaci Date: Wed, 29 Jul 2015 00:01:20 -0700 Subject: [PATCH 325/987] React to DNX renames --- src/Microsoft.AspNet.Hosting/Program.cs | 2 +- src/Microsoft.AspNet.Hosting/WebHostBuilder.cs | 2 +- src/Microsoft.AspNet.Hosting/project.json | 2 +- .../Deployers/IISExpressDeployer.cs | 4 ++-- src/Microsoft.AspNet.Server.Testing/project.json | 2 +- src/Microsoft.AspNet.TestHost/TestServer.cs | 3 +-- test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs | 2 +- test/Microsoft.AspNet.Hosting.Tests/WebHostBuilderTests.cs | 2 +- test/Microsoft.AspNet.Hosting.Tests/project.json | 2 +- test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs | 1 - 10 files changed, 10 insertions(+), 12 deletions(-) diff --git a/src/Microsoft.AspNet.Hosting/Program.cs b/src/Microsoft.AspNet.Hosting/Program.cs index 2ef0635d6f..ba8dc8bc1b 100644 --- a/src/Microsoft.AspNet.Hosting/Program.cs +++ b/src/Microsoft.AspNet.Hosting/Program.cs @@ -4,7 +4,7 @@ using System; using Microsoft.Framework.Configuration; using Microsoft.Framework.DependencyInjection; -using Microsoft.Framework.Runtime; +using Microsoft.Dnx.Runtime; namespace Microsoft.AspNet.Hosting { diff --git a/src/Microsoft.AspNet.Hosting/WebHostBuilder.cs b/src/Microsoft.AspNet.Hosting/WebHostBuilder.cs index b1786b336e..c9edac597a 100644 --- a/src/Microsoft.AspNet.Hosting/WebHostBuilder.cs +++ b/src/Microsoft.AspNet.Hosting/WebHostBuilder.cs @@ -7,11 +7,11 @@ using Microsoft.AspNet.Hosting.Builder; using Microsoft.AspNet.Hosting.Internal; using Microsoft.AspNet.Hosting.Server; using Microsoft.AspNet.Hosting.Startup; +using Microsoft.Dnx.Runtime; using Microsoft.Framework.Configuration; using Microsoft.Framework.DependencyInjection; using Microsoft.Framework.Internal; using Microsoft.Framework.Logging; -using Microsoft.Framework.Runtime; namespace Microsoft.AspNet.Hosting { diff --git a/src/Microsoft.AspNet.Hosting/project.json b/src/Microsoft.AspNet.Hosting/project.json index 8b202b7129..f407a3ae74 100644 --- a/src/Microsoft.AspNet.Hosting/project.json +++ b/src/Microsoft.AspNet.Hosting/project.json @@ -18,7 +18,7 @@ "Microsoft.Framework.Configuration.Ini": "1.0.0-*", "Microsoft.Framework.DependencyInjection": "1.0.0-*", "Microsoft.Framework.Logging": "1.0.0-*", - "Microsoft.Framework.Runtime.Abstractions": "1.0.0-*", + "Microsoft.Dnx.Runtime.Abstractions": "1.0.0-*", "Microsoft.Framework.NotNullAttribute.Sources": { "type": "build", "version": "1.0.0-*" }, "Newtonsoft.Json": "6.0.6" }, diff --git a/src/Microsoft.AspNet.Server.Testing/Deployers/IISExpressDeployer.cs b/src/Microsoft.AspNet.Server.Testing/Deployers/IISExpressDeployer.cs index 5dbf924e5a..69edd89026 100644 --- a/src/Microsoft.AspNet.Server.Testing/Deployers/IISExpressDeployer.cs +++ b/src/Microsoft.AspNet.Server.Testing/Deployers/IISExpressDeployer.cs @@ -5,9 +5,9 @@ using System; using System.Diagnostics; using System.IO; using System.Threading; +using Microsoft.Dnx.Runtime; +using Microsoft.Dnx.Runtime.Infrastructure; using Microsoft.Framework.Logging; -using Microsoft.Framework.Runtime; -using Microsoft.Framework.Runtime.Infrastructure; namespace Microsoft.AspNet.Server.Testing { diff --git a/src/Microsoft.AspNet.Server.Testing/project.json b/src/Microsoft.AspNet.Server.Testing/project.json index 84b84fe211..1898cddb4a 100644 --- a/src/Microsoft.AspNet.Server.Testing/project.json +++ b/src/Microsoft.AspNet.Server.Testing/project.json @@ -8,7 +8,7 @@ "dependencies": { "Microsoft.AspNet.Testing": "1.0.0-*", "Microsoft.Framework.Logging.Abstractions": "1.0.0-*", - "Microsoft.Framework.Runtime.Abstractions": "1.0.0-*" + "Microsoft.Dnx.Runtime.Abstractions": "1.0.0-*" }, "frameworks": { "dnx451": { diff --git a/src/Microsoft.AspNet.TestHost/TestServer.cs b/src/Microsoft.AspNet.TestHost/TestServer.cs index 9bacf1226c..571ceb2662 100644 --- a/src/Microsoft.AspNet.TestHost/TestServer.cs +++ b/src/Microsoft.AspNet.TestHost/TestServer.cs @@ -7,12 +7,11 @@ using System.Threading.Tasks; using Microsoft.AspNet.Builder; using Microsoft.AspNet.Hosting; using Microsoft.AspNet.Hosting.Server; -using Microsoft.AspNet.Hosting.Startup; using Microsoft.AspNet.Http; using Microsoft.AspNet.Http.Features; +using Microsoft.Dnx.Runtime.Infrastructure; using Microsoft.Framework.Configuration; using Microsoft.Framework.DependencyInjection; -using Microsoft.Framework.Runtime.Infrastructure; namespace Microsoft.AspNet.TestHost { diff --git a/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs b/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs index 6e19e004ad..5fc960078f 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs @@ -18,7 +18,7 @@ using Microsoft.Framework.Configuration; using Microsoft.Framework.DependencyInjection; using Microsoft.Framework.Logging; using Microsoft.Framework.OptionsModel; -using Microsoft.Framework.Runtime.Infrastructure; +using Microsoft.Dnx.Runtime.Infrastructure; using Moq; using Xunit; diff --git a/test/Microsoft.AspNet.Hosting.Tests/WebHostBuilderTests.cs b/test/Microsoft.AspNet.Hosting.Tests/WebHostBuilderTests.cs index 94cf636d9c..21f58bddbc 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/WebHostBuilderTests.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/WebHostBuilderTests.cs @@ -2,7 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using Microsoft.AspNet.Hosting.Internal; -using Microsoft.Framework.Runtime.Infrastructure; +using Microsoft.Dnx.Runtime.Infrastructure; using Xunit; namespace Microsoft.AspNet.Hosting diff --git a/test/Microsoft.AspNet.Hosting.Tests/project.json b/test/Microsoft.AspNet.Hosting.Tests/project.json index 3465647dff..cb5c6a1159 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/project.json +++ b/test/Microsoft.AspNet.Hosting.Tests/project.json @@ -4,7 +4,7 @@ "Microsoft.AspNet.Owin": "1.0.0-*", "Microsoft.AspNet.Testing": "1.0.0-*", "Microsoft.Framework.OptionsModel": "1.0.0-*", - "Microsoft.Framework.Runtime.Abstractions": "1.0.0-*", + "Microsoft.Dnx.Runtime.Abstractions": "1.0.0-*", "Moq": "4.2.1312.1622", "xunit.runner.aspnet": "2.0.0-aspnet-*" }, diff --git a/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs b/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs index d1dbcb93e1..94b9afce84 100644 --- a/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs +++ b/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs @@ -13,7 +13,6 @@ using Microsoft.AspNet.Http; using Microsoft.Framework.Configuration; using Microsoft.Framework.DependencyInjection; using Microsoft.Framework.Logging; -using Microsoft.Framework.Runtime.Infrastructure; using Xunit; namespace Microsoft.AspNet.TestHost From 4154dbb8c36e754a974939ae4556ad056c9b12f3 Mon Sep 17 00:00:00 2001 From: Victor Hurdugaci Date: Wed, 29 Jul 2015 01:30:00 -0700 Subject: [PATCH 326/987] Fix dnx arguments --- src/Microsoft.AspNet.Hosting/Program.cs | 2 +- src/Microsoft.AspNet.Server.Testing/Deployers/MonoDeployer.cs | 2 +- .../Deployers/SelfHostDeployer.cs | 2 +- test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Microsoft.AspNet.Hosting/Program.cs b/src/Microsoft.AspNet.Hosting/Program.cs index ba8dc8bc1b..8b6a14c387 100644 --- a/src/Microsoft.AspNet.Hosting/Program.cs +++ b/src/Microsoft.AspNet.Hosting/Program.cs @@ -2,9 +2,9 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using Microsoft.Dnx.Runtime; using Microsoft.Framework.Configuration; using Microsoft.Framework.DependencyInjection; -using Microsoft.Dnx.Runtime; namespace Microsoft.AspNet.Hosting { diff --git a/src/Microsoft.AspNet.Server.Testing/Deployers/MonoDeployer.cs b/src/Microsoft.AspNet.Server.Testing/Deployers/MonoDeployer.cs index 4b8a17eb7a..6619bc8e12 100644 --- a/src/Microsoft.AspNet.Server.Testing/Deployers/MonoDeployer.cs +++ b/src/Microsoft.AspNet.Server.Testing/Deployers/MonoDeployer.cs @@ -62,7 +62,7 @@ namespace Microsoft.AspNet.Server.Testing throw new InvalidOperationException("kestrel is the only valid ServerType for Mono"); } - var dnxArgs = $"--appbase \"{DeploymentParameters.ApplicationPath}\" Microsoft.Framework.ApplicationHost kestrel --server.urls {DeploymentParameters.ApplicationBaseUriHint}"; + var dnxArgs = $"--appbase \"{DeploymentParameters.ApplicationPath}\" Microsoft.Dnx.ApplicationHost kestrel --server.urls {DeploymentParameters.ApplicationBaseUriHint}"; Logger.LogInformation("Executing command: dnx {dnxArgs}", dnxArgs); diff --git a/src/Microsoft.AspNet.Server.Testing/Deployers/SelfHostDeployer.cs b/src/Microsoft.AspNet.Server.Testing/Deployers/SelfHostDeployer.cs index 58c1c9420e..685a88e388 100644 --- a/src/Microsoft.AspNet.Server.Testing/Deployers/SelfHostDeployer.cs +++ b/src/Microsoft.AspNet.Server.Testing/Deployers/SelfHostDeployer.cs @@ -49,7 +49,7 @@ namespace Microsoft.AspNet.Server.Testing { var commandName = DeploymentParameters.ServerType == ServerType.WebListener ? "web" : "kestrel"; var dnxPath = Path.Combine(ChosenRuntimePath, "dnx.exe"); - var dnxArgs = $"--appbase \"{DeploymentParameters.ApplicationPath}\" Microsoft.Framework.ApplicationHost {commandName} --server.urls {DeploymentParameters.ApplicationBaseUriHint}"; + var dnxArgs = $"--appbase \"{DeploymentParameters.ApplicationPath}\" Microsoft.Dnx.ApplicationHost {commandName} --server.urls {DeploymentParameters.ApplicationBaseUriHint}"; Logger.LogInformation("Executing {dnxexe} {dnxArgs}", dnxPath, dnxArgs); var startInfo = new ProcessStartInfo diff --git a/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs b/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs index 5fc960078f..efb0335121 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs @@ -14,11 +14,11 @@ using Microsoft.AspNet.Http; using Microsoft.AspNet.Http.Features; using Microsoft.AspNet.Http.Features.Internal; using Microsoft.AspNet.Testing.xunit; +using Microsoft.Dnx.Runtime.Infrastructure; using Microsoft.Framework.Configuration; using Microsoft.Framework.DependencyInjection; using Microsoft.Framework.Logging; using Microsoft.Framework.OptionsModel; -using Microsoft.Dnx.Runtime.Infrastructure; using Moq; using Xunit; From 466c44188202f6bd7079f5f9be6331eb9f54154d Mon Sep 17 00:00:00 2001 From: mishfit Date: Mon, 27 Jul 2015 11:29:05 -0500 Subject: [PATCH 327/987] show how to exit - grammer - verbiage --- src/Microsoft.AspNet.Hosting/Program.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Microsoft.AspNet.Hosting/Program.cs b/src/Microsoft.AspNet.Hosting/Program.cs index 8b6a14c387..985feeda86 100644 --- a/src/Microsoft.AspNet.Hosting/Program.cs +++ b/src/Microsoft.AspNet.Hosting/Program.cs @@ -37,7 +37,8 @@ namespace Microsoft.AspNet.Hosting var host = new WebHostBuilder(_serviceProvider, config).Build(); using (host.Start()) { - Console.WriteLine("Started"); + Console.WriteLine("Application started. Press Ctrl+C to shut down."); + var appShutdownService = host.ApplicationServices.GetRequiredService(); Console.CancelKeyPress += (sender, eventArgs) => { From 712b1d1aeca13d38ec86175f5ab775efb0a80383 Mon Sep 17 00:00:00 2001 From: anurse Date: Fri, 31 Jul 2015 11:48:21 -0700 Subject: [PATCH 328/987] fix build --- .../Deployers/IISExpressDeployer.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Microsoft.AspNet.Server.Testing/Deployers/IISExpressDeployer.cs b/src/Microsoft.AspNet.Server.Testing/Deployers/IISExpressDeployer.cs index 69edd89026..5309a59925 100644 --- a/src/Microsoft.AspNet.Server.Testing/Deployers/IISExpressDeployer.cs +++ b/src/Microsoft.AspNet.Server.Testing/Deployers/IISExpressDeployer.cs @@ -132,7 +132,7 @@ namespace Microsoft.AspNet.Server.Testing private void CopyAspNetLoader() { var libraryManager = (ILibraryManager)CallContextServiceLocator.Locator.ServiceProvider.GetService(typeof(ILibraryManager)); - var interopLibrary = libraryManager.GetLibraryInformation("Microsoft.AspNet.Loader.IIS.Interop"); + var interopLibrary = libraryManager.GetLibrary("Microsoft.AspNet.Loader.IIS.Interop"); if (interopLibrary == null) { From b138f2a4601041dd051d3a9089d9f939afcc6886 Mon Sep 17 00:00:00 2001 From: Chris R Date: Mon, 3 Aug 2015 15:46:01 -0700 Subject: [PATCH 329/987] React to IFeatureCollection API changes. --- .../HostingEngineTests.cs | 66 +++++++++++-------- 1 file changed, 39 insertions(+), 27 deletions(-) diff --git a/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs b/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs index efb0335121..579febdd8f 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs @@ -2,11 +2,11 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.Collections; using System.Collections.Generic; using System.IO; using System.Threading.Tasks; using Microsoft.AspNet.Builder; -using Microsoft.AspNet.Hosting.Builder; using Microsoft.AspNet.Hosting.Internal; using Microsoft.AspNet.Hosting.Server; using Microsoft.AspNet.Hosting.Startup; @@ -17,7 +17,7 @@ using Microsoft.AspNet.Testing.xunit; using Microsoft.Dnx.Runtime.Infrastructure; using Microsoft.Framework.Configuration; using Microsoft.Framework.DependencyInjection; -using Microsoft.Framework.Logging; +using Microsoft.Framework.Internal; using Microsoft.Framework.OptionsModel; using Moq; using Xunit; @@ -254,14 +254,8 @@ namespace Microsoft.AspNet.Hosting httpContext = innerHttpContext; return Task.FromResult(0); }); - var featuresSupportedByHost = new Mock(); - featuresSupportedByHost - .Setup(fc => fc.Add(It.IsAny(), It.IsAny())) - .Throws(new NotImplementedException()); - featuresSupportedByHost - .Setup(fc => fc.Add(new KeyValuePair(It.IsAny(), It.IsAny()))) - .Throws(new NotImplementedException()); - _featuresSupportedByThisHost = featuresSupportedByHost.Object; + + _featuresSupportedByThisHost = new ReadOnlyFeatureCollection(); var hostingEngine = CreateHostingEngine(requestDelegate); @@ -284,7 +278,7 @@ namespace Microsoft.AspNet.Hosting return Task.FromResult(0); }); var requestIdentifierFeature = new Mock().Object; - _featuresSupportedByThisHost.Add(typeof(IHttpRequestIdentifierFeature), requestIdentifierFeature); + _featuresSupportedByThisHost[typeof(IHttpRequestIdentifierFeature)] = requestIdentifierFeature; var hostingEngine = CreateHostingEngine(requestDelegate); // Act @@ -346,25 +340,10 @@ namespace Microsoft.AspNet.Hosting private IHostingEngine CreateHostingEngine(RequestDelegate requestDelegate) { - var applicationBuilder = new Mock(); - applicationBuilder.Setup(appBuilder => appBuilder.Build()).Returns(requestDelegate); - var applicationBuilderFactory = new Mock(); - applicationBuilderFactory - .Setup(abf => abf.CreateBuilder(It.IsAny())) - .Returns(applicationBuilder.Object); - var host = CreateBuilder() .UseServer(this) - .UseServices(s => - { - s.AddInstance(applicationBuilderFactory.Object); - s.AddInstance(new Mock>().Object); - s.AddSingleton(); - s.AddInstance(new Mock().Object); - s.AddInstance(new Mock().Object); - }) .UseStartup( - appBuilder => { }, + appBuilder => { appBuilder.Run(requestDelegate); }, configureServices => configureServices.BuildServiceProvider()); return host.Build(); } @@ -431,5 +410,38 @@ namespace Microsoft.AspNet.Hosting throw new NotImplementedException(); } } + + private class ReadOnlyFeatureCollection : IFeatureCollection + { + public object this[[NotNull] Type key] + { + get { return null; } + set { throw new NotSupportedException(); } + } + + public bool IsReadOnly + { + get { return true; } + } + + public int Revision + { + get { return 0; } + } + + public void Dispose() + { + } + + public IEnumerator> GetEnumerator() + { + yield break; + } + + IEnumerator IEnumerable.GetEnumerator() + { + yield break; + } + } } } From 051bb8757830f5067ce54a526c6637927ad53b82 Mon Sep 17 00:00:00 2001 From: Troy Dai Date: Tue, 4 Aug 2015 10:15:27 -0700 Subject: [PATCH 330/987] Update CoreCLR versions --- src/Microsoft.AspNet.Server.Testing/project.json | 12 ++++++------ src/Microsoft.AspNet.TestHost/project.json | 4 ++-- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Testing/project.json b/src/Microsoft.AspNet.Server.Testing/project.json index 1898cddb4a..77260810ac 100644 --- a/src/Microsoft.AspNet.Server.Testing/project.json +++ b/src/Microsoft.AspNet.Server.Testing/project.json @@ -24,13 +24,13 @@ "dependencies": { "System.Diagnostics.Process": "4.0.0-beta-*", "System.IO.FileSystem": "4.0.0-*", - "System.Net.Http": "4.0.0-beta-*", - "System.Net.Primitives": "4.0.10-beta-*", - "System.Runtime.Extensions": "4.0.10-beta-*", - "System.Text.RegularExpressions": "4.0.10-beta-*", - "System.Threading": "4.0.10-beta-*", + "System.Net.Http": "4.0.1-beta-*", + "System.Net.Primitives": "4.0.11-beta-*", + "System.Runtime.Extensions": "4.0.11-beta-*", + "System.Text.RegularExpressions": "4.0.11-beta-*", + "System.Threading": "4.0.11-beta-*", "System.Threading.Thread": "4.0.0-*" } } } -} \ No newline at end of file +} diff --git a/src/Microsoft.AspNet.TestHost/project.json b/src/Microsoft.AspNet.TestHost/project.json index 009a2aac6a..c59e21f29d 100644 --- a/src/Microsoft.AspNet.TestHost/project.json +++ b/src/Microsoft.AspNet.TestHost/project.json @@ -17,8 +17,8 @@ }, "dnxcore50": { "dependencies": { - "System.Diagnostics.Contracts": "4.0.0-beta-*", - "System.Net.Http": "4.0.0-beta-*" + "System.Diagnostics.Contracts": "4.0.1-beta-*", + "System.Net.Http": "4.0.1-beta-*" } } } From 44b762cf08b39491cac3a9e0220e63fa19c6b431 Mon Sep 17 00:00:00 2001 From: Kiran Challa Date: Tue, 11 Aug 2015 17:04:07 -0700 Subject: [PATCH 331/987] Enable pinning build script --- build.cmd | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/build.cmd b/build.cmd index 41025afb26..ccf195aee8 100644 --- a/build.cmd +++ b/build.cmd @@ -3,6 +3,8 @@ cd %~dp0 SETLOCAL SET CACHED_NUGET=%LocalAppData%\NuGet\NuGet.exe +SET BUILDCMD_KOREBUILD_VERSION="" +SET BUILDCMD_DNX_VERSION="" IF EXIST %CACHED_NUGET% goto copynuget echo Downloading latest version of NuGet.exe... @@ -16,13 +18,21 @@ copy %CACHED_NUGET% .nuget\nuget.exe > nul :restore IF EXIST packages\KoreBuild goto run -.nuget\NuGet.exe install KoreBuild -ExcludeVersion -o packages -nocache -pre +IF %BUILDCMD_KOREBUILD_VERSION%=="" ( + .nuget\NuGet.exe install KoreBuild -ExcludeVersion -o packages -nocache -pre +) ELSE ( + .nuget\NuGet.exe install KoreBuild -version %BUILDCMD_KOREBUILD_VERSION% -ExcludeVersion -o packages -nocache -pre +) .nuget\NuGet.exe install Sake -version 0.2 -o packages -ExcludeVersion IF "%SKIP_DNX_INSTALL%"=="1" goto run -CALL packages\KoreBuild\build\dnvm upgrade -runtime CLR -arch x86 +IF %BUILDCMD_DNX_VERSION%=="" ( + CALL packages\KoreBuild\build\dnvm upgrade -runtime CLR -arch x86 +) ELSE ( + CALL packages\KoreBuild\build\dnvm install %BUILDCMD_DNX_VERSION% -runtime CLR -arch x86 -a default +) CALL packages\KoreBuild\build\dnvm install default -runtime CoreCLR -arch x86 :run CALL packages\KoreBuild\build\dnvm use default -runtime CLR -arch x86 -packages\Sake\tools\Sake.exe -I packages\KoreBuild\build -f makefile.shade %* +packages\Sake\tools\Sake.exe -I packages\KoreBuild\build -f makefile.shade %* \ No newline at end of file From ad6e4b838a5daad0b9a36870e5d0e3f586e9ca06 Mon Sep 17 00:00:00 2001 From: Hao Kung Date: Wed, 12 Aug 2015 13:13:27 -0700 Subject: [PATCH 332/987] Goodbye HttpContextAccessor --- .../IHttpContextAccessor.cs | 12 ----- .../HttpContextAccessor.cs | 48 ------------------- .../WebHostBuilder.cs | 2 + 3 files changed, 2 insertions(+), 60 deletions(-) delete mode 100644 src/Microsoft.AspNet.Hosting.Abstractions/IHttpContextAccessor.cs delete mode 100644 src/Microsoft.AspNet.Hosting/HttpContextAccessor.cs diff --git a/src/Microsoft.AspNet.Hosting.Abstractions/IHttpContextAccessor.cs b/src/Microsoft.AspNet.Hosting.Abstractions/IHttpContextAccessor.cs deleted file mode 100644 index eab12b1344..0000000000 --- a/src/Microsoft.AspNet.Hosting.Abstractions/IHttpContextAccessor.cs +++ /dev/null @@ -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; } - } -} \ No newline at end of file diff --git a/src/Microsoft.AspNet.Hosting/HttpContextAccessor.cs b/src/Microsoft.AspNet.Hosting/HttpContextAccessor.cs deleted file mode 100644 index f649d95016..0000000000 --- a/src/Microsoft.AspNet.Hosting/HttpContextAccessor.cs +++ /dev/null @@ -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 _httpContextCurrent = new AsyncLocal(); - public HttpContext HttpContext - { - get - { - return _httpContextCurrent.Value; - } - set - { - _httpContextCurrent.Value = value; - } - } -#endif - } -} diff --git a/src/Microsoft.AspNet.Hosting/WebHostBuilder.cs b/src/Microsoft.AspNet.Hosting/WebHostBuilder.cs index c9edac597a..f6ec3b3e0c 100644 --- a/src/Microsoft.AspNet.Hosting/WebHostBuilder.cs +++ b/src/Microsoft.AspNet.Hosting/WebHostBuilder.cs @@ -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; From b67ca0a277de900250bfaf3aedf48cab0d612491 Mon Sep 17 00:00:00 2001 From: Kirthi Krishnamraju Date: Thu, 13 Aug 2015 22:22:45 -0700 Subject: [PATCH 333/987] fix build break due to aspnet\Configuration #246 --- src/Microsoft.AspNet.Hosting/WebHostBuilder.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Microsoft.AspNet.Hosting/WebHostBuilder.cs b/src/Microsoft.AspNet.Hosting/WebHostBuilder.cs index f6ec3b3e0c..502d9bc09a 100644 --- a/src/Microsoft.AspNet.Hosting/WebHostBuilder.cs +++ b/src/Microsoft.AspNet.Hosting/WebHostBuilder.cs @@ -108,12 +108,12 @@ namespace Microsoft.AspNet.Hosting // Only one of these should be set, but they are used in priority engine.ServerFactory = _serverFactory; - engine.ServerFactoryLocation = _config.Get(ServerKey) ?? _config.Get(OldServerKey) ?? _serverFactoryLocation; + engine.ServerFactoryLocation = _config[ServerKey] ?? _config[OldServerKey] ?? _serverFactoryLocation; // Only one of these should be set, but they are used in priority engine.Startup = _startup; engine.StartupType = _startupType; - engine.StartupAssemblyName = _startupAssemblyName ?? _config.Get(ApplicationKey) ?? _config.Get(OldApplicationKey) ?? appEnvironment.ApplicationName; + engine.StartupAssemblyName = _startupAssemblyName ?? _config[ApplicationKey] ?? _config[OldApplicationKey] ?? appEnvironment.ApplicationName; return engine; } From 8e39bf4ffbee7365bb1d28436c5c98a66eb776d7 Mon Sep 17 00:00:00 2001 From: Hisham Abdullah Bin Ateya Date: Mon, 18 May 2015 08:01:00 +0300 Subject: [PATCH 334/987] Shift 'Development' & 'Production' constants into 'EnvironmentName' class Make 'EnvironmentName' static Change constants -> static readonly fields Remove trailing spaces --- .../EnvironmentName.cs | 11 +++++++++++ .../HostingEnvironmentExtensions.cs | 7 ++----- src/Microsoft.AspNet.Hosting/HostingEnvironment.cs | 4 +--- .../HostingEngineTests.cs | 4 ++-- 4 files changed, 16 insertions(+), 10 deletions(-) create mode 100644 src/Microsoft.AspNet.Hosting.Abstractions/EnvironmentName.cs diff --git a/src/Microsoft.AspNet.Hosting.Abstractions/EnvironmentName.cs b/src/Microsoft.AspNet.Hosting.Abstractions/EnvironmentName.cs new file mode 100644 index 0000000000..664744383c --- /dev/null +++ b/src/Microsoft.AspNet.Hosting.Abstractions/EnvironmentName.cs @@ -0,0 +1,11 @@ +// 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. + +namespace Microsoft.AspNet.Hosting +{ + public static class EnvironmentName + { + public static readonly string Development = "Development"; + public static readonly string Production = "Production"; + } +} \ No newline at end of file diff --git a/src/Microsoft.AspNet.Hosting.Abstractions/HostingEnvironmentExtensions.cs b/src/Microsoft.AspNet.Hosting.Abstractions/HostingEnvironmentExtensions.cs index d0baeb570f..8fc1b8e43b 100644 --- a/src/Microsoft.AspNet.Hosting.Abstractions/HostingEnvironmentExtensions.cs +++ b/src/Microsoft.AspNet.Hosting.Abstractions/HostingEnvironmentExtensions.cs @@ -9,9 +9,6 @@ namespace Microsoft.AspNet.Hosting { public static class HostingEnvironmentExtensions { - private const string DevelopmentEnvironmentName = "Development"; - private const string ProductionEnvironmentName = "Production"; - /// /// Checks if the current hosting environment name is development. /// @@ -19,7 +16,7 @@ namespace Microsoft.AspNet.Hosting /// True if the environment name is Development, otherwise false. public static bool IsDevelopment([NotNull]this IHostingEnvironment hostingEnvironment) { - return hostingEnvironment.IsEnvironment(DevelopmentEnvironmentName); + return hostingEnvironment.IsEnvironment(EnvironmentName.Development); } /// @@ -29,7 +26,7 @@ namespace Microsoft.AspNet.Hosting /// True if the environment name is Production, otherwise false. public static bool IsProduction([NotNull]this IHostingEnvironment hostingEnvironment) { - return hostingEnvironment.IsEnvironment(ProductionEnvironmentName); + return hostingEnvironment.IsEnvironment(EnvironmentName.Production); } /// diff --git a/src/Microsoft.AspNet.Hosting/HostingEnvironment.cs b/src/Microsoft.AspNet.Hosting/HostingEnvironment.cs index 323f0c0270..57617c2893 100644 --- a/src/Microsoft.AspNet.Hosting/HostingEnvironment.cs +++ b/src/Microsoft.AspNet.Hosting/HostingEnvironment.cs @@ -8,9 +8,7 @@ namespace Microsoft.AspNet.Hosting { public class HostingEnvironment : IHostingEnvironment { - internal const string DefaultEnvironmentName = "Production"; - - public string EnvironmentName { get; set; } = DefaultEnvironmentName; + public string EnvironmentName { get; set; } = Microsoft.AspNet.Hosting.EnvironmentName.Production; public string WebRootPath { get; set; } diff --git a/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs b/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs index 579febdd8f..1642ec7235 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs @@ -146,7 +146,7 @@ namespace Microsoft.AspNet.Hosting { var engine = CreateBuilder().Build(); var env = engine.ApplicationServices.GetRequiredService(); - Assert.Equal("Production", env.EnvironmentName); + Assert.Equal(EnvironmentName.Production, env.EnvironmentName); } [Fact] @@ -199,7 +199,7 @@ namespace Microsoft.AspNet.Hosting using (engine.Start()) { var env = engine.ApplicationServices.GetRequiredService(); - Assert.True(env.IsEnvironment("Production")); + Assert.True(env.IsEnvironment(EnvironmentName.Production)); Assert.True(env.IsEnvironment("producTion")); } } From 52388e89f87909c726645c2a60d3fd4f913faf94 Mon Sep 17 00:00:00 2001 From: David Fowler Date: Sat, 15 Aug 2015 01:25:49 -0700 Subject: [PATCH 335/987] Removed builder arg parameter from IStartupFilter - It broke the composition model by allowing you to reach out to the original app builder. This breaks the ability to properly wrap and have all configure methods see the wrapper. --- .../Internal/AutoRequestServicesStartupFilter.cs | 4 ++-- src/Microsoft.AspNet.Hosting/Internal/HostingEngine.cs | 2 +- src/Microsoft.AspNet.Hosting/Startup/IStartupFilter.cs | 3 +-- test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs | 4 ++-- 4 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/Microsoft.AspNet.Hosting/Internal/AutoRequestServicesStartupFilter.cs b/src/Microsoft.AspNet.Hosting/Internal/AutoRequestServicesStartupFilter.cs index 205440b5fe..2ae344670e 100644 --- a/src/Microsoft.AspNet.Hosting/Internal/AutoRequestServicesStartupFilter.cs +++ b/src/Microsoft.AspNet.Hosting/Internal/AutoRequestServicesStartupFilter.cs @@ -9,11 +9,11 @@ namespace Microsoft.AspNet.Hosting.Internal { public class AutoRequestServicesStartupFilter : IStartupFilter { - public Action Configure(IApplicationBuilder app, Action next) + public Action Configure(Action next) { return builder => { - app.UseMiddleware(); + builder.UseMiddleware(); next(builder); }; } diff --git a/src/Microsoft.AspNet.Hosting/Internal/HostingEngine.cs b/src/Microsoft.AspNet.Hosting/Internal/HostingEngine.cs index 04b77d4113..79aa7774dd 100644 --- a/src/Microsoft.AspNet.Hosting/Internal/HostingEngine.cs +++ b/src/Microsoft.AspNet.Hosting/Internal/HostingEngine.cs @@ -151,7 +151,7 @@ namespace Microsoft.AspNet.Hosting.Internal var configure = Startup.ConfigureDelegate; foreach (var filter in startupFilters) { - configure = filter.Configure(builder, configure); + configure = filter.Configure(configure); } configure(builder); diff --git a/src/Microsoft.AspNet.Hosting/Startup/IStartupFilter.cs b/src/Microsoft.AspNet.Hosting/Startup/IStartupFilter.cs index 437a841e89..79bf34401e 100644 --- a/src/Microsoft.AspNet.Hosting/Startup/IStartupFilter.cs +++ b/src/Microsoft.AspNet.Hosting/Startup/IStartupFilter.cs @@ -8,7 +8,6 @@ namespace Microsoft.AspNet.Hosting.Startup { public interface IStartupFilter { - // TODO: replace with ConfigureDelegate? - Action Configure(IApplicationBuilder app, Action next); + Action Configure(Action next); } } diff --git a/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs b/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs index 94b9afce84..c4b486ca45 100644 --- a/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs +++ b/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs @@ -78,11 +78,11 @@ namespace Microsoft.AspNet.TestHost public class RequestServicesFilter : IStartupFilter { - public Action Configure(IApplicationBuilder app, Action next) + public Action Configure(Action next) { return builder => { - app.UseMiddleware(); + builder.UseMiddleware(); next(builder); }; } From 9dd9d39bff58b8124e7647facda55ff3b868aa35 Mon Sep 17 00:00:00 2001 From: Troy Dai Date: Mon, 17 Aug 2015 11:10:26 -0700 Subject: [PATCH 336/987] Update packages' versions --- src/Microsoft.AspNet.Server.Testing/project.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Microsoft.AspNet.Server.Testing/project.json b/src/Microsoft.AspNet.Server.Testing/project.json index 77260810ac..44cd34edf5 100644 --- a/src/Microsoft.AspNet.Server.Testing/project.json +++ b/src/Microsoft.AspNet.Server.Testing/project.json @@ -23,7 +23,7 @@ "dnxcore50": { "dependencies": { "System.Diagnostics.Process": "4.0.0-beta-*", - "System.IO.FileSystem": "4.0.0-*", + "System.IO.FileSystem": "4.0.1-beta-*", "System.Net.Http": "4.0.1-beta-*", "System.Net.Primitives": "4.0.11-beta-*", "System.Runtime.Extensions": "4.0.11-beta-*", From b6bb7a52a2accf7362280b3b3a3444c1591eab80 Mon Sep 17 00:00:00 2001 From: Pranav K Date: Mon, 17 Aug 2015 14:48:25 -0700 Subject: [PATCH 337/987] Updating to release NuGet.config. --- NuGet.Config | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/NuGet.Config b/NuGet.Config index da57d47267..3b8d545754 100644 --- a/NuGet.Config +++ b/NuGet.Config @@ -1,7 +1,7 @@ - + - + \ No newline at end of file From a9fe23a2c66fa8e276b448cd73d77f18b58d0873 Mon Sep 17 00:00:00 2001 From: Pranav K Date: Tue, 18 Aug 2015 14:00:20 -0700 Subject: [PATCH 338/987] Updating to aspnetliterelease. --- NuGet.Config | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NuGet.Config b/NuGet.Config index 3b8d545754..e2378fe359 100644 --- a/NuGet.Config +++ b/NuGet.Config @@ -1,7 +1,7 @@ - + \ No newline at end of file From 3480d53e1cb3d67e137fee086fce9b41027dfc59 Mon Sep 17 00:00:00 2001 From: Pranav K Date: Tue, 18 Aug 2015 14:00:21 -0700 Subject: [PATCH 339/987] Updating to aspnetlitedev. --- NuGet.Config | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/NuGet.Config b/NuGet.Config index da57d47267..6685c5330a 100644 --- a/NuGet.Config +++ b/NuGet.Config @@ -1,7 +1,7 @@ - + - + \ No newline at end of file From b590c0c7a2c91ed545312831d2c4b81a71b07f91 Mon Sep 17 00:00:00 2001 From: "N. Taylor Mullen" Date: Wed, 19 Aug 2015 14:53:35 -0700 Subject: [PATCH 340/987] Update NuGet feed from v2 => v3. --- NuGet.Config | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NuGet.Config b/NuGet.Config index 6685c5330a..10cec18a32 100644 --- a/NuGet.Config +++ b/NuGet.Config @@ -2,6 +2,6 @@ - + \ No newline at end of file From d733f17fbde0904214710c01a6d0fbf0ef38a6df Mon Sep 17 00:00:00 2001 From: "N. Taylor Mullen" Date: Thu, 20 Aug 2015 15:37:33 -0700 Subject: [PATCH 341/987] Update 'build.cmd' to pull Sake from v2 NuGet feed. --- build.cmd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.cmd b/build.cmd index ccf195aee8..b54d91cf74 100644 --- a/build.cmd +++ b/build.cmd @@ -23,7 +23,7 @@ IF %BUILDCMD_KOREBUILD_VERSION%=="" ( ) ELSE ( .nuget\NuGet.exe install KoreBuild -version %BUILDCMD_KOREBUILD_VERSION% -ExcludeVersion -o packages -nocache -pre ) -.nuget\NuGet.exe install Sake -version 0.2 -o packages -ExcludeVersion +.nuget\NuGet.exe install Sake -ExcludeVersion -Source https://www.nuget.org/api/v2/ -Out packages IF "%SKIP_DNX_INSTALL%"=="1" goto run IF %BUILDCMD_DNX_VERSION%=="" ( From 7f5045d62f7b39a23199336c879cc197e70d0bd9 Mon Sep 17 00:00:00 2001 From: "N. Taylor Mullen" Date: Thu, 20 Aug 2015 20:46:27 -0700 Subject: [PATCH 342/987] Update 'build.sh' to pull Sake from v2 NuGet feed. --- build.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.sh b/build.sh index 3ef874f9bd..68c3e8cb52 100755 --- a/build.sh +++ b/build.sh @@ -24,7 +24,7 @@ fi if test ! -d packages/KoreBuild; then mono .nuget/nuget.exe install KoreBuild -ExcludeVersion -o packages -nocache -pre - mono .nuget/nuget.exe install Sake -version 0.2 -o packages -ExcludeVersion + mono .nuget/nuget.exe install Sake -ExcludeVersion -Source https://www.nuget.org/api/v2/ -Out packages fi if ! type dnvm > /dev/null 2>&1; then From 55b28abeab524c39bacc1a0e0717d5126ec3a6a7 Mon Sep 17 00:00:00 2001 From: Hao Kung Date: Tue, 25 Aug 2015 12:23:56 -0700 Subject: [PATCH 343/987] Explicitly set ApplicationServices for HttpContext --- .../Internal/HostingEngine.cs | 1 + .../Fakes/Startup.cs | 1 - .../TestServerTests.cs | 52 ++++++++++++++++++- 3 files changed, 52 insertions(+), 2 deletions(-) diff --git a/src/Microsoft.AspNet.Hosting/Internal/HostingEngine.cs b/src/Microsoft.AspNet.Hosting/Internal/HostingEngine.cs index 79aa7774dd..90139ad93e 100644 --- a/src/Microsoft.AspNet.Hosting/Internal/HostingEngine.cs +++ b/src/Microsoft.AspNet.Hosting/Internal/HostingEngine.cs @@ -71,6 +71,7 @@ namespace Microsoft.AspNet.Hosting.Internal async features => { var httpContext = contextFactory.CreateHttpContext(features); + httpContext.ApplicationServices = _applicationServices; var requestIdentifier = GetRequestIdentifier(httpContext); using (logger.BeginScope("Request Id: {RequestId}", requestIdentifier)) diff --git a/test/Microsoft.AspNet.Hosting.Tests/Fakes/Startup.cs b/test/Microsoft.AspNet.Hosting.Tests/Fakes/Startup.cs index 87950f61dc..700fbf6d7e 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/Fakes/Startup.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/Fakes/Startup.cs @@ -3,7 +3,6 @@ using Microsoft.AspNet.Builder; using Microsoft.Framework.DependencyInjection; -using Microsoft.Framework.OptionsModel; using System; namespace Microsoft.AspNet.Hosting.Fakes diff --git a/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs b/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs index c4b486ca45..564b29ab91 100644 --- a/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs +++ b/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs @@ -43,7 +43,7 @@ namespace Microsoft.AspNet.TestHost [Fact] public async Task RequestServicesAutoCreated() { - TestServer server = TestServer.Create(app => + var server = TestServer.Create(app => { app.Run(context => { @@ -55,6 +55,33 @@ namespace Microsoft.AspNet.TestHost Assert.Equal("RequestServices:True", result); } + public class CustomContainerStartup + { + public IServiceProvider Services; + public IServiceProvider ConfigureServices(IServiceCollection services) + { + Services = services.BuildServiceProvider(); + return Services; + } + + public void Configure(IApplicationBuilder app) + { + app.Run(async context => + { + await context.Response.WriteAsync("ApplicationServicesEqual:" + (context.ApplicationServices == Services)); + }); + } + + } + + [Fact] + public async Task CustomServiceProviderReplacesApplicationServices() + { + var server = new TestServer(TestServer.CreateBuilder().UseStartup()); + string result = await server.CreateClient().GetStringAsync("/path"); + Assert.Equal("ApplicationServicesEqual:True", result); + } + public class TestService { } public class TestRequestServiceMiddleware @@ -104,6 +131,29 @@ namespace Microsoft.AspNet.TestHost Assert.Equal("Found:True", result); } + public class EnsureApplicationServicesFilter : IStartupFilter + { + public Action Configure(IApplicationBuilder app, Action next) + { + return builder => + { + app.Run(context => { + Assert.NotNull(context.ApplicationServices); + return context.Response.WriteAsync("Done"); + }); + }; + } + } + + [Fact] + public async Task ApplicationServicesShouldSetBeforeStatupFilters() + { + var server = TestServer.Create(app => { }, + services => services.AddTransient()); + string result = await server.CreateClient().GetStringAsync("/path"); + Assert.Equal("Done", result); + } + [Fact] public async Task CanAccessLogger() From 28268ee64b1e9edc9078345d453bb3120a812a19 Mon Sep 17 00:00:00 2001 From: Chris R Date: Fri, 28 Aug 2015 09:57:11 -0700 Subject: [PATCH 344/987] Fix IStartupFilter complier break in ApplicationServices test. --- test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs b/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs index 564b29ab91..47277d7286 100644 --- a/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs +++ b/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs @@ -133,11 +133,11 @@ namespace Microsoft.AspNet.TestHost public class EnsureApplicationServicesFilter : IStartupFilter { - public Action Configure(IApplicationBuilder app, Action next) + public Action Configure(Action next) { return builder => { - app.Run(context => { + builder.Run(context => { Assert.NotNull(context.ApplicationServices); return context.Response.WriteAsync("Done"); }); From d448c6e389e4c11aefd572ec0dd693986fab2703 Mon Sep 17 00:00:00 2001 From: Chris R Date: Fri, 28 Aug 2015 12:27:17 -0700 Subject: [PATCH 345/987] React to string[] -> StringValues changes. --- src/Microsoft.AspNet.TestHost/ClientHandler.cs | 9 +++++---- src/Microsoft.AspNet.TestHost/RequestFeature.cs | 5 +++-- src/Microsoft.AspNet.TestHost/ResponseFeature.cs | 5 +++-- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/Microsoft.AspNet.TestHost/ClientHandler.cs b/src/Microsoft.AspNet.TestHost/ClientHandler.cs index a5f61bd4f9..df72462e24 100644 --- a/src/Microsoft.AspNet.TestHost/ClientHandler.cs +++ b/src/Microsoft.AspNet.TestHost/ClientHandler.cs @@ -2,6 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; using System.Diagnostics.Contracts; using System.IO; @@ -135,14 +136,14 @@ namespace Microsoft.AspNet.TestHost foreach (var header in request.Headers) { - serverRequest.Headers.AppendValues(header.Key, header.Value.ToArray()); + serverRequest.Headers.Append(header.Key, header.Value.ToArray()); } var requestContent = request.Content; if (requestContent != null) { foreach (var header in request.Content.Headers) { - serverRequest.Headers.AppendValues(header.Key, header.Value.ToArray()); + serverRequest.Headers.Append(header.Key, header.Value.ToArray()); } } @@ -187,9 +188,9 @@ namespace Microsoft.AspNet.TestHost foreach (var header in HttpContext.Response.Headers) { - if (!response.Headers.TryAddWithoutValidation(header.Key, header.Value)) + if (!response.Headers.TryAddWithoutValidation(header.Key, (IEnumerable)header.Value)) { - bool success = response.Content.Headers.TryAddWithoutValidation(header.Key, header.Value); + bool success = response.Content.Headers.TryAddWithoutValidation(header.Key, (IEnumerable)header.Value); Contract.Assert(success, "Bad header"); } } diff --git a/src/Microsoft.AspNet.TestHost/RequestFeature.cs b/src/Microsoft.AspNet.TestHost/RequestFeature.cs index eebdd28372..b55b02b6ff 100644 --- a/src/Microsoft.AspNet.TestHost/RequestFeature.cs +++ b/src/Microsoft.AspNet.TestHost/RequestFeature.cs @@ -5,6 +5,7 @@ using System; using System.Collections.Generic; using System.IO; using Microsoft.AspNet.Http.Features; +using Microsoft.Framework.Primitives; namespace Microsoft.AspNet.TestHost { @@ -13,7 +14,7 @@ namespace Microsoft.AspNet.TestHost public RequestFeature() { Body = Stream.Null; - Headers = new Dictionary(StringComparer.OrdinalIgnoreCase); + Headers = new Dictionary(StringComparer.OrdinalIgnoreCase); Method = "GET"; Path = ""; PathBase = ""; @@ -24,7 +25,7 @@ namespace Microsoft.AspNet.TestHost public Stream Body { get; set; } - public IDictionary Headers { get; set; } + public IDictionary Headers { get; set; } public string Method { get; set; } diff --git a/src/Microsoft.AspNet.TestHost/ResponseFeature.cs b/src/Microsoft.AspNet.TestHost/ResponseFeature.cs index 25d9b3260d..2f699e572d 100644 --- a/src/Microsoft.AspNet.TestHost/ResponseFeature.cs +++ b/src/Microsoft.AspNet.TestHost/ResponseFeature.cs @@ -6,6 +6,7 @@ using System.Collections.Generic; using System.IO; using System.Threading.Tasks; using Microsoft.AspNet.Http.Features; +using Microsoft.Framework.Primitives; namespace Microsoft.AspNet.TestHost { @@ -16,7 +17,7 @@ namespace Microsoft.AspNet.TestHost public ResponseFeature() { - Headers = new Dictionary(StringComparer.OrdinalIgnoreCase); + Headers = new Dictionary(StringComparer.OrdinalIgnoreCase); Body = new MemoryStream(); // 200 is the default status code all the way down to the host, so we set it @@ -28,7 +29,7 @@ namespace Microsoft.AspNet.TestHost public string ReasonPhrase { get; set; } - public IDictionary Headers { get; set; } + public IDictionary Headers { get; set; } public Stream Body { get; set; } From adae42b66f82a782ee51a8b4c80403248ae871e4 Mon Sep 17 00:00:00 2001 From: Chris R Date: Mon, 31 Aug 2015 07:22:34 -0700 Subject: [PATCH 346/987] Use new HttpContext.Features API. --- .../Internal/HostingEngine.cs | 4 ++-- src/Microsoft.AspNet.TestHost/ClientHandler.cs | 13 +++++-------- .../HostingEngineTests.cs | 6 +++--- .../HttpContextFactoryFacts.cs | 5 +++-- .../ClientHandlerTests.cs | 2 +- 5 files changed, 14 insertions(+), 16 deletions(-) diff --git a/src/Microsoft.AspNet.Hosting/Internal/HostingEngine.cs b/src/Microsoft.AspNet.Hosting/Internal/HostingEngine.cs index 90139ad93e..4af23ea665 100644 --- a/src/Microsoft.AspNet.Hosting/Internal/HostingEngine.cs +++ b/src/Microsoft.AspNet.Hosting/Internal/HostingEngine.cs @@ -162,14 +162,14 @@ namespace Microsoft.AspNet.Hosting.Internal private string GetRequestIdentifier(HttpContext httpContext) { - var requestIdentifierFeature = httpContext.GetFeature(); + var requestIdentifierFeature = httpContext.Features.Get(); if (requestIdentifierFeature == null) { requestIdentifierFeature = new HttpRequestIdentifierFeature() { TraceIdentifier = Guid.NewGuid().ToString() }; - httpContext.SetFeature(requestIdentifierFeature); + httpContext.Features.Set(requestIdentifierFeature); } return requestIdentifierFeature.TraceIdentifier; diff --git a/src/Microsoft.AspNet.TestHost/ClientHandler.cs b/src/Microsoft.AspNet.TestHost/ClientHandler.cs index df72462e24..23308d5161 100644 --- a/src/Microsoft.AspNet.TestHost/ClientHandler.cs +++ b/src/Microsoft.AspNet.TestHost/ClientHandler.cs @@ -70,7 +70,7 @@ namespace Microsoft.AspNet.TestHost { try { - await _next(state.FeatureCollection); + await _next(state.HttpContext.Features); state.CompleteResponse(); } catch (Exception ex) @@ -108,11 +108,10 @@ namespace Microsoft.AspNet.TestHost request.Headers.Host = request.RequestUri.GetComponents(UriComponents.HostAndPort, UriFormat.UriEscaped); } - FeatureCollection = new FeatureCollection(); - HttpContext = new DefaultHttpContext(FeatureCollection); - HttpContext.SetFeature(new RequestFeature()); + HttpContext = new DefaultHttpContext(); + HttpContext.Features.Set(new RequestFeature()); _responseFeature = new ResponseFeature(); - HttpContext.SetFeature(_responseFeature); + HttpContext.Features.Set(_responseFeature); var serverRequest = HttpContext.Request; serverRequest.Protocol = "HTTP/" + request.Version.ToString(2); serverRequest.Scheme = request.RequestUri.Scheme; @@ -154,8 +153,6 @@ namespace Microsoft.AspNet.TestHost public HttpContext HttpContext { get; private set; } - public IFeatureCollection FeatureCollection { get; private set; } - public Task ResponseTask { get { return _responseTcs.Task; } @@ -180,7 +177,7 @@ namespace Microsoft.AspNet.TestHost var response = new HttpResponseMessage(); response.StatusCode = (HttpStatusCode)HttpContext.Response.StatusCode; - response.ReasonPhrase = HttpContext.GetFeature().ReasonPhrase; + response.ReasonPhrase = HttpContext.Features.Get().ReasonPhrase; response.RequestMessage = _request; // response.Version = owinResponse.Protocol; diff --git a/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs b/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs index 1642ec7235..a33e7367aa 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs @@ -241,7 +241,7 @@ namespace Microsoft.AspNet.Hosting // Assert Assert.NotNull(httpContext); - Assert.IsType(httpContext.GetFeature()); + Assert.IsType(httpContext.Features.Get()); } [Fact] @@ -264,7 +264,7 @@ namespace Microsoft.AspNet.Hosting // Assert Assert.NotNull(httpContext); - Assert.IsType(httpContext.GetFeature()); + Assert.IsType(httpContext.Features.Get()); } [Fact] @@ -286,7 +286,7 @@ namespace Microsoft.AspNet.Hosting // Assert Assert.NotNull(httpContext); - Assert.Same(requestIdentifierFeature, httpContext.GetFeature()); + Assert.Same(requestIdentifierFeature, httpContext.Features.Get()); } [Fact] diff --git a/test/Microsoft.AspNet.Hosting.Tests/HttpContextFactoryFacts.cs b/test/Microsoft.AspNet.Hosting.Tests/HttpContextFactoryFacts.cs index 2188bfbb7c..302da49712 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/HttpContextFactoryFacts.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/HttpContextFactoryFacts.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using Microsoft.AspNet.Hosting.Builder; +using Microsoft.AspNet.Http.Features; using Microsoft.AspNet.Owin; using Xunit; @@ -18,8 +19,8 @@ namespace Microsoft.AspNet.Hosting.Tests var context = contextFactory.CreateHttpContext(new OwinFeatureCollection(env)); // Setting a feature will throw if the above feature collection is not wrapped in a mutable feature collection. - context.SetFeature(new CustomFeature(100)); - Assert.Equal(100, context.GetFeature().Value); + context.Features.Set(new CustomFeature(100)); + Assert.Equal(100, context.Features.Get().Value); } private interface ICustomFeature diff --git a/test/Microsoft.AspNet.TestHost.Tests/ClientHandlerTests.cs b/test/Microsoft.AspNet.TestHost.Tests/ClientHandlerTests.cs index c52b38dc28..d4092e5ea2 100644 --- a/test/Microsoft.AspNet.TestHost.Tests/ClientHandlerTests.cs +++ b/test/Microsoft.AspNet.TestHost.Tests/ClientHandlerTests.cs @@ -36,7 +36,7 @@ namespace Microsoft.AspNet.TestHost Assert.NotNull(context.Response.Headers); Assert.NotNull(context.Response.Body); Assert.Equal(200, context.Response.StatusCode); - Assert.Null(context.GetFeature().ReasonPhrase); + Assert.Null(context.Features.Get().ReasonPhrase); Assert.Equal("example.com", context.Request.Host.Value); return Task.FromResult(0); From 25b5a42ca61477df3ea9bf44e639db54a17e31c1 Mon Sep 17 00:00:00 2001 From: Chris R Date: Mon, 31 Aug 2015 11:24:13 -0700 Subject: [PATCH 347/987] #329 Change IServerInformation to IFeatureCollection. --- .../IServerFactory.cs | 4 ++-- .../IServerInformation.cs | 10 ---------- .../Internal/HostingEngine.cs | 2 +- src/Microsoft.AspNet.TestHost/TestServer.cs | 19 +++---------------- .../HostingEngineTests.cs | 4 ++-- 5 files changed, 8 insertions(+), 31 deletions(-) delete mode 100644 src/Microsoft.AspNet.Hosting.Server.Abstractions/IServerInformation.cs diff --git a/src/Microsoft.AspNet.Hosting.Server.Abstractions/IServerFactory.cs b/src/Microsoft.AspNet.Hosting.Server.Abstractions/IServerFactory.cs index 09c696b8c8..ff188af7d1 100644 --- a/src/Microsoft.AspNet.Hosting.Server.Abstractions/IServerFactory.cs +++ b/src/Microsoft.AspNet.Hosting.Server.Abstractions/IServerFactory.cs @@ -10,7 +10,7 @@ namespace Microsoft.AspNet.Hosting.Server { public interface IServerFactory { - IServerInformation Initialize(IConfiguration configuration); - IDisposable Start(IServerInformation serverInformation, Func application); + IFeatureCollection Initialize(IConfiguration configuration); + IDisposable Start(IFeatureCollection serverFeatures, Func application); } } diff --git a/src/Microsoft.AspNet.Hosting.Server.Abstractions/IServerInformation.cs b/src/Microsoft.AspNet.Hosting.Server.Abstractions/IServerInformation.cs deleted file mode 100644 index 2e3af1e7a2..0000000000 --- a/src/Microsoft.AspNet.Hosting.Server.Abstractions/IServerInformation.cs +++ /dev/null @@ -1,10 +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. - -namespace Microsoft.AspNet.Hosting.Server -{ - public interface IServerInformation - { - string Name { get; } - } -} diff --git a/src/Microsoft.AspNet.Hosting/Internal/HostingEngine.cs b/src/Microsoft.AspNet.Hosting/Internal/HostingEngine.cs index 4af23ea665..d072b36285 100644 --- a/src/Microsoft.AspNet.Hosting/Internal/HostingEngine.cs +++ b/src/Microsoft.AspNet.Hosting/Internal/HostingEngine.cs @@ -36,7 +36,7 @@ namespace Microsoft.AspNet.Hosting.Internal // Only one of these should be set internal IServerFactory ServerFactory { get; set; } internal string ServerFactoryLocation { get; set; } - private IServerInformation _serverInstance; + private IFeatureCollection _serverInstance; public HostingEngine( [NotNull] IServiceCollection appServices, diff --git a/src/Microsoft.AspNet.TestHost/TestServer.cs b/src/Microsoft.AspNet.TestHost/TestServer.cs index 571ceb2662..80efe05f7e 100644 --- a/src/Microsoft.AspNet.TestHost/TestServer.cs +++ b/src/Microsoft.AspNet.TestHost/TestServer.cs @@ -19,7 +19,7 @@ namespace Microsoft.AspNet.TestHost { private const string DefaultEnvironmentName = "Development"; private const string ServerName = nameof(TestServer); - private static readonly ServerInformation ServerInfo = new ServerInformation(); + private static readonly IFeatureCollection ServerInfo = new FeatureCollection(); private Func _appDelegate; private IDisposable _appInstance; private bool _disposed = false; @@ -107,18 +107,13 @@ namespace Microsoft.AspNet.TestHost return new RequestBuilder(this, path); } - public IServerInformation Initialize(IConfiguration configuration) + public IFeatureCollection Initialize(IConfiguration configuration) { return ServerInfo; } - public IDisposable Start(IServerInformation serverInformation, Func application) + public IDisposable Start(IFeatureCollection serverInformation, Func application) { - if (!(serverInformation.GetType() == typeof(ServerInformation))) - { - throw new ArgumentException(string.Format("The server must be {0}", ServerName), "serverInformation"); - } - _appDelegate = application; return this; @@ -138,13 +133,5 @@ namespace Microsoft.AspNet.TestHost _disposed = true; _appInstance.Dispose(); } - - private class ServerInformation : IServerInformation - { - public string Name - { - get { return ServerName; } - } - } } } \ No newline at end of file diff --git a/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs b/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs index a33e7367aa..5b9c50ba9a 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs @@ -368,12 +368,12 @@ namespace Microsoft.AspNet.Hosting config ?? new ConfigurationBuilder().Build()); } - public IServerInformation Initialize(IConfiguration configuration) + public IFeatureCollection Initialize(IConfiguration configuration) { return null; } - public IDisposable Start(IServerInformation serverInformation, Func application) + public IDisposable Start(IFeatureCollection serverFeatures, Func application) { var startInstance = new StartInstance(application); _startInstances.Add(startInstance); From 2ee7384400ea434883754edcfc67a081190eae02 Mon Sep 17 00:00:00 2001 From: Master T Date: Sat, 22 Aug 2015 13:44:27 +0200 Subject: [PATCH 348/987] TestHost: Add WebSocket support. --- .../ClientHandler.cs | 30 +- src/Microsoft.AspNet.TestHost/TestServer.cs | 6 + .../TestWebSocket.cs | 354 ++++++++++++++++++ .../WebSocketClient.cs | 179 +++++++++ .../TestClientTests.cs | 134 +++++++ 5 files changed, 688 insertions(+), 15 deletions(-) create mode 100644 src/Microsoft.AspNet.TestHost/TestWebSocket.cs create mode 100644 src/Microsoft.AspNet.TestHost/WebSocketClient.cs diff --git a/src/Microsoft.AspNet.TestHost/ClientHandler.cs b/src/Microsoft.AspNet.TestHost/ClientHandler.cs index 23308d5161..970c232afe 100644 --- a/src/Microsoft.AspNet.TestHost/ClientHandler.cs +++ b/src/Microsoft.AspNet.TestHost/ClientHandler.cs @@ -67,22 +67,22 @@ namespace Microsoft.AspNet.TestHost // Async offload, don't let the test code block the caller. var offload = Task.Factory.StartNew(async () => + { + try { - try - { - await _next(state.HttpContext.Features); - state.CompleteResponse(); - } - catch (Exception ex) - { - state.Abort(ex); - } - finally - { - registration.Dispose(); - state.Dispose(); - } - }); + await _next(state.HttpContext.Features); + state.CompleteResponse(); + } + catch (Exception ex) + { + state.Abort(ex); + } + finally + { + registration.Dispose(); + state.Dispose(); + } + }); return await state.ResponseTask; } diff --git a/src/Microsoft.AspNet.TestHost/TestServer.cs b/src/Microsoft.AspNet.TestHost/TestServer.cs index 80efe05f7e..3a6522c476 100644 --- a/src/Microsoft.AspNet.TestHost/TestServer.cs +++ b/src/Microsoft.AspNet.TestHost/TestServer.cs @@ -97,6 +97,12 @@ namespace Microsoft.AspNet.TestHost return new HttpClient(CreateHandler()) { BaseAddress = BaseAddress }; } + public WebSocketClient CreateWebSocketClient() + { + var pathBase = BaseAddress == null ? PathString.Empty : PathString.FromUriComponent(BaseAddress); + return new WebSocketClient(Invoke, pathBase); + } + /// /// Begins constructing a request message for submission. /// diff --git a/src/Microsoft.AspNet.TestHost/TestWebSocket.cs b/src/Microsoft.AspNet.TestHost/TestWebSocket.cs new file mode 100644 index 0000000000..f028d8f053 --- /dev/null +++ b/src/Microsoft.AspNet.TestHost/TestWebSocket.cs @@ -0,0 +1,354 @@ +// 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; +using System.Collections.Generic; +using System.IO; +using System.Net.WebSockets; +using System.Threading; +using System.Threading.Tasks; + +namespace Microsoft.AspNet.TestHost +{ + internal class TestWebSocket : WebSocket + { + private ReceiverSenderBuffer _receiveBuffer; + private ReceiverSenderBuffer _sendBuffer; + private readonly string _subProtocol; + private WebSocketState _state; + private WebSocketCloseStatus? _closeStatus; + private string _closeStatusDescription; + private Message _receiveMessage; + + public static Tuple CreatePair(string subProtocol) + { + var buffers = new[] { new ReceiverSenderBuffer(), new ReceiverSenderBuffer() }; + return Tuple.Create( + new TestWebSocket(subProtocol, buffers[0], buffers[1]), + new TestWebSocket(subProtocol, buffers[1], buffers[0])); + } + + public override WebSocketCloseStatus? CloseStatus + { + get { return _closeStatus; } + } + + public override string CloseStatusDescription + { + get { return _closeStatusDescription; } + } + + public override WebSocketState State + { + get { return _state; } + } + + public override string SubProtocol + { + get { return _subProtocol; } + } + + public async override Task CloseAsync(WebSocketCloseStatus closeStatus, string statusDescription, CancellationToken cancellationToken) + { + ThrowIfDisposed(); + + if (State == WebSocketState.Open || State == WebSocketState.CloseReceived) + { + // Send a close message. + await CloseOutputAsync(closeStatus, statusDescription, cancellationToken); + } + + if (State == WebSocketState.CloseSent) + { + // Do a receiving drain + var data = new byte[1024]; + WebSocketReceiveResult result; + do + { + result = await ReceiveAsync(new ArraySegment(data), cancellationToken); + } + while (result.MessageType != WebSocketMessageType.Close); + } + } + + public async override Task CloseOutputAsync(WebSocketCloseStatus closeStatus, string statusDescription, CancellationToken cancellationToken) + { + ThrowIfDisposed(); + ThrowIfOutputClosed(); + + var message = new Message(closeStatus, statusDescription); + await _sendBuffer.SendAsync(message, cancellationToken); + + if (State == WebSocketState.Open) + { + _state = WebSocketState.CloseSent; + } + else if (State == WebSocketState.CloseReceived) + { + _state = WebSocketState.Closed; + Close(); + } + } + + public override void Abort() + { + if (_state >= WebSocketState.Closed) // or Aborted + { + return; + } + + _state = WebSocketState.Aborted; + Close(); + } + + public override void Dispose() + { + if (_state >= WebSocketState.Closed) // or Aborted + { + return; + } + + _state = WebSocketState.Closed; + Close(); + } + + public override async Task ReceiveAsync(ArraySegment buffer, CancellationToken cancellationToken) + { + ThrowIfDisposed(); + ThrowIfInputClosed(); + ValidateSegment(buffer); + // TODO: InvalidOperationException if any receives are currently in progress. + + Message receiveMessage = _receiveMessage; + _receiveMessage = null; + if (receiveMessage == null) + { + receiveMessage = await _receiveBuffer.ReceiveAsync(cancellationToken); + } + if (receiveMessage.MessageType == WebSocketMessageType.Close) + { + _closeStatus = receiveMessage.CloseStatus; + _closeStatusDescription = receiveMessage.CloseStatusDescription ?? string.Empty; + var result = new WebSocketReceiveResult(0, WebSocketMessageType.Close, true, _closeStatus, _closeStatusDescription); + if (_state == WebSocketState.Open) + { + _state = WebSocketState.CloseReceived; + } + else if (_state == WebSocketState.CloseSent) + { + _state = WebSocketState.Closed; + Close(); + } + return result; + } + else + { + int count = Math.Min(buffer.Count, receiveMessage.Buffer.Count); + bool endOfMessage = count == receiveMessage.Buffer.Count; + Array.Copy(receiveMessage.Buffer.Array, receiveMessage.Buffer.Offset, buffer.Array, buffer.Offset, count); + if (!endOfMessage) + { + receiveMessage.Buffer = new ArraySegment(receiveMessage.Buffer.Array, receiveMessage.Buffer.Offset + count, receiveMessage.Buffer.Count - count); + _receiveMessage = receiveMessage; + } + endOfMessage = endOfMessage && receiveMessage.EndOfMessage; + return new WebSocketReceiveResult(count, receiveMessage.MessageType, endOfMessage); + } + } + + public override Task SendAsync(ArraySegment buffer, WebSocketMessageType messageType, bool endOfMessage, CancellationToken cancellationToken) + { + ValidateSegment(buffer); + if (messageType != WebSocketMessageType.Binary && messageType != WebSocketMessageType.Text) + { + // Block control frames + throw new ArgumentOutOfRangeException(nameof(messageType), messageType, string.Empty); + } + + var message = new Message(buffer, messageType, endOfMessage, cancellationToken); + return _sendBuffer.SendAsync(message, cancellationToken); + } + + private void Close() + { + _receiveBuffer.SetReceiverClosed(); + _sendBuffer.SetSenderClosed(); + } + + private void ThrowIfDisposed() + { + if (_state >= WebSocketState.Closed) // or Aborted + { + throw new ObjectDisposedException(typeof(TestWebSocket).FullName); + } + } + + private void ThrowIfOutputClosed() + { + if (State == WebSocketState.CloseSent) + { + throw new InvalidOperationException("Close already sent."); + } + } + + private void ThrowIfInputClosed() + { + if (State == WebSocketState.CloseReceived) + { + throw new InvalidOperationException("Close already received."); + } + } + + private void ValidateSegment(ArraySegment buffer) + { + if (buffer.Array == null) + { + throw new ArgumentNullException(nameof(buffer)); + } + if (buffer.Offset < 0 || buffer.Offset > buffer.Array.Length) + { + throw new ArgumentOutOfRangeException(nameof(buffer.Offset), buffer.Offset, string.Empty); + } + if (buffer.Count < 0 || buffer.Count > buffer.Array.Length - buffer.Offset) + { + throw new ArgumentOutOfRangeException(nameof(buffer.Count), buffer.Count, string.Empty); + } + } + + private TestWebSocket(string subProtocol, ReceiverSenderBuffer readBuffer, ReceiverSenderBuffer writeBuffer) + { + _state = WebSocketState.Open; + _subProtocol = subProtocol; + _receiveBuffer = readBuffer; + _sendBuffer = writeBuffer; + } + + private class Message + { + public Message(ArraySegment buffer, WebSocketMessageType messageType, bool endOfMessage, CancellationToken token) + { + Buffer = buffer; + CloseStatus = null; + CloseStatusDescription = null; + EndOfMessage = endOfMessage; + MessageType = messageType; + } + + public Message(WebSocketCloseStatus? closeStatus, string closeStatusDescription) + { + Buffer = new ArraySegment(new byte[0]); + CloseStatus = closeStatus; + CloseStatusDescription = closeStatusDescription; + MessageType = WebSocketMessageType.Close; + EndOfMessage = true; + } + + public WebSocketCloseStatus? CloseStatus { get; set; } + public string CloseStatusDescription { get; set; } + public ArraySegment Buffer { get; set; } + public bool EndOfMessage { get; set; } + public WebSocketMessageType MessageType { get; set; } + } + + private class ReceiverSenderBuffer + { + private bool _receiverClosed; + private bool _senderClosed; + private bool _disposed; + private SemaphoreSlim _sem; + private Queue _messageQueue; + + public ReceiverSenderBuffer() + { + _sem = new SemaphoreSlim(0); + _messageQueue = new Queue(); + } + + public async virtual Task ReceiveAsync(CancellationToken cancellationToken) + { + if (_disposed) + { + ThrowNoReceive(); + } + await _sem.WaitAsync(cancellationToken); + lock (_messageQueue) + { + if (_messageQueue.Count == 0) + { + _disposed = true; + _sem.Dispose(); + ThrowNoReceive(); + } + return _messageQueue.Dequeue(); + } + } + + public virtual Task SendAsync(Message message, CancellationToken cancellationToken) + { + lock (_messageQueue) + { + if (_senderClosed) + { + throw new ObjectDisposedException(typeof(TestWebSocket).FullName); + } + if (_receiverClosed) + { + throw new IOException("The remote end closed the connection.", new ObjectDisposedException(typeof(TestWebSocket).FullName)); + } + + // we return immediately so we need to copy the buffer since the sender can re-use it + var array = new byte[message.Buffer.Count]; + Array.Copy(message.Buffer.Array, message.Buffer.Offset, array, 0, message.Buffer.Count); + message.Buffer = new ArraySegment(array); + + _messageQueue.Enqueue(message); + _sem.Release(); + + return Task.FromResult(true); + } + } + + public void SetReceiverClosed() + { + lock (_messageQueue) + { + if (!_receiverClosed) + { + _receiverClosed = true; + if (!_disposed) + { + _sem.Release(); + } + } + } + } + + public void SetSenderClosed() + { + lock (_messageQueue) + { + if (!_senderClosed) + { + _senderClosed = true; + if (!_disposed) + { + _sem.Release(); + } + } + } + } + + private void ThrowNoReceive() + { + if (_receiverClosed) + { + throw new ObjectDisposedException(typeof(TestWebSocket).FullName); + } + else // _senderClosed + { + throw new IOException("The remote end closed the connection.", new ObjectDisposedException(typeof(TestWebSocket).FullName)); + } + } + } + } +} diff --git a/src/Microsoft.AspNet.TestHost/WebSocketClient.cs b/src/Microsoft.AspNet.TestHost/WebSocketClient.cs new file mode 100644 index 0000000000..0c0f958fa0 --- /dev/null +++ b/src/Microsoft.AspNet.TestHost/WebSocketClient.cs @@ -0,0 +1,179 @@ +// 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; +using System.Collections.Generic; +using System.IO; +using System.Net.WebSockets; +using System.Security.Cryptography; +using System.Threading; +using System.Threading.Tasks; +using Microsoft.AspNet.Http.Features; +using Microsoft.AspNet.Http; +using Microsoft.AspNet.Http.Internal; +using Microsoft.Framework.Internal; + +namespace Microsoft.AspNet.TestHost +{ + public class WebSocketClient + { + private readonly Func _next; + private readonly PathString _pathBase; + + internal WebSocketClient([NotNull] Func next, PathString pathBase) + { + _next = next; + + // PathString.StartsWithSegments that we use below requires the base path to not end in a slash. + if (pathBase.HasValue && pathBase.Value.EndsWith("/")) + { + pathBase = new PathString(pathBase.Value.Substring(0, pathBase.Value.Length - 1)); + } + _pathBase = pathBase; + + SubProtocols = new List(); + } + + public IList SubProtocols + { + get; + private set; + } + + public Action ConfigureRequest + { + get; + set; + } + + public async Task ConnectAsync(Uri uri, CancellationToken cancellationToken) + { + var state = new RequestState(uri, _pathBase, cancellationToken); + + if (ConfigureRequest != null) + { + ConfigureRequest(state.HttpContext.Request); + } + + // Async offload, don't let the test code block the caller. + var offload = Task.Factory.StartNew(async () => + { + try + { + await _next(state.FeatureCollection); + state.PipelineComplete(); + } + catch (Exception ex) + { + state.PipelineFailed(ex); + } + finally + { + state.Dispose(); + } + }); + + return await state.WebSocketTask; + } + + private class RequestState : IDisposable, IHttpWebSocketFeature + { + private TaskCompletionSource _clientWebSocketTcs; + private WebSocket _serverWebSocket; + + public IFeatureCollection FeatureCollection { get; private set; } + public HttpContext HttpContext { get; private set; } + public Task WebSocketTask { get { return _clientWebSocketTcs.Task; } } + + public RequestState(Uri uri, PathString pathBase, CancellationToken cancellationToken) + { + _clientWebSocketTcs = new TaskCompletionSource(); + + // HttpContext + FeatureCollection = new FeatureCollection(); + HttpContext = new DefaultHttpContext(FeatureCollection); + + // Request + HttpContext.SetFeature(new RequestFeature()); + var request = HttpContext.Request; + request.Protocol = "HTTP/1.1"; + var scheme = uri.Scheme; + scheme = (scheme == "ws") ? "http" : scheme; + scheme = (scheme == "wss") ? "https" : scheme; + request.Scheme = scheme; + request.Method = "GET"; + var fullPath = PathString.FromUriComponent(uri); + PathString remainder; + if (fullPath.StartsWithSegments(pathBase, out remainder)) + { + request.PathBase = pathBase; + request.Path = remainder; + } + else + { + request.PathBase = PathString.Empty; + request.Path = fullPath; + } + request.QueryString = QueryString.FromUriComponent(uri); + request.Headers.Add("Connection", new string[] { "Upgrade" }); + request.Headers.Add("Upgrade", new string[] { "websocket" }); + request.Headers.Add("Sec-WebSocket-Version", new string[] { "13" }); + request.Headers.Add("Sec-WebSocket-Key", new string[] { CreateRequestKey() }); + request.Body = Stream.Null; + + // Response + HttpContext.SetFeature(new ResponseFeature()); + var response = HttpContext.Response; + response.Body = Stream.Null; + response.StatusCode = 200; + + // WebSocket + HttpContext.SetFeature(this); + } + + public void PipelineComplete() + { + PipelineFailed(new InvalidOperationException("Incomplete handshake, status code: " + HttpContext.Response.StatusCode)); + } + + public void PipelineFailed(Exception ex) + { + _clientWebSocketTcs.TrySetException(new InvalidOperationException("The websocket was not accepted.", ex)); + } + + public void Dispose() + { + if (_serverWebSocket != null) + { + _serverWebSocket.Dispose(); + } + } + + private string CreateRequestKey() + { + byte[] data = new byte[16]; + var rng = RandomNumberGenerator.Create(); + rng.GetBytes(data); + return Convert.ToBase64String(data); + } + + bool IHttpWebSocketFeature.IsWebSocketRequest + { + get + { + return true; + } + } + + Task IHttpWebSocketFeature.AcceptAsync(WebSocketAcceptContext context) + { + HttpContext.Response.StatusCode = 101; // Switching Protocols + + var websockets = TestWebSocket.CreatePair(context.SubProtocol); + _clientWebSocketTcs.SetResult(websockets.Item1); + _serverWebSocket = websockets.Item2; + return Task.FromResult(_serverWebSocket); + } + } + } +} \ No newline at end of file diff --git a/test/Microsoft.AspNet.TestHost.Tests/TestClientTests.cs b/test/Microsoft.AspNet.TestHost.Tests/TestClientTests.cs index b77a681862..e207d499fc 100644 --- a/test/Microsoft.AspNet.TestHost.Tests/TestClientTests.cs +++ b/test/Microsoft.AspNet.TestHost.Tests/TestClientTests.cs @@ -2,7 +2,11 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.IO; +using System.Linq; using System.Net.Http; +using System.Net.WebSockets; +using System.Text; +using System.Threading; using System.Threading.Tasks; using Microsoft.AspNet.Builder; using Microsoft.AspNet.Http; @@ -111,5 +115,135 @@ namespace Microsoft.AspNet.TestHost // Assert Assert.Equal("Hello world POST Response", await response.Content.ReadAsStringAsync()); } + + [Fact] + public async Task WebSocketWorks() + { + // Arrange + RequestDelegate appDelegate = async ctx => + { + if (ctx.WebSockets.IsWebSocketRequest) + { + var websocket = await ctx.WebSockets.AcceptWebSocketAsync(); + var receiveArray = new byte[1024]; + while (true) + { + var receiveResult = await websocket.ReceiveAsync(new System.ArraySegment(receiveArray), CancellationToken.None); + if (receiveResult.MessageType == WebSocketMessageType.Close) + { + await websocket.CloseAsync(WebSocketCloseStatus.NormalClosure, "Normal Closure", CancellationToken.None); + break; + } + else + { + var sendBuffer = new System.ArraySegment(receiveArray, 0, receiveResult.Count); + await websocket.SendAsync(sendBuffer, receiveResult.MessageType, receiveResult.EndOfMessage, CancellationToken.None); + } + } + } + }; + var server = TestServer.Create(app => + { + app.Run(appDelegate); + }); + + // Act + var client = server.CreateWebSocketClient(); + var clientSocket = await client.ConnectAsync(new System.Uri("http://localhost"), CancellationToken.None); + var hello = Encoding.UTF8.GetBytes("hello"); + await clientSocket.SendAsync(new System.ArraySegment(hello), WebSocketMessageType.Text, true, CancellationToken.None); + var world = Encoding.UTF8.GetBytes("world!"); + await clientSocket.SendAsync(new System.ArraySegment(world), WebSocketMessageType.Binary, true, CancellationToken.None); + await clientSocket.CloseOutputAsync(WebSocketCloseStatus.NormalClosure, "Normal Closure", CancellationToken.None); + + // Assert + Assert.Equal(WebSocketState.CloseSent, clientSocket.State); + + var buffer = new byte[1024]; + var result = await clientSocket.ReceiveAsync(new System.ArraySegment(buffer), CancellationToken.None); + Assert.Equal(hello.Length, result.Count); + Assert.True(hello.SequenceEqual(buffer.Take(hello.Length))); + Assert.Equal(WebSocketMessageType.Text, result.MessageType); + + result = await clientSocket.ReceiveAsync(new System.ArraySegment(buffer), CancellationToken.None); + Assert.Equal(world.Length, result.Count); + Assert.True(world.SequenceEqual(buffer.Take(world.Length))); + Assert.Equal(WebSocketMessageType.Binary, result.MessageType); + + result = await clientSocket.ReceiveAsync(new System.ArraySegment(buffer), CancellationToken.None); + Assert.Equal(WebSocketMessageType.Close, result.MessageType); + Assert.Equal(WebSocketState.Closed, clientSocket.State); + + clientSocket.Dispose(); + } + + [Fact] + public async Task WebSocketDisposalThrowsOnPeer() + { + // Arrange + RequestDelegate appDelegate = async ctx => + { + if (ctx.WebSockets.IsWebSocketRequest) + { + var websocket = await ctx.WebSockets.AcceptWebSocketAsync(); + websocket.Dispose(); + } + }; + var server = TestServer.Create(app => + { + app.Run(appDelegate); + }); + + // Act + var client = server.CreateWebSocketClient(); + var clientSocket = await client.ConnectAsync(new System.Uri("http://localhost"), CancellationToken.None); + var buffer = new byte[1024]; + await Assert.ThrowsAsync(async () => await clientSocket.ReceiveAsync(new System.ArraySegment(buffer), CancellationToken.None)); + + clientSocket.Dispose(); + } + + [Fact] + public async Task WebSocketTinyReceiveGeneratesEndOfMessage() + { + // Arrange + RequestDelegate appDelegate = async ctx => + { + if (ctx.WebSockets.IsWebSocketRequest) + { + var websocket = await ctx.WebSockets.AcceptWebSocketAsync(); + var receiveArray = new byte[1024]; + while (true) + { + var receiveResult = await websocket.ReceiveAsync(new System.ArraySegment(receiveArray), CancellationToken.None); + var sendBuffer = new System.ArraySegment(receiveArray, 0, receiveResult.Count); + await websocket.SendAsync(sendBuffer, receiveResult.MessageType, receiveResult.EndOfMessage, CancellationToken.None); + } + } + }; + var server = TestServer.Create(app => + { + app.Run(appDelegate); + }); + + // Act + var client = server.CreateWebSocketClient(); + var clientSocket = await client.ConnectAsync(new System.Uri("http://localhost"), CancellationToken.None); + var hello = Encoding.UTF8.GetBytes("hello"); + await clientSocket.SendAsync(new System.ArraySegment(hello), WebSocketMessageType.Text, true, CancellationToken.None); + + // Assert + var buffer = new byte[1]; + for (int i = 0; i < hello.Length; i++) + { + bool last = i == (hello.Length - 1); + var result = await clientSocket.ReceiveAsync(new System.ArraySegment(buffer), CancellationToken.None); + Assert.Equal(buffer.Length, result.Count); + Assert.Equal(buffer[0], hello[i]); + Assert.Equal(last, result.EndOfMessage); + } + + clientSocket.Dispose(); + } } } From ee7825ecb803836e247567dfa8249abfb6f06e6b Mon Sep 17 00:00:00 2001 From: Chris R Date: Tue, 1 Sep 2015 16:05:37 -0700 Subject: [PATCH 349/987] React to HttpContext.Features API changes. --- src/Microsoft.AspNet.TestHost/WebSocketClient.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Microsoft.AspNet.TestHost/WebSocketClient.cs b/src/Microsoft.AspNet.TestHost/WebSocketClient.cs index 0c0f958fa0..1eaecbcb61 100644 --- a/src/Microsoft.AspNet.TestHost/WebSocketClient.cs +++ b/src/Microsoft.AspNet.TestHost/WebSocketClient.cs @@ -94,7 +94,7 @@ namespace Microsoft.AspNet.TestHost HttpContext = new DefaultHttpContext(FeatureCollection); // Request - HttpContext.SetFeature(new RequestFeature()); + HttpContext.Features.Set(new RequestFeature()); var request = HttpContext.Request; request.Protocol = "HTTP/1.1"; var scheme = uri.Scheme; @@ -122,13 +122,13 @@ namespace Microsoft.AspNet.TestHost request.Body = Stream.Null; // Response - HttpContext.SetFeature(new ResponseFeature()); + HttpContext.Features.Set(new ResponseFeature()); var response = HttpContext.Response; response.Body = Stream.Null; response.StatusCode = 200; // WebSocket - HttpContext.SetFeature(this); + HttpContext.Features.Set(this); } public void PipelineComplete() From 7dbe5dfbe408a4ca538f0c015b81f2fb03758ad4 Mon Sep 17 00:00:00 2001 From: Master T Date: Wed, 2 Sep 2015 20:36:55 +0200 Subject: [PATCH 350/987] Implement HttpContext.RequestAborted --- .../ClientHandler.cs | 75 +++++++++++-------- .../ResponseStream.cs | 44 ++++++----- .../TestClientTests.cs | 63 ++++++++++++++++ 3 files changed, 130 insertions(+), 52 deletions(-) diff --git a/src/Microsoft.AspNet.TestHost/ClientHandler.cs b/src/Microsoft.AspNet.TestHost/ClientHandler.cs index 970c232afe..12e03e8980 100644 --- a/src/Microsoft.AspNet.TestHost/ClientHandler.cs +++ b/src/Microsoft.AspNet.TestHost/ClientHandler.cs @@ -54,7 +54,7 @@ namespace Microsoft.AspNet.TestHost [NotNull] HttpRequestMessage request, CancellationToken cancellationToken) { - var state = new RequestState(request, _pathBase, cancellationToken); + var state = new RequestState(request, _pathBase); var requestContent = request.Content ?? new StreamContent(Stream.Null); var body = await requestContent.ReadAsStreamAsync(); if (body.CanSeek) @@ -63,41 +63,44 @@ namespace Microsoft.AspNet.TestHost body.Seek(0, SeekOrigin.Begin); } state.HttpContext.Request.Body = body; - var registration = cancellationToken.Register(state.Abort); + var registration = cancellationToken.Register(state.AbortRequest); // Async offload, don't let the test code block the caller. var offload = Task.Factory.StartNew(async () => - { - try { - await _next(state.HttpContext.Features); - state.CompleteResponse(); - } - catch (Exception ex) - { - state.Abort(ex); - } - finally - { - registration.Dispose(); - state.Dispose(); - } - }); + try + { + await _next(state.HttpContext.Features); + state.CompleteResponse(); + } + catch (Exception ex) + { + state.Abort(ex); + } + finally + { + registration.Dispose(); + } + }); return await state.ResponseTask; } - private class RequestState : IDisposable + private class RequestState { private readonly HttpRequestMessage _request; private TaskCompletionSource _responseTcs; private ResponseStream _responseStream; private ResponseFeature _responseFeature; + private CancellationTokenSource _requestAbortedSource; + private bool _pipelineFinished; - internal RequestState(HttpRequestMessage request, PathString pathBase, CancellationToken cancellationToken) + internal RequestState(HttpRequestMessage request, PathString pathBase) { _request = request; _responseTcs = new TaskCompletionSource(); + _requestAbortedSource = new CancellationTokenSource(); + _pipelineFinished = false; if (request.RequestUri.IsDefaultPort) { @@ -131,7 +134,6 @@ namespace Microsoft.AspNet.TestHost } serverRequest.QueryString = QueryString.FromUriComponent(request.RequestUri); - // TODO: serverRequest.CallCancelled = cancellationToken; foreach (var header in request.Headers) { @@ -146,9 +148,10 @@ namespace Microsoft.AspNet.TestHost } } - _responseStream = new ResponseStream(CompleteResponse); + _responseStream = new ResponseStream(ReturnResponseMessage, AbortRequest); HttpContext.Response.Body = _responseStream; HttpContext.Response.StatusCode = 200; + HttpContext.RequestAborted = _requestAbortedSource.Token; } public HttpContext HttpContext { get; private set; } @@ -158,7 +161,23 @@ namespace Microsoft.AspNet.TestHost get { return _responseTcs.Task; } } + internal void AbortRequest() + { + if (!_pipelineFinished) + { + _requestAbortedSource.Cancel(); + } + _responseStream.Complete(); + } + internal void CompleteResponse() + { + _pipelineFinished = true; + ReturnResponseMessage(); + _responseStream.Complete(); + } + + internal void ReturnResponseMessage() { if (!_responseTcs.Task.IsCompleted) { @@ -171,7 +190,7 @@ namespace Microsoft.AspNet.TestHost [SuppressMessage("Microsoft.Reliability", "CA2000:DisposeObjectsBeforeLosingScope", Justification = "HttpResposneMessage must be returned to the caller.")] - internal HttpResponseMessage GenerateResponse() + private HttpResponseMessage GenerateResponse() { _responseFeature.FireOnSendingHeaders(); @@ -194,22 +213,12 @@ namespace Microsoft.AspNet.TestHost return response; } - internal void Abort() - { - Abort(new OperationCanceledException()); - } - internal void Abort(Exception exception) { + _pipelineFinished = true; _responseStream.Abort(exception); _responseTcs.TrySetException(exception); } - - public void Dispose() - { - _responseStream.Dispose(); - // Do not dispose the request, that will be disposed by the caller. - } } } } diff --git a/src/Microsoft.AspNet.TestHost/ResponseStream.cs b/src/Microsoft.AspNet.TestHost/ResponseStream.cs index 42a8a419c5..7f75c5983f 100644 --- a/src/Microsoft.AspNet.TestHost/ResponseStream.cs +++ b/src/Microsoft.AspNet.TestHost/ResponseStream.cs @@ -16,7 +16,7 @@ namespace Microsoft.AspNet.TestHost // when requested by the client. internal class ResponseStream : Stream { - private bool _disposed; + private bool _complete; private bool _aborted; private Exception _abortException; private ConcurrentQueue _bufferedData; @@ -28,11 +28,13 @@ namespace Microsoft.AspNet.TestHost private Action _onFirstWrite; private bool _firstWrite; + private Action _abortRequest; - internal ResponseStream([NotNull] Action onFirstWrite) + internal ResponseStream([NotNull] Action onFirstWrite, [NotNull] Action abortRequest) { _onFirstWrite = onFirstWrite; _firstWrite = true; + _abortRequest = abortRequest; _readLock = new SemaphoreSlim(1, 1); _writeLock = new SemaphoreSlim(1, 1); @@ -83,7 +85,7 @@ namespace Microsoft.AspNet.TestHost public override void Flush() { - CheckDisposed(); + CheckNotComplete(); _writeLock.Wait(); try @@ -130,7 +132,7 @@ namespace Microsoft.AspNet.TestHost byte[] topBuffer = null; while (!_bufferedData.TryDequeue(out topBuffer)) { - if (_disposed) + if (_complete) { CheckAborted(); // Graceful close @@ -189,7 +191,7 @@ namespace Microsoft.AspNet.TestHost byte[] topBuffer = null; while (!_bufferedData.TryDequeue(out topBuffer)) { - if (_disposed) + if (_complete) { CheckAborted(); // Graceful close @@ -233,7 +235,7 @@ namespace Microsoft.AspNet.TestHost public override void Write(byte[] buffer, int offset, int count) { VerifyBuffer(buffer, offset, count, allowEmpty: true); - CheckDisposed(); + CheckNotComplete(); _writeLock.Wait(); try @@ -317,7 +319,7 @@ namespace Microsoft.AspNet.TestHost { _readWaitingForData = new TaskCompletionSource(); - if (!_bufferedData.IsEmpty || _disposed) + if (!_bufferedData.IsEmpty || _complete) { // Race, data could have arrived before we created the TCS. _readWaitingForData.TrySetResult(null); @@ -337,7 +339,18 @@ namespace Microsoft.AspNet.TestHost Contract.Requires(innerException != null); _aborted = true; _abortException = innerException; - Dispose(); + Complete(); + } + + internal void Complete() + { + // Prevent race with WaitForDataAsync + lock (_signalReadLock) + { + // Throw for further writes, but not reads. Allow reads to drain the buffered data and then return 0 for further reads. + _complete = true; + _readWaitingForData.TrySetResult(null); + } } private void CheckAborted() @@ -354,23 +367,16 @@ namespace Microsoft.AspNet.TestHost { if (disposing) { - // Prevent race with WaitForDataAsync - lock (_signalReadLock) - { - // Throw for further writes, but not reads. Allow reads to drain the buffered data and then return 0 for further reads. - _disposed = true; - _readWaitingForData.TrySetResult(null); - } + _abortRequest(); } - base.Dispose(disposing); } - private void CheckDisposed() + private void CheckNotComplete() { - if (_disposed) + if (_complete) { - throw new ObjectDisposedException(GetType().FullName); + throw new IOException("The request was aborted or the pipeline has finished"); } } } diff --git a/test/Microsoft.AspNet.TestHost.Tests/TestClientTests.cs b/test/Microsoft.AspNet.TestHost.Tests/TestClientTests.cs index e207d499fc..ae1dfd19ca 100644 --- a/test/Microsoft.AspNet.TestHost.Tests/TestClientTests.cs +++ b/test/Microsoft.AspNet.TestHost.Tests/TestClientTests.cs @@ -1,6 +1,7 @@ // 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; using System.IO; using System.Linq; using System.Net.Http; @@ -245,5 +246,67 @@ namespace Microsoft.AspNet.TestHost clientSocket.Dispose(); } + + [Fact] + public async Task ClientDisposalAbortsRequest() + { + // Arrange + TaskCompletionSource tcs = new TaskCompletionSource(); + RequestDelegate appDelegate = async ctx => + { + // Write Headers + await ctx.Response.Body.FlushAsync(); + + var sem = new SemaphoreSlim(0); + try + { + await sem.WaitAsync(ctx.RequestAborted); + } + catch (Exception e) + { + tcs.SetException(e); + } + }; + + // Act + var server = TestServer.Create(app => app.Run(appDelegate)); + var client = server.CreateClient(); + var request = new HttpRequestMessage(HttpMethod.Get, "http://localhost:12345"); + var response = await client.SendAsync(request, HttpCompletionOption.ResponseHeadersRead); + // Abort Request + response.Dispose(); + + // Assert + var exception = await Assert.ThrowsAnyAsync(async () => await tcs.Task); + } + + [Fact] + public async Task ClientCancellationAbortsRequest() + { + // Arrange + TaskCompletionSource tcs = new TaskCompletionSource(); + RequestDelegate appDelegate = async ctx => + { + var sem = new SemaphoreSlim(0); + try + { + await sem.WaitAsync(ctx.RequestAborted); + } + catch (Exception e) + { + tcs.SetException(e); + } + }; + + // Act + var server = TestServer.Create(app => app.Run(appDelegate)); + var client = server.CreateClient(); + var cts = new CancellationTokenSource(); + cts.CancelAfter(500); + var response = await client.GetAsync("http://localhost:12345", cts.Token); + + // Assert + var exception = await Assert.ThrowsAnyAsync(async () => await tcs.Task); + } } } From 74fe851f548289fc25cb244fb57016a83b09e8c8 Mon Sep 17 00:00:00 2001 From: Hao Kung Date: Wed, 2 Sep 2015 14:02:01 -0700 Subject: [PATCH 351/987] React to options --- test/Microsoft.AspNet.Hosting.Tests/StartupManagerTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/Microsoft.AspNet.Hosting.Tests/StartupManagerTests.cs b/test/Microsoft.AspNet.Hosting.Tests/StartupManagerTests.cs index 9cc385ae40..a5afed8b7b 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/StartupManagerTests.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/StartupManagerTests.cs @@ -61,7 +61,7 @@ namespace Microsoft.AspNet.Hosting.Tests app.ApplicationServices = startup.ConfigureServicesDelegate(new ServiceCollection()); startup.ConfigureDelegate(app); - var options = app.ApplicationServices.GetRequiredService>().Options; + var options = app.ApplicationServices.GetRequiredService>().Value; Assert.NotNull(options); Assert.True(options.Configured); Assert.Equal(environment, options.Environment); From 5fb45b3cfb9a4eafa0933941a62e6965facbe705 Mon Sep 17 00:00:00 2001 From: "N. Taylor Mullen" Date: Wed, 2 Sep 2015 15:34:19 -0700 Subject: [PATCH 352/987] Update project.json to have warningsAsErrors accept a bool. --- src/Microsoft.AspNet.Hosting/project.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Microsoft.AspNet.Hosting/project.json b/src/Microsoft.AspNet.Hosting/project.json index f407a3ae74..fe3ed63b3c 100644 --- a/src/Microsoft.AspNet.Hosting/project.json +++ b/src/Microsoft.AspNet.Hosting/project.json @@ -5,7 +5,7 @@ "type": "git", "url": "git://github.com/aspnet/hosting" }, - "compilationOptions": { "warningsAsErrors": "true" }, + "compilationOptions": { "warningsAsErrors": true }, "dependencies": { "Microsoft.AspNet.FileProviders.Physical": "1.0.0-*", "Microsoft.AspNet.Hosting.Abstractions": "1.0.0-*", From 1b790467a1663d257c4b393de257ceea48fa8a43 Mon Sep 17 00:00:00 2001 From: Chris R Date: Tue, 8 Sep 2015 09:50:47 -0700 Subject: [PATCH 353/987] #269 Use a json file instead of an ini file to configure hosting. --- src/Microsoft.AspNet.Hosting/Program.cs | 6 +++--- src/Microsoft.AspNet.Hosting/project.json | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Microsoft.AspNet.Hosting/Program.cs b/src/Microsoft.AspNet.Hosting/Program.cs index 985feeda86..3a8a941cc2 100644 --- a/src/Microsoft.AspNet.Hosting/Program.cs +++ b/src/Microsoft.AspNet.Hosting/Program.cs @@ -10,7 +10,7 @@ namespace Microsoft.AspNet.Hosting { public class Program { - private const string HostingIniFile = "Microsoft.AspNet.Hosting.ini"; + private const string HostingJsonFile = "Microsoft.AspNet.Hosting.json"; private const string ConfigFileKey = "config"; private readonly IServiceProvider _serviceProvider; @@ -25,11 +25,11 @@ namespace Microsoft.AspNet.Hosting // Allow the location of the ini file to be specified via a --config command line arg var tempBuilder = new ConfigurationBuilder().AddCommandLine(args); var tempConfig = tempBuilder.Build(); - var configFilePath = tempConfig[ConfigFileKey] ?? HostingIniFile; + var configFilePath = tempConfig[ConfigFileKey] ?? HostingJsonFile; var appBasePath = _serviceProvider.GetRequiredService().ApplicationBasePath; var builder = new ConfigurationBuilder(appBasePath); - builder.AddIniFile(configFilePath, optional: true); + builder.AddJsonFile(configFilePath, optional: true); builder.AddEnvironmentVariables(); builder.AddCommandLine(args); var config = builder.Build(); diff --git a/src/Microsoft.AspNet.Hosting/project.json b/src/Microsoft.AspNet.Hosting/project.json index fe3ed63b3c..ad736ead8e 100644 --- a/src/Microsoft.AspNet.Hosting/project.json +++ b/src/Microsoft.AspNet.Hosting/project.json @@ -15,7 +15,7 @@ "Microsoft.Framework.Configuration": "1.0.0-*", "Microsoft.Framework.Configuration.CommandLine": "1.0.0-*", "Microsoft.Framework.Configuration.EnvironmentVariables": "1.0.0-*", - "Microsoft.Framework.Configuration.Ini": "1.0.0-*", + "Microsoft.Framework.Configuration.Json": "1.0.0-*", "Microsoft.Framework.DependencyInjection": "1.0.0-*", "Microsoft.Framework.Logging": "1.0.0-*", "Microsoft.Dnx.Runtime.Abstractions": "1.0.0-*", From 3e6585dcc81777676665c844af988ddfec87aba7 Mon Sep 17 00:00:00 2001 From: Pranav K Date: Thu, 10 Sep 2015 17:38:08 -0700 Subject: [PATCH 354/987] Adding NeutralResourcesLanguageAttribute --- .../Properties/AssemblyInfo.cs | 4 +++- .../Properties/AssemblyInfo.cs | 8 ++++++++ src/Microsoft.AspNet.Hosting/Properties/AssemblyInfo.cs | 2 ++ src/Microsoft.AspNet.TestHost/Properties/AssemblyInfo.cs | 3 +++ 4 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 src/Microsoft.AspNet.Hosting.Server.Abstractions/Properties/AssemblyInfo.cs diff --git a/src/Microsoft.AspNet.Hosting.Abstractions/Properties/AssemblyInfo.cs b/src/Microsoft.AspNet.Hosting.Abstractions/Properties/AssemblyInfo.cs index 025a94598c..b16f6dfb0a 100644 --- a/src/Microsoft.AspNet.Hosting.Abstractions/Properties/AssemblyInfo.cs +++ b/src/Microsoft.AspNet.Hosting.Abstractions/Properties/AssemblyInfo.cs @@ -2,5 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Reflection; +using System.Resources; -[assembly: AssemblyMetadata("Serviceable", "True")] \ No newline at end of file +[assembly: AssemblyMetadata("Serviceable", "True")] +[assembly: NeutralResourcesLanguage("en-us")] diff --git a/src/Microsoft.AspNet.Hosting.Server.Abstractions/Properties/AssemblyInfo.cs b/src/Microsoft.AspNet.Hosting.Server.Abstractions/Properties/AssemblyInfo.cs new file mode 100644 index 0000000000..b16f6dfb0a --- /dev/null +++ b/src/Microsoft.AspNet.Hosting.Server.Abstractions/Properties/AssemblyInfo.cs @@ -0,0 +1,8 @@ +// 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.Reflection; +using System.Resources; + +[assembly: AssemblyMetadata("Serviceable", "True")] +[assembly: NeutralResourcesLanguage("en-us")] diff --git a/src/Microsoft.AspNet.Hosting/Properties/AssemblyInfo.cs b/src/Microsoft.AspNet.Hosting/Properties/AssemblyInfo.cs index 6145905b3a..1ee4059c80 100644 --- a/src/Microsoft.AspNet.Hosting/Properties/AssemblyInfo.cs +++ b/src/Microsoft.AspNet.Hosting/Properties/AssemblyInfo.cs @@ -2,7 +2,9 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Reflection; +using System.Resources; using System.Runtime.CompilerServices; [assembly: AssemblyMetadata("Serviceable", "True")] [assembly: InternalsVisibleTo("Microsoft.AspNet.Hosting.Tests")] +[assembly: NeutralResourcesLanguage("en-us")] diff --git a/src/Microsoft.AspNet.TestHost/Properties/AssemblyInfo.cs b/src/Microsoft.AspNet.TestHost/Properties/AssemblyInfo.cs index d052161863..726e557599 100644 --- a/src/Microsoft.AspNet.TestHost/Properties/AssemblyInfo.cs +++ b/src/Microsoft.AspNet.TestHost/Properties/AssemblyInfo.cs @@ -16,6 +16,7 @@ // permissions and limitations under the License. using System.Reflection; +using System.Resources; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; @@ -37,3 +38,5 @@ using System.Runtime.InteropServices; [assembly: InternalsVisibleTo("Microsoft.AspNet.TestHost.Tests")] [assembly: AssemblyMetadata("Serviceable", "True")] +[assembly: NeutralResourcesLanguage("en-us")] + From 896c146e24f2fe9e59cc1e698c99ec5af6b10c92 Mon Sep 17 00:00:00 2001 From: Pranav K Date: Mon, 14 Sep 2015 10:42:16 -0700 Subject: [PATCH 355/987] Replacing NotNullAttribute with thrown exceptions --- .../HostingEnvironmentExtensions.cs | 29 ++++++++-- .../project.json | 3 +- .../Internal/HostingEngine.cs | 22 ++++++-- .../RequestServicesContainerMiddleware.cs | 20 ++++++- .../Server/ServerLoader.cs | 8 ++- .../Startup/ConfigureServicesDelegate.cs | 15 ++++- .../WebHostBuilder.cs | 56 +++++++++++++++---- src/Microsoft.AspNet.Hosting/project.json | 1 - .../ClientHandler.cs | 15 ++++- .../RequestBuilder.cs | 16 ++++-- .../ResponseStream.cs | 13 ++++- .../WebSocketClient.cs | 12 ++-- src/Microsoft.AspNet.TestHost/project.json | 3 +- .../HostingEngineTests.cs | 2 +- 14 files changed, 169 insertions(+), 46 deletions(-) diff --git a/src/Microsoft.AspNet.Hosting.Abstractions/HostingEnvironmentExtensions.cs b/src/Microsoft.AspNet.Hosting.Abstractions/HostingEnvironmentExtensions.cs index 8fc1b8e43b..1d62b061dc 100644 --- a/src/Microsoft.AspNet.Hosting.Abstractions/HostingEnvironmentExtensions.cs +++ b/src/Microsoft.AspNet.Hosting.Abstractions/HostingEnvironmentExtensions.cs @@ -3,7 +3,6 @@ using System; using System.IO; -using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Hosting { @@ -14,8 +13,13 @@ namespace Microsoft.AspNet.Hosting /// /// An instance of service. /// True if the environment name is Development, otherwise false. - public static bool IsDevelopment([NotNull]this IHostingEnvironment hostingEnvironment) + public static bool IsDevelopment(this IHostingEnvironment hostingEnvironment) { + if (hostingEnvironment == null) + { + throw new ArgumentNullException(nameof(hostingEnvironment)); + } + return hostingEnvironment.IsEnvironment(EnvironmentName.Development); } @@ -24,8 +28,13 @@ namespace Microsoft.AspNet.Hosting /// /// An instance of service. /// True if the environment name is Production, otherwise false. - public static bool IsProduction([NotNull]this IHostingEnvironment hostingEnvironment) + public static bool IsProduction(this IHostingEnvironment hostingEnvironment) { + if (hostingEnvironment == null) + { + throw new ArgumentNullException(nameof(hostingEnvironment)); + } + return hostingEnvironment.IsEnvironment(EnvironmentName.Production); } @@ -36,9 +45,14 @@ namespace Microsoft.AspNet.Hosting /// Environment name to validate against. /// True if the specified name is same as the current environment. public static bool IsEnvironment( - [NotNull]this IHostingEnvironment hostingEnvironment, + this IHostingEnvironment hostingEnvironment, string environmentName) { + if (hostingEnvironment == null) + { + throw new ArgumentNullException(nameof(hostingEnvironment)); + } + return string.Equals( hostingEnvironment.EnvironmentName, environmentName, @@ -52,9 +66,14 @@ namespace Microsoft.AspNet.Hosting /// Path relative to the root. /// Physical path corresponding to virtual path. public static string MapPath( - [NotNull]this IHostingEnvironment hostingEnvironment, + this IHostingEnvironment hostingEnvironment, string virtualPath) { + if (hostingEnvironment == null) + { + throw new ArgumentNullException(nameof(hostingEnvironment)); + } + if (virtualPath == null) { return hostingEnvironment.WebRootPath; diff --git a/src/Microsoft.AspNet.Hosting.Abstractions/project.json b/src/Microsoft.AspNet.Hosting.Abstractions/project.json index 6e143904ae..daaa329df3 100644 --- a/src/Microsoft.AspNet.Hosting.Abstractions/project.json +++ b/src/Microsoft.AspNet.Hosting.Abstractions/project.json @@ -7,8 +7,7 @@ }, "dependencies": { "Microsoft.AspNet.Http.Abstractions": "1.0.0-*", - "Microsoft.AspNet.FileProviders.Abstractions": "1.0.0-*", - "Microsoft.Framework.NotNullAttribute.Sources": { "type": "build", "version": "1.0.0-*" } + "Microsoft.AspNet.FileProviders.Abstractions": "1.0.0-*" }, "frameworks": { "dnx451": {}, diff --git a/src/Microsoft.AspNet.Hosting/Internal/HostingEngine.cs b/src/Microsoft.AspNet.Hosting/Internal/HostingEngine.cs index d072b36285..b57a218031 100644 --- a/src/Microsoft.AspNet.Hosting/Internal/HostingEngine.cs +++ b/src/Microsoft.AspNet.Hosting/Internal/HostingEngine.cs @@ -14,7 +14,6 @@ using Microsoft.AspNet.Http.Features; using Microsoft.AspNet.Http.Features.Internal; using Microsoft.Framework.Configuration; using Microsoft.Framework.DependencyInjection; -using Microsoft.Framework.Internal; using Microsoft.Framework.Logging; namespace Microsoft.AspNet.Hosting.Internal @@ -39,10 +38,25 @@ namespace Microsoft.AspNet.Hosting.Internal private IFeatureCollection _serverInstance; public HostingEngine( - [NotNull] IServiceCollection appServices, - [NotNull] IStartupLoader startupLoader, - [NotNull] IConfiguration config) + IServiceCollection appServices, + IStartupLoader startupLoader, + IConfiguration config) { + if (appServices == null) + { + throw new ArgumentNullException(nameof(appServices)); + } + + if (startupLoader == null) + { + throw new ArgumentNullException(nameof(startupLoader)); + } + + if (config == null) + { + throw new ArgumentNullException(nameof(config)); + } + _config = config; _applicationServiceCollection = appServices; _startupLoader = startupLoader; diff --git a/src/Microsoft.AspNet.Hosting/Internal/RequestServicesContainerMiddleware.cs b/src/Microsoft.AspNet.Hosting/Internal/RequestServicesContainerMiddleware.cs index 9c740ba7f1..ab3fda31ab 100644 --- a/src/Microsoft.AspNet.Hosting/Internal/RequestServicesContainerMiddleware.cs +++ b/src/Microsoft.AspNet.Hosting/Internal/RequestServicesContainerMiddleware.cs @@ -6,7 +6,6 @@ using System.Threading.Tasks; using Microsoft.AspNet.Builder; using Microsoft.AspNet.Http; using Microsoft.Framework.DependencyInjection; -using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Hosting.Internal { @@ -15,14 +14,29 @@ namespace Microsoft.AspNet.Hosting.Internal private readonly RequestDelegate _next; private readonly IServiceProvider _services; - public RequestServicesContainerMiddleware([NotNull] RequestDelegate next, [NotNull] IServiceProvider services) + public RequestServicesContainerMiddleware(RequestDelegate next, IServiceProvider services) { + if (next == null) + { + throw new ArgumentNullException(nameof(next)); + } + + if (services == null) + { + throw new ArgumentNullException(nameof(services)); + } + _services = services; _next = next; } - public async Task Invoke([NotNull] HttpContext httpContext) + public async Task Invoke(HttpContext httpContext) { + if (httpContext == null) + { + throw new ArgumentNullException(nameof(httpContext)); + } + // All done if there request services is set if (httpContext.RequestServices != null) { diff --git a/src/Microsoft.AspNet.Hosting/Server/ServerLoader.cs b/src/Microsoft.AspNet.Hosting/Server/ServerLoader.cs index 367f7bea05..3a94dfaca5 100644 --- a/src/Microsoft.AspNet.Hosting/Server/ServerLoader.cs +++ b/src/Microsoft.AspNet.Hosting/Server/ServerLoader.cs @@ -5,7 +5,6 @@ using System; using System.Linq; using System.Reflection; using Microsoft.Framework.DependencyInjection; -using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Hosting.Server { @@ -18,8 +17,13 @@ namespace Microsoft.AspNet.Hosting.Server _services = services; } - public IServerFactory LoadServerFactory([NotNull] string assemblyName) + public IServerFactory LoadServerFactory(string assemblyName) { + if (assemblyName == null) + { + throw new ArgumentNullException(nameof(assemblyName)); + } + if (string.IsNullOrEmpty(assemblyName)) { throw new ArgumentException(string.Empty, nameof(assemblyName)); diff --git a/src/Microsoft.AspNet.Hosting/Startup/ConfigureServicesDelegate.cs b/src/Microsoft.AspNet.Hosting/Startup/ConfigureServicesDelegate.cs index 977cb07238..716795bc8d 100644 --- a/src/Microsoft.AspNet.Hosting/Startup/ConfigureServicesDelegate.cs +++ b/src/Microsoft.AspNet.Hosting/Startup/ConfigureServicesDelegate.cs @@ -5,14 +5,18 @@ using System; using System.Linq; using System.Reflection; using Microsoft.Framework.DependencyInjection; -using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Hosting.Startup { public class ConfigureServicesBuilder { - public ConfigureServicesBuilder([NotNull] MethodInfo configureServices) + public ConfigureServicesBuilder(MethodInfo configureServices) { + if (configureServices == null) + { + throw new ArgumentNullException(nameof(configureServices)); + } + // Only support IServiceCollection parameters var parameters = configureServices.GetParameters(); if (parameters.Length > 1 || @@ -28,8 +32,13 @@ namespace Microsoft.AspNet.Hosting.Startup public Func Build(object instance) => services => Invoke(instance, services); - private IServiceProvider Invoke(object instance, [NotNull] IServiceCollection exportServices) + private IServiceProvider Invoke(object instance, IServiceCollection exportServices) { + if (exportServices == null) + { + throw new ArgumentNullException(nameof(exportServices)); + } + var parameters = new object[MethodInfo.GetParameters().Length]; // Ctor ensures we have at most one IServiceCollection parameter diff --git a/src/Microsoft.AspNet.Hosting/WebHostBuilder.cs b/src/Microsoft.AspNet.Hosting/WebHostBuilder.cs index 502d9bc09a..6efc8042d5 100644 --- a/src/Microsoft.AspNet.Hosting/WebHostBuilder.cs +++ b/src/Microsoft.AspNet.Hosting/WebHostBuilder.cs @@ -12,7 +12,6 @@ using Microsoft.AspNet.Http.Internal; using Microsoft.Dnx.Runtime; using Microsoft.Framework.Configuration; using Microsoft.Framework.DependencyInjection; -using Microsoft.Framework.Internal; using Microsoft.Framework.Logging; namespace Microsoft.AspNet.Hosting @@ -44,13 +43,23 @@ namespace Microsoft.AspNet.Hosting private string _serverFactoryLocation; private IServerFactory _serverFactory; - public WebHostBuilder([NotNull] IServiceProvider services) + public WebHostBuilder(IServiceProvider services) : this(services, config: new ConfigurationBuilder().Build()) { } - public WebHostBuilder([NotNull] IServiceProvider services, [NotNull] IConfiguration config) + public WebHostBuilder(IServiceProvider services, IConfiguration config) { + if (services == null) + { + throw new ArgumentNullException(nameof(services)); + } + + if (config == null) + { + throw new ArgumentNullException(nameof(config)); + } + _hostingEnvironment = new HostingEnvironment(); _loggerFactory = new LoggerFactory(); _services = services; @@ -124,14 +133,24 @@ namespace Microsoft.AspNet.Hosting return this; } - public WebHostBuilder UseEnvironment([NotNull] string environment) + public WebHostBuilder UseEnvironment(string environment) { + if (environment == null) + { + throw new ArgumentNullException(nameof(environment)); + } + _hostingEnvironment.EnvironmentName = environment; return this; } - public WebHostBuilder UseServer([NotNull] string assemblyName) + public WebHostBuilder UseServer(string assemblyName) { + if (assemblyName == null) + { + throw new ArgumentNullException(nameof(assemblyName)); + } + _serverFactoryLocation = assemblyName; return this; } @@ -142,22 +161,24 @@ namespace Microsoft.AspNet.Hosting return this; } - public WebHostBuilder UseStartup([NotNull] string startupAssemblyName) + public WebHostBuilder UseStartup(string startupAssemblyName) { if (startupAssemblyName == null) { throw new ArgumentNullException(nameof(startupAssemblyName)); } + _startupAssemblyName = startupAssemblyName; return this; } - public WebHostBuilder UseStartup([NotNull] Type startupType) + public WebHostBuilder UseStartup(Type startupType) { if (startupType == null) { throw new ArgumentNullException(nameof(startupType)); } + _startupType = startupType; return this; } @@ -167,19 +188,34 @@ namespace Microsoft.AspNet.Hosting return UseStartup(typeof(TStartup)); } - public WebHostBuilder UseStartup([NotNull] Action configureApp) + public WebHostBuilder UseStartup(Action configureApp) { + if (configureApp == null) + { + throw new ArgumentNullException(nameof(configureApp)); + } + return UseStartup(configureApp, configureServices: null); } - public WebHostBuilder UseStartup([NotNull] Action configureApp, Func configureServices) + public WebHostBuilder UseStartup(Action configureApp, Func configureServices) { + if (configureApp == null) + { + throw new ArgumentNullException(nameof(configureApp)); + } + _startup = new StartupMethods(configureApp, configureServices); return this; } - public WebHostBuilder UseStartup([NotNull] Action configureApp, Action configureServices) + public WebHostBuilder UseStartup(Action configureApp, Action configureServices) { + if (configureApp == null) + { + throw new ArgumentNullException(nameof(configureApp)); + } + _startup = new StartupMethods(configureApp, services => { diff --git a/src/Microsoft.AspNet.Hosting/project.json b/src/Microsoft.AspNet.Hosting/project.json index ad736ead8e..00218c9fb5 100644 --- a/src/Microsoft.AspNet.Hosting/project.json +++ b/src/Microsoft.AspNet.Hosting/project.json @@ -19,7 +19,6 @@ "Microsoft.Framework.DependencyInjection": "1.0.0-*", "Microsoft.Framework.Logging": "1.0.0-*", "Microsoft.Dnx.Runtime.Abstractions": "1.0.0-*", - "Microsoft.Framework.NotNullAttribute.Sources": { "type": "build", "version": "1.0.0-*" }, "Newtonsoft.Json": "6.0.6" }, "frameworks": { diff --git a/src/Microsoft.AspNet.TestHost/ClientHandler.cs b/src/Microsoft.AspNet.TestHost/ClientHandler.cs index 12e03e8980..efcb5dc06e 100644 --- a/src/Microsoft.AspNet.TestHost/ClientHandler.cs +++ b/src/Microsoft.AspNet.TestHost/ClientHandler.cs @@ -14,7 +14,6 @@ using System.Threading.Tasks; using Microsoft.AspNet.Http; using Microsoft.AspNet.Http.Features; using Microsoft.AspNet.Http.Internal; -using Microsoft.Framework.Internal; namespace Microsoft.AspNet.TestHost { @@ -31,8 +30,13 @@ namespace Microsoft.AspNet.TestHost /// Create a new handler. /// /// The pipeline entry point. - public ClientHandler([NotNull] Func next, PathString pathBase) + public ClientHandler(Func next, PathString pathBase) { + if (next == null) + { + throw new ArgumentNullException(nameof(next)); + } + _next = next; // PathString.StartsWithSegments that we use below requires the base path to not end in a slash. @@ -51,9 +55,14 @@ namespace Microsoft.AspNet.TestHost /// /// protected override async Task SendAsync( - [NotNull] HttpRequestMessage request, + HttpRequestMessage request, CancellationToken cancellationToken) { + if (request == null) + { + throw new ArgumentNullException(nameof(request)); + } + var state = new RequestState(request, _pathBase); var requestContent = request.Content ?? new StreamContent(Stream.Null); var body = await requestContent.ReadAsStreamAsync(); diff --git a/src/Microsoft.AspNet.TestHost/RequestBuilder.cs b/src/Microsoft.AspNet.TestHost/RequestBuilder.cs index 3de390f63a..2de21ead03 100644 --- a/src/Microsoft.AspNet.TestHost/RequestBuilder.cs +++ b/src/Microsoft.AspNet.TestHost/RequestBuilder.cs @@ -3,11 +3,9 @@ using System; using System.Diagnostics.CodeAnalysis; -using System.Globalization; using System.IO; using System.Net.Http; using System.Threading.Tasks; -using Microsoft.Framework.Internal; namespace Microsoft.AspNet.TestHost { @@ -27,8 +25,13 @@ namespace Microsoft.AspNet.TestHost /// /// [SuppressMessage("Microsoft.Usage", "CA2234:PassSystemUriObjectsInsteadOfStrings", Justification = "Not a full URI")] - public RequestBuilder([NotNull] TestServer server, string path) + public RequestBuilder(TestServer server, string path) { + if (server == null) + { + throw new ArgumentNullException(nameof(server)); + } + _server = server; _req = new HttpRequestMessage(HttpMethod.Get, path); } @@ -38,8 +41,13 @@ namespace Microsoft.AspNet.TestHost /// /// /// - public RequestBuilder And([NotNull] Action configure) + public RequestBuilder And(Action configure) { + if (configure == null) + { + throw new ArgumentNullException(nameof(configure)); + } + configure(_req); return this; } diff --git a/src/Microsoft.AspNet.TestHost/ResponseStream.cs b/src/Microsoft.AspNet.TestHost/ResponseStream.cs index 7f75c5983f..a1dd0df091 100644 --- a/src/Microsoft.AspNet.TestHost/ResponseStream.cs +++ b/src/Microsoft.AspNet.TestHost/ResponseStream.cs @@ -8,7 +8,6 @@ using System.Diagnostics.Contracts; using System.IO; using System.Threading; using System.Threading.Tasks; -using Microsoft.Framework.Internal; namespace Microsoft.AspNet.TestHost { @@ -30,8 +29,18 @@ namespace Microsoft.AspNet.TestHost private bool _firstWrite; private Action _abortRequest; - internal ResponseStream([NotNull] Action onFirstWrite, [NotNull] Action abortRequest) + internal ResponseStream(Action onFirstWrite, Action abortRequest) { + if (onFirstWrite == null) + { + throw new ArgumentNullException(nameof(onFirstWrite)); + } + + if (abortRequest == null) + { + throw new ArgumentNullException(nameof(abortRequest)); + } + _onFirstWrite = onFirstWrite; _firstWrite = true; _abortRequest = abortRequest; diff --git a/src/Microsoft.AspNet.TestHost/WebSocketClient.cs b/src/Microsoft.AspNet.TestHost/WebSocketClient.cs index 1eaecbcb61..9946d5e4bd 100644 --- a/src/Microsoft.AspNet.TestHost/WebSocketClient.cs +++ b/src/Microsoft.AspNet.TestHost/WebSocketClient.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// 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; @@ -11,7 +11,6 @@ using System.Threading.Tasks; using Microsoft.AspNet.Http.Features; using Microsoft.AspNet.Http; using Microsoft.AspNet.Http.Internal; -using Microsoft.Framework.Internal; namespace Microsoft.AspNet.TestHost { @@ -20,10 +19,15 @@ namespace Microsoft.AspNet.TestHost private readonly Func _next; private readonly PathString _pathBase; - internal WebSocketClient([NotNull] Func next, PathString pathBase) + internal WebSocketClient(Func next, PathString pathBase) { + if (next == null) + { + throw new ArgumentNullException(nameof(next)); + } + _next = next; - + // PathString.StartsWithSegments that we use below requires the base path to not end in a slash. if (pathBase.HasValue && pathBase.Value.EndsWith("/")) { diff --git a/src/Microsoft.AspNet.TestHost/project.json b/src/Microsoft.AspNet.TestHost/project.json index c59e21f29d..34769e53cd 100644 --- a/src/Microsoft.AspNet.TestHost/project.json +++ b/src/Microsoft.AspNet.TestHost/project.json @@ -6,8 +6,7 @@ "url": "git://github.com/aspnet/hosting" }, "dependencies": { - "Microsoft.AspNet.Hosting": "1.0.0-*", - "Microsoft.Framework.NotNullAttribute.Sources": { "version": "1.0.0-*", "type": "build" } + "Microsoft.AspNet.Hosting": "1.0.0-*" }, "frameworks": { "dnx451": { diff --git a/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs b/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs index 5b9c50ba9a..1ded347dbb 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs @@ -413,7 +413,7 @@ namespace Microsoft.AspNet.Hosting private class ReadOnlyFeatureCollection : IFeatureCollection { - public object this[[NotNull] Type key] + public object this[Type key] { get { return null; } set { throw new NotSupportedException(); } From bda0386a93c295e8a04527310d23c98722c2fe41 Mon Sep 17 00:00:00 2001 From: Chris R Date: Fri, 11 Sep 2015 12:14:29 -0700 Subject: [PATCH 356/987] #331 Add IServerAddressesFeature. --- .../IServerAddressesFeature.cs | 12 ++++++++++++ .../Internal/HostingEngine.cs | 10 ++++++++++ 2 files changed, 22 insertions(+) create mode 100644 src/Microsoft.AspNet.Hosting.Server.Abstractions/IServerAddressesFeature.cs diff --git a/src/Microsoft.AspNet.Hosting.Server.Abstractions/IServerAddressesFeature.cs b/src/Microsoft.AspNet.Hosting.Server.Abstractions/IServerAddressesFeature.cs new file mode 100644 index 0000000000..1afbfe7c92 --- /dev/null +++ b/src/Microsoft.AspNet.Hosting.Server.Abstractions/IServerAddressesFeature.cs @@ -0,0 +1,12 @@ +// 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.Collections.Generic; + +namespace Microsoft.AspNet.Server.Features +{ + public interface IServerAddressesFeature + { + ICollection Addresses { get; } + } +} diff --git a/src/Microsoft.AspNet.Hosting/Internal/HostingEngine.cs b/src/Microsoft.AspNet.Hosting/Internal/HostingEngine.cs index b57a218031..516fab462e 100644 --- a/src/Microsoft.AspNet.Hosting/Internal/HostingEngine.cs +++ b/src/Microsoft.AspNet.Hosting/Internal/HostingEngine.cs @@ -12,6 +12,7 @@ using Microsoft.AspNet.Hosting.Startup; using Microsoft.AspNet.Http; using Microsoft.AspNet.Http.Features; using Microsoft.AspNet.Http.Features.Internal; +using Microsoft.AspNet.Server.Features; using Microsoft.Framework.Configuration; using Microsoft.Framework.DependencyInjection; using Microsoft.Framework.Logging; @@ -95,6 +96,15 @@ namespace Microsoft.AspNet.Hosting.Internal } }); + var serverAddresses = _serverInstance.Get(); + if (serverAddresses != null) + { + foreach (var address in serverAddresses.Addresses) + { + logger.LogInformation("Now listening on: " + address); + } + } + _applicationLifetime.NotifyStarted(); return new Disposable(() => From 10176373c822b8df148ee70f9180e922ea820ae8 Mon Sep 17 00:00:00 2001 From: Chris R Date: Mon, 14 Sep 2015 15:07:15 -0700 Subject: [PATCH 357/987] #351 Display hosting environment name and listening addresses on console. --- .../Internal/Application.cs | 37 +++++++++++++++++++ .../Internal/HostingEngine.cs | 15 ++------ .../Internal/IApplication.cs | 15 ++++++++ .../Internal/IHostingEngine.cs | 2 +- src/Microsoft.AspNet.Hosting/Program.cs | 20 ++++++++-- 5 files changed, 73 insertions(+), 16 deletions(-) create mode 100644 src/Microsoft.AspNet.Hosting/Internal/Application.cs create mode 100644 src/Microsoft.AspNet.Hosting/Internal/IApplication.cs diff --git a/src/Microsoft.AspNet.Hosting/Internal/Application.cs b/src/Microsoft.AspNet.Hosting/Internal/Application.cs new file mode 100644 index 0000000000..ecbb916a6e --- /dev/null +++ b/src/Microsoft.AspNet.Hosting/Internal/Application.cs @@ -0,0 +1,37 @@ +// 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; +using Microsoft.AspNet.Http.Features; + +namespace Microsoft.AspNet.Hosting.Internal +{ + public class Application : IApplication + { + private readonly IDisposable _stop; + private readonly IServiceProvider _services; + private readonly IFeatureCollection _server; + + public Application(IServiceProvider services, IFeatureCollection server, IDisposable stop) + { + _services = services; + _server = server; + _stop = stop; + } + + public IFeatureCollection ServerFeatures + { + get { return _server; } + } + + public IServiceProvider Services + { + get { return _services; } + } + + public void Dispose() + { + _stop.Dispose(); + } + } +} diff --git a/src/Microsoft.AspNet.Hosting/Internal/HostingEngine.cs b/src/Microsoft.AspNet.Hosting/Internal/HostingEngine.cs index 516fab462e..d77831fd18 100644 --- a/src/Microsoft.AspNet.Hosting/Internal/HostingEngine.cs +++ b/src/Microsoft.AspNet.Hosting/Internal/HostingEngine.cs @@ -73,7 +73,7 @@ namespace Microsoft.AspNet.Hosting.Internal } } - public virtual IDisposable Start() + public virtual IApplication Start() { EnsureApplicationServices(); @@ -96,23 +96,14 @@ namespace Microsoft.AspNet.Hosting.Internal } }); - var serverAddresses = _serverInstance.Get(); - if (serverAddresses != null) - { - foreach (var address in serverAddresses.Addresses) - { - logger.LogInformation("Now listening on: " + address); - } - } - _applicationLifetime.NotifyStarted(); - return new Disposable(() => + return new Application(ApplicationServices, _serverInstance, new Disposable(() => { _applicationLifetime.NotifyStopping(); server.Dispose(); _applicationLifetime.NotifyStopped(); - }); + })); } private void EnsureApplicationServices() diff --git a/src/Microsoft.AspNet.Hosting/Internal/IApplication.cs b/src/Microsoft.AspNet.Hosting/Internal/IApplication.cs new file mode 100644 index 0000000000..99f807e10c --- /dev/null +++ b/src/Microsoft.AspNet.Hosting/Internal/IApplication.cs @@ -0,0 +1,15 @@ +// 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; +using Microsoft.AspNet.Http.Features; + +namespace Microsoft.AspNet.Hosting.Internal +{ + public interface IApplication : IDisposable + { + IFeatureCollection ServerFeatures { get; } + + IServiceProvider Services { get; } + } +} diff --git a/src/Microsoft.AspNet.Hosting/Internal/IHostingEngine.cs b/src/Microsoft.AspNet.Hosting/Internal/IHostingEngine.cs index d0a3818867..4b8789a9ca 100644 --- a/src/Microsoft.AspNet.Hosting/Internal/IHostingEngine.cs +++ b/src/Microsoft.AspNet.Hosting/Internal/IHostingEngine.cs @@ -7,7 +7,7 @@ namespace Microsoft.AspNet.Hosting.Internal { public interface IHostingEngine { - IDisposable Start(); + IApplication Start(); // Accessing this will block Use methods IServiceProvider ApplicationServices { get; } diff --git a/src/Microsoft.AspNet.Hosting/Program.cs b/src/Microsoft.AspNet.Hosting/Program.cs index 3a8a941cc2..4cde138e65 100644 --- a/src/Microsoft.AspNet.Hosting/Program.cs +++ b/src/Microsoft.AspNet.Hosting/Program.cs @@ -2,6 +2,8 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using Microsoft.AspNet.Http.Features; +using Microsoft.AspNet.Server.Features; using Microsoft.Dnx.Runtime; using Microsoft.Framework.Configuration; using Microsoft.Framework.DependencyInjection; @@ -22,7 +24,7 @@ namespace Microsoft.AspNet.Hosting public void Main(string[] args) { - // Allow the location of the ini file to be specified via a --config command line arg + // Allow the location of the json file to be specified via a --config command line arg var tempBuilder = new ConfigurationBuilder().AddCommandLine(args); var tempConfig = tempBuilder.Build(); var configFilePath = tempConfig[ConfigFileKey] ?? HostingJsonFile; @@ -35,11 +37,23 @@ namespace Microsoft.AspNet.Hosting var config = builder.Build(); var host = new WebHostBuilder(_serviceProvider, config).Build(); - using (host.Start()) + using (var app = host.Start()) { + var hostingEnv = app.Services.GetRequiredService(); + Console.WriteLine("Hosting environment: " + hostingEnv.EnvironmentName); + + var serverAddresses = app.ServerFeatures.Get(); + if (serverAddresses != null) + { + foreach (var address in serverAddresses.Addresses) + { + Console.WriteLine("Now listening on: " + address); + } + } + Console.WriteLine("Application started. Press Ctrl+C to shut down."); - var appShutdownService = host.ApplicationServices.GetRequiredService(); + var appShutdownService = app.Services.GetRequiredService(); Console.CancelKeyPress += (sender, eventArgs) => { appShutdownService.RequestShutdown(); From 6758010e1af8af6fd775d9c8903237f03a030d4a Mon Sep 17 00:00:00 2001 From: Chris R Date: Wed, 16 Sep 2015 11:01:29 -0700 Subject: [PATCH 358/987] #353,#354 Add telemetry for begin/end request and unhandled exceptions. --- .../Internal/HostingEngine.cs | 30 ++++- .../WebHostBuilder.cs | 5 + src/Microsoft.AspNet.Hosting/project.json | 9 +- .../TestServerTests.cs | 107 ++++++++++++++++++ .../project.json | 1 + 5 files changed, 147 insertions(+), 5 deletions(-) diff --git a/src/Microsoft.AspNet.Hosting/Internal/HostingEngine.cs b/src/Microsoft.AspNet.Hosting/Internal/HostingEngine.cs index d77831fd18..50cd13443f 100644 --- a/src/Microsoft.AspNet.Hosting/Internal/HostingEngine.cs +++ b/src/Microsoft.AspNet.Hosting/Internal/HostingEngine.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Generic; +using System.Diagnostics.Tracing; using System.Linq; using System.Threading; using Microsoft.AspNet.Builder; @@ -82,6 +83,7 @@ namespace Microsoft.AspNet.Hosting.Internal var logger = _applicationServices.GetRequiredService>(); var contextFactory = _applicationServices.GetRequiredService(); var contextAccessor = _applicationServices.GetRequiredService(); + var telemetrySource = _applicationServices.GetRequiredService(); var server = ServerFactory.Start(_serverInstance, async features => { @@ -89,10 +91,32 @@ namespace Microsoft.AspNet.Hosting.Internal httpContext.ApplicationServices = _applicationServices; var requestIdentifier = GetRequestIdentifier(httpContext); - using (logger.BeginScope("Request Id: {RequestId}", requestIdentifier)) + if (telemetrySource.IsEnabled("Microsoft.AspNet.Hosting.BeginRequest")) { - contextAccessor.HttpContext = httpContext; - await application(httpContext); + telemetrySource.WriteTelemetry("Microsoft.AspNet.Hosting.BeginRequest", new { httpContext = httpContext }); + } + + try + { + using (logger.BeginScope("Request Id: {RequestId}", requestIdentifier)) + { + contextAccessor.HttpContext = httpContext; + await application(httpContext); + } + } + catch (Exception ex) + { + if (telemetrySource.IsEnabled("Microsoft.AspNet.Hosting.UnhandledException")) + { + telemetrySource.WriteTelemetry("Microsoft.AspNet.Hosting.UnhandledException", new { httpContext = httpContext, exception = ex }); + } + + throw; + } + + if (telemetrySource.IsEnabled("Microsoft.AspNet.Hosting.EndRequest")) + { + telemetrySource.WriteTelemetry("Microsoft.AspNet.Hosting.EndRequest", new { httpContext = httpContext }); } }); diff --git a/src/Microsoft.AspNet.Hosting/WebHostBuilder.cs b/src/Microsoft.AspNet.Hosting/WebHostBuilder.cs index 6efc8042d5..4d2bc9eebf 100644 --- a/src/Microsoft.AspNet.Hosting/WebHostBuilder.cs +++ b/src/Microsoft.AspNet.Hosting/WebHostBuilder.cs @@ -2,6 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.Diagnostics.Tracing; using Microsoft.AspNet.Builder; using Microsoft.AspNet.Hosting.Builder; using Microsoft.AspNet.Hosting.Internal; @@ -91,6 +92,10 @@ namespace Microsoft.AspNet.Hosting services.AddSingleton(); services.AddLogging(); + var telemetrySource = new TelemetryListener("Microsoft.AspNet"); + services.AddInstance(telemetrySource); + services.AddInstance(telemetrySource); + // Conjure up a RequestServices services.AddTransient(); diff --git a/src/Microsoft.AspNet.Hosting/project.json b/src/Microsoft.AspNet.Hosting/project.json index 00218c9fb5..c8b50aad56 100644 --- a/src/Microsoft.AspNet.Hosting/project.json +++ b/src/Microsoft.AspNet.Hosting/project.json @@ -19,10 +19,15 @@ "Microsoft.Framework.DependencyInjection": "1.0.0-*", "Microsoft.Framework.Logging": "1.0.0-*", "Microsoft.Dnx.Runtime.Abstractions": "1.0.0-*", - "Newtonsoft.Json": "6.0.6" + "Newtonsoft.Json": "6.0.6", + "System.Diagnostics.Tracing.Telemetry": "4.0.0-beta-*" }, "frameworks": { - "dnx451": { }, + "dnx451": { + "frameworkAssemblies": { + "System.Runtime": "" + } + }, "dnxcore50": { "dependencies": { "System.Console": "4.0.0-beta-*" diff --git a/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs b/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs index 47277d7286..ed4bc90a05 100644 --- a/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs +++ b/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs @@ -2,6 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.Diagnostics.Tracing; using System.IO; using System.Net; using System.Net.Http; @@ -13,6 +14,7 @@ using Microsoft.AspNet.Http; using Microsoft.Framework.Configuration; using Microsoft.Framework.DependencyInjection; using Microsoft.Framework.Logging; +using Microsoft.Framework.TelemetryAdapter; using Xunit; namespace Microsoft.AspNet.TestHost @@ -310,6 +312,111 @@ namespace Microsoft.AspNet.TestHost Assert.Equal("FoundFoo:False", await result.Content.ReadAsStringAsync()); } + [Fact] + public async Task BeginEndTelemetryAvailable() + { + TelemetryListener telemetryListener = null; + var server = TestServer.Create(app => + { + telemetryListener = app.ApplicationServices.GetRequiredService(); + app.Run(context => + { + return context.Response.WriteAsync("Hello World"); + }); + }); + var listener = new TestTelemetryListener(); + telemetryListener.SubscribeWithAdapter(listener); + var result = await server.CreateClient().GetStringAsync("/path"); + + Assert.Equal("Hello World", result); + Assert.NotNull(listener.BeginRequest?.HttpContext); + Assert.NotNull(listener.EndRequest?.HttpContext); + Assert.Null(listener.UnhandledException); + } + + [Fact] + public async Task ExceptionTelemetryAvailable() + { + TelemetryListener telemetryListener = null; + var server = TestServer.Create(app => + { + telemetryListener = app.ApplicationServices.GetRequiredService(); + app.Run(context => + { + throw new Exception("Test exception"); + }); + }); + var listener = new TestTelemetryListener(); + telemetryListener.SubscribeWithAdapter(listener); + await Assert.ThrowsAsync(() => server.CreateClient().GetAsync("/path")); + + Assert.NotNull(listener.BeginRequest?.HttpContext); + Assert.Null(listener.EndRequest?.HttpContext); + Assert.NotNull(listener.UnhandledException?.HttpContext); + Assert.NotNull(listener.UnhandledException?.Exception); + } + + public class TestTelemetryListener + { + public class OnBeginRequestEventData + { + public IProxyHttpContext HttpContext { get; set; } + } + + public OnBeginRequestEventData BeginRequest { get; set; } + + [TelemetryName("Microsoft.AspNet.Hosting.BeginRequest")] + public virtual void OnBeginRequest(IProxyHttpContext httpContext) + { + BeginRequest = new OnBeginRequestEventData() + { + HttpContext = httpContext, + }; + } + + public class OnEndRequestEventData + { + public IProxyHttpContext HttpContext { get; set; } + } + + public OnEndRequestEventData EndRequest { get; set; } + + [TelemetryName("Microsoft.AspNet.Hosting.EndRequest")] + public virtual void OnEndRequest(IProxyHttpContext httpContext) + { + EndRequest = new OnEndRequestEventData() + { + HttpContext = httpContext, + }; + } + + public class OnUnhandledExceptionEventData + { + public IProxyHttpContext HttpContext { get; set; } + public IProxyException Exception { get; set; } + } + + public OnUnhandledExceptionEventData UnhandledException { get; set; } + + [TelemetryName("Microsoft.AspNet.Hosting.UnhandledException")] + public virtual void OnUnhandledException(IProxyHttpContext httpContext, IProxyException exception) + { + UnhandledException = new OnUnhandledExceptionEventData() + { + HttpContext = httpContext, + Exception = exception, + }; + } + } + + public interface IProxyHttpContext + { + } + + public interface IProxyException + { + } + public class Startup { public void Configure(IApplicationBuilder builder) diff --git a/test/Microsoft.AspNet.TestHost.Tests/project.json b/test/Microsoft.AspNet.TestHost.Tests/project.json index b203628aa6..1d9db6febe 100644 --- a/test/Microsoft.AspNet.TestHost.Tests/project.json +++ b/test/Microsoft.AspNet.TestHost.Tests/project.json @@ -2,6 +2,7 @@ "dependencies": { "Microsoft.AspNet.Testing": "1.0.0-*", "Microsoft.AspNet.TestHost": "1.0.0-*", + "Microsoft.Framework.TelemetryAdapter": "1.0.0-*", "xunit.runner.aspnet": "2.0.0-aspnet-*" }, "commands": { From 9b061ececba620784a0fb54eb4bd3bf33509393e Mon Sep 17 00:00:00 2001 From: David Fowler Date: Wed, 16 Sep 2015 14:52:54 -0700 Subject: [PATCH 359/987] Dispose the service provider on app shutdown - Added a unit test #322 --- .../Internal/Application.cs | 1 + .../Fakes/FakeService.cs | 12 ++++++++- .../HostingEngineTests.cs | 27 +++++++++++++++++++ 3 files changed, 39 insertions(+), 1 deletion(-) diff --git a/src/Microsoft.AspNet.Hosting/Internal/Application.cs b/src/Microsoft.AspNet.Hosting/Internal/Application.cs index ecbb916a6e..0603b48628 100644 --- a/src/Microsoft.AspNet.Hosting/Internal/Application.cs +++ b/src/Microsoft.AspNet.Hosting/Internal/Application.cs @@ -32,6 +32,7 @@ namespace Microsoft.AspNet.Hosting.Internal public void Dispose() { _stop.Dispose(); + (_services as IDisposable)?.Dispose(); } } } diff --git a/test/Microsoft.AspNet.Hosting.Tests/Fakes/FakeService.cs b/test/Microsoft.AspNet.Hosting.Tests/Fakes/FakeService.cs index 75176f8928..8f90f3899b 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/Fakes/FakeService.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/Fakes/FakeService.cs @@ -1,7 +1,17 @@ // 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; + namespace Microsoft.AspNet.Hosting.Fakes { - public class FakeService : IFakeEveryService { } + public class FakeService : IFakeEveryService, IDisposable + { + public bool Disposed { get; private set; } + + public void Dispose() + { + Disposed = true; + } + } } \ No newline at end of file diff --git a/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs b/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs index 1ded347dbb..b831277232 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs @@ -7,6 +7,7 @@ using System.Collections.Generic; using System.IO; using System.Threading.Tasks; using Microsoft.AspNet.Builder; +using Microsoft.AspNet.Hosting.Fakes; using Microsoft.AspNet.Hosting.Internal; using Microsoft.AspNet.Hosting.Server; using Microsoft.AspNet.Hosting.Startup; @@ -92,6 +93,32 @@ namespace Microsoft.AspNet.Hosting Assert.Equal(1, _startInstances[0].DisposeCalls); } + [Fact] + public void HostingEngineDisposesServiceProvider() + { + var engine = CreateBuilder() + .UseServer(this) + .UseServices(s => + { + s.AddTransient(); + s.AddSingleton(); + }) + .UseStartup("Microsoft.AspNet.Hosting.Tests") + .Build() + .Start(); + + var singleton = (FakeService)engine.Services.GetService(); + var transient = (FakeService)engine.Services.GetService(); + + Assert.False(singleton.Disposed); + Assert.False(transient.Disposed); + + engine.Dispose(); + + Assert.True(singleton.Disposed); + Assert.True(transient.Disposed); + } + [Fact] public void HostingEngineNotifiesApplicationStarted() { From 82f58d5f1606e17d09f3c05302637a04e966130b Mon Sep 17 00:00:00 2001 From: David Fowler Date: Wed, 16 Sep 2015 15:01:22 -0700 Subject: [PATCH 360/987] CR Feedback --- src/Microsoft.AspNet.Hosting/Internal/Application.cs | 1 - src/Microsoft.AspNet.Hosting/Internal/HostingEngine.cs | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Microsoft.AspNet.Hosting/Internal/Application.cs b/src/Microsoft.AspNet.Hosting/Internal/Application.cs index 0603b48628..ecbb916a6e 100644 --- a/src/Microsoft.AspNet.Hosting/Internal/Application.cs +++ b/src/Microsoft.AspNet.Hosting/Internal/Application.cs @@ -32,7 +32,6 @@ namespace Microsoft.AspNet.Hosting.Internal public void Dispose() { _stop.Dispose(); - (_services as IDisposable)?.Dispose(); } } } diff --git a/src/Microsoft.AspNet.Hosting/Internal/HostingEngine.cs b/src/Microsoft.AspNet.Hosting/Internal/HostingEngine.cs index 50cd13443f..aa68a00689 100644 --- a/src/Microsoft.AspNet.Hosting/Internal/HostingEngine.cs +++ b/src/Microsoft.AspNet.Hosting/Internal/HostingEngine.cs @@ -127,6 +127,7 @@ namespace Microsoft.AspNet.Hosting.Internal _applicationLifetime.NotifyStopping(); server.Dispose(); _applicationLifetime.NotifyStopped(); + (_applicationServices as IDisposable)?.Dispose(); })); } From 6442fe8a8694ff839c633202aea4daa340ddd6c9 Mon Sep 17 00:00:00 2001 From: "N. Taylor Mullen" Date: Thu, 17 Sep 2015 18:32:39 -0700 Subject: [PATCH 361/987] Update nuget.exe and corresponding feeds to v3. --- NuGet.Config => NuGet.config | 2 +- build.cmd | 11 ++++++----- build.sh | 12 +++++++----- 3 files changed, 14 insertions(+), 11 deletions(-) rename NuGet.Config => NuGet.config (83%) diff --git a/NuGet.Config b/NuGet.config similarity index 83% rename from NuGet.Config rename to NuGet.config index 10cec18a32..1707938c61 100644 --- a/NuGet.Config +++ b/NuGet.config @@ -1,7 +1,7 @@ - + \ No newline at end of file diff --git a/build.cmd b/build.cmd index b54d91cf74..177997c42e 100644 --- a/build.cmd +++ b/build.cmd @@ -2,14 +2,15 @@ cd %~dp0 SETLOCAL -SET CACHED_NUGET=%LocalAppData%\NuGet\NuGet.exe +SET NUGET_VERSION=latest +SET CACHED_NUGET=%LocalAppData%\NuGet\nuget.%NUGET_VERSION%.exe SET BUILDCMD_KOREBUILD_VERSION="" SET BUILDCMD_DNX_VERSION="" IF EXIST %CACHED_NUGET% goto copynuget echo Downloading latest version of NuGet.exe... IF NOT EXIST %LocalAppData%\NuGet md %LocalAppData%\NuGet -@powershell -NoProfile -ExecutionPolicy unrestricted -Command "$ProgressPreference = 'SilentlyContinue'; Invoke-WebRequest 'https://www.nuget.org/nuget.exe' -OutFile '%CACHED_NUGET%'" +@powershell -NoProfile -ExecutionPolicy unrestricted -Command "$ProgressPreference = 'SilentlyContinue'; Invoke-WebRequest 'https://dist.nuget.org/win-x86-commandline/%NUGET_VERSION%/nuget.exe' -OutFile '%CACHED_NUGET%'" :copynuget IF EXIST .nuget\nuget.exe goto restore @@ -19,11 +20,11 @@ copy %CACHED_NUGET% .nuget\nuget.exe > nul :restore IF EXIST packages\KoreBuild goto run IF %BUILDCMD_KOREBUILD_VERSION%=="" ( - .nuget\NuGet.exe install KoreBuild -ExcludeVersion -o packages -nocache -pre + .nuget\nuget.exe install KoreBuild -ExcludeVersion -o packages -nocache -pre ) ELSE ( - .nuget\NuGet.exe install KoreBuild -version %BUILDCMD_KOREBUILD_VERSION% -ExcludeVersion -o packages -nocache -pre + .nuget\nuget.exe install KoreBuild -version %BUILDCMD_KOREBUILD_VERSION% -ExcludeVersion -o packages -nocache -pre ) -.nuget\NuGet.exe install Sake -ExcludeVersion -Source https://www.nuget.org/api/v2/ -Out packages +.nuget\nuget.exe install Sake -ExcludeVersion -Out packages IF "%SKIP_DNX_INSTALL%"=="1" goto run IF %BUILDCMD_DNX_VERSION%=="" ( diff --git a/build.sh b/build.sh index 68c3e8cb52..0c66139817 100755 --- a/build.sh +++ b/build.sh @@ -10,21 +10,23 @@ else fi fi mkdir -p $cachedir +nugetVersion=latest +cachePath=$cachedir/nuget.$nugetVersion.exe -url=https://www.nuget.org/nuget.exe +url=https://dist.nuget.org/win-x86-commandline/$nugetVersion/nuget.exe -if test ! -f $cachedir/nuget.exe; then - wget -O $cachedir/nuget.exe $url 2>/dev/null || curl -o $cachedir/nuget.exe --location $url /dev/null +if test ! -f $cachePath; then + wget -O $cachePath $url 2>/dev/null || curl -o $cachePath --location $url /dev/null fi if test ! -e .nuget; then mkdir .nuget - cp $cachedir/nuget.exe .nuget/nuget.exe + cp $cachePath .nuget/nuget.exe fi if test ! -d packages/KoreBuild; then mono .nuget/nuget.exe install KoreBuild -ExcludeVersion -o packages -nocache -pre - mono .nuget/nuget.exe install Sake -ExcludeVersion -Source https://www.nuget.org/api/v2/ -Out packages + mono .nuget/nuget.exe install Sake -ExcludeVersion -Out packages fi if ! type dnvm > /dev/null 2>&1; then From fa1896869ef77089baaa5716c6e1624014b8b379 Mon Sep 17 00:00:00 2001 From: Chris R Date: Fri, 18 Sep 2015 12:41:39 -0700 Subject: [PATCH 362/987] #358 Support HTTP_PLATFORM_PORT. --- .../Internal/HostingEngine.cs | 13 +++++++++ .../HostingEngineTests.cs | 29 ++++++++++++++++++- 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/src/Microsoft.AspNet.Hosting/Internal/HostingEngine.cs b/src/Microsoft.AspNet.Hosting/Internal/HostingEngine.cs index aa68a00689..28b72659d2 100644 --- a/src/Microsoft.AspNet.Hosting/Internal/HostingEngine.cs +++ b/src/Microsoft.AspNet.Hosting/Internal/HostingEngine.cs @@ -22,6 +22,9 @@ namespace Microsoft.AspNet.Hosting.Internal { public class HostingEngine : IHostingEngine { + // This is defined by IIS's HttpPlatformHandler. + private static readonly string ServerPort = "HTTP_PLATFORM_PORT"; + private readonly IServiceCollection _applicationServiceCollection; private readonly IStartupLoader _startupLoader; private readonly ApplicationLifetime _applicationLifetime; @@ -188,6 +191,16 @@ namespace Microsoft.AspNet.Hosting.Internal var builder = builderFactory.CreateBuilder(_serverInstance); builder.ApplicationServices = _applicationServices; + var port = _config[ServerPort]; + if (!string.IsNullOrEmpty(port)) + { + var addresses = builder.ServerFeatures.Get()?.Addresses; + if (addresses != null && !addresses.IsReadOnly) + { + addresses.Add(port); + } + } + var startupFilters = _applicationServices.GetService>(); var configure = Startup.ConfigureDelegate; foreach (var filter in startupFilters) diff --git a/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs b/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs index b831277232..16fbe6149a 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs @@ -5,6 +5,7 @@ using System; using System.Collections; using System.Collections.Generic; using System.IO; +using System.Linq; using System.Threading.Tasks; using Microsoft.AspNet.Builder; using Microsoft.AspNet.Hosting.Fakes; @@ -14,6 +15,7 @@ using Microsoft.AspNet.Hosting.Startup; using Microsoft.AspNet.Http; using Microsoft.AspNet.Http.Features; using Microsoft.AspNet.Http.Features.Internal; +using Microsoft.AspNet.Server.Features; using Microsoft.AspNet.Testing.xunit; using Microsoft.Dnx.Runtime.Infrastructure; using Microsoft.Framework.Configuration; @@ -75,6 +77,24 @@ namespace Microsoft.AspNet.Hosting Assert.NotNull(host.ApplicationServices.GetRequiredService()); } + [Fact] + public void CanSpecifyPortConfig() + { + var vals = new Dictionary + { + { "Hosting:Server", "Microsoft.AspNet.Hosting.Tests" }, + { "HTTP_PLATFORM_PORT", "abc123" } + }; + + var builder = new ConfigurationBuilder() + .AddInMemoryCollection(vals); + var config = builder.Build(); + var host = CreateBuilder(config).Build(); + var app = host.Start(); + Assert.NotNull(host.ApplicationServices.GetRequiredService()); + Assert.Equal("abc123", app.ServerFeatures.Get().Addresses.First()); + } + [Fact] public void HostingEngineCanBeStarted() { @@ -397,7 +417,9 @@ namespace Microsoft.AspNet.Hosting public IFeatureCollection Initialize(IConfiguration configuration) { - return null; + var features = new FeatureCollection(); + features.Set(new ServerAddressesFeature()); + return features; } public IDisposable Start(IFeatureCollection serverFeatures, Func application) @@ -470,5 +492,10 @@ namespace Microsoft.AspNet.Hosting yield break; } } + + private class ServerAddressesFeature : IServerAddressesFeature + { + public ICollection Addresses { get; } = new List(); + } } } From 285da613e462d996c0e090ee1a614bd0a866d01c Mon Sep 17 00:00:00 2001 From: Chris R Date: Tue, 22 Sep 2015 08:46:48 -0700 Subject: [PATCH 363/987] #358 Redo port, add default address. --- .../Internal/HostingEngine.cs | 16 +++++++++++----- .../HostingEngineTests.cs | 19 ++++++++++++++++++- 2 files changed, 29 insertions(+), 6 deletions(-) diff --git a/src/Microsoft.AspNet.Hosting/Internal/HostingEngine.cs b/src/Microsoft.AspNet.Hosting/Internal/HostingEngine.cs index 28b72659d2..986def36af 100644 --- a/src/Microsoft.AspNet.Hosting/Internal/HostingEngine.cs +++ b/src/Microsoft.AspNet.Hosting/Internal/HostingEngine.cs @@ -191,13 +191,19 @@ namespace Microsoft.AspNet.Hosting.Internal var builder = builderFactory.CreateBuilder(_serverInstance); builder.ApplicationServices = _applicationServices; - var port = _config[ServerPort]; - if (!string.IsNullOrEmpty(port)) + var addresses = builder.ServerFeatures?.Get()?.Addresses; + if (addresses != null && !addresses.IsReadOnly) { - var addresses = builder.ServerFeatures.Get()?.Addresses; - if (addresses != null && !addresses.IsReadOnly) + var port = _config[ServerPort]; + if (!string.IsNullOrEmpty(port)) { - addresses.Add(port); + addresses.Add("http://localhost:" + port); + } + + // Provide a default address if there aren't any configured. + if (addresses.Count == 0) + { + addresses.Add("http://localhost:5000"); } } diff --git a/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs b/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs index 16fbe6149a..ded586de90 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs @@ -92,7 +92,24 @@ namespace Microsoft.AspNet.Hosting var host = CreateBuilder(config).Build(); var app = host.Start(); Assert.NotNull(host.ApplicationServices.GetRequiredService()); - Assert.Equal("abc123", app.ServerFeatures.Get().Addresses.First()); + Assert.Equal("http://localhost:abc123", app.ServerFeatures.Get().Addresses.First()); + } + + [Fact] + public void CanDefaultAddresseIfNotConfigured() + { + var vals = new Dictionary + { + { "Hosting:Server", "Microsoft.AspNet.Hosting.Tests" } + }; + + var builder = new ConfigurationBuilder() + .AddInMemoryCollection(vals); + var config = builder.Build(); + var host = CreateBuilder(config).Build(); + var app = host.Start(); + Assert.NotNull(host.ApplicationServices.GetRequiredService()); + Assert.Equal("http://localhost:5000", app.ServerFeatures.Get().Addresses.First()); } [Fact] From 49520a2a73251a9f718743df4a43d26514021767 Mon Sep 17 00:00:00 2001 From: Hao Kung Date: Wed, 23 Sep 2015 13:33:07 -0700 Subject: [PATCH 364/987] Switch to IServiceProvidersFeature for RequestServices --- .../RequestServicesContainerFeature.cs | 70 +++++++++++++ .../RequestServicesContainerMiddleware.cs | 31 +++--- .../TestServerTests.cs | 99 +++++++++++++++++++ 3 files changed, 182 insertions(+), 18 deletions(-) create mode 100644 src/Microsoft.AspNet.Hosting/Internal/RequestServicesContainerFeature.cs diff --git a/src/Microsoft.AspNet.Hosting/Internal/RequestServicesContainerFeature.cs b/src/Microsoft.AspNet.Hosting/Internal/RequestServicesContainerFeature.cs new file mode 100644 index 0000000000..4edc13392b --- /dev/null +++ b/src/Microsoft.AspNet.Hosting/Internal/RequestServicesContainerFeature.cs @@ -0,0 +1,70 @@ +// 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; +using Microsoft.AspNet.Http.Features.Internal; +using Microsoft.Framework.DependencyInjection; + +namespace Microsoft.AspNet.Hosting.Internal +{ + public class RequestServicesFeature : IServiceProvidersFeature, IDisposable + { + private IServiceProvider _appServices; + private IServiceProvider _requestServices; + private IServiceScope _scope; + private bool _requestServicesSet; + + public RequestServicesFeature(IServiceProvider applicationServices) + { + if (applicationServices == null) + { + throw new ArgumentNullException(nameof(applicationServices)); + } + + ApplicationServices = applicationServices; + } + + public IServiceProvider ApplicationServices + { + get + { + return _appServices; + } + set + { + if (value == null) + { + throw new ArgumentNullException(nameof(value)); + } + _appServices = value; + } + } + + public IServiceProvider RequestServices + { + get + { + if (!_requestServicesSet) + { + _scope = ApplicationServices.GetRequiredService().CreateScope(); + _requestServices = _scope.ServiceProvider; + _requestServicesSet = true; + } + return _requestServices; + } + + set + { + _requestServicesSet = true; + RequestServices = value; + } + } + + public void Dispose() + { + _scope?.Dispose(); + _scope = null; + _requestServices = null; + } + } +} \ No newline at end of file diff --git a/src/Microsoft.AspNet.Hosting/Internal/RequestServicesContainerMiddleware.cs b/src/Microsoft.AspNet.Hosting/Internal/RequestServicesContainerMiddleware.cs index ab3fda31ab..25949db506 100644 --- a/src/Microsoft.AspNet.Hosting/Internal/RequestServicesContainerMiddleware.cs +++ b/src/Microsoft.AspNet.Hosting/Internal/RequestServicesContainerMiddleware.cs @@ -5,6 +5,8 @@ using System; using System.Threading.Tasks; using Microsoft.AspNet.Builder; using Microsoft.AspNet.Http; +using Microsoft.AspNet.Http.Features; +using Microsoft.AspNet.Http.Features.Internal; using Microsoft.Framework.DependencyInjection; namespace Microsoft.AspNet.Hosting.Internal @@ -20,7 +22,6 @@ namespace Microsoft.AspNet.Hosting.Internal { throw new ArgumentNullException(nameof(next)); } - if (services == null) { throw new ArgumentNullException(nameof(services)); @@ -37,32 +38,26 @@ namespace Microsoft.AspNet.Hosting.Internal throw new ArgumentNullException(nameof(httpContext)); } - // All done if there request services is set - if (httpContext.RequestServices != null) + var existingFeature = httpContext.Features.Get(); + + // All done if request services is set + if (existingFeature?.RequestServices != null) { await _next.Invoke(httpContext); return; } - var priorApplicationServices = httpContext.ApplicationServices; - var serviceProvider = priorApplicationServices ?? _services; - var scopeFactory = serviceProvider.GetRequiredService(); - - try + using (var feature = new RequestServicesFeature(_services)) { - // Creates the scope and temporarily swap services - using (var scope = scopeFactory.CreateScope()) + try { - httpContext.ApplicationServices = serviceProvider; - httpContext.RequestServices = scope.ServiceProvider; - + httpContext.Features.Set(feature); await _next.Invoke(httpContext); } - } - finally - { - httpContext.RequestServices = null; - httpContext.ApplicationServices = priorApplicationServices; + finally + { + httpContext.Features.Set(existingFeature); + } } } } diff --git a/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs b/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs index ed4bc90a05..a41a9141f8 100644 --- a/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs +++ b/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs @@ -11,6 +11,8 @@ using Microsoft.AspNet.Builder; using Microsoft.AspNet.Hosting; using Microsoft.AspNet.Hosting.Startup; using Microsoft.AspNet.Http; +using Microsoft.AspNet.Http.Features; +using Microsoft.AspNet.Http.Features.Internal; using Microsoft.Framework.Configuration; using Microsoft.Framework.DependencyInjection; using Microsoft.Framework.Logging; @@ -133,6 +135,103 @@ namespace Microsoft.AspNet.TestHost Assert.Equal("Found:True", result); } + [Fact] + public async Task SettingApplicationServicesOnFeatureToNullThrows() + { + var server = TestServer.Create(app => + { + app.Run(context => + { + var feature = context.Features.Get(); + Assert.Throws(() => feature.ApplicationServices = null); + return context.Response.WriteAsync("Success"); + }); + }); + string result = await server.CreateClient().GetStringAsync("/path"); + Assert.Equal("Success", result); + } + + public class ReplaceServiceProvidersFeatureFilter : IStartupFilter, IServiceProvidersFeature + { + public ReplaceServiceProvidersFeatureFilter(IServiceProvider appServices, IServiceProvider requestServices) + { + ApplicationServices = appServices; + RequestServices = requestServices; + } + + public IServiceProvider ApplicationServices { get; set; } + + public IServiceProvider RequestServices { get; set; } + + public Action Configure(Action next) + { + return app => + { + app.Use(async (context, nxt) => + { + context.Features.Set(this); + await nxt(); + }); + next(app); + }; + } + } + + [Fact] + public async Task ExistingServiceProviderFeatureWillNotBeReplaced() + { + var appServices = new ServiceCollection().BuildServiceProvider(); + var server = TestServer.Create(app => + { + app.Run(context => + { + Assert.Equal(appServices, context.ApplicationServices); + Assert.Equal(appServices, context.RequestServices); + return context.Response.WriteAsync("Success"); + }); + }, + services => services.AddInstance(new ReplaceServiceProvidersFeatureFilter(appServices, appServices))); + var result = await server.CreateClient().GetStringAsync("/path"); + Assert.Equal("Success", result); + } + + public class NullServiceProvidersFeatureFilter : IStartupFilter, IServiceProvidersFeature + { + public IServiceProvider ApplicationServices { get; set; } + + public IServiceProvider RequestServices { get; set; } + + public Action Configure(Action next) + { + return app => + { + app.Use(async (context, nxt) => + { + context.Features.Set(this); + await nxt(); + }); + next(app); + }; + } + } + + [Fact] + public async Task WillReplaceServiceProviderFeatureWithNullRequestServices() + { + var server = TestServer.Create(app => + { + app.Run(context => + { + Assert.NotNull(context.ApplicationServices); + Assert.NotNull(context.RequestServices); + return context.Response.WriteAsync("Success"); + }); + }, + services => services.AddTransient()); + var result = await server.CreateClient().GetStringAsync("/path"); + Assert.Equal("Success", result); + } + public class EnsureApplicationServicesFilter : IStartupFilter { public Action Configure(Action next) From cde733a63a0ddb26df5fa2a1fc629c2c98f0aa4e Mon Sep 17 00:00:00 2001 From: Ajay Bhargav Baaskaran Date: Wed, 23 Sep 2015 12:53:00 -0700 Subject: [PATCH 365/987] Enabling NuGetPackageVerifier --- NuGetPackageVerifier.json | 29 +++++++++++++++++++ .../Properties/AssemblyInfo.cs | 8 +++++ 2 files changed, 37 insertions(+) create mode 100644 NuGetPackageVerifier.json create mode 100644 src/Microsoft.AspNet.Server.Testing/Properties/AssemblyInfo.cs diff --git a/NuGetPackageVerifier.json b/NuGetPackageVerifier.json new file mode 100644 index 0000000000..c599e23fea --- /dev/null +++ b/NuGetPackageVerifier.json @@ -0,0 +1,29 @@ +{ + "adx": { // Packages written by the ADX team and that ship on NuGet.org + "rules": [ + "AssemblyHasDocumentFileRule", + "AssemblyHasVersionAttributesRule", + "AssemblyHasServicingAttributeRule", + "AssemblyHasNeutralResourcesLanguageAttributeRule", + "SatellitePackageRule", + "StrictSemanticVersionValidationRule" + ], + "packages": { + "Microsoft.AspNet.Hosting": { }, + "Microsoft.AspNet.Hosting.Abstractions": { }, + "Microsoft.AspNet.Hosting.Server.Abstractions": { }, + "Microsoft.AspNet.Server.Testing": { }, + "Microsoft.AspNet.TestHost": { } + } + }, + "Default": { // Rules to run for packages not listed in any other set. + "rules": [ + "AssemblyHasDocumentFileRule", + "AssemblyHasVersionAttributesRule", + "AssemblyHasServicingAttributeRule", + "AssemblyHasNeutralResourcesLanguageAttributeRule", + "SatellitePackageRule", + "StrictSemanticVersionValidationRule" + ] + } +} \ No newline at end of file diff --git a/src/Microsoft.AspNet.Server.Testing/Properties/AssemblyInfo.cs b/src/Microsoft.AspNet.Server.Testing/Properties/AssemblyInfo.cs new file mode 100644 index 0000000000..aab4e278a4 --- /dev/null +++ b/src/Microsoft.AspNet.Server.Testing/Properties/AssemblyInfo.cs @@ -0,0 +1,8 @@ +// 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.Reflection; +using System.Resources; + +[assembly: AssemblyMetadata("Serviceable", "True")] +[assembly: NeutralResourcesLanguage("en-us")] From 520fc2b5fdee91c7bded01dbade2cfdf18ff412b Mon Sep 17 00:00:00 2001 From: "N. Taylor Mullen" Date: Thu, 24 Sep 2015 17:09:29 -0700 Subject: [PATCH 366/987] Fixed stack overflow when setting RequestServices - Added tests --- .../RequestServicesContainerFeature.cs | 2 +- .../TestServerTests.cs | 26 +++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/src/Microsoft.AspNet.Hosting/Internal/RequestServicesContainerFeature.cs b/src/Microsoft.AspNet.Hosting/Internal/RequestServicesContainerFeature.cs index 4edc13392b..6a0972fe58 100644 --- a/src/Microsoft.AspNet.Hosting/Internal/RequestServicesContainerFeature.cs +++ b/src/Microsoft.AspNet.Hosting/Internal/RequestServicesContainerFeature.cs @@ -55,8 +55,8 @@ namespace Microsoft.AspNet.Hosting.Internal set { + _requestServices = value; _requestServicesSet = true; - RequestServices = value; } } diff --git a/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs b/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs index a41a9141f8..174b29c092 100644 --- a/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs +++ b/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs @@ -151,6 +151,31 @@ namespace Microsoft.AspNet.TestHost Assert.Equal("Success", result); } + [Fact] + public async Task CanSetCustomServiceProvider() + { + var server = TestServer.Create(app => + { + app.Run(context => + { + context.ApplicationServices = new ServiceCollection() + .AddTransient() + .BuildServiceProvider(); + + context.RequestServices = new ServiceCollection() + .AddTransient() + .BuildServiceProvider(); + + var s1 = context.ApplicationServices.GetRequiredService(); + var s2 = context.RequestServices.GetRequiredService(); + + return context.Response.WriteAsync("Success"); + }); + }); + string result = await server.CreateClient().GetStringAsync("/path"); + Assert.Equal("Success", result); + } + public class ReplaceServiceProvidersFeatureFilter : IStartupFilter, IServiceProvidersFeature { public ReplaceServiceProvidersFeatureFilter(IServiceProvider appServices, IServiceProvider requestServices) @@ -232,6 +257,7 @@ namespace Microsoft.AspNet.TestHost Assert.Equal("Success", result); } + public class EnsureApplicationServicesFilter : IStartupFilter { public Action Configure(Action next) From a9e7948d726c1d66dd5a7865ebcb4f60a6ec6c0d Mon Sep 17 00:00:00 2001 From: Chris R Date: Wed, 23 Sep 2015 20:54:42 -0700 Subject: [PATCH 367/987] #77 Catch startup exceptions and show them in the browser. --- .../Internal/HostingEngine.cs | 110 +++- src/Microsoft.AspNet.Hosting/Program.cs | 2 +- .../Startup/StartupExceptionPage.cs | 520 ++++++++++++++++++ .../WebHostBuilder.cs | 10 +- .../resources/Compilation_Exception.html | 6 + .../compiler/resources/GenericError.html | 151 +++++ .../resources/GenericError_Exception.html | 8 + .../resources/GenericError_Footer.html | 3 + .../resources/GenericError_Message.html | 3 + src/Microsoft.AspNet.Hosting/project.json | 4 +- .../Fakes/RuntimeEnvironment.cs | 20 + .../Fakes/StartupConfigureServicesThrows.cs | 22 + .../Fakes/StartupConfigureThrows.cs | 21 + .../Fakes/StartupCtorThrows.cs | 20 + .../Fakes/StartupStaticCtorThrows.cs | 20 + .../WebHostBuilderTests.cs | 115 +++- 16 files changed, 1001 insertions(+), 34 deletions(-) create mode 100644 src/Microsoft.AspNet.Hosting/Startup/StartupExceptionPage.cs create mode 100644 src/Microsoft.AspNet.Hosting/compiler/resources/Compilation_Exception.html create mode 100644 src/Microsoft.AspNet.Hosting/compiler/resources/GenericError.html create mode 100644 src/Microsoft.AspNet.Hosting/compiler/resources/GenericError_Exception.html create mode 100644 src/Microsoft.AspNet.Hosting/compiler/resources/GenericError_Footer.html create mode 100644 src/Microsoft.AspNet.Hosting/compiler/resources/GenericError_Message.html create mode 100644 test/Microsoft.AspNet.Hosting.Tests/Fakes/RuntimeEnvironment.cs create mode 100644 test/Microsoft.AspNet.Hosting.Tests/Fakes/StartupConfigureServicesThrows.cs create mode 100644 test/Microsoft.AspNet.Hosting.Tests/Fakes/StartupConfigureThrows.cs create mode 100644 test/Microsoft.AspNet.Hosting.Tests/Fakes/StartupCtorThrows.cs create mode 100644 test/Microsoft.AspNet.Hosting.Tests/Fakes/StartupStaticCtorThrows.cs diff --git a/src/Microsoft.AspNet.Hosting/Internal/HostingEngine.cs b/src/Microsoft.AspNet.Hosting/Internal/HostingEngine.cs index 986def36af..97bdc06e23 100644 --- a/src/Microsoft.AspNet.Hosting/Internal/HostingEngine.cs +++ b/src/Microsoft.AspNet.Hosting/Internal/HostingEngine.cs @@ -14,6 +14,7 @@ using Microsoft.AspNet.Http; using Microsoft.AspNet.Http.Features; using Microsoft.AspNet.Http.Features.Internal; using Microsoft.AspNet.Server.Features; +using Microsoft.Dnx.Runtime; using Microsoft.Framework.Configuration; using Microsoft.Framework.DependencyInjection; using Microsoft.Framework.Logging; @@ -24,11 +25,13 @@ namespace Microsoft.AspNet.Hosting.Internal { // This is defined by IIS's HttpPlatformHandler. private static readonly string ServerPort = "HTTP_PLATFORM_PORT"; + private static readonly string DetailedErrors = "Hosting:DetailedErrors"; private readonly IServiceCollection _applicationServiceCollection; private readonly IStartupLoader _startupLoader; private readonly ApplicationLifetime _applicationLifetime; private readonly IConfiguration _config; + private readonly bool _captureStartupErrors; private IServiceProvider _applicationServices; @@ -45,7 +48,8 @@ namespace Microsoft.AspNet.Hosting.Internal public HostingEngine( IServiceCollection appServices, IStartupLoader startupLoader, - IConfiguration config) + IConfiguration config, + bool captureStartupErrors) { if (appServices == null) { @@ -65,6 +69,7 @@ namespace Microsoft.AspNet.Hosting.Internal _config = config; _applicationServiceCollection = appServices; _startupLoader = startupLoader; + _captureStartupErrors = captureStartupErrors; _applicationLifetime = new ApplicationLifetime(); } @@ -79,8 +84,6 @@ namespace Microsoft.AspNet.Hosting.Internal public virtual IApplication Start() { - EnsureApplicationServices(); - var application = BuildApplication(); var logger = _applicationServices.GetRequiredService>(); @@ -174,6 +177,67 @@ namespace Microsoft.AspNet.Hosting.Internal } private RequestDelegate BuildApplication() + { + try + { + EnsureApplicationServices(); + EnsureServer(); + + var builderFactory = _applicationServices.GetRequiredService(); + var builder = builderFactory.CreateBuilder(_serverInstance); + builder.ApplicationServices = _applicationServices; + + var startupFilters = _applicationServices.GetService>(); + var configure = Startup.ConfigureDelegate; + foreach (var filter in startupFilters) + { + configure = filter.Configure(configure); + } + + configure(builder); + + return builder.Build(); + } + catch (Exception ex) + { + if (!_captureStartupErrors) + { + throw; + } + + // EnsureApplicationServices may have failed due to a missing or throwing Startup class. + if (_applicationServices == null) + { + _applicationServices = _applicationServiceCollection.BuildServiceProvider(); + } + + EnsureServer(); + + // Write errors to standard out so they can be retrieved when not in development mode. + Console.Out.WriteLine("Application startup exception: " + ex.ToString()); + var logger = _applicationServices.GetRequiredService>(); + logger.LogError("Application startup exception", ex); + + // Generate an HTML error page. + var runtimeEnv = _applicationServices.GetRequiredService(); + var hostingEnv = _applicationServices.GetRequiredService(); + var showDetailedErrors = hostingEnv.IsDevelopment() + || string.Equals("true", _config[DetailedErrors], StringComparison.OrdinalIgnoreCase) + || string.Equals("1", _config[DetailedErrors], StringComparison.OrdinalIgnoreCase); + var errorBytes = StartupExceptionPage.GenerateErrorHtml(showDetailedErrors, runtimeEnv, ex); + + return context => + { + context.Response.StatusCode = 500; + context.Response.Headers["Cache-Control"] = "private, max-age=0"; + context.Response.ContentType = "text/html; charset=utf-8"; + context.Response.ContentLength = errorBytes.Length; + return context.Response.Body.WriteAsync(errorBytes, 0, errorBytes.Length); + }; + } + } + + private void EnsureServer() { if (ServerFactory == null) { @@ -186,37 +250,25 @@ namespace Microsoft.AspNet.Hosting.Internal ServerFactory = _applicationServices.GetRequiredService().LoadServerFactory(ServerFactoryLocation); } - _serverInstance = ServerFactory.Initialize(_config); - var builderFactory = _applicationServices.GetRequiredService(); - var builder = builderFactory.CreateBuilder(_serverInstance); - builder.ApplicationServices = _applicationServices; - - var addresses = builder.ServerFeatures?.Get()?.Addresses; - if (addresses != null && !addresses.IsReadOnly) + if (_serverInstance == null) { - var port = _config[ServerPort]; - if (!string.IsNullOrEmpty(port)) + _serverInstance = ServerFactory.Initialize(_config); + var addresses = _serverInstance?.Get()?.Addresses; + if (addresses != null && !addresses.IsReadOnly) { - addresses.Add("http://localhost:" + port); - } + var port = _config[ServerPort]; + if (!string.IsNullOrEmpty(port)) + { + addresses.Add("http://localhost:" + port); + } - // Provide a default address if there aren't any configured. - if (addresses.Count == 0) - { - addresses.Add("http://localhost:5000"); + // Provide a default address if there aren't any configured. + if (addresses.Count == 0) + { + addresses.Add("http://localhost:5000"); + } } } - - var startupFilters = _applicationServices.GetService>(); - var configure = Startup.ConfigureDelegate; - foreach (var filter in startupFilters) - { - configure = filter.Configure(configure); - } - - configure(builder); - - return builder.Build(); } private string GetRequestIdentifier(HttpContext httpContext) diff --git a/src/Microsoft.AspNet.Hosting/Program.cs b/src/Microsoft.AspNet.Hosting/Program.cs index 4cde138e65..fe4b261ffd 100644 --- a/src/Microsoft.AspNet.Hosting/Program.cs +++ b/src/Microsoft.AspNet.Hosting/Program.cs @@ -36,7 +36,7 @@ namespace Microsoft.AspNet.Hosting builder.AddCommandLine(args); var config = builder.Build(); - var host = new WebHostBuilder(_serviceProvider, config).Build(); + var host = new WebHostBuilder(_serviceProvider, config, captureStartupErrors: true).Build(); using (var app = host.Start()) { var hostingEnv = app.Services.GetRequiredService(); diff --git a/src/Microsoft.AspNet.Hosting/Startup/StartupExceptionPage.cs b/src/Microsoft.AspNet.Hosting/Startup/StartupExceptionPage.cs new file mode 100644 index 0000000000..70b6befd8d --- /dev/null +++ b/src/Microsoft.AspNet.Hosting/Startup/StartupExceptionPage.cs @@ -0,0 +1,520 @@ +// 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; +using System.Collections.Generic; +using System.Diagnostics; +using System.Globalization; +using System.IO; +using System.Linq; +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.ExceptionServices; +using System.Text; +using Microsoft.Dnx.Compilation; +using Microsoft.Dnx.Runtime; +using Microsoft.Framework.WebEncoders; + +namespace Microsoft.AspNet.Hosting.Startup +{ + internal static class StartupExceptionPage + { + private const int MaxCompilationErrorsToShow = 20; + + private static readonly string _errorPageFormatString = GetResourceString("GenericError.html", escapeBraces: true); + private static readonly string _errorMessageFormatString = GetResourceString("GenericError_Message.html"); + private static readonly string _errorExceptionFormatString = GetResourceString("GenericError_Exception.html"); + private static readonly string _errorFooterFormatString = GetResourceString("GenericError_Footer.html"); + private static readonly string _compilationExceptionFormatString = GetResourceString("Compilation_Exception.html"); + + public static byte[] GenerateErrorHtml(bool showDetails, IRuntimeEnvironment runtimeEnvironment, params object[] errorDetails) + { + if (!showDetails) + { + errorDetails = new[] { "An error occurred while starting the application." }; + } + + // Build the message for each error + var wasSourceCodeWrittenOntoPage = false; + var builder = new StringBuilder(); + var rawExceptionDetails = new StringBuilder(); + + foreach (object error in errorDetails ?? new object[0]) + { + var ex = error as Exception; + if (ex == null && error is ExceptionDispatchInfo) + { + ex = ((ExceptionDispatchInfo)error).SourceException; + } + + if (ex != null) + { + var flattenedExceptions = FlattenAndReverseExceptionTree(ex); + + var compilationException = flattenedExceptions.OfType() + .FirstOrDefault(); + if (compilationException != null) + { + WriteException(compilationException, builder, ref wasSourceCodeWrittenOntoPage); + + var compilationErrorMessages = compilationException.CompilationFailures + .SelectMany(f => f.Messages.Select(m => m.FormattedMessage)) + .Take(MaxCompilationErrorsToShow); + + WriteRawExceptionDetails("Show raw compilation error details", compilationErrorMessages, rawExceptionDetails); + } + else + { + foreach (var innerEx in flattenedExceptions) + { + WriteException(innerEx, builder, ref wasSourceCodeWrittenOntoPage); + } + + WriteRawExceptionDetails("Show raw exception details", new[] { ex.ToString() }, rawExceptionDetails); + } + } + else + { + var message = Convert.ToString(error, CultureInfo.InvariantCulture); + WriteMessage(message, builder); + } + } + + // Generate the footer + var footer = showDetails ? GenerateFooterEncoded(runtimeEnvironment) : null; + + // And generate the full markup + return Encoding.UTF8.GetBytes(string.Format(CultureInfo.InvariantCulture, _errorPageFormatString, builder, rawExceptionDetails, footer)); + } + + private static string BuildCodeSnippetDiv(StackFrame frame) + { + var filename = frame.GetFileName(); + if (!string.IsNullOrEmpty(filename)) + { + int failingLineNumber = frame.GetFileLineNumber(); + if (failingLineNumber >= 1) + { + var lines = GetFailingCallSiteInFile(filename, failingLineNumber); + if (lines != null) + { + return @"
" + + @"
" + HtmlEncodeAndReplaceLineBreaks(filename) + "
" + Environment.NewLine + + string.Join(Environment.NewLine, lines) + "
" + Environment.NewLine; + } + } + } + + // fallback + return null; + } + + private static string BuildLineForStackFrame(StackFrame frame) + { + var builder = new StringBuilder("
");
+            var method = frame.GetMethod();
+
+            // Special case: no method available
+            if (method == null)
+            {
+                return null;
+            }
+
+            // First, write the type name
+            var type = method.DeclaringType;
+            if (type != null)
+            {
+                // Special-case ExceptionDispatchInfo.Throw()
+                if (type == typeof(ExceptionDispatchInfo) && method.Name == "Throw")
+                {
+                    return @"
--- exception rethrown ---
"; + } + + string prefix, friendlyName; + SplitTypeIntoPrefixAndFriendlyName(type, out prefix, out friendlyName); + builder.AppendFormat(CultureInfo.InvariantCulture, @"at {0}", HtmlEncodeAndReplaceLineBreaks(prefix)); + builder.Append(HtmlEncodeAndReplaceLineBreaks(friendlyName)); + } + + // Next, write the method signature + builder.Append(HtmlEncodeAndReplaceLineBreaks("." + method.Name)); + + // Is this method generic? + if (method.IsGenericMethod) + { + builder.Append(HtmlEncodeAndReplaceLineBreaks(BuildMethodGenericParametersUnescaped(method))); + } + + // Build method parameters + builder.AppendFormat(CultureInfo.InvariantCulture, @"{0}", HtmlEncodeAndReplaceLineBreaks(BuildMethodParametersUnescaped(method))); + + // Do we have source information for this frame? + if (frame.GetILOffset() != -1) + { + var filename = frame.GetFileName(); + if (!string.IsNullOrEmpty(filename)) + { + builder.AppendFormat(CultureInfo.InvariantCulture, " in {0}:line {1:D}", HtmlEncodeAndReplaceLineBreaks(filename), frame.GetFileLineNumber()); + } + } + + // Finish + builder.Append("
"); + return builder.ToString(); + } + + private static string BuildMethodGenericParametersUnescaped(MethodBase method) + { + Debug.Assert(method.IsGenericMethod); + return "<" + string.Join(", ", method.GetGenericArguments().Select(PrettyPrintTypeName)) + ">"; + } + + private static string BuildMethodParametersUnescaped(MethodBase method) + { + return "(" + string.Join(", ", method.GetParameters().Select(p => { + Type parameterType = p.ParameterType; + return ((parameterType != null) ? PrettyPrintTypeName(parameterType) : "?") + " " + p.Name; + })) + ")"; + } + + private static void BuildCodeSnippetDiv(CompilationFailure failure, + StringBuilder builder, + ref int totalErrorsShown) + { + const int NumContextLines = 3; + var fileName = failure.SourceFilePath; + if (totalErrorsShown < MaxCompilationErrorsToShow && + !string.IsNullOrEmpty(fileName)) + { + builder.Append(@"
") + .AppendFormat(@"
{0}
", HtmlEncodeAndReplaceLineBreaks(fileName)) + .AppendLine(); + + IEnumerable fileContent; + if (string.IsNullOrEmpty(failure.SourceFileContent)) + { + fileContent = File.ReadLines(fileName); + } + else + { + fileContent = failure.SourceFileContent.Split(new[] { Environment.NewLine }, StringSplitOptions.None); + } + foreach (var message in failure.Messages) + { + if (totalErrorsShown++ > MaxCompilationErrorsToShow) + { + break; + } + + if (totalErrorsShown > 1) + { + builder.AppendLine("
"); + } + + builder.Append(@"
") + .Append(HtmlEncodeAndReplaceLineBreaks(message.Message)) + .Append("
"); + + // StartLine and EndLine are 1-based + var startLine = message.StartLine - 1; + var endLine = message.EndLine - 1; + var preContextIndex = Math.Max(startLine - NumContextLines, 0); + var index = preContextIndex + 1; + foreach (var line in fileContent.Skip(preContextIndex).Take(startLine - preContextIndex)) + { + builder.Append(@"
") + .AppendFormat(@"{0}", index++) + .Append(HtmlEncodeAndReplaceLineBreaks(line)) + .AppendLine("
"); + } + + var numErrorLines = 1 + Math.Max(0, endLine - startLine); + foreach (var line in fileContent.Skip(startLine).Take(numErrorLines)) + { + builder.Append(@"
") + .AppendFormat(@"{0}", index++) + .Append(HtmlEncodeAndReplaceLineBreaks(line)) + .AppendLine("
"); + } + foreach (var line in fileContent.Skip(message.EndLine).Take(NumContextLines)) + { + builder.Append(@"
") + .AppendFormat(@"{0}", index++) + .Append(HtmlEncodeAndReplaceLineBreaks(line)) + .AppendLine("
"); + } + } + + builder.AppendLine("
"); // Close codeSnippet div + } + } + + private static string GetResourceString(string name, bool escapeBraces = false) + { + // '{' and '}' are special in CSS, so we use "[[[0]]]" instead for {0} (and so on). + var assembly = typeof(StartupExceptionPage).GetTypeInfo().Assembly; + var resourceName = assembly.GetName().Name + ".compiler.resources." + name; + var manifestStream = assembly.GetManifestResourceStream(resourceName); + var formatString = new StreamReader(manifestStream, Encoding.UTF8, detectEncodingFromByteOrderMarks: false).ReadToEnd(); + if (escapeBraces) + { + formatString = formatString.Replace("{", "{{").Replace("}", "}}").Replace("[[[", "{").Replace("]]]", "}"); + } + + return formatString; + } + + private static List GetFailingCallSiteInFile(string filename, int failedLineNumber) + { + // We figure out the [first, last] range of lines to read from the file. + var firstLineNumber = failedLineNumber - 2; + firstLineNumber = Math.Max(1, firstLineNumber); + var lastLineNumber = failedLineNumber + 2; + lastLineNumber = Math.Max(lastLineNumber, failedLineNumber); + + // Figure out how many characters lastLineNumber will take to print. + var lastLineNumberCharLength = lastLineNumber.ToString("D", CultureInfo.InvariantCulture).Length; + + var errorSubContents = new List(); + var didReadFailingLine = false; + + try + { + var thisLineNum = 0; + foreach (var line in File.ReadLines(filename)) + { + thisLineNum++; + + // Are we within the correct range? + if (thisLineNum < firstLineNumber) + { + continue; + } + if (thisLineNum > lastLineNumber) + { + break; + } + + var encodedLine = HtmlEncodeAndReplaceLineBreaks("Line " + + thisLineNum.ToString("D", CultureInfo.InvariantCulture).PadLeft(lastLineNumberCharLength) + + ": " + + line); + + if (thisLineNum == failedLineNumber) + { + didReadFailingLine = true; + errorSubContents.Add(@"
" + encodedLine + "
"); + } + else + { + errorSubContents.Add(@"
" + encodedLine + "
"); + } + } + } + catch + { + // If there's an error for any reason, don't show source. + return null; + } + + return (didReadFailingLine) ? errorSubContents : null; + } + + private static string PrettyPrintTypeName(Type t) + { + try + { + RuntimeHelpers.EnsureSufficientExecutionStack(); + + var name = t.Name; + + // Degenerate case + if (string.IsNullOrEmpty(name)) + { + name = "?"; + } + + // Handle generic types + if (t.GetTypeInfo().IsGenericType) + { + // strip off the CLR generic type marker if it exists + var indexOfGenericTypeMarker = name.LastIndexOf('`'); + if (indexOfGenericTypeMarker >= 0) + { + name = name.Substring(0, indexOfGenericTypeMarker); + name += "<" + string.Join(", ", t.GetGenericArguments().Select(PrettyPrintTypeName)) + ">"; + } + } + + // Handle nested types + if (!t.IsGenericParameter) + { + var containerType = t.DeclaringType; + if (containerType != null) + { + name = PrettyPrintTypeName(containerType) + "." + name; + } + } + + return name; + } + catch + { + // If anything at all goes wrong, fall back to the full type name so that we don't crash the server. + return t.FullName; + } + } + + private static void SplitTypeIntoPrefixAndFriendlyName(Type type, out string prefix, out string friendlyName) + { + prefix = type.Namespace; + friendlyName = PrettyPrintTypeName(type); + + if (!string.IsNullOrEmpty(friendlyName) && !string.IsNullOrEmpty(prefix)) + { + prefix += "."; + } + } + + private static string GenerateFooterEncoded(IRuntimeEnvironment environment) + { + var runtimeType = HtmlEncodeAndReplaceLineBreaks(environment.RuntimeType); +#if DNXCORE50 + var systemRuntimeAssembly = typeof(System.ComponentModel.DefaultValueAttribute).GetTypeInfo().Assembly; + var assemblyVersion = new AssemblyName(systemRuntimeAssembly.FullName).Version.ToString(); + var clrVersion = HtmlEncodeAndReplaceLineBreaks(assemblyVersion); +#else + var clrVersion = HtmlEncodeAndReplaceLineBreaks(Environment.Version.ToString()); +#endif + var runtimeArch = HtmlEncodeAndReplaceLineBreaks(environment.RuntimeArchitecture); + var dnxVersion = HtmlEncodeAndReplaceLineBreaks(environment.RuntimeVersion); + var currentAssembly = typeof(StartupExceptionPage).GetTypeInfo().Assembly; + var currentAssemblyVersion = currentAssembly.GetCustomAttribute().InformationalVersion; + currentAssemblyVersion = HtmlEncodeAndReplaceLineBreaks(currentAssemblyVersion); + + var os = HtmlEncodeAndReplaceLineBreaks(environment.OperatingSystem); + var osVersion = HtmlEncodeAndReplaceLineBreaks(environment.OperatingSystemVersion); + + return string.Format(CultureInfo.InvariantCulture, _errorFooterFormatString, runtimeType, clrVersion, + runtimeArch, dnxVersion, currentAssemblyVersion, os, osVersion); + } + + private static string HtmlEncodeAndReplaceLineBreaks(string input) + { + if (string.IsNullOrEmpty(input)) + { + return string.Empty; + } + + // Split on line breaks before passing it through the encoder. + // We use the static default encoder since we can't depend on DI in the error handling logic. + return string.Join("
" + Environment.NewLine, + input.Split(new[] { "\r\n" }, StringSplitOptions.None) + .SelectMany(s => s.Split(new[] { '\r', '\n' }, StringSplitOptions.None)) + .Select(HtmlEncoder.Default.HtmlEncode)); + } + + private static void WriteException(Exception ex, StringBuilder builder, ref bool wasFailingCallSiteSourceWritten) + { + string inlineSourceDiv = null; + + // First, build the stack trace + var firstStackFrame = true; + var stackTraceBuilder = new StringBuilder(); + var needFileInfo = true; + foreach (var frame in new StackTrace(ex, needFileInfo).GetFrames() ?? Enumerable.Empty()) + { + if (!firstStackFrame) + { + stackTraceBuilder.Append("
"); + } + firstStackFrame = false; + var thisFrameLine = BuildLineForStackFrame(frame); + stackTraceBuilder.AppendLine(thisFrameLine); + + // Try to include the source code in the error page if we can. + if (!wasFailingCallSiteSourceWritten && inlineSourceDiv == null) + { + inlineSourceDiv = BuildCodeSnippetDiv(frame); + if (inlineSourceDiv != null) + { + wasFailingCallSiteSourceWritten = true; + } + } + } + + // Finally, build the rest of the
+ builder.AppendFormat(CultureInfo.InvariantCulture, _errorExceptionFormatString, + HtmlEncodeAndReplaceLineBreaks(ex.GetType().FullName), + HtmlEncodeAndReplaceLineBreaks(ex.Message), + inlineSourceDiv, + stackTraceBuilder); + } + + private static void WriteRawExceptionDetails(string linkText, IEnumerable lines, StringBuilder rawExceptionDetails) + { + rawExceptionDetails + .AppendLine("
") + .AppendFormat($" ") + .AppendLine() + .AppendLine("
") + .Append("
");
+
+            foreach (var line in lines)
+            {
+                rawExceptionDetails.AppendLine(line);
+            }
+
+            rawExceptionDetails
+                .AppendLine("
") + .AppendLine("
") + .AppendLine("
"); + } + + private static void WriteException(ICompilationException compilationException, + StringBuilder builder, + ref bool wasSourceCodeWrittenOntoPage) + { + var totalErrorsShown = 0; + var inlineSourceDiv = new StringBuilder(); + var firstStackFrame = true; + foreach (var failure in compilationException.CompilationFailures) + { + if (firstStackFrame) + { + firstStackFrame = false; + } + else + { + inlineSourceDiv.AppendLine("
"); + } + + BuildCodeSnippetDiv(failure, inlineSourceDiv, ref totalErrorsShown); + } + + wasSourceCodeWrittenOntoPage = totalErrorsShown > 0; + + builder.AppendFormat(CultureInfo.InvariantCulture, + _compilationExceptionFormatString, + inlineSourceDiv); + } + + private static void WriteMessage(string message, StringBuilder builder) + { + // Build the
+ builder.AppendFormat(CultureInfo.InvariantCulture, _errorMessageFormatString, + HtmlEncodeAndReplaceLineBreaks(message)); + } + + private static IEnumerable FlattenAndReverseExceptionTree(Exception ex) + { + var list = new List(); + for (; ex != null; ex = ex.InnerException) + { + list.Add(ex); + } + list.Reverse(); + return list; + } + } +} diff --git a/src/Microsoft.AspNet.Hosting/WebHostBuilder.cs b/src/Microsoft.AspNet.Hosting/WebHostBuilder.cs index 4d2bc9eebf..2563776356 100644 --- a/src/Microsoft.AspNet.Hosting/WebHostBuilder.cs +++ b/src/Microsoft.AspNet.Hosting/WebHostBuilder.cs @@ -39,6 +39,7 @@ namespace Microsoft.AspNet.Hosting private StartupMethods _startup; private Type _startupType; private string _startupAssemblyName; + private readonly bool _captureStartupErrors; // Only one of these should be set private string _serverFactoryLocation; @@ -50,6 +51,11 @@ namespace Microsoft.AspNet.Hosting } public WebHostBuilder(IServiceProvider services, IConfiguration config) + : this(services, config: config, captureStartupErrors: false) + { + } + + public WebHostBuilder(IServiceProvider services, IConfiguration config, bool captureStartupErrors) { if (services == null) { @@ -65,6 +71,7 @@ namespace Microsoft.AspNet.Hosting _loggerFactory = new LoggerFactory(); _services = services; _config = config; + _captureStartupErrors = captureStartupErrors; } private IServiceCollection BuildHostingServices() @@ -117,8 +124,7 @@ namespace Microsoft.AspNet.Hosting var startupLoader = hostingContainer.GetRequiredService(); _hostingEnvironment.Initialize(appEnvironment.ApplicationBasePath, _config?[EnvironmentKey] ?? _config?[OldEnvironmentKey]); - - var engine = new HostingEngine(hostingServices, startupLoader, _config); + var engine = new HostingEngine(hostingServices, startupLoader, _config, _captureStartupErrors); // Only one of these should be set, but they are used in priority engine.ServerFactory = _serverFactory; diff --git a/src/Microsoft.AspNet.Hosting/compiler/resources/Compilation_Exception.html b/src/Microsoft.AspNet.Hosting/compiler/resources/Compilation_Exception.html new file mode 100644 index 0000000000..4a4faf1d23 --- /dev/null +++ b/src/Microsoft.AspNet.Hosting/compiler/resources/Compilation_Exception.html @@ -0,0 +1,6 @@ +
+ One or more compilation errors occured:
+
+ {0} +
+
diff --git a/src/Microsoft.AspNet.Hosting/compiler/resources/GenericError.html b/src/Microsoft.AspNet.Hosting/compiler/resources/GenericError.html new file mode 100644 index 0000000000..e7b4dc1bbd --- /dev/null +++ b/src/Microsoft.AspNet.Hosting/compiler/resources/GenericError.html @@ -0,0 +1,151 @@ + + + + + + 500 Internal Server Error + + + + + + + + [[[0]]] + + [[[1]]] + + [[[2]]] + + diff --git a/src/Microsoft.AspNet.Hosting/compiler/resources/GenericError_Exception.html b/src/Microsoft.AspNet.Hosting/compiler/resources/GenericError_Exception.html new file mode 100644 index 0000000000..012e05bee7 --- /dev/null +++ b/src/Microsoft.AspNet.Hosting/compiler/resources/GenericError_Exception.html @@ -0,0 +1,8 @@ +
+ {0}
+ {1}
+ {2} +
+ {3} +
+
diff --git a/src/Microsoft.AspNet.Hosting/compiler/resources/GenericError_Footer.html b/src/Microsoft.AspNet.Hosting/compiler/resources/GenericError_Footer.html new file mode 100644 index 0000000000..54042e8bf9 --- /dev/null +++ b/src/Microsoft.AspNet.Hosting/compiler/resources/GenericError_Footer.html @@ -0,0 +1,3 @@ +
+ .NET Framework {0} version {1}   |   DNX {2} version {3}   |   Microsoft.AspNet.Hosting version {4}   |   {5} {6}   |   Need help? +
diff --git a/src/Microsoft.AspNet.Hosting/compiler/resources/GenericError_Message.html b/src/Microsoft.AspNet.Hosting/compiler/resources/GenericError_Message.html new file mode 100644 index 0000000000..39a83d8754 --- /dev/null +++ b/src/Microsoft.AspNet.Hosting/compiler/resources/GenericError_Message.html @@ -0,0 +1,3 @@ +
+ {0}
+
diff --git a/src/Microsoft.AspNet.Hosting/project.json b/src/Microsoft.AspNet.Hosting/project.json index c8b50aad56..ac5468cff2 100644 --- a/src/Microsoft.AspNet.Hosting/project.json +++ b/src/Microsoft.AspNet.Hosting/project.json @@ -18,6 +18,7 @@ "Microsoft.Framework.Configuration.Json": "1.0.0-*", "Microsoft.Framework.DependencyInjection": "1.0.0-*", "Microsoft.Framework.Logging": "1.0.0-*", + "Microsoft.Dnx.Compilation.Abstractions": "1.0.0-*", "Microsoft.Dnx.Runtime.Abstractions": "1.0.0-*", "Newtonsoft.Json": "6.0.6", "System.Diagnostics.Tracing.Telemetry": "4.0.0-beta-*" @@ -30,7 +31,8 @@ }, "dnxcore50": { "dependencies": { - "System.Console": "4.0.0-beta-*" + "System.Console": "4.0.0-beta-*", + "System.Diagnostics.StackTrace": "4.0.1-beta-*" } } } diff --git a/test/Microsoft.AspNet.Hosting.Tests/Fakes/RuntimeEnvironment.cs b/test/Microsoft.AspNet.Hosting.Tests/Fakes/RuntimeEnvironment.cs new file mode 100644 index 0000000000..276ba0ea8c --- /dev/null +++ b/test/Microsoft.AspNet.Hosting.Tests/Fakes/RuntimeEnvironment.cs @@ -0,0 +1,20 @@ +// 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.Dnx.Runtime; + +namespace Microsoft.AspNet.Hosting.Fakes +{ + public class RuntimeEnvironment : IRuntimeEnvironment + { + public string OperatingSystem { get; } = "TestOs"; + + public string OperatingSystemVersion { get; } = "TestOsVersion"; + + public string RuntimeArchitecture { get; } = "TestArch"; + + public string RuntimeType { get; } = "TestRuntime"; + + public string RuntimeVersion { get; } = "TestRuntimeVersion"; + } +} diff --git a/test/Microsoft.AspNet.Hosting.Tests/Fakes/StartupConfigureServicesThrows.cs b/test/Microsoft.AspNet.Hosting.Tests/Fakes/StartupConfigureServicesThrows.cs new file mode 100644 index 0000000000..b7b3cfcdef --- /dev/null +++ b/test/Microsoft.AspNet.Hosting.Tests/Fakes/StartupConfigureServicesThrows.cs @@ -0,0 +1,22 @@ +// 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; +using Microsoft.AspNet.Builder; +using Microsoft.Framework.DependencyInjection; + +namespace Microsoft.AspNet.Hosting.Fakes +{ + public class StartupConfigureServicesThrows + { + public void ConfigureServices(IServiceCollection services) + { + throw new Exception("Exception from ConfigureServices"); + } + + public void Configure(IApplicationBuilder builder) + { + + } + } +} \ No newline at end of file diff --git a/test/Microsoft.AspNet.Hosting.Tests/Fakes/StartupConfigureThrows.cs b/test/Microsoft.AspNet.Hosting.Tests/Fakes/StartupConfigureThrows.cs new file mode 100644 index 0000000000..063404a4d1 --- /dev/null +++ b/test/Microsoft.AspNet.Hosting.Tests/Fakes/StartupConfigureThrows.cs @@ -0,0 +1,21 @@ +// 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; +using Microsoft.AspNet.Builder; +using Microsoft.Framework.DependencyInjection; + +namespace Microsoft.AspNet.Hosting.Fakes +{ + public class StartupConfigureThrows + { + public void ConfigureServices(IServiceCollection services) + { + } + + public void Configure(IApplicationBuilder builder) + { + throw new Exception("Exception from Configure"); + } + } +} \ No newline at end of file diff --git a/test/Microsoft.AspNet.Hosting.Tests/Fakes/StartupCtorThrows.cs b/test/Microsoft.AspNet.Hosting.Tests/Fakes/StartupCtorThrows.cs new file mode 100644 index 0000000000..b0a88f3a85 --- /dev/null +++ b/test/Microsoft.AspNet.Hosting.Tests/Fakes/StartupCtorThrows.cs @@ -0,0 +1,20 @@ +// 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; +using Microsoft.AspNet.Builder; + +namespace Microsoft.AspNet.Hosting.Fakes +{ + public class StartupCtorThrows + { + public StartupCtorThrows() + { + throw new Exception("Exception from constructor"); + } + + public void Configure(IApplicationBuilder app) + { + } + } +} \ No newline at end of file diff --git a/test/Microsoft.AspNet.Hosting.Tests/Fakes/StartupStaticCtorThrows.cs b/test/Microsoft.AspNet.Hosting.Tests/Fakes/StartupStaticCtorThrows.cs new file mode 100644 index 0000000000..cd90f5181d --- /dev/null +++ b/test/Microsoft.AspNet.Hosting.Tests/Fakes/StartupStaticCtorThrows.cs @@ -0,0 +1,20 @@ +// 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; +using Microsoft.AspNet.Builder; + +namespace Microsoft.AspNet.Hosting.Fakes +{ + public class StartupStaticCtorThrows + { + static StartupStaticCtorThrows() + { + throw new Exception("Exception from static constructor"); + } + + public void Configure(IApplicationBuilder app) + { + } + } +} \ No newline at end of file diff --git a/test/Microsoft.AspNet.Hosting.Tests/WebHostBuilderTests.cs b/test/Microsoft.AspNet.Hosting.Tests/WebHostBuilderTests.cs index 21f58bddbc..8d1b812ad8 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/WebHostBuilderTests.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/WebHostBuilderTests.cs @@ -1,8 +1,17 @@ // 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; +using System.Collections.Generic; +using System.IO; +using System.Threading.Tasks; +using Microsoft.AspNet.Hosting.Fakes; using Microsoft.AspNet.Hosting.Internal; +using Microsoft.AspNet.Hosting.Server; +using Microsoft.AspNet.Http.Features; +using Microsoft.AspNet.Http.Internal; using Microsoft.Dnx.Runtime.Infrastructure; +using Microsoft.Framework.Configuration; using Xunit; namespace Microsoft.AspNet.Hosting @@ -29,6 +38,110 @@ namespace Microsoft.AspNet.Hosting Assert.Equal("MyStartupAssembly", engine.StartupAssemblyName); } - private WebHostBuilder CreateWebHostBuilder() => new WebHostBuilder(CallContextServiceLocator.Locator.ServiceProvider); + [Fact] + public async Task StartupMissing_Fallback() + { + var builder = CreateWebHostBuilder(); + var serverFactory = new TestServerFactory(); + var engine = (HostingEngine)builder.UseServer(serverFactory).UseStartup("MissingStartupAssembly").Build(); + using (engine.Start()) + { + await AssertResponseContains(serverFactory.Application, "MissingStartupAssembly"); + } + } + + [Fact] + public async Task StartupStaticCtorThrows_Fallback() + { + var builder = CreateWebHostBuilder(); + var serverFactory = new TestServerFactory(); + var engine = (HostingEngine)builder.UseServer(serverFactory).UseStartup().Build(); + using (engine.Start()) + { + await AssertResponseContains(serverFactory.Application, "Exception from static constructor"); + } + } + + [Fact] + public async Task StartupCtorThrows_Fallback() + { + var builder = CreateWebHostBuilder(); + var serverFactory = new TestServerFactory(); + var engine = (HostingEngine)builder.UseServer(serverFactory).UseStartup().Build(); + using (engine.Start()) + { + await AssertResponseContains(serverFactory.Application, "Exception from constructor"); + } + } + + [Fact] + public async Task StartupConfigureServicesThrows_Fallback() + { + var builder = CreateWebHostBuilder(); + var serverFactory = new TestServerFactory(); + var engine = (HostingEngine)builder.UseServer(serverFactory).UseStartup().Build(); + using (engine.Start()) + { + await AssertResponseContains(serverFactory.Application, "Exception from ConfigureServices"); + } + } + + [Fact] + public async Task StartupConfigureThrows_Fallback() + { + var builder = CreateWebHostBuilder(); + var serverFactory = new TestServerFactory(); + var engine = (HostingEngine)builder.UseServer(serverFactory).UseStartup().Build(); + using (engine.Start()) + { + await AssertResponseContains(serverFactory.Application, "Exception from Configure"); + } + } + + private WebHostBuilder CreateWebHostBuilder() + { + var vals = new Dictionary + { + { "server", "Microsoft.AspNet.Hosting.Tests" }, + { "Hosting:DetailedErrors", "true" }, + }; + var builder = new ConfigurationBuilder() + .AddInMemoryCollection(vals); + var config = builder.Build(); + return new WebHostBuilder(CallContextServiceLocator.Locator.ServiceProvider, config, captureStartupErrors: true); + } + + private async Task AssertResponseContains(Func app, string expectedText) + { + var httpContext = new DefaultHttpContext(); + httpContext.Response.Body = new MemoryStream(); + await app(httpContext.Features); + httpContext.Response.Body.Seek(0, SeekOrigin.Begin); + var bodyText = new StreamReader(httpContext.Response.Body).ReadToEnd(); + Assert.Contains(expectedText, bodyText); + } + + private class TestServerFactory : IServerFactory + { + public Func Application { get; set; } + + public IFeatureCollection Initialize(IConfiguration configuration) + { + return new FeatureCollection(); + } + + public IDisposable Start(IFeatureCollection serverFeatures, Func application) + { + Application = application; + return new Disposable(); + } + + private class Disposable : IDisposable + { + public void Dispose() + { + } + } + } } } From c426fa97d548372f41299ef43b44f24118cc36d5 Mon Sep 17 00:00:00 2001 From: Chris R Date: Fri, 25 Sep 2015 06:28:58 -0700 Subject: [PATCH 368/987] React to configuration API changes. --- src/Microsoft.AspNet.Hosting/Program.cs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/Microsoft.AspNet.Hosting/Program.cs b/src/Microsoft.AspNet.Hosting/Program.cs index fe4b261ffd..269f415d8b 100644 --- a/src/Microsoft.AspNet.Hosting/Program.cs +++ b/src/Microsoft.AspNet.Hosting/Program.cs @@ -30,11 +30,12 @@ namespace Microsoft.AspNet.Hosting var configFilePath = tempConfig[ConfigFileKey] ?? HostingJsonFile; var appBasePath = _serviceProvider.GetRequiredService().ApplicationBasePath; - var builder = new ConfigurationBuilder(appBasePath); - builder.AddJsonFile(configFilePath, optional: true); - builder.AddEnvironmentVariables(); - builder.AddCommandLine(args); - var config = builder.Build(); + var config = new ConfigurationBuilder() + .SetBasePath(appBasePath) + .AddJsonFile(configFilePath, optional: true) + .AddEnvironmentVariables() + .AddCommandLine(args) + .Build(); var host = new WebHostBuilder(_serviceProvider, config, captureStartupErrors: true).Build(); using (var app = host.Start()) From 7e52a004999d009e3118088055e99aa35958a7fc Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Sat, 26 Sep 2015 14:34:49 +0100 Subject: [PATCH 369/987] Start log scope only if logging is enabled --- src/Microsoft.AspNet.Hosting/Internal/HostingEngine.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Microsoft.AspNet.Hosting/Internal/HostingEngine.cs b/src/Microsoft.AspNet.Hosting/Internal/HostingEngine.cs index 97bdc06e23..2f88460264 100644 --- a/src/Microsoft.AspNet.Hosting/Internal/HostingEngine.cs +++ b/src/Microsoft.AspNet.Hosting/Internal/HostingEngine.cs @@ -104,7 +104,9 @@ namespace Microsoft.AspNet.Hosting.Internal try { - using (logger.BeginScope("Request Id: {RequestId}", requestIdentifier)) + using (logger.IsEnabled(LogLevel.Critical) + ? logger.BeginScope("Request Id: {RequestId}", requestIdentifier) + : null) { contextAccessor.HttpContext = httpContext; await application(httpContext); From 07b3814f32fef234c77afc1d83453dfa06e3ca3b Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Sat, 26 Sep 2015 22:51:06 +0100 Subject: [PATCH 370/987] Correct test Yuk... --- src/Microsoft.AspNet.Hosting/Internal/HostingEngine.cs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Microsoft.AspNet.Hosting/Internal/HostingEngine.cs b/src/Microsoft.AspNet.Hosting/Internal/HostingEngine.cs index 2f88460264..3bdf2ade61 100644 --- a/src/Microsoft.AspNet.Hosting/Internal/HostingEngine.cs +++ b/src/Microsoft.AspNet.Hosting/Internal/HostingEngine.cs @@ -104,7 +104,12 @@ namespace Microsoft.AspNet.Hosting.Internal try { - using (logger.IsEnabled(LogLevel.Critical) + using (logger.IsEnabled(LogLevel.Critical) || + logger.IsEnabled(LogLevel.Error) || + logger.IsEnabled(LogLevel.Warning) || + logger.IsEnabled(LogLevel.Information) || + logger.IsEnabled(LogLevel.Verbose) || + logger.IsEnabled(LogLevel.Debug) ? logger.BeginScope("Request Id: {RequestId}", requestIdentifier) : null) { From ed1fd4a2e8143b0213b2630ab6834fe207fbd213 Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Mon, 28 Sep 2015 01:45:47 +0100 Subject: [PATCH 371/987] Lazy eval requestIdentifier Until is moved to httpContext? --- src/Microsoft.AspNet.Hosting/Internal/HostingEngine.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Microsoft.AspNet.Hosting/Internal/HostingEngine.cs b/src/Microsoft.AspNet.Hosting/Internal/HostingEngine.cs index 3bdf2ade61..556103b78a 100644 --- a/src/Microsoft.AspNet.Hosting/Internal/HostingEngine.cs +++ b/src/Microsoft.AspNet.Hosting/Internal/HostingEngine.cs @@ -95,7 +95,6 @@ namespace Microsoft.AspNet.Hosting.Internal { var httpContext = contextFactory.CreateHttpContext(features); httpContext.ApplicationServices = _applicationServices; - var requestIdentifier = GetRequestIdentifier(httpContext); if (telemetrySource.IsEnabled("Microsoft.AspNet.Hosting.BeginRequest")) { @@ -110,7 +109,7 @@ namespace Microsoft.AspNet.Hosting.Internal logger.IsEnabled(LogLevel.Information) || logger.IsEnabled(LogLevel.Verbose) || logger.IsEnabled(LogLevel.Debug) - ? logger.BeginScope("Request Id: {RequestId}", requestIdentifier) + ? logger.BeginScope("Request Id: {RequestId}", GetRequestIdentifier(httpContext)) : null) { contextAccessor.HttpContext = httpContext; From 434bddeec5765fc6c72ab04243a33a727b99c42c Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Mon, 28 Sep 2015 01:52:17 +0100 Subject: [PATCH 372/987] Revert for grumpy test --- src/Microsoft.AspNet.Hosting/Internal/HostingEngine.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Microsoft.AspNet.Hosting/Internal/HostingEngine.cs b/src/Microsoft.AspNet.Hosting/Internal/HostingEngine.cs index 556103b78a..3bdf2ade61 100644 --- a/src/Microsoft.AspNet.Hosting/Internal/HostingEngine.cs +++ b/src/Microsoft.AspNet.Hosting/Internal/HostingEngine.cs @@ -95,6 +95,7 @@ namespace Microsoft.AspNet.Hosting.Internal { var httpContext = contextFactory.CreateHttpContext(features); httpContext.ApplicationServices = _applicationServices; + var requestIdentifier = GetRequestIdentifier(httpContext); if (telemetrySource.IsEnabled("Microsoft.AspNet.Hosting.BeginRequest")) { @@ -109,7 +110,7 @@ namespace Microsoft.AspNet.Hosting.Internal logger.IsEnabled(LogLevel.Information) || logger.IsEnabled(LogLevel.Verbose) || logger.IsEnabled(LogLevel.Debug) - ? logger.BeginScope("Request Id: {RequestId}", GetRequestIdentifier(httpContext)) + ? logger.BeginScope("Request Id: {RequestId}", requestIdentifier) : null) { contextAccessor.HttpContext = httpContext; From 0131015b4327787d2d9f556ca1d7694581c733ec Mon Sep 17 00:00:00 2001 From: Chris R Date: Sat, 26 Sep 2015 22:29:08 -0700 Subject: [PATCH 373/987] Update server test infrastructure, remove Helios concepts. --- .../Common/DeploymentParameters.cs | 3 ++ .../Common/RetryHelper.cs | 18 +++---- .../Common/ServerType.cs | 1 - .../Deployers/ApplicationDeployer.cs | 24 ++++------ .../Deployers/ApplicationDeployerFactory.cs | 1 - .../Deployers/IISDeployer.cs | 45 ++++------------- .../Deployers/IISExpressDeployer.cs | 48 ++----------------- .../Deployers/SelfHostDeployer.cs | 8 +++- ...fIISNativeVariationsNotEnabledAttribute.cs | 33 ------------- 9 files changed, 42 insertions(+), 139 deletions(-) delete mode 100644 src/Microsoft.AspNet.Server.Testing/xunit/SkipIfIISNativeVariationsNotEnabledAttribute.cs diff --git a/src/Microsoft.AspNet.Server.Testing/Common/DeploymentParameters.cs b/src/Microsoft.AspNet.Server.Testing/Common/DeploymentParameters.cs index 86d29d9b2b..842e65b70f 100644 --- a/src/Microsoft.AspNet.Server.Testing/Common/DeploymentParameters.cs +++ b/src/Microsoft.AspNet.Server.Testing/Common/DeploymentParameters.cs @@ -89,6 +89,9 @@ namespace Microsoft.AspNet.Server.Testing /// public Action UserAdditionalCleanup { get; set; } + // Which command in the test project to run. + public string Command { get; set; } + public override string ToString() { return string.Format( diff --git a/src/Microsoft.AspNet.Server.Testing/Common/RetryHelper.cs b/src/Microsoft.AspNet.Server.Testing/Common/RetryHelper.cs index ae2cedd6e7..48b47b4706 100644 --- a/src/Microsoft.AspNet.Server.Testing/Common/RetryHelper.cs +++ b/src/Microsoft.AspNet.Server.Testing/Common/RetryHelper.cs @@ -27,14 +27,14 @@ namespace Microsoft.AspNet.Server.Testing { for (int retry = 0; retry < retryCount; retry++) { + if (cancellationToken.IsCancellationRequested) + { + logger.LogInformation("Failed to connect, retry canceled."); + throw new OperationCanceledException("Failed to connect, retry canceled.", cancellationToken); + } + try { - if (cancellationToken.IsCancellationRequested) - { - logger.LogInformation("Stopping retry as cancellation token is triggered."); - break; - } - logger.LogWarning("Retry count {retryCount}..", retry + 1); var response = await retryBlock(); @@ -45,12 +45,13 @@ namespace Microsoft.AspNet.Server.Testing continue; } - return response; //Went through successfully + return response; // Went through successfully } catch (Exception exception) { if (retry == retryCount - 1) { + logger.LogError("Failed to connect, retry limit exceeded.", exception); throw; } else @@ -68,7 +69,8 @@ namespace Microsoft.AspNet.Server.Testing } } - return null; + logger.LogInformation("Failed to connect, retry limit exceeded."); + throw new OperationCanceledException("Failed to connect, retry limit exceeded."); } } } \ No newline at end of file diff --git a/src/Microsoft.AspNet.Server.Testing/Common/ServerType.cs b/src/Microsoft.AspNet.Server.Testing/Common/ServerType.cs index 3d17cb23bd..eca333942e 100644 --- a/src/Microsoft.AspNet.Server.Testing/Common/ServerType.cs +++ b/src/Microsoft.AspNet.Server.Testing/Common/ServerType.cs @@ -7,7 +7,6 @@ namespace Microsoft.AspNet.Server.Testing { IISExpress, IIS, - IISNativeModule, WebListener, Kestrel } diff --git a/src/Microsoft.AspNet.Server.Testing/Deployers/ApplicationDeployer.cs b/src/Microsoft.AspNet.Server.Testing/Deployers/ApplicationDeployer.cs index 6dd076e1a1..19fe88337b 100644 --- a/src/Microsoft.AspNet.Server.Testing/Deployers/ApplicationDeployer.cs +++ b/src/Microsoft.AspNet.Server.Testing/Deployers/ApplicationDeployer.cs @@ -40,7 +40,7 @@ namespace Microsoft.AspNet.Server.Testing { var runtimePath = Process.GetCurrentProcess().MainModule.FileName; Logger.LogInformation(string.Empty); - Logger.LogInformation("Current runtime path is : {0}", runtimePath); + Logger.LogInformation($"Current runtime path is : {runtimePath}"); var replaceStr = new StringBuilder(). Append("dnx"). @@ -62,7 +62,7 @@ namespace Microsoft.AspNet.Server.Testing ChosenRuntimeName = runtimeDirectoryInfo.Parent.Name; Logger.LogInformation(string.Empty); - Logger.LogInformation("Changing to use runtime : {runtimeName}", ChosenRuntimeName); + Logger.LogInformation($"Changing to use runtime : {ChosenRuntimeName}"); return ChosenRuntimeName; } @@ -70,16 +70,13 @@ namespace Microsoft.AspNet.Server.Testing { DeploymentParameters.PublishedApplicationRootPath = Path.Combine(publishRoot ?? Path.GetTempPath(), Guid.NewGuid().ToString()); - var parameters = - string.Format( - "publish {0} -o {1} --runtime {2} {3}", - DeploymentParameters.ApplicationPath, - DeploymentParameters.PublishedApplicationRootPath, - DeploymentParameters.DnxRuntime, - DeploymentParameters.PublishWithNoSource ? "--no-source" : string.Empty); + var noSource = DeploymentParameters.PublishWithNoSource ? "--no-source" : string.Empty; + var command = DeploymentParameters.Command ?? "web"; + var parameters = $"publish {DeploymentParameters.ApplicationPath} -o {DeploymentParameters.PublishedApplicationRootPath}" + + $" --runtime {DeploymentParameters.DnxRuntime} {noSource} --iis-command {command}"; var dnuPath = Path.Combine(ChosenRuntimePath, "dnu.cmd"); - Logger.LogInformation("Executing command {dnu} {args}", dnuPath, parameters); + Logger.LogInformation($"Executing command {dnuPath} {parameters}"); var startInfo = new ProcessStartInfo { @@ -106,13 +103,12 @@ namespace Microsoft.AspNet.Server.Testing DeploymentParameters.ApplicationPath = (DeploymentParameters.ServerType == ServerType.IISExpress || - DeploymentParameters.ServerType == ServerType.IISNativeModule || DeploymentParameters.ServerType == ServerType.IIS) ? Path.Combine(DeploymentParameters.PublishedApplicationRootPath, "wwwroot") : Path.Combine(DeploymentParameters.PublishedApplicationRootPath, "approot", "src", new DirectoryInfo(DeploymentParameters.ApplicationPath).Name); - Logger.LogInformation("dnu publish finished with exit code : {exitCode}", hostProcess.ExitCode); + Logger.LogInformation($"dnu publish finished with exit code : {hostProcess.ExitCode}"); } protected void CleanPublishedOutput() @@ -124,7 +120,7 @@ namespace Microsoft.AspNet.Server.Testing } catch (Exception exception) { - Logger.LogWarning("Failed to delete directory : {error}", exception.Message); + Logger.LogWarning($"Failed to delete directory : {exception.Message}"); } } @@ -225,7 +221,7 @@ namespace Microsoft.AspNet.Server.Testing protected void StartTimer() { - Logger.LogInformation("Deploying {VariationDetails}", DeploymentParameters.ToString()); + Logger.LogInformation($"Deploying {DeploymentParameters.ToString()}"); StopWatch.Start(); } diff --git a/src/Microsoft.AspNet.Server.Testing/Deployers/ApplicationDeployerFactory.cs b/src/Microsoft.AspNet.Server.Testing/Deployers/ApplicationDeployerFactory.cs index 6422d3f507..d40a6562c1 100644 --- a/src/Microsoft.AspNet.Server.Testing/Deployers/ApplicationDeployerFactory.cs +++ b/src/Microsoft.AspNet.Server.Testing/Deployers/ApplicationDeployerFactory.cs @@ -40,7 +40,6 @@ namespace Microsoft.AspNet.Server.Testing return new IISExpressDeployer(deploymentParameters, logger); #if DNX451 case ServerType.IIS: - case ServerType.IISNativeModule: return new IISDeployer(deploymentParameters, logger); #endif case ServerType.WebListener: diff --git a/src/Microsoft.AspNet.Server.Testing/Deployers/IISDeployer.cs b/src/Microsoft.AspNet.Server.Testing/Deployers/IISDeployer.cs index b7290b9f9c..fe3e046254 100644 --- a/src/Microsoft.AspNet.Server.Testing/Deployers/IISDeployer.cs +++ b/src/Microsoft.AspNet.Server.Testing/Deployers/IISDeployer.cs @@ -41,14 +41,8 @@ namespace Microsoft.AspNet.Server.Testing // Publish to IIS root\application folder. DnuPublish(publishRoot: _application.WebSiteRootFolder); - // Drop an ini file instead of setting environment variable. - SetAspEnvironmentWithIni(); - - // Setup the IIS Application. - if (DeploymentParameters.ServerType == ServerType.IISNativeModule) - { - TurnRammFarOnNativeModule(); - } + // Drop a json file instead of setting environment variable. + SetAspEnvironmentWithJson(); lock (_syncObject) { @@ -70,30 +64,12 @@ namespace Microsoft.AspNet.Server.Testing }; } - private void SetAspEnvironmentWithIni() + private void SetAspEnvironmentWithJson() { - // Drop a Microsoft.AspNet.Hosting.ini with ASPNET_ENV information. - Logger.LogInformation("Creating Microsoft.AspNet.Hosting.ini file with ASPNET_ENV."); - var iniFile = Path.Combine(DeploymentParameters.ApplicationPath, "Microsoft.AspNet.Hosting.ini"); - File.WriteAllText(iniFile, string.Format("ASPNET_ENV={0}", DeploymentParameters.EnvironmentName)); - } - - private void TurnRammFarOnNativeModule() - { - Logger.LogInformation("Turning runAllManagedModulesForAllRequests=true in web.config for native module."); - var webConfig = Path.Combine(DeploymentParameters.ApplicationPath, "web.config"); - var configuration = new XmlDocument(); - configuration.LoadXml(File.ReadAllText(webConfig)); - - // https://github.com/aspnet/Helios/issues/77 - var rammfarAttribute = configuration.CreateAttribute("runAllManagedModulesForAllRequests"); - rammfarAttribute.Value = "true"; - var modulesNode = configuration.CreateElement("modules"); - modulesNode.Attributes.Append(rammfarAttribute); - var systemWebServerNode = configuration.CreateElement("system.webServer"); - systemWebServerNode.AppendChild(modulesNode); - configuration.SelectSingleNode("//configuration").AppendChild(systemWebServerNode); - configuration.Save(webConfig); + // Drop a Microsoft.AspNet.Hosting.json with Hosting:Environment information. + Logger.LogInformation("Creating Microsoft.AspNet.Hosting.json file with Hosting:Environment."); + var jsonFile = Path.Combine(DeploymentParameters.ApplicationPath, "Microsoft.AspNet.Hosting.json"); + File.WriteAllText(jsonFile, string.Format("{ \"Hosting:Environment\":\"{0}\" }", DeploymentParameters.EnvironmentName)); } public override void Dispose() @@ -118,8 +94,6 @@ namespace Microsoft.AspNet.Server.Testing private class IISApplication { private const string WebSiteName = "ASPNETTESTRUNS"; - private const string NativeModuleManagedRuntimeVersion = "vCoreFX"; - private const string Dotnet45RuntimeVersion = "v4.0.30319"; private readonly ServerManager _serverManager = new ServerManager(); private readonly DeploymentParameters _deploymentParameters; @@ -176,10 +150,7 @@ namespace Microsoft.AspNet.Server.Testing private ApplicationPool CreateAppPool(string appPoolName) { var applicationPool = _serverManager.ApplicationPools.Add(appPoolName); - applicationPool.ManagedRuntimeVersion = - _deploymentParameters.ServerType == ServerType.IISNativeModule ? - NativeModuleManagedRuntimeVersion : - Dotnet45RuntimeVersion; + applicationPool.ManagedRuntimeVersion = string.Empty; applicationPool.Enable32BitAppOnWin64 = (_deploymentParameters.RuntimeArchitecture == RuntimeArchitecture.x86); _logger.LogInformation("Created {bit} application pool '{name}' with runtime version {runtime}.", diff --git a/src/Microsoft.AspNet.Server.Testing/Deployers/IISExpressDeployer.cs b/src/Microsoft.AspNet.Server.Testing/Deployers/IISExpressDeployer.cs index 5309a59925..bd334652a8 100644 --- a/src/Microsoft.AspNet.Server.Testing/Deployers/IISExpressDeployer.cs +++ b/src/Microsoft.AspNet.Server.Testing/Deployers/IISExpressDeployer.cs @@ -5,8 +5,6 @@ using System; using System.Diagnostics; using System.IO; using System.Threading; -using Microsoft.Dnx.Runtime; -using Microsoft.Dnx.Runtime.Infrastructure; using Microsoft.Framework.Logging; namespace Microsoft.AspNet.Server.Testing @@ -30,6 +28,8 @@ namespace Microsoft.AspNet.Server.Testing DeploymentParameters.DnxRuntime = PopulateChosenRuntimeInformation(); + // For now we always auto-publish. Otherwise we'll have to write our own local web.config for the HttpPlatformHandler + DeploymentParameters.PublishApplicationBeforeDeployment = true; if (DeploymentParameters.PublishApplicationBeforeDeployment) { DnuPublish(); @@ -57,18 +57,12 @@ namespace Microsoft.AspNet.Server.Testing DeploymentParameters.ApplicationHostConfigTemplateContent = DeploymentParameters.ApplicationHostConfigTemplateContent - .Replace("[ApplicationPhysicalPath]", Path.Combine(DeploymentParameters.ApplicationPath, "wwwroot")) - .Replace("[PORT]", new Uri(DeploymentParameters.ApplicationBaseUriHint).Port.ToString()); + .Replace("[ApplicationPhysicalPath]", DeploymentParameters.ApplicationPath) + .Replace("[PORT]", new Uri(DeploymentParameters.ApplicationBaseUriHint).Port.ToString()); DeploymentParameters.ApplicationHostConfigLocation = Path.GetTempFileName(); - File.WriteAllText(DeploymentParameters.ApplicationHostConfigLocation, - DeploymentParameters.ApplicationHostConfigTemplateContent.Replace("[ApplicationPhysicalPath]", DeploymentParameters.ApplicationPath)); - } - - if (!DeploymentParameters.PublishApplicationBeforeDeployment) - { - CopyAspNetLoader(); + File.WriteAllText(DeploymentParameters.ApplicationHostConfigLocation, DeploymentParameters.ApplicationHostConfigTemplateContent); } var webroot = DeploymentParameters.ApplicationPath; @@ -129,38 +123,6 @@ namespace Microsoft.AspNet.Server.Testing return hostExitTokenSource.Token; } - private void CopyAspNetLoader() - { - var libraryManager = (ILibraryManager)CallContextServiceLocator.Locator.ServiceProvider.GetService(typeof(ILibraryManager)); - var interopLibrary = libraryManager.GetLibrary("Microsoft.AspNet.Loader.IIS.Interop"); - - if (interopLibrary == null) - { - throw new Exception( - string.Format("Include Microsoft.AspNet.Server.IIS package in your project.json to deploy in {0}.", - ServerType.IISExpress)); - } - - var aspNetLoaderSrcPath = Path.Combine(interopLibrary.Path, "tools", "AspNet.Loader.dll"); - var aspNetLoaderDestPath = Path.Combine(DeploymentParameters.ApplicationPath, "wwwroot", "bin", "AspNet.Loader.dll"); - - // Create bin directory if it does not exist. - Directory.CreateDirectory(new DirectoryInfo(aspNetLoaderDestPath).Parent.FullName); - - if (!File.Exists(aspNetLoaderDestPath)) - { - try - { - File.Copy(aspNetLoaderSrcPath, aspNetLoaderDestPath); - } - catch (IOException) - { - // Ignore file already exists exception. Sometimes multiple tests might try - // doing the same and one of them wins. - } - } - } - private string GetIISExpressPath() { // Get path to program files diff --git a/src/Microsoft.AspNet.Server.Testing/Deployers/SelfHostDeployer.cs b/src/Microsoft.AspNet.Server.Testing/Deployers/SelfHostDeployer.cs index 685a88e388..cd1293028d 100644 --- a/src/Microsoft.AspNet.Server.Testing/Deployers/SelfHostDeployer.cs +++ b/src/Microsoft.AspNet.Server.Testing/Deployers/SelfHostDeployer.cs @@ -47,9 +47,13 @@ namespace Microsoft.AspNet.Server.Testing private CancellationToken StartSelfHost() { - var commandName = DeploymentParameters.ServerType == ServerType.WebListener ? "web" : "kestrel"; + var commandName = DeploymentParameters.Command; + if (string.IsNullOrEmpty(commandName)) + { + commandName = DeploymentParameters.ServerType == ServerType.WebListener ? "web" : "kestrel"; + } var dnxPath = Path.Combine(ChosenRuntimePath, "dnx.exe"); - var dnxArgs = $"--appbase \"{DeploymentParameters.ApplicationPath}\" Microsoft.Dnx.ApplicationHost {commandName} --server.urls {DeploymentParameters.ApplicationBaseUriHint}"; + var dnxArgs = $"-p \"{DeploymentParameters.ApplicationPath}\" Microsoft.Dnx.ApplicationHost {commandName} --server.urls {DeploymentParameters.ApplicationBaseUriHint}"; Logger.LogInformation("Executing {dnxexe} {dnxArgs}", dnxPath, dnxArgs); var startInfo = new ProcessStartInfo diff --git a/src/Microsoft.AspNet.Server.Testing/xunit/SkipIfIISNativeVariationsNotEnabledAttribute.cs b/src/Microsoft.AspNet.Server.Testing/xunit/SkipIfIISNativeVariationsNotEnabledAttribute.cs deleted file mode 100644 index b3c13646ce..0000000000 --- a/src/Microsoft.AspNet.Server.Testing/xunit/SkipIfIISNativeVariationsNotEnabledAttribute.cs +++ /dev/null @@ -1,33 +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; -using Microsoft.AspNet.Testing.xunit; - -namespace Microsoft.AspNet.Server.Testing -{ - /// - /// Skip test if IIS native module is not enabled. To enable setup native module - /// and set environment variable IIS_NATIVE_VARIATIONS_ENABLED=true for the test process. - /// - [AttributeUsage(AttributeTargets.Method, AllowMultiple = false)] - public class SkipIfIISNativeVariationsNotEnabledAttribute : Attribute, ITestCondition - { - public bool IsMet - { - get - { - return Environment.GetEnvironmentVariable("IIS_NATIVE_VARIATIONS_ENABLED") == "true"; - } - } - - public string SkipReason - { - get - { - return "Skipping Native module test since native module variations are not enabled. " + - "To run the test, setup the native module and set the environment variable IIS_NATIVE_VARIATIONS_ENABLED=true."; - } - } - } -} \ No newline at end of file From 49035fd292773ef1a6d2d9c548fff3119a4b5e57 Mon Sep 17 00:00:00 2001 From: Anthony van der Hoorn Date: Mon, 28 Sep 2015 12:30:12 -0700 Subject: [PATCH 374/987] Order the setting of ContextAccessor so it happens before the BeginRequest event occurs. --- src/Microsoft.AspNet.Hosting/Internal/HostingEngine.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Microsoft.AspNet.Hosting/Internal/HostingEngine.cs b/src/Microsoft.AspNet.Hosting/Internal/HostingEngine.cs index 97bdc06e23..6ecfb793ee 100644 --- a/src/Microsoft.AspNet.Hosting/Internal/HostingEngine.cs +++ b/src/Microsoft.AspNet.Hosting/Internal/HostingEngine.cs @@ -96,6 +96,7 @@ namespace Microsoft.AspNet.Hosting.Internal var httpContext = contextFactory.CreateHttpContext(features); httpContext.ApplicationServices = _applicationServices; var requestIdentifier = GetRequestIdentifier(httpContext); + contextAccessor.HttpContext = httpContext; if (telemetrySource.IsEnabled("Microsoft.AspNet.Hosting.BeginRequest")) { @@ -106,7 +107,6 @@ namespace Microsoft.AspNet.Hosting.Internal { using (logger.BeginScope("Request Id: {RequestId}", requestIdentifier)) { - contextAccessor.HttpContext = httpContext; await application(httpContext); } } From 371511aaf16ba0f0d9ab84cf9b617f7b12f0efea Mon Sep 17 00:00:00 2001 From: Hisham Bin Ateya Date: Wed, 23 Sep 2015 23:46:45 +0300 Subject: [PATCH 375/987] Add description to project.json --- src/Microsoft.AspNet.Hosting.Server.Abstractions/project.json | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Microsoft.AspNet.Hosting.Server.Abstractions/project.json b/src/Microsoft.AspNet.Hosting.Server.Abstractions/project.json index 07cab5d291..85f0dc5415 100644 --- a/src/Microsoft.AspNet.Hosting.Server.Abstractions/project.json +++ b/src/Microsoft.AspNet.Hosting.Server.Abstractions/project.json @@ -1,5 +1,6 @@ { "version": "1.0.0-*", + "description": "ASP.NET 5 Hosting server abstractions.", "repository": { "type": "git", "url": "git://github.com/aspnet/hosting" From 4eba4902171cefe0988b6700149af632bbcec1ec Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Mon, 28 Sep 2015 18:46:11 -0700 Subject: [PATCH 376/987] Only test for critical logging --- src/Microsoft.AspNet.Hosting/Internal/HostingEngine.cs | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/Microsoft.AspNet.Hosting/Internal/HostingEngine.cs b/src/Microsoft.AspNet.Hosting/Internal/HostingEngine.cs index 3bdf2ade61..60174887af 100644 --- a/src/Microsoft.AspNet.Hosting/Internal/HostingEngine.cs +++ b/src/Microsoft.AspNet.Hosting/Internal/HostingEngine.cs @@ -104,12 +104,7 @@ namespace Microsoft.AspNet.Hosting.Internal try { - using (logger.IsEnabled(LogLevel.Critical) || - logger.IsEnabled(LogLevel.Error) || - logger.IsEnabled(LogLevel.Warning) || - logger.IsEnabled(LogLevel.Information) || - logger.IsEnabled(LogLevel.Verbose) || - logger.IsEnabled(LogLevel.Debug) + using (logger.IsEnabled(LogLevel.Critical) ? logger.BeginScope("Request Id: {RequestId}", requestIdentifier) : null) { From 430f83e13bad42bae840014d546966b723541eef Mon Sep 17 00:00:00 2001 From: Pranav K Date: Mon, 28 Sep 2015 23:12:40 -0700 Subject: [PATCH 377/987] Updating to release NuGet.config. --- NuGet.config | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NuGet.config b/NuGet.config index 1707938c61..9db87a421e 100644 --- a/NuGet.config +++ b/NuGet.config @@ -1,7 +1,7 @@ - + \ No newline at end of file From 3d5f70fd01ca93e308bf7b1ebb68dfb33f270255 Mon Sep 17 00:00:00 2001 From: moozzyk Date: Tue, 29 Sep 2015 13:52:13 -0700 Subject: [PATCH 378/987] Updating RuntimeEnvironment after IRuntimeEnvironment changes --- test/Microsoft.AspNet.Hosting.Tests/Fakes/RuntimeEnvironment.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/Microsoft.AspNet.Hosting.Tests/Fakes/RuntimeEnvironment.cs b/test/Microsoft.AspNet.Hosting.Tests/Fakes/RuntimeEnvironment.cs index 276ba0ea8c..330ff30c29 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/Fakes/RuntimeEnvironment.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/Fakes/RuntimeEnvironment.cs @@ -16,5 +16,7 @@ namespace Microsoft.AspNet.Hosting.Fakes public string RuntimeType { get; } = "TestRuntime"; public string RuntimeVersion { get; } = "TestRuntimeVersion"; + + public string RuntimePath { get; } = "TestRuntimePath"; } } From b0a1a520688b6bc2bb7d5a823ddbac435fd64a66 Mon Sep 17 00:00:00 2001 From: "N. Taylor Mullen" Date: Thu, 1 Oct 2015 11:57:48 -0700 Subject: [PATCH 379/987] Update 'build.cmd' alias parameter to use full name. --- build.cmd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.cmd b/build.cmd index 177997c42e..70d974a61f 100644 --- a/build.cmd +++ b/build.cmd @@ -30,7 +30,7 @@ IF "%SKIP_DNX_INSTALL%"=="1" goto run IF %BUILDCMD_DNX_VERSION%=="" ( CALL packages\KoreBuild\build\dnvm upgrade -runtime CLR -arch x86 ) ELSE ( - CALL packages\KoreBuild\build\dnvm install %BUILDCMD_DNX_VERSION% -runtime CLR -arch x86 -a default + CALL packages\KoreBuild\build\dnvm install %BUILDCMD_DNX_VERSION% -runtime CLR -arch x86 -alias default ) CALL packages\KoreBuild\build\dnvm install default -runtime CoreCLR -arch x86 From 818575c20178103a5b61a30867e68f35995bacbb Mon Sep 17 00:00:00 2001 From: Chris R Date: Thu, 1 Oct 2015 14:30:01 -0700 Subject: [PATCH 380/987] Fix server testing dnx scripts. --- src/Microsoft.AspNet.Server.Testing/Deployers/MonoDeployer.cs | 2 +- .../Deployers/SelfHostDeployer.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Testing/Deployers/MonoDeployer.cs b/src/Microsoft.AspNet.Server.Testing/Deployers/MonoDeployer.cs index 6619bc8e12..8a5961be4d 100644 --- a/src/Microsoft.AspNet.Server.Testing/Deployers/MonoDeployer.cs +++ b/src/Microsoft.AspNet.Server.Testing/Deployers/MonoDeployer.cs @@ -62,7 +62,7 @@ namespace Microsoft.AspNet.Server.Testing throw new InvalidOperationException("kestrel is the only valid ServerType for Mono"); } - var dnxArgs = $"--appbase \"{DeploymentParameters.ApplicationPath}\" Microsoft.Dnx.ApplicationHost kestrel --server.urls {DeploymentParameters.ApplicationBaseUriHint}"; + var dnxArgs = $"-p \"{DeploymentParameters.ApplicationPath}\" kestrel --server.urls {DeploymentParameters.ApplicationBaseUriHint}"; Logger.LogInformation("Executing command: dnx {dnxArgs}", dnxArgs); diff --git a/src/Microsoft.AspNet.Server.Testing/Deployers/SelfHostDeployer.cs b/src/Microsoft.AspNet.Server.Testing/Deployers/SelfHostDeployer.cs index cd1293028d..07c175babc 100644 --- a/src/Microsoft.AspNet.Server.Testing/Deployers/SelfHostDeployer.cs +++ b/src/Microsoft.AspNet.Server.Testing/Deployers/SelfHostDeployer.cs @@ -53,7 +53,7 @@ namespace Microsoft.AspNet.Server.Testing commandName = DeploymentParameters.ServerType == ServerType.WebListener ? "web" : "kestrel"; } var dnxPath = Path.Combine(ChosenRuntimePath, "dnx.exe"); - var dnxArgs = $"-p \"{DeploymentParameters.ApplicationPath}\" Microsoft.Dnx.ApplicationHost {commandName} --server.urls {DeploymentParameters.ApplicationBaseUriHint}"; + var dnxArgs = $"-p \"{DeploymentParameters.ApplicationPath}\" {commandName} --server.urls {DeploymentParameters.ApplicationBaseUriHint}"; Logger.LogInformation("Executing {dnxexe} {dnxArgs}", dnxPath, dnxArgs); var startInfo = new ProcessStartInfo From d61586c6a1b10583dd66e457a0484974963acfd0 Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Fri, 2 Oct 2015 16:47:23 -0400 Subject: [PATCH 381/987] Use Jit recongised, standard loop construct For bounds check elimination. --- src/Microsoft.AspNet.Hosting/Startup/ConfigureDelegate.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Microsoft.AspNet.Hosting/Startup/ConfigureDelegate.cs b/src/Microsoft.AspNet.Hosting/Startup/ConfigureDelegate.cs index 50f2b22005..c9a814eaac 100644 --- a/src/Microsoft.AspNet.Hosting/Startup/ConfigureDelegate.cs +++ b/src/Microsoft.AspNet.Hosting/Startup/ConfigureDelegate.cs @@ -27,7 +27,7 @@ namespace Microsoft.AspNet.Hosting.Startup var serviceProvider = builder.ApplicationServices; var parameterInfos = MethodInfo.GetParameters(); var parameters = new object[parameterInfos.Length]; - for (var index = 0; index != parameterInfos.Length; ++index) + for (var index = 0; index < parameterInfos.Length; index++) { var parameterInfo = parameterInfos[index]; if (parameterInfo.ParameterType == typeof(IApplicationBuilder)) @@ -54,4 +54,4 @@ namespace Microsoft.AspNet.Hosting.Startup MethodInfo.Invoke(instance, parameters); } } -} \ No newline at end of file +} From 797962b60801b2bce54e8159f6b70d490e07105e Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Fri, 2 Oct 2015 16:56:39 -0400 Subject: [PATCH 382/987] Simpler loop construct --- src/Microsoft.AspNet.Hosting/Startup/StartupExceptionPage.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Microsoft.AspNet.Hosting/Startup/StartupExceptionPage.cs b/src/Microsoft.AspNet.Hosting/Startup/StartupExceptionPage.cs index 70b6befd8d..924b30ebbf 100644 --- a/src/Microsoft.AspNet.Hosting/Startup/StartupExceptionPage.cs +++ b/src/Microsoft.AspNet.Hosting/Startup/StartupExceptionPage.cs @@ -509,9 +509,10 @@ namespace Microsoft.AspNet.Hosting.Startup private static IEnumerable FlattenAndReverseExceptionTree(Exception ex) { var list = new List(); - for (; ex != null; ex = ex.InnerException) + while (ex != null) { list.Add(ex); + ex = ex.InnerException; } list.Reverse(); return list; From e3298992e7bdacbe5ffce9c0b0c97093e4f32d96 Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Fri, 2 Oct 2015 16:57:34 -0400 Subject: [PATCH 383/987] use var --- src/Microsoft.AspNet.Server.Testing/Common/RetryHelper.cs | 2 +- test/Microsoft.AspNet.TestHost.Tests/TestClientTests.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Testing/Common/RetryHelper.cs b/src/Microsoft.AspNet.Server.Testing/Common/RetryHelper.cs index 48b47b4706..1835b55e52 100644 --- a/src/Microsoft.AspNet.Server.Testing/Common/RetryHelper.cs +++ b/src/Microsoft.AspNet.Server.Testing/Common/RetryHelper.cs @@ -25,7 +25,7 @@ namespace Microsoft.AspNet.Server.Testing CancellationToken cancellationToken = default(CancellationToken), int retryCount = 60) { - for (int retry = 0; retry < retryCount; retry++) + for (var retry = 0; retry < retryCount; retry++) { if (cancellationToken.IsCancellationRequested) { diff --git a/test/Microsoft.AspNet.TestHost.Tests/TestClientTests.cs b/test/Microsoft.AspNet.TestHost.Tests/TestClientTests.cs index ae1dfd19ca..e2ed03d89c 100644 --- a/test/Microsoft.AspNet.TestHost.Tests/TestClientTests.cs +++ b/test/Microsoft.AspNet.TestHost.Tests/TestClientTests.cs @@ -235,7 +235,7 @@ namespace Microsoft.AspNet.TestHost // Assert var buffer = new byte[1]; - for (int i = 0; i < hello.Length; i++) + for (var i = 0; i < hello.Length; i++) { bool last = i == (hello.Length - 1); var result = await clientSocket.ReceiveAsync(new System.ArraySegment(buffer), CancellationToken.None); From 1ef8474be2fdcfae27b880cc3544979fd3d68d88 Mon Sep 17 00:00:00 2001 From: Pranav K Date: Sat, 3 Oct 2015 15:44:40 -0700 Subject: [PATCH 384/987] Renaming Microsoft.Framework.* -> Microsoft.Extensions.* --- .../IServerFactory.cs | 2 +- .../project.json | 4 ++-- .../Internal/HostingEngine.cs | 6 +++--- .../Internal/RequestServicesContainerFeature.cs | 2 +- .../Internal/RequestServicesContainerMiddleware.cs | 2 +- src/Microsoft.AspNet.Hosting/Program.cs | 4 ++-- src/Microsoft.AspNet.Hosting/Server/ServerLoader.cs | 2 +- .../Startup/ConfigureDelegate.cs | 2 +- .../Startup/ConfigureServicesDelegate.cs | 2 +- .../Startup/StartupExceptionPage.cs | 4 ++-- .../Startup/StartupLoader.cs | 2 +- .../Startup/StartupMethods.cs | 2 +- src/Microsoft.AspNet.Hosting/WebHostBuilder.cs | 6 +++--- src/Microsoft.AspNet.Hosting/project.json | 12 ++++++------ .../Common/RetryHelper.cs | 2 +- .../Deployers/ApplicationDeployer.cs | 2 +- .../Deployers/ApplicationDeployerFactory.cs | 2 +- .../Deployers/IISDeployer.cs | 2 +- .../Deployers/IISExpressDeployer.cs | 2 +- .../Deployers/MonoDeployer.cs | 2 +- .../Deployers/SelfHostDeployer.cs | 2 +- src/Microsoft.AspNet.Server.Testing/project.json | 2 +- src/Microsoft.AspNet.TestHost/RequestFeature.cs | 2 +- src/Microsoft.AspNet.TestHost/ResponseFeature.cs | 2 +- src/Microsoft.AspNet.TestHost/TestServer.cs | 4 ++-- test/Microsoft.AspNet.Hosting.Tests/Fakes/Startup.cs | 2 +- .../Fakes/StartupBase.cs | 2 +- .../Fakes/StartupConfigureServicesThrows.cs | 2 +- .../Fakes/StartupConfigureThrows.cs | 2 +- .../Fakes/StartupTwoConfigureServices.cs | 2 +- .../Fakes/StartupWithConfigureServices.cs | 4 ++-- .../Fakes/StartupWithNullConfigureServices.cs | 4 ++-- .../HostingEngineTests.cs | 8 ++++---- .../StartupManagerTests.cs | 4 ++-- .../WebHostBuilderTests.cs | 4 ++-- test/Microsoft.AspNet.Hosting.Tests/project.json | 2 +- .../TestServerTests.cs | 8 ++++---- test/Microsoft.AspNet.TestHost.Tests/project.json | 2 +- 38 files changed, 61 insertions(+), 61 deletions(-) diff --git a/src/Microsoft.AspNet.Hosting.Server.Abstractions/IServerFactory.cs b/src/Microsoft.AspNet.Hosting.Server.Abstractions/IServerFactory.cs index ff188af7d1..c685ff8570 100644 --- a/src/Microsoft.AspNet.Hosting.Server.Abstractions/IServerFactory.cs +++ b/src/Microsoft.AspNet.Hosting.Server.Abstractions/IServerFactory.cs @@ -4,7 +4,7 @@ using System; using System.Threading.Tasks; using Microsoft.AspNet.Http.Features; -using Microsoft.Framework.Configuration; +using Microsoft.Extensions.Configuration; namespace Microsoft.AspNet.Hosting.Server { diff --git a/src/Microsoft.AspNet.Hosting.Server.Abstractions/project.json b/src/Microsoft.AspNet.Hosting.Server.Abstractions/project.json index 85f0dc5415..c36c180620 100644 --- a/src/Microsoft.AspNet.Hosting.Server.Abstractions/project.json +++ b/src/Microsoft.AspNet.Hosting.Server.Abstractions/project.json @@ -1,4 +1,4 @@ -{ +{ "version": "1.0.0-*", "description": "ASP.NET 5 Hosting server abstractions.", "repository": { @@ -7,7 +7,7 @@ }, "dependencies": { "Microsoft.AspNet.Http.Features": "1.0.0-*", - "Microsoft.Framework.Configuration.Abstractions": "1.0.0-*" + "Microsoft.Extensions.Configuration.Abstractions": "1.0.0-*" }, "frameworks": { diff --git a/src/Microsoft.AspNet.Hosting/Internal/HostingEngine.cs b/src/Microsoft.AspNet.Hosting/Internal/HostingEngine.cs index 6d92a39688..786ba49eff 100644 --- a/src/Microsoft.AspNet.Hosting/Internal/HostingEngine.cs +++ b/src/Microsoft.AspNet.Hosting/Internal/HostingEngine.cs @@ -15,9 +15,9 @@ using Microsoft.AspNet.Http.Features; using Microsoft.AspNet.Http.Features.Internal; using Microsoft.AspNet.Server.Features; using Microsoft.Dnx.Runtime; -using Microsoft.Framework.Configuration; -using Microsoft.Framework.DependencyInjection; -using Microsoft.Framework.Logging; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; namespace Microsoft.AspNet.Hosting.Internal { diff --git a/src/Microsoft.AspNet.Hosting/Internal/RequestServicesContainerFeature.cs b/src/Microsoft.AspNet.Hosting/Internal/RequestServicesContainerFeature.cs index 6a0972fe58..0de3d46ac6 100644 --- a/src/Microsoft.AspNet.Hosting/Internal/RequestServicesContainerFeature.cs +++ b/src/Microsoft.AspNet.Hosting/Internal/RequestServicesContainerFeature.cs @@ -3,7 +3,7 @@ using System; using Microsoft.AspNet.Http.Features.Internal; -using Microsoft.Framework.DependencyInjection; +using Microsoft.Extensions.DependencyInjection; namespace Microsoft.AspNet.Hosting.Internal { diff --git a/src/Microsoft.AspNet.Hosting/Internal/RequestServicesContainerMiddleware.cs b/src/Microsoft.AspNet.Hosting/Internal/RequestServicesContainerMiddleware.cs index 25949db506..8cf659227e 100644 --- a/src/Microsoft.AspNet.Hosting/Internal/RequestServicesContainerMiddleware.cs +++ b/src/Microsoft.AspNet.Hosting/Internal/RequestServicesContainerMiddleware.cs @@ -7,7 +7,7 @@ using Microsoft.AspNet.Builder; using Microsoft.AspNet.Http; using Microsoft.AspNet.Http.Features; using Microsoft.AspNet.Http.Features.Internal; -using Microsoft.Framework.DependencyInjection; +using Microsoft.Extensions.DependencyInjection; namespace Microsoft.AspNet.Hosting.Internal { diff --git a/src/Microsoft.AspNet.Hosting/Program.cs b/src/Microsoft.AspNet.Hosting/Program.cs index 269f415d8b..7c2cbb2127 100644 --- a/src/Microsoft.AspNet.Hosting/Program.cs +++ b/src/Microsoft.AspNet.Hosting/Program.cs @@ -5,8 +5,8 @@ using System; using Microsoft.AspNet.Http.Features; using Microsoft.AspNet.Server.Features; using Microsoft.Dnx.Runtime; -using Microsoft.Framework.Configuration; -using Microsoft.Framework.DependencyInjection; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; namespace Microsoft.AspNet.Hosting { diff --git a/src/Microsoft.AspNet.Hosting/Server/ServerLoader.cs b/src/Microsoft.AspNet.Hosting/Server/ServerLoader.cs index 3a94dfaca5..4f3b5fe4f0 100644 --- a/src/Microsoft.AspNet.Hosting/Server/ServerLoader.cs +++ b/src/Microsoft.AspNet.Hosting/Server/ServerLoader.cs @@ -4,7 +4,7 @@ using System; using System.Linq; using System.Reflection; -using Microsoft.Framework.DependencyInjection; +using Microsoft.Extensions.DependencyInjection; namespace Microsoft.AspNet.Hosting.Server { diff --git a/src/Microsoft.AspNet.Hosting/Startup/ConfigureDelegate.cs b/src/Microsoft.AspNet.Hosting/Startup/ConfigureDelegate.cs index c9a814eaac..da39fa6d3c 100644 --- a/src/Microsoft.AspNet.Hosting/Startup/ConfigureDelegate.cs +++ b/src/Microsoft.AspNet.Hosting/Startup/ConfigureDelegate.cs @@ -4,7 +4,7 @@ using System; using System.Reflection; using Microsoft.AspNet.Builder; -using Microsoft.Framework.DependencyInjection; +using Microsoft.Extensions.DependencyInjection; namespace Microsoft.AspNet.Hosting.Startup { diff --git a/src/Microsoft.AspNet.Hosting/Startup/ConfigureServicesDelegate.cs b/src/Microsoft.AspNet.Hosting/Startup/ConfigureServicesDelegate.cs index 716795bc8d..f5eaea5aed 100644 --- a/src/Microsoft.AspNet.Hosting/Startup/ConfigureServicesDelegate.cs +++ b/src/Microsoft.AspNet.Hosting/Startup/ConfigureServicesDelegate.cs @@ -4,7 +4,7 @@ using System; using System.Linq; using System.Reflection; -using Microsoft.Framework.DependencyInjection; +using Microsoft.Extensions.DependencyInjection; namespace Microsoft.AspNet.Hosting.Startup { diff --git a/src/Microsoft.AspNet.Hosting/Startup/StartupExceptionPage.cs b/src/Microsoft.AspNet.Hosting/Startup/StartupExceptionPage.cs index 924b30ebbf..bf3125e834 100644 --- a/src/Microsoft.AspNet.Hosting/Startup/StartupExceptionPage.cs +++ b/src/Microsoft.AspNet.Hosting/Startup/StartupExceptionPage.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// 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; @@ -13,7 +13,7 @@ using System.Runtime.ExceptionServices; using System.Text; using Microsoft.Dnx.Compilation; using Microsoft.Dnx.Runtime; -using Microsoft.Framework.WebEncoders; +using Microsoft.Extensions.WebEncoders; namespace Microsoft.AspNet.Hosting.Startup { diff --git a/src/Microsoft.AspNet.Hosting/Startup/StartupLoader.cs b/src/Microsoft.AspNet.Hosting/Startup/StartupLoader.cs index 28d716ffa4..f97b024bec 100644 --- a/src/Microsoft.AspNet.Hosting/Startup/StartupLoader.cs +++ b/src/Microsoft.AspNet.Hosting/Startup/StartupLoader.cs @@ -6,7 +6,7 @@ using System.Collections.Generic; using System.Globalization; using System.Linq; using System.Reflection; -using Microsoft.Framework.DependencyInjection; +using Microsoft.Extensions.DependencyInjection; namespace Microsoft.AspNet.Hosting.Startup { diff --git a/src/Microsoft.AspNet.Hosting/Startup/StartupMethods.cs b/src/Microsoft.AspNet.Hosting/Startup/StartupMethods.cs index e8b61efdab..b62dae27f7 100644 --- a/src/Microsoft.AspNet.Hosting/Startup/StartupMethods.cs +++ b/src/Microsoft.AspNet.Hosting/Startup/StartupMethods.cs @@ -3,7 +3,7 @@ using System; using Microsoft.AspNet.Builder; -using Microsoft.Framework.DependencyInjection; +using Microsoft.Extensions.DependencyInjection; namespace Microsoft.AspNet.Hosting.Startup { diff --git a/src/Microsoft.AspNet.Hosting/WebHostBuilder.cs b/src/Microsoft.AspNet.Hosting/WebHostBuilder.cs index 2563776356..2e969d90cc 100644 --- a/src/Microsoft.AspNet.Hosting/WebHostBuilder.cs +++ b/src/Microsoft.AspNet.Hosting/WebHostBuilder.cs @@ -11,9 +11,9 @@ 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; -using Microsoft.Framework.Logging; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; namespace Microsoft.AspNet.Hosting { diff --git a/src/Microsoft.AspNet.Hosting/project.json b/src/Microsoft.AspNet.Hosting/project.json index ac5468cff2..10d8cfadfb 100644 --- a/src/Microsoft.AspNet.Hosting/project.json +++ b/src/Microsoft.AspNet.Hosting/project.json @@ -12,12 +12,12 @@ "Microsoft.AspNet.Hosting.Server.Abstractions": "1.0.0-*", "Microsoft.AspNet.Http": "1.0.0-*", "Microsoft.AspNet.Http.Extensions": "1.0.0-*", - "Microsoft.Framework.Configuration": "1.0.0-*", - "Microsoft.Framework.Configuration.CommandLine": "1.0.0-*", - "Microsoft.Framework.Configuration.EnvironmentVariables": "1.0.0-*", - "Microsoft.Framework.Configuration.Json": "1.0.0-*", - "Microsoft.Framework.DependencyInjection": "1.0.0-*", - "Microsoft.Framework.Logging": "1.0.0-*", + "Microsoft.Extensions.Configuration": "1.0.0-*", + "Microsoft.Extensions.Configuration.CommandLine": "1.0.0-*", + "Microsoft.Extensions.Configuration.EnvironmentVariables": "1.0.0-*", + "Microsoft.Extensions.Configuration.Json": "1.0.0-*", + "Microsoft.Extensions.DependencyInjection": "1.0.0-*", + "Microsoft.Extensions.Logging": "1.0.0-*", "Microsoft.Dnx.Compilation.Abstractions": "1.0.0-*", "Microsoft.Dnx.Runtime.Abstractions": "1.0.0-*", "Newtonsoft.Json": "6.0.6", diff --git a/src/Microsoft.AspNet.Server.Testing/Common/RetryHelper.cs b/src/Microsoft.AspNet.Server.Testing/Common/RetryHelper.cs index 1835b55e52..e6f9038725 100644 --- a/src/Microsoft.AspNet.Server.Testing/Common/RetryHelper.cs +++ b/src/Microsoft.AspNet.Server.Testing/Common/RetryHelper.cs @@ -6,7 +6,7 @@ using System.Net; using System.Net.Http; using System.Threading; using System.Threading.Tasks; -using Microsoft.Framework.Logging; +using Microsoft.Extensions.Logging; namespace Microsoft.AspNet.Server.Testing { diff --git a/src/Microsoft.AspNet.Server.Testing/Deployers/ApplicationDeployer.cs b/src/Microsoft.AspNet.Server.Testing/Deployers/ApplicationDeployer.cs index 19fe88337b..2c0d8f1742 100644 --- a/src/Microsoft.AspNet.Server.Testing/Deployers/ApplicationDeployer.cs +++ b/src/Microsoft.AspNet.Server.Testing/Deployers/ApplicationDeployer.cs @@ -7,7 +7,7 @@ using System.IO; using System.Text; using System.Text.RegularExpressions; using System.Threading; -using Microsoft.Framework.Logging; +using Microsoft.Extensions.Logging; namespace Microsoft.AspNet.Server.Testing { diff --git a/src/Microsoft.AspNet.Server.Testing/Deployers/ApplicationDeployerFactory.cs b/src/Microsoft.AspNet.Server.Testing/Deployers/ApplicationDeployerFactory.cs index d40a6562c1..3bdcd17684 100644 --- a/src/Microsoft.AspNet.Server.Testing/Deployers/ApplicationDeployerFactory.cs +++ b/src/Microsoft.AspNet.Server.Testing/Deployers/ApplicationDeployerFactory.cs @@ -2,7 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using Microsoft.Framework.Logging; +using Microsoft.Extensions.Logging; namespace Microsoft.AspNet.Server.Testing { diff --git a/src/Microsoft.AspNet.Server.Testing/Deployers/IISDeployer.cs b/src/Microsoft.AspNet.Server.Testing/Deployers/IISDeployer.cs index fe3e046254..744c216dfd 100644 --- a/src/Microsoft.AspNet.Server.Testing/Deployers/IISDeployer.cs +++ b/src/Microsoft.AspNet.Server.Testing/Deployers/IISDeployer.cs @@ -7,7 +7,7 @@ using System.IO; using System.Linq; using System.Threading; using System.Xml; -using Microsoft.Framework.Logging; +using Microsoft.Extensions.Logging; using Microsoft.Web.Administration; namespace Microsoft.AspNet.Server.Testing diff --git a/src/Microsoft.AspNet.Server.Testing/Deployers/IISExpressDeployer.cs b/src/Microsoft.AspNet.Server.Testing/Deployers/IISExpressDeployer.cs index bd334652a8..a9aaea2a35 100644 --- a/src/Microsoft.AspNet.Server.Testing/Deployers/IISExpressDeployer.cs +++ b/src/Microsoft.AspNet.Server.Testing/Deployers/IISExpressDeployer.cs @@ -5,7 +5,7 @@ using System; using System.Diagnostics; using System.IO; using System.Threading; -using Microsoft.Framework.Logging; +using Microsoft.Extensions.Logging; namespace Microsoft.AspNet.Server.Testing { diff --git a/src/Microsoft.AspNet.Server.Testing/Deployers/MonoDeployer.cs b/src/Microsoft.AspNet.Server.Testing/Deployers/MonoDeployer.cs index 8a5961be4d..93913099f2 100644 --- a/src/Microsoft.AspNet.Server.Testing/Deployers/MonoDeployer.cs +++ b/src/Microsoft.AspNet.Server.Testing/Deployers/MonoDeployer.cs @@ -6,7 +6,7 @@ using System.Diagnostics; using System.IO; using System.Linq; using System.Threading; -using Microsoft.Framework.Logging; +using Microsoft.Extensions.Logging; namespace Microsoft.AspNet.Server.Testing { diff --git a/src/Microsoft.AspNet.Server.Testing/Deployers/SelfHostDeployer.cs b/src/Microsoft.AspNet.Server.Testing/Deployers/SelfHostDeployer.cs index 07c175babc..d9a67a6f89 100644 --- a/src/Microsoft.AspNet.Server.Testing/Deployers/SelfHostDeployer.cs +++ b/src/Microsoft.AspNet.Server.Testing/Deployers/SelfHostDeployer.cs @@ -5,7 +5,7 @@ using System; using System.Diagnostics; using System.IO; using System.Threading; -using Microsoft.Framework.Logging; +using Microsoft.Extensions.Logging; namespace Microsoft.AspNet.Server.Testing { diff --git a/src/Microsoft.AspNet.Server.Testing/project.json b/src/Microsoft.AspNet.Server.Testing/project.json index 44cd34edf5..90279d5ecf 100644 --- a/src/Microsoft.AspNet.Server.Testing/project.json +++ b/src/Microsoft.AspNet.Server.Testing/project.json @@ -7,7 +7,7 @@ }, "dependencies": { "Microsoft.AspNet.Testing": "1.0.0-*", - "Microsoft.Framework.Logging.Abstractions": "1.0.0-*", + "Microsoft.Extensions.Logging.Abstractions": "1.0.0-*", "Microsoft.Dnx.Runtime.Abstractions": "1.0.0-*" }, "frameworks": { diff --git a/src/Microsoft.AspNet.TestHost/RequestFeature.cs b/src/Microsoft.AspNet.TestHost/RequestFeature.cs index b55b02b6ff..a82bd17759 100644 --- a/src/Microsoft.AspNet.TestHost/RequestFeature.cs +++ b/src/Microsoft.AspNet.TestHost/RequestFeature.cs @@ -5,7 +5,7 @@ using System; using System.Collections.Generic; using System.IO; using Microsoft.AspNet.Http.Features; -using Microsoft.Framework.Primitives; +using Microsoft.Extensions.Primitives; namespace Microsoft.AspNet.TestHost { diff --git a/src/Microsoft.AspNet.TestHost/ResponseFeature.cs b/src/Microsoft.AspNet.TestHost/ResponseFeature.cs index 2f699e572d..ec63ebe73f 100644 --- a/src/Microsoft.AspNet.TestHost/ResponseFeature.cs +++ b/src/Microsoft.AspNet.TestHost/ResponseFeature.cs @@ -6,7 +6,7 @@ using System.Collections.Generic; using System.IO; using System.Threading.Tasks; using Microsoft.AspNet.Http.Features; -using Microsoft.Framework.Primitives; +using Microsoft.Extensions.Primitives; namespace Microsoft.AspNet.TestHost { diff --git a/src/Microsoft.AspNet.TestHost/TestServer.cs b/src/Microsoft.AspNet.TestHost/TestServer.cs index 3a6522c476..6cdaffc401 100644 --- a/src/Microsoft.AspNet.TestHost/TestServer.cs +++ b/src/Microsoft.AspNet.TestHost/TestServer.cs @@ -10,8 +10,8 @@ using Microsoft.AspNet.Hosting.Server; using Microsoft.AspNet.Http; using Microsoft.AspNet.Http.Features; using Microsoft.Dnx.Runtime.Infrastructure; -using Microsoft.Framework.Configuration; -using Microsoft.Framework.DependencyInjection; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; namespace Microsoft.AspNet.TestHost { diff --git a/test/Microsoft.AspNet.Hosting.Tests/Fakes/Startup.cs b/test/Microsoft.AspNet.Hosting.Tests/Fakes/Startup.cs index 700fbf6d7e..d3fd5bb8bf 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/Fakes/Startup.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/Fakes/Startup.cs @@ -2,7 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using Microsoft.AspNet.Builder; -using Microsoft.Framework.DependencyInjection; +using Microsoft.Extensions.DependencyInjection; using System; namespace Microsoft.AspNet.Hosting.Fakes diff --git a/test/Microsoft.AspNet.Hosting.Tests/Fakes/StartupBase.cs b/test/Microsoft.AspNet.Hosting.Tests/Fakes/StartupBase.cs index d2f27bdf40..90edd4e1cc 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/Fakes/StartupBase.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/Fakes/StartupBase.cs @@ -1,7 +1,7 @@ // 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.Framework.DependencyInjection; +using Microsoft.Extensions.DependencyInjection; namespace Microsoft.AspNet.Hosting.Fakes { diff --git a/test/Microsoft.AspNet.Hosting.Tests/Fakes/StartupConfigureServicesThrows.cs b/test/Microsoft.AspNet.Hosting.Tests/Fakes/StartupConfigureServicesThrows.cs index b7b3cfcdef..f3c19ac07d 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/Fakes/StartupConfigureServicesThrows.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/Fakes/StartupConfigureServicesThrows.cs @@ -3,7 +3,7 @@ using System; using Microsoft.AspNet.Builder; -using Microsoft.Framework.DependencyInjection; +using Microsoft.Extensions.DependencyInjection; namespace Microsoft.AspNet.Hosting.Fakes { diff --git a/test/Microsoft.AspNet.Hosting.Tests/Fakes/StartupConfigureThrows.cs b/test/Microsoft.AspNet.Hosting.Tests/Fakes/StartupConfigureThrows.cs index 063404a4d1..55db505105 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/Fakes/StartupConfigureThrows.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/Fakes/StartupConfigureThrows.cs @@ -3,7 +3,7 @@ using System; using Microsoft.AspNet.Builder; -using Microsoft.Framework.DependencyInjection; +using Microsoft.Extensions.DependencyInjection; namespace Microsoft.AspNet.Hosting.Fakes { diff --git a/test/Microsoft.AspNet.Hosting.Tests/Fakes/StartupTwoConfigureServices.cs b/test/Microsoft.AspNet.Hosting.Tests/Fakes/StartupTwoConfigureServices.cs index 0442c3785c..335dd4eaa8 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/Fakes/StartupTwoConfigureServices.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/Fakes/StartupTwoConfigureServices.cs @@ -2,7 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using Microsoft.AspNet.Builder; -using Microsoft.Framework.DependencyInjection; +using Microsoft.Extensions.DependencyInjection; namespace Microsoft.AspNet.Hosting.Fakes { diff --git a/test/Microsoft.AspNet.Hosting.Tests/Fakes/StartupWithConfigureServices.cs b/test/Microsoft.AspNet.Hosting.Tests/Fakes/StartupWithConfigureServices.cs index 8c580bb13b..31213c0c08 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/Fakes/StartupWithConfigureServices.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/Fakes/StartupWithConfigureServices.cs @@ -1,6 +1,6 @@ -using System; +using System; using Microsoft.AspNet.Builder; -using Microsoft.Framework.DependencyInjection; +using Microsoft.Extensions.DependencyInjection; namespace Microsoft.AspNet.Hosting.Fakes { diff --git a/test/Microsoft.AspNet.Hosting.Tests/Fakes/StartupWithNullConfigureServices.cs b/test/Microsoft.AspNet.Hosting.Tests/Fakes/StartupWithNullConfigureServices.cs index b14bf11e99..5a6df112ac 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/Fakes/StartupWithNullConfigureServices.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/Fakes/StartupWithNullConfigureServices.cs @@ -1,6 +1,6 @@ -using System; +using System; using Microsoft.AspNet.Builder; -using Microsoft.Framework.DependencyInjection; +using Microsoft.Extensions.DependencyInjection; namespace Microsoft.AspNet.Hosting.Fakes { diff --git a/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs b/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs index ded586de90..9594e06f26 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs @@ -18,10 +18,10 @@ using Microsoft.AspNet.Http.Features.Internal; using Microsoft.AspNet.Server.Features; using Microsoft.AspNet.Testing.xunit; using Microsoft.Dnx.Runtime.Infrastructure; -using Microsoft.Framework.Configuration; -using Microsoft.Framework.DependencyInjection; -using Microsoft.Framework.Internal; -using Microsoft.Framework.OptionsModel; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Internal; +using Microsoft.Extensions.OptionsModel; using Moq; using Xunit; diff --git a/test/Microsoft.AspNet.Hosting.Tests/StartupManagerTests.cs b/test/Microsoft.AspNet.Hosting.Tests/StartupManagerTests.cs index a5afed8b7b..e186469f0b 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/StartupManagerTests.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/StartupManagerTests.cs @@ -8,8 +8,8 @@ using Microsoft.AspNet.Builder; using Microsoft.AspNet.Builder.Internal; using Microsoft.AspNet.Hosting.Fakes; using Microsoft.AspNet.Hosting.Startup; -using Microsoft.Framework.DependencyInjection; -using Microsoft.Framework.OptionsModel; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.OptionsModel; using Xunit; namespace Microsoft.AspNet.Hosting.Tests diff --git a/test/Microsoft.AspNet.Hosting.Tests/WebHostBuilderTests.cs b/test/Microsoft.AspNet.Hosting.Tests/WebHostBuilderTests.cs index 8d1b812ad8..4cd92b967e 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/WebHostBuilderTests.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/WebHostBuilderTests.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// 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; @@ -11,7 +11,7 @@ using Microsoft.AspNet.Hosting.Server; using Microsoft.AspNet.Http.Features; using Microsoft.AspNet.Http.Internal; using Microsoft.Dnx.Runtime.Infrastructure; -using Microsoft.Framework.Configuration; +using Microsoft.Extensions.Configuration; using Xunit; namespace Microsoft.AspNet.Hosting diff --git a/test/Microsoft.AspNet.Hosting.Tests/project.json b/test/Microsoft.AspNet.Hosting.Tests/project.json index cb5c6a1159..f4cb38366d 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/project.json +++ b/test/Microsoft.AspNet.Hosting.Tests/project.json @@ -3,7 +3,7 @@ "Microsoft.AspNet.Hosting": "1.0.0-*", "Microsoft.AspNet.Owin": "1.0.0-*", "Microsoft.AspNet.Testing": "1.0.0-*", - "Microsoft.Framework.OptionsModel": "1.0.0-*", + "Microsoft.Extensions.OptionsModel": "1.0.0-*", "Microsoft.Dnx.Runtime.Abstractions": "1.0.0-*", "Moq": "4.2.1312.1622", "xunit.runner.aspnet": "2.0.0-aspnet-*" diff --git a/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs b/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs index 174b29c092..58d8e09699 100644 --- a/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs +++ b/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs @@ -13,10 +13,10 @@ using Microsoft.AspNet.Hosting.Startup; using Microsoft.AspNet.Http; using Microsoft.AspNet.Http.Features; using Microsoft.AspNet.Http.Features.Internal; -using Microsoft.Framework.Configuration; -using Microsoft.Framework.DependencyInjection; -using Microsoft.Framework.Logging; -using Microsoft.Framework.TelemetryAdapter; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; +using Microsoft.Extensions.TelemetryAdapter; using Xunit; namespace Microsoft.AspNet.TestHost diff --git a/test/Microsoft.AspNet.TestHost.Tests/project.json b/test/Microsoft.AspNet.TestHost.Tests/project.json index 1d9db6febe..af78732d7c 100644 --- a/test/Microsoft.AspNet.TestHost.Tests/project.json +++ b/test/Microsoft.AspNet.TestHost.Tests/project.json @@ -2,7 +2,7 @@ "dependencies": { "Microsoft.AspNet.Testing": "1.0.0-*", "Microsoft.AspNet.TestHost": "1.0.0-*", - "Microsoft.Framework.TelemetryAdapter": "1.0.0-*", + "Microsoft.Extensions.TelemetryAdapter": "1.0.0-*", "xunit.runner.aspnet": "2.0.0-aspnet-*" }, "commands": { From 7441855c3466aa03f63633dd19ca3660a5ea3089 Mon Sep 17 00:00:00 2001 From: damianedwards Date: Fri, 2 Oct 2015 11:44:34 -0700 Subject: [PATCH 385/987] Don't use a GUID for request ID because it's slow: - FastHttpRequestIdentifierFeature uses an incrementing long with an int seed - Everything is lazy so no computer incurred if ID is not asked for - Optimized routine to stringify the ID - #306 --- .../FastHttpRequestIdentifierFeature.cs | 60 +++++++++++++++++++ .../Internal/HostingEngine.cs | 6 +- .../HostingEngineTests.cs | 4 +- .../FastHttpRequestIdentifierFeatureTests.cs | 44 ++++++++++++++ 4 files changed, 107 insertions(+), 7 deletions(-) create mode 100644 src/Microsoft.AspNet.Hosting/Internal/FastHttpRequestIdentifierFeature.cs create mode 100644 test/Microsoft.AspNet.Hosting.Tests/Internal/FastHttpRequestIdentifierFeatureTests.cs diff --git a/src/Microsoft.AspNet.Hosting/Internal/FastHttpRequestIdentifierFeature.cs b/src/Microsoft.AspNet.Hosting/Internal/FastHttpRequestIdentifierFeature.cs new file mode 100644 index 0000000000..74f7b36d6e --- /dev/null +++ b/src/Microsoft.AspNet.Hosting/Internal/FastHttpRequestIdentifierFeature.cs @@ -0,0 +1,60 @@ +// 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; +using System.Threading; +using Microsoft.AspNet.Http.Features; + +namespace Microsoft.AspNet.Hosting.Internal +{ + public class FastHttpRequestIdentifierFeature : IHttpRequestIdentifierFeature + { + private static readonly string _hexChars = "0123456789ABCDEF"; + // Seed the _requestId for this application instance with a random int + private static long _requestId = new Random().Next(); + + private string _id = null; + + public string TraceIdentifier + { + get + { + // Don't incur the cost of generating the request ID until it's asked for + if (_id == null) + { + _id = GenerateRequestId(Interlocked.Increment(ref _requestId)); + } + return _id; + } + set + { + _id = value; + } + } + + private static string GenerateRequestId(long id) + { + // The following routine is ~33% faster than calling long.ToString() when testing in tight loops of + // 1 million iterations. + var charBuffer = new char[sizeof(long) * 2]; + charBuffer[0] = _hexChars[(int)(id >> 60) & 0x0f]; + charBuffer[1] = _hexChars[(int)(id >> 56) & 0x0f]; + charBuffer[2] = _hexChars[(int)(id >> 52) & 0x0f]; + charBuffer[3] = _hexChars[(int)(id >> 48) & 0x0f]; + charBuffer[4] = _hexChars[(int)(id >> 44) & 0x0f]; + charBuffer[5] = _hexChars[(int)(id >> 40) & 0x0f]; + charBuffer[6] = _hexChars[(int)(id >> 36) & 0x0f]; + charBuffer[7] = _hexChars[(int)(id >> 32) & 0x0f]; + charBuffer[8] = _hexChars[(int)(id >> 28) & 0x0f]; + charBuffer[9] = _hexChars[(int)(id >> 24) & 0x0f]; + charBuffer[10] = _hexChars[(int)(id >> 20) & 0x0f]; + charBuffer[11] = _hexChars[(int)(id >> 16) & 0x0f]; + charBuffer[12] = _hexChars[(int)(id >> 12) & 0x0f]; + charBuffer[13] = _hexChars[(int)(id >> 8) & 0x0f]; + charBuffer[14] = _hexChars[(int)(id >> 4) & 0x0f]; + charBuffer[15] = _hexChars[(int)(id >> 0) & 0x0f]; + + return new string(charBuffer); + } + } +} diff --git a/src/Microsoft.AspNet.Hosting/Internal/HostingEngine.cs b/src/Microsoft.AspNet.Hosting/Internal/HostingEngine.cs index 786ba49eff..55b4170469 100644 --- a/src/Microsoft.AspNet.Hosting/Internal/HostingEngine.cs +++ b/src/Microsoft.AspNet.Hosting/Internal/HostingEngine.cs @@ -12,7 +12,6 @@ using Microsoft.AspNet.Hosting.Server; using Microsoft.AspNet.Hosting.Startup; using Microsoft.AspNet.Http; using Microsoft.AspNet.Http.Features; -using Microsoft.AspNet.Http.Features.Internal; using Microsoft.AspNet.Server.Features; using Microsoft.Dnx.Runtime; using Microsoft.Extensions.Configuration; @@ -278,10 +277,7 @@ namespace Microsoft.AspNet.Hosting.Internal var requestIdentifierFeature = httpContext.Features.Get(); if (requestIdentifierFeature == null) { - requestIdentifierFeature = new HttpRequestIdentifierFeature() - { - TraceIdentifier = Guid.NewGuid().ToString() - }; + requestIdentifierFeature = new FastHttpRequestIdentifierFeature(); httpContext.Features.Set(requestIdentifierFeature); } diff --git a/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs b/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs index 9594e06f26..e3bd3759a7 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs @@ -305,7 +305,7 @@ namespace Microsoft.AspNet.Hosting // Assert Assert.NotNull(httpContext); - Assert.IsType(httpContext.Features.Get()); + Assert.IsType(httpContext.Features.Get()); } [Fact] @@ -328,7 +328,7 @@ namespace Microsoft.AspNet.Hosting // Assert Assert.NotNull(httpContext); - Assert.IsType(httpContext.Features.Get()); + Assert.IsType(httpContext.Features.Get()); } [Fact] diff --git a/test/Microsoft.AspNet.Hosting.Tests/Internal/FastHttpRequestIdentifierFeatureTests.cs b/test/Microsoft.AspNet.Hosting.Tests/Internal/FastHttpRequestIdentifierFeatureTests.cs new file mode 100644 index 0000000000..fff0fb603a --- /dev/null +++ b/test/Microsoft.AspNet.Hosting.Tests/Internal/FastHttpRequestIdentifierFeatureTests.cs @@ -0,0 +1,44 @@ +// 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.Hosting.Internal; +using Xunit; + +namespace Microsoft.AspNet.Hosting.Tests.Internal +{ + public class FastHttpRequestIdentifierFeatureTests + { + [Fact] + public void TraceIdentifier_ReturnsId() + { + var feature = new FastHttpRequestIdentifierFeature(); + + var id = feature.TraceIdentifier; + + Assert.NotNull(id); + } + + [Fact] + public void TraceIdentifier_ReturnsStableId() + { + var feature = new FastHttpRequestIdentifierFeature(); + + var id1 = feature.TraceIdentifier; + var id2 = feature.TraceIdentifier; + + Assert.Equal(id1, id2); + } + + [Fact] + public void TraceIdentifier_ReturnsUniqueIdForDifferentInstances() + { + var feature1 = new FastHttpRequestIdentifierFeature(); + var feature2 = new FastHttpRequestIdentifierFeature(); + + var id1 = feature1.TraceIdentifier; + var id2 = feature2.TraceIdentifier; + + Assert.NotEqual(id1, id2); + } + } +} From 62ce39afb6f0222ae33b082eee031ee32c3fc27f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=81=82=E3=81=BE=E3=81=BF=E3=82=84=20=E3=82=86=E3=81=86?= =?UTF-8?q?=E3=81=93?= <1@1234.sh> Date: Wed, 7 Oct 2015 07:11:56 +0800 Subject: [PATCH 386/987] To correct the word spelling To correct the word spelling --- .../compiler/resources/Compilation_Exception.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Microsoft.AspNet.Hosting/compiler/resources/Compilation_Exception.html b/src/Microsoft.AspNet.Hosting/compiler/resources/Compilation_Exception.html index 4a4faf1d23..76f56157ba 100644 --- a/src/Microsoft.AspNet.Hosting/compiler/resources/Compilation_Exception.html +++ b/src/Microsoft.AspNet.Hosting/compiler/resources/Compilation_Exception.html @@ -1,5 +1,5 @@ 
- One or more compilation errors occured:
+ One or more compilation errors occurred:
{0}
From f88b20608249a0d4e703b0e8048a16ff0b3dc548 Mon Sep 17 00:00:00 2001 From: Chris R Date: Wed, 7 Oct 2015 09:20:12 -0700 Subject: [PATCH 387/987] #310 Do not automatically wrap IFeatureCollections. --- .../Builder/HttpContextFactory.cs | 2 +- .../HostingEngineTests.cs | 23 ------------------- .../HttpContextFactoryFacts.cs | 2 +- 3 files changed, 2 insertions(+), 25 deletions(-) diff --git a/src/Microsoft.AspNet.Hosting/Builder/HttpContextFactory.cs b/src/Microsoft.AspNet.Hosting/Builder/HttpContextFactory.cs index 7fccad6854..d24250405b 100644 --- a/src/Microsoft.AspNet.Hosting/Builder/HttpContextFactory.cs +++ b/src/Microsoft.AspNet.Hosting/Builder/HttpContextFactory.cs @@ -11,7 +11,7 @@ namespace Microsoft.AspNet.Hosting.Builder { public HttpContext CreateHttpContext(IFeatureCollection featureCollection) { - return new DefaultHttpContext(new FeatureCollection(featureCollection)); + return new DefaultHttpContext(featureCollection); } } } \ No newline at end of file diff --git a/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs b/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs index e3bd3759a7..159c2775b5 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs @@ -308,29 +308,6 @@ namespace Microsoft.AspNet.Hosting Assert.IsType(httpContext.Features.Get()); } - [Fact] - public void Hosting_CreatesDefaultRequestIdentifierFeature_IfNotPresent_ForImmutableFeatureCollection() - { - // Arrange - HttpContext httpContext = null; - var requestDelegate = new RequestDelegate(innerHttpContext => - { - httpContext = innerHttpContext; - return Task.FromResult(0); - }); - - _featuresSupportedByThisHost = new ReadOnlyFeatureCollection(); - - var hostingEngine = CreateHostingEngine(requestDelegate); - - // Act - var disposable = hostingEngine.Start(); - - // Assert - Assert.NotNull(httpContext); - Assert.IsType(httpContext.Features.Get()); - } - [Fact] public void HostingEngine_DoesNot_CreateDefaultRequestIdentifierFeature_IfPresent() { diff --git a/test/Microsoft.AspNet.Hosting.Tests/HttpContextFactoryFacts.cs b/test/Microsoft.AspNet.Hosting.Tests/HttpContextFactoryFacts.cs index 302da49712..a355ca0842 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/HttpContextFactoryFacts.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/HttpContextFactoryFacts.cs @@ -16,7 +16,7 @@ namespace Microsoft.AspNet.Hosting.Tests { var env = new Dictionary(); var contextFactory = new HttpContextFactory(); - var context = contextFactory.CreateHttpContext(new OwinFeatureCollection(env)); + var context = contextFactory.CreateHttpContext(new FeatureCollection(new OwinFeatureCollection(env))); // Setting a feature will throw if the above feature collection is not wrapped in a mutable feature collection. context.Features.Set(new CustomFeature(100)); From 2da9f13db3d0e0e7b6ae69953a5356c98e321c92 Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Mon, 5 Oct 2015 10:37:42 -0400 Subject: [PATCH 388/987] Less allocs in GenerateRequestId Case insentive base32 encoding --- .../FastHttpRequestIdentifierFeature.cs | 53 ++++++++++--------- src/Microsoft.AspNet.Hosting/project.json | 5 +- 2 files changed, 33 insertions(+), 25 deletions(-) diff --git a/src/Microsoft.AspNet.Hosting/Internal/FastHttpRequestIdentifierFeature.cs b/src/Microsoft.AspNet.Hosting/Internal/FastHttpRequestIdentifierFeature.cs index 74f7b36d6e..95e7806557 100644 --- a/src/Microsoft.AspNet.Hosting/Internal/FastHttpRequestIdentifierFeature.cs +++ b/src/Microsoft.AspNet.Hosting/Internal/FastHttpRequestIdentifierFeature.cs @@ -9,9 +9,12 @@ namespace Microsoft.AspNet.Hosting.Internal { public class FastHttpRequestIdentifierFeature : IHttpRequestIdentifierFeature { - private static readonly string _hexChars = "0123456789ABCDEF"; - // Seed the _requestId for this application instance with a random int - private static long _requestId = new Random().Next(); + // Base64 encoding - but in ascii sort order for easy text based sorting + private static readonly string _encode32Chars = "0123456789ABCDEFGHIJKLMNOPQRSTUV"; + // Seed the _requestId for this application instance with + // the number of 100-nanosecond intervals that have elapsed since 12:00:00 midnight, January 1, 0001 + // for a roughly increasing _requestId over restarts + private static long _requestId = DateTime.UtcNow.Ticks; private string _id = null; @@ -32,29 +35,31 @@ namespace Microsoft.AspNet.Hosting.Internal } } - private static string GenerateRequestId(long id) + private static unsafe string GenerateRequestId(long id) { - // The following routine is ~33% faster than calling long.ToString() when testing in tight loops of - // 1 million iterations. - var charBuffer = new char[sizeof(long) * 2]; - charBuffer[0] = _hexChars[(int)(id >> 60) & 0x0f]; - charBuffer[1] = _hexChars[(int)(id >> 56) & 0x0f]; - charBuffer[2] = _hexChars[(int)(id >> 52) & 0x0f]; - charBuffer[3] = _hexChars[(int)(id >> 48) & 0x0f]; - charBuffer[4] = _hexChars[(int)(id >> 44) & 0x0f]; - charBuffer[5] = _hexChars[(int)(id >> 40) & 0x0f]; - charBuffer[6] = _hexChars[(int)(id >> 36) & 0x0f]; - charBuffer[7] = _hexChars[(int)(id >> 32) & 0x0f]; - charBuffer[8] = _hexChars[(int)(id >> 28) & 0x0f]; - charBuffer[9] = _hexChars[(int)(id >> 24) & 0x0f]; - charBuffer[10] = _hexChars[(int)(id >> 20) & 0x0f]; - charBuffer[11] = _hexChars[(int)(id >> 16) & 0x0f]; - charBuffer[12] = _hexChars[(int)(id >> 12) & 0x0f]; - charBuffer[13] = _hexChars[(int)(id >> 8) & 0x0f]; - charBuffer[14] = _hexChars[(int)(id >> 4) & 0x0f]; - charBuffer[15] = _hexChars[(int)(id >> 0) & 0x0f]; + // The following routine is ~310% faster than calling long.ToString() on x64 + // and ~600% faster than calling long.ToString() on x86 in tight loops of 1 million+ iterations + // See: https://github.com/aspnet/Hosting/pull/385 - return new string(charBuffer); + // stackalloc to allocate array on stack rather than heap + char* charBuffer = stackalloc char[13]; + + charBuffer[0] = _encode32Chars[(int)(id >> 60) & 31]; + charBuffer[1] = _encode32Chars[(int)(id >> 55) & 31]; + charBuffer[2] = _encode32Chars[(int)(id >> 50) & 31]; + charBuffer[3] = _encode32Chars[(int)(id >> 45) & 31]; + charBuffer[4] = _encode32Chars[(int)(id >> 40) & 31]; + charBuffer[5] = _encode32Chars[(int)(id >> 35) & 31]; + charBuffer[6] = _encode32Chars[(int)(id >> 30) & 31]; + charBuffer[7] = _encode32Chars[(int)(id >> 25) & 31]; + charBuffer[8] = _encode32Chars[(int)(id >> 20) & 31]; + charBuffer[9] = _encode32Chars[(int)(id >> 15) & 31]; + charBuffer[10] = _encode32Chars[(int)(id >> 10) & 31]; + charBuffer[11] = _encode32Chars[(int)(id >> 5) & 31]; + charBuffer[12] = _encode32Chars[(int)id & 31]; + + // string ctor overload that takes char* + return new string(charBuffer, 0, 13); } } } diff --git a/src/Microsoft.AspNet.Hosting/project.json b/src/Microsoft.AspNet.Hosting/project.json index 10d8cfadfb..18ea116249 100644 --- a/src/Microsoft.AspNet.Hosting/project.json +++ b/src/Microsoft.AspNet.Hosting/project.json @@ -5,7 +5,10 @@ "type": "git", "url": "git://github.com/aspnet/hosting" }, - "compilationOptions": { "warningsAsErrors": true }, + "compilationOptions": { + "warningsAsErrors": true, + "allowUnsafe": true + }, "dependencies": { "Microsoft.AspNet.FileProviders.Physical": "1.0.0-*", "Microsoft.AspNet.Hosting.Abstractions": "1.0.0-*", From 9a12085ef95bc5d9ab4f78aa3c2e5ab88f927816 Mon Sep 17 00:00:00 2001 From: Ryan Nowak Date: Thu, 8 Oct 2015 11:17:14 -0700 Subject: [PATCH 389/987] Suppress [Obsolete] warnings for TelemetrySource --- NuGet.config | 2 +- .../Internal/HostingEngine.cs | 12 ++++++++---- src/Microsoft.AspNet.Hosting/WebHostBuilder.cs | 2 ++ .../TestServerTests.cs | 2 ++ 4 files changed, 13 insertions(+), 5 deletions(-) diff --git a/NuGet.config b/NuGet.config index 1707938c61..03704957e8 100644 --- a/NuGet.config +++ b/NuGet.config @@ -1,4 +1,4 @@ - + diff --git a/src/Microsoft.AspNet.Hosting/Internal/HostingEngine.cs b/src/Microsoft.AspNet.Hosting/Internal/HostingEngine.cs index 55b4170469..d0a951849d 100644 --- a/src/Microsoft.AspNet.Hosting/Internal/HostingEngine.cs +++ b/src/Microsoft.AspNet.Hosting/Internal/HostingEngine.cs @@ -88,7 +88,9 @@ namespace Microsoft.AspNet.Hosting.Internal var logger = _applicationServices.GetRequiredService>(); var contextFactory = _applicationServices.GetRequiredService(); var contextAccessor = _applicationServices.GetRequiredService(); +#pragma warning disable 0618 var telemetrySource = _applicationServices.GetRequiredService(); +#pragma warning restore 0618 var server = ServerFactory.Start(_serverInstance, async features => { @@ -96,12 +98,12 @@ namespace Microsoft.AspNet.Hosting.Internal httpContext.ApplicationServices = _applicationServices; var requestIdentifier = GetRequestIdentifier(httpContext); contextAccessor.HttpContext = httpContext; - +#pragma warning disable 0618 if (telemetrySource.IsEnabled("Microsoft.AspNet.Hosting.BeginRequest")) { telemetrySource.WriteTelemetry("Microsoft.AspNet.Hosting.BeginRequest", new { httpContext = httpContext }); } - +#pragma warning restore 0618 try { using (logger.IsEnabled(LogLevel.Critical) @@ -113,18 +115,20 @@ namespace Microsoft.AspNet.Hosting.Internal } catch (Exception ex) { +#pragma warning disable 0618 if (telemetrySource.IsEnabled("Microsoft.AspNet.Hosting.UnhandledException")) { telemetrySource.WriteTelemetry("Microsoft.AspNet.Hosting.UnhandledException", new { httpContext = httpContext, exception = ex }); } - +#pragma warning restore 0618 throw; } - +#pragma warning disable 0618 if (telemetrySource.IsEnabled("Microsoft.AspNet.Hosting.EndRequest")) { telemetrySource.WriteTelemetry("Microsoft.AspNet.Hosting.EndRequest", new { httpContext = httpContext }); } +#pragma warning restore 0618 }); _applicationLifetime.NotifyStarted(); diff --git a/src/Microsoft.AspNet.Hosting/WebHostBuilder.cs b/src/Microsoft.AspNet.Hosting/WebHostBuilder.cs index 2e969d90cc..e3ae6b3517 100644 --- a/src/Microsoft.AspNet.Hosting/WebHostBuilder.cs +++ b/src/Microsoft.AspNet.Hosting/WebHostBuilder.cs @@ -99,9 +99,11 @@ namespace Microsoft.AspNet.Hosting services.AddSingleton(); services.AddLogging(); +#pragma warning disable 0618 var telemetrySource = new TelemetryListener("Microsoft.AspNet"); services.AddInstance(telemetrySource); services.AddInstance(telemetrySource); +#pragma warning restore 0618 // Conjure up a RequestServices services.AddTransient(); diff --git a/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs b/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs index 58d8e09699..9bb5cdd9e6 100644 --- a/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs +++ b/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs @@ -437,6 +437,7 @@ namespace Microsoft.AspNet.TestHost Assert.Equal("FoundFoo:False", await result.Content.ReadAsStringAsync()); } +#pragma warning disable 0618 [Fact] public async Task BeginEndTelemetryAvailable() { @@ -480,6 +481,7 @@ namespace Microsoft.AspNet.TestHost Assert.NotNull(listener.UnhandledException?.HttpContext); Assert.NotNull(listener.UnhandledException?.Exception); } +#pragma warning restore 0618 public class TestTelemetryListener { From f7c7306881770e3c3fbf06be66df7489487875f2 Mon Sep 17 00:00:00 2001 From: Chris R Date: Thu, 8 Oct 2015 10:17:28 -0700 Subject: [PATCH 390/987] React to IHeaderDictionary changes. --- src/Microsoft.AspNet.TestHost/RequestFeature.cs | 9 ++++----- src/Microsoft.AspNet.TestHost/ResponseFeature.cs | 8 ++++---- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/Microsoft.AspNet.TestHost/RequestFeature.cs b/src/Microsoft.AspNet.TestHost/RequestFeature.cs index a82bd17759..7f63957663 100644 --- a/src/Microsoft.AspNet.TestHost/RequestFeature.cs +++ b/src/Microsoft.AspNet.TestHost/RequestFeature.cs @@ -1,11 +1,10 @@ // 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; -using System.Collections.Generic; using System.IO; +using Microsoft.AspNet.Http; using Microsoft.AspNet.Http.Features; -using Microsoft.Extensions.Primitives; +using Microsoft.AspNet.Http.Internal; namespace Microsoft.AspNet.TestHost { @@ -14,7 +13,7 @@ namespace Microsoft.AspNet.TestHost public RequestFeature() { Body = Stream.Null; - Headers = new Dictionary(StringComparer.OrdinalIgnoreCase); + Headers = new HeaderDictionary(); Method = "GET"; Path = ""; PathBase = ""; @@ -25,7 +24,7 @@ namespace Microsoft.AspNet.TestHost public Stream Body { get; set; } - public IDictionary Headers { get; set; } + public IHeaderDictionary Headers { get; set; } public string Method { get; set; } diff --git a/src/Microsoft.AspNet.TestHost/ResponseFeature.cs b/src/Microsoft.AspNet.TestHost/ResponseFeature.cs index ec63ebe73f..c0744d9239 100644 --- a/src/Microsoft.AspNet.TestHost/ResponseFeature.cs +++ b/src/Microsoft.AspNet.TestHost/ResponseFeature.cs @@ -2,11 +2,11 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using System.Collections.Generic; using System.IO; using System.Threading.Tasks; +using Microsoft.AspNet.Http; using Microsoft.AspNet.Http.Features; -using Microsoft.Extensions.Primitives; +using Microsoft.AspNet.Http.Internal; namespace Microsoft.AspNet.TestHost { @@ -17,7 +17,7 @@ namespace Microsoft.AspNet.TestHost public ResponseFeature() { - Headers = new Dictionary(StringComparer.OrdinalIgnoreCase); + Headers = new HeaderDictionary(); Body = new MemoryStream(); // 200 is the default status code all the way down to the host, so we set it @@ -29,7 +29,7 @@ namespace Microsoft.AspNet.TestHost public string ReasonPhrase { get; set; } - public IDictionary Headers { get; set; } + public IHeaderDictionary Headers { get; set; } public Stream Body { get; set; } From a0c632d64331cd6a006c4ccf9c844b909a5e1cc7 Mon Sep 17 00:00:00 2001 From: Doug Bunting Date: Thu, 8 Oct 2015 19:00:46 -0700 Subject: [PATCH 391/987] React to aspnet/Universe#290 fix --- build.cmd | 25 +++++++++++++------------ build.sh | 12 +++++++----- 2 files changed, 20 insertions(+), 17 deletions(-) diff --git a/build.cmd b/build.cmd index 70d974a61f..84dc87e480 100644 --- a/build.cmd +++ b/build.cmd @@ -18,22 +18,23 @@ md .nuget copy %CACHED_NUGET% .nuget\nuget.exe > nul :restore -IF EXIST packages\KoreBuild goto run +IF EXIST packages\Sake goto getdnx IF %BUILDCMD_KOREBUILD_VERSION%=="" ( - .nuget\nuget.exe install KoreBuild -ExcludeVersion -o packages -nocache -pre + .nuget\nuget.exe install KoreBuild -ExcludeVersion -o packages -nocache -pre ) ELSE ( - .nuget\nuget.exe install KoreBuild -version %BUILDCMD_KOREBUILD_VERSION% -ExcludeVersion -o packages -nocache -pre + .nuget\nuget.exe install KoreBuild -version %BUILDCMD_KOREBUILD_VERSION% -ExcludeVersion -o packages -nocache -pre ) -.nuget\nuget.exe install Sake -ExcludeVersion -Out packages +.nuget\NuGet.exe install Sake -ExcludeVersion -Source https://www.nuget.org/api/v2/ -Out packages -IF "%SKIP_DNX_INSTALL%"=="1" goto run -IF %BUILDCMD_DNX_VERSION%=="" ( - CALL packages\KoreBuild\build\dnvm upgrade -runtime CLR -arch x86 +:getdnx +IF "%SKIP_DNX_INSTALL%"=="" ( + IF "%BUILDCMD_DNX_VERSION%"=="" ( + BUILDCMD_DNX_VERSION=latest + ) + CALL packages\KoreBuild\build\dnvm install %BUILDCMD_DNX_VERSION% -runtime CoreCLR -arch x86 -alias default + CALL packages\KoreBuild\build\dnvm install default -runtime CLR -arch x86 -alias default ) ELSE ( - CALL packages\KoreBuild\build\dnvm install %BUILDCMD_DNX_VERSION% -runtime CLR -arch x86 -alias default + CALL packages\KoreBuild\build\dnvm use default -runtime CLR -arch x86 ) -CALL packages\KoreBuild\build\dnvm install default -runtime CoreCLR -arch x86 -:run -CALL packages\KoreBuild\build\dnvm use default -runtime CLR -arch x86 -packages\Sake\tools\Sake.exe -I packages\KoreBuild\build -f makefile.shade %* \ No newline at end of file +packages\Sake\tools\Sake.exe -I packages\KoreBuild\build -f makefile.shade %* diff --git a/build.sh b/build.sh index 0c66139817..da4e3fcd1c 100755 --- a/build.sh +++ b/build.sh @@ -24,18 +24,20 @@ if test ! -e .nuget; then cp $cachePath .nuget/nuget.exe fi -if test ! -d packages/KoreBuild; then +if test ! -d packages/Sake; then mono .nuget/nuget.exe install KoreBuild -ExcludeVersion -o packages -nocache -pre - mono .nuget/nuget.exe install Sake -ExcludeVersion -Out packages + mono .nuget/nuget.exe install Sake -ExcludeVersion -Source https://www.nuget.org/api/v2/ -Out packages fi if ! type dnvm > /dev/null 2>&1; then source packages/KoreBuild/build/dnvm.sh fi -if ! type dnx > /dev/null 2>&1; then - dnvm upgrade +if ! type dnx > /dev/null 2>&1 || [ -z "$SKIP_DNX_INSTALL" ]; then + dnvm install latest -runtime coreclr -alias default + dnvm install default -runtime mono -alias default +else + dnvm use default -runtime mono fi mono packages/Sake/tools/Sake.exe -I packages/KoreBuild/build -f makefile.shade "$@" - From 2a951aaeaa3fead9c5e095666a320578a2f1a21a Mon Sep 17 00:00:00 2001 From: Doug Bunting Date: Mon, 12 Oct 2015 12:55:15 -0700 Subject: [PATCH 392/987] Fix local build break --- build.cmd | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/build.cmd b/build.cmd index 84dc87e480..553e3929a0 100644 --- a/build.cmd +++ b/build.cmd @@ -4,8 +4,8 @@ cd %~dp0 SETLOCAL SET NUGET_VERSION=latest SET CACHED_NUGET=%LocalAppData%\NuGet\nuget.%NUGET_VERSION%.exe -SET BUILDCMD_KOREBUILD_VERSION="" -SET BUILDCMD_DNX_VERSION="" +SET BUILDCMD_KOREBUILD_VERSION= +SET BUILDCMD_DNX_VERSION= IF EXIST %CACHED_NUGET% goto copynuget echo Downloading latest version of NuGet.exe... @@ -19,7 +19,7 @@ copy %CACHED_NUGET% .nuget\nuget.exe > nul :restore IF EXIST packages\Sake goto getdnx -IF %BUILDCMD_KOREBUILD_VERSION%=="" ( +IF "%BUILDCMD_KOREBUILD_VERSION%"=="" ( .nuget\nuget.exe install KoreBuild -ExcludeVersion -o packages -nocache -pre ) ELSE ( .nuget\nuget.exe install KoreBuild -version %BUILDCMD_KOREBUILD_VERSION% -ExcludeVersion -o packages -nocache -pre @@ -27,10 +27,10 @@ IF %BUILDCMD_KOREBUILD_VERSION%=="" ( .nuget\NuGet.exe install Sake -ExcludeVersion -Source https://www.nuget.org/api/v2/ -Out packages :getdnx +IF "%BUILDCMD_DNX_VERSION%"=="" ( + SET BUILDCMD_DNX_VERSION=latest +) IF "%SKIP_DNX_INSTALL%"=="" ( - IF "%BUILDCMD_DNX_VERSION%"=="" ( - BUILDCMD_DNX_VERSION=latest - ) CALL packages\KoreBuild\build\dnvm install %BUILDCMD_DNX_VERSION% -runtime CoreCLR -arch x86 -alias default CALL packages\KoreBuild\build\dnvm install default -runtime CLR -arch x86 -alias default ) ELSE ( From 79a8a4e799a9ca78cd53ce19fcbba006f4c388ff Mon Sep 17 00:00:00 2001 From: Kiran Challa Date: Thu, 24 Sep 2015 10:01:02 -0700 Subject: [PATCH 393/987] Fix deployers --- global.json | 2 +- .../Deployers/ApplicationDeployer.cs | 118 ++++++++++++++---- .../Deployers/MonoDeployer.cs | 32 +++-- .../Deployers/SelfHostDeployer.cs | 7 +- .../HostingEngineTests.cs | 3 +- 5 files changed, 127 insertions(+), 35 deletions(-) diff --git a/global.json b/global.json index 983ba0401e..dd6bbaf48b 100644 --- a/global.json +++ b/global.json @@ -1,3 +1,3 @@ { - "projects": ["src"] + "projects": ["src","c:/github/testing/src","/home/kiran/github/testing/src"] } diff --git a/src/Microsoft.AspNet.Server.Testing/Deployers/ApplicationDeployer.cs b/src/Microsoft.AspNet.Server.Testing/Deployers/ApplicationDeployer.cs index 2c0d8f1742..c7a303affe 100644 --- a/src/Microsoft.AspNet.Server.Testing/Deployers/ApplicationDeployer.cs +++ b/src/Microsoft.AspNet.Server.Testing/Deployers/ApplicationDeployer.cs @@ -3,10 +3,12 @@ using System; using System.Diagnostics; +using System.Linq; using System.IO; using System.Text; using System.Text.RegularExpressions; using System.Threading; +using Microsoft.AspNet.Testing; using Microsoft.Extensions.Logging; namespace Microsoft.AspNet.Server.Testing @@ -16,8 +18,14 @@ namespace Microsoft.AspNet.Server.Testing /// public abstract class ApplicationDeployer : IApplicationDeployer { + /// + /// Example: runtimes/dnx-coreclr-win-x64.1.0.0-rc1-15844/bin + /// protected string ChosenRuntimePath { get; set; } + /// + /// Examples: dnx-coreclr-win-x64.1.0.0-rc1-15844, dnx-mono.1.0.0-rc1-15844 + /// protected string ChosenRuntimeName { get; set; } protected DeploymentParameters DeploymentParameters { get; private set; } @@ -26,6 +34,59 @@ namespace Microsoft.AspNet.Server.Testing protected Stopwatch StopWatch { get; private set; } = new Stopwatch(); + protected string OSPrefix + { + get + { + if (TestPlatformHelper.IsLinux) + { + return "linux"; + } + else if (TestPlatformHelper.IsMac) + { + return "darwin"; + } + else if (TestPlatformHelper.IsWindows) + { + return "win"; + } + else + { + throw new InvalidOperationException("Unrecognized operating system"); + } + } + } + + protected string DnuCommandName + { + get + { + if (TestPlatformHelper.IsWindows) + { + return "dnu.cmd"; + } + else + { + return "dnu"; + } + } + } + + protected string DnxCommandName + { + get + { + if (TestPlatformHelper.IsWindows) + { + return "dnx.exe"; + } + else + { + return "dnx"; + } + } + } + public abstract DeploymentResult Deploy(); public ApplicationDeployer( @@ -38,31 +99,44 @@ namespace Microsoft.AspNet.Server.Testing protected string PopulateChosenRuntimeInformation() { - var runtimePath = Process.GetCurrentProcess().MainModule.FileName; - Logger.LogInformation(string.Empty); - Logger.LogInformation($"Current runtime path is : {runtimePath}"); + // ex: runtimes/dnx-coreclr-win-x64.1.0.0-rc1-15844/bin + var currentRuntimeBinPath = Path.GetDirectoryName(Process.GetCurrentProcess().MainModule.FileName); + Logger.LogInformation($"Current runtime path is : {currentRuntimeBinPath}"); - var replaceStr = new StringBuilder(). - Append("dnx"). - Append((DeploymentParameters.RuntimeFlavor == RuntimeFlavor.CoreClr) ? "-coreclr" : "-clr"). - Append("-win"). - Append((DeploymentParameters.RuntimeArchitecture == RuntimeArchitecture.x86) ? "-x86" : "-x64"). - ToString(); + var targetRuntimeName = new StringBuilder() + .Append("dnx") + .Append((DeploymentParameters.RuntimeFlavor == RuntimeFlavor.CoreClr) ? "-coreclr" : "-clr") + .Append($"-{OSPrefix}") + .Append((DeploymentParameters.RuntimeArchitecture == RuntimeArchitecture.x86) ? "-x86" : "-x64") + .ToString(); - runtimePath = Regex.Replace(runtimePath, "dnx-(clr|coreclr)-win-(x86|x64)", replaceStr, RegexOptions.IgnoreCase); - ChosenRuntimePath = Path.GetDirectoryName(runtimePath); - - var runtimeDirectoryInfo = new DirectoryInfo(ChosenRuntimePath); - if (!runtimeDirectoryInfo.Exists) + string targetRuntimeBinPath; + // Ex: When current runtime is Mono and the tests are being run for CoreClr + if (currentRuntimeBinPath.Contains("dnx-mono")) { - throw new Exception( - string.Format("Requested runtime at location '{0}' does not exist. Please make sure it is installed before running test.", - runtimeDirectoryInfo.FullName)); + targetRuntimeBinPath = currentRuntimeBinPath.Replace("dnx-mono", targetRuntimeName); + } + else + { + targetRuntimeBinPath = Regex.Replace( + currentRuntimeBinPath, + "dnx-(clr|coreclr)-(win|linux|darwin)-(x86|x64)", + targetRuntimeName, + RegexOptions.IgnoreCase); } - ChosenRuntimeName = runtimeDirectoryInfo.Parent.Name; - Logger.LogInformation(string.Empty); - Logger.LogInformation($"Changing to use runtime : {ChosenRuntimeName}"); + var targetRuntimeBinDir = new DirectoryInfo(targetRuntimeBinPath); + if (targetRuntimeBinDir == null || !targetRuntimeBinDir.Exists) + { + throw new Exception($"Requested runtime at location '{targetRuntimeBinPath}' does not exist.Please make sure it is installed before running test."); + } + + ChosenRuntimePath = targetRuntimeBinDir.FullName; + ChosenRuntimeName = targetRuntimeBinDir.Parent.Name; + DeploymentParameters.DnxRuntime = ChosenRuntimeName; + + Logger.LogInformation($"Chosen runtime path is {ChosenRuntimePath}"); + return ChosenRuntimeName; } @@ -75,7 +149,7 @@ namespace Microsoft.AspNet.Server.Testing var parameters = $"publish {DeploymentParameters.ApplicationPath} -o {DeploymentParameters.PublishedApplicationRootPath}" + $" --runtime {DeploymentParameters.DnxRuntime} {noSource} --iis-command {command}"; - var dnuPath = Path.Combine(ChosenRuntimePath, "dnu.cmd"); + var dnuPath = Path.Combine(ChosenRuntimePath, DnuCommandName); Logger.LogInformation($"Executing command {dnuPath} {parameters}"); var startInfo = new ProcessStartInfo @@ -115,7 +189,7 @@ namespace Microsoft.AspNet.Server.Testing { try { - // We've originally published the application in a temp folder. We need to delete it. + // We've originally published the application in a temp folder. We need to delete it. Directory.Delete(DeploymentParameters.PublishedApplicationRootPath, true); } catch (Exception exception) diff --git a/src/Microsoft.AspNet.Server.Testing/Deployers/MonoDeployer.cs b/src/Microsoft.AspNet.Server.Testing/Deployers/MonoDeployer.cs index 93913099f2..00e1d9b999 100644 --- a/src/Microsoft.AspNet.Server.Testing/Deployers/MonoDeployer.cs +++ b/src/Microsoft.AspNet.Server.Testing/Deployers/MonoDeployer.cs @@ -2,6 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; @@ -36,13 +37,20 @@ namespace Microsoft.AspNet.Server.Testing throw new Exception("Runtime not detected on the machine."); } + var runtimeBinDir = new DirectoryInfo(runtimeBin); + ChosenRuntimePath = runtimeBinDir.FullName; + ChosenRuntimeName = runtimeBinDir.Parent.Name; + DeploymentParameters.DnxRuntime = ChosenRuntimeName; + if (DeploymentParameters.PublishApplicationBeforeDeployment) { // We use full path to runtime to pack. - DeploymentParameters.DnxRuntime = new DirectoryInfo(runtimeBin).Parent.FullName; DnuPublish(); } + DeploymentParameters.EnvironmentVariables + .Add(new KeyValuePair("DNX_APPBASE", DeploymentParameters.ApplicationPath)); + // Launch the host process. var hostExitToken = StartMonoHost(); @@ -62,29 +70,36 @@ namespace Microsoft.AspNet.Server.Testing throw new InvalidOperationException("kestrel is the only valid ServerType for Mono"); } + var dnxPath = Path.Combine(ChosenRuntimePath, DnxCommandName); var dnxArgs = $"-p \"{DeploymentParameters.ApplicationPath}\" kestrel --server.urls {DeploymentParameters.ApplicationBaseUriHint}"; - - Logger.LogInformation("Executing command: dnx {dnxArgs}", dnxArgs); + Logger.LogInformation($"Executing command {dnxPath} {dnxArgs}"); var startInfo = new ProcessStartInfo { - FileName = "dnx", + FileName = dnxPath, Arguments = dnxArgs, UseShellExecute = false, CreateNoWindow = true, + RedirectStandardError = true, + RedirectStandardOutput = true, + // Trying a work around for https://github.com/aspnet/Hosting/issues/140. RedirectStandardInput = true }; - _hostProcess = Process.Start(startInfo); + AddEnvironmentVariablesToProcess(startInfo); + + _hostProcess = new Process() { StartInfo = startInfo }; + _hostProcess.ErrorDataReceived += (sender, dataArgs) => { Logger.LogError(dataArgs.Data ?? string.Empty); }; + _hostProcess.OutputDataReceived += (sender, dataArgs) => { Logger.LogInformation(dataArgs.Data ?? string.Empty); }; _hostProcess.EnableRaisingEvents = true; var hostExitTokenSource = new CancellationTokenSource(); _hostProcess.Exited += (sender, e) => { - Logger.LogError("Host process {processName} exited with code {exitCode}.", startInfo.FileName, _hostProcess.ExitCode); TriggerHostShutdown(hostExitTokenSource); }; - - Logger.LogInformation("Started {0}. Process Id : {1}", _hostProcess.MainModule.FileName, _hostProcess.Id); + _hostProcess.Start(); + _hostProcess.BeginErrorReadLine(); + _hostProcess.BeginOutputReadLine(); if (_hostProcess.HasExited) { @@ -92,6 +107,7 @@ namespace Microsoft.AspNet.Server.Testing throw new Exception("Failed to start host"); } + Logger.LogInformation("Started {fileName}. Process Id : {processId}", startInfo.FileName, _hostProcess.Id); return hostExitTokenSource.Token; } diff --git a/src/Microsoft.AspNet.Server.Testing/Deployers/SelfHostDeployer.cs b/src/Microsoft.AspNet.Server.Testing/Deployers/SelfHostDeployer.cs index d9a67a6f89..1d2c2b1ed7 100644 --- a/src/Microsoft.AspNet.Server.Testing/Deployers/SelfHostDeployer.cs +++ b/src/Microsoft.AspNet.Server.Testing/Deployers/SelfHostDeployer.cs @@ -5,6 +5,7 @@ using System; using System.Diagnostics; using System.IO; using System.Threading; +using Microsoft.AspNet.Testing; using Microsoft.Extensions.Logging; namespace Microsoft.AspNet.Server.Testing @@ -50,11 +51,11 @@ namespace Microsoft.AspNet.Server.Testing var commandName = DeploymentParameters.Command; if (string.IsNullOrEmpty(commandName)) { - commandName = DeploymentParameters.ServerType == ServerType.WebListener ? "web" : "kestrel"; + commandName = DeploymentParameters.ServerType == ServerType.WebListener ? "weblistener" : "kestrel"; } - var dnxPath = Path.Combine(ChosenRuntimePath, "dnx.exe"); + var dnxPath = Path.Combine(ChosenRuntimePath, DnxCommandName); var dnxArgs = $"-p \"{DeploymentParameters.ApplicationPath}\" {commandName} --server.urls {DeploymentParameters.ApplicationBaseUriHint}"; - Logger.LogInformation("Executing {dnxexe} {dnxArgs}", dnxPath, dnxArgs); + Logger.LogInformation($"Executing {dnxPath} {dnxArgs}"); var startInfo = new ProcessStartInfo { diff --git a/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs b/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs index 159c2775b5..e640180a97 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs @@ -281,7 +281,8 @@ namespace Microsoft.AspNet.Hosting } [ConditionalTheory] - [OSSkipCondition(OperatingSystems.Linux | OperatingSystems.MacOSX)] + [OSSkipCondition(OperatingSystems.Linux)] + [OSSkipCondition(OperatingSystems.MacOSX)] [InlineData(@"sub/sub2\sub3\", @"sub/sub2/sub3/")] public void MapPath_Windows_Facts(string virtualPath, string expectedSuffix) { From 374526b2704f6a6b1dbb6587b704efd29109ab30 Mon Sep 17 00:00:00 2001 From: David Fowler Date: Tue, 13 Oct 2015 03:31:33 -0700 Subject: [PATCH 394/987] Merge IApplicationShutdown and IApplicationLifetime - Added StopApplication to IApplicationLifetime. This will replace IApplicationShutdown.RequestShutdown. --- .../IApplicationLifetime.cs | 5 +++ .../ApplicationLifetime.cs | 41 ++++++++----------- .../Internal/HostingEngine.cs | 2 +- src/Microsoft.AspNet.Hosting/Program.cs | 8 ++-- 4 files changed, 27 insertions(+), 29 deletions(-) diff --git a/src/Microsoft.AspNet.Hosting.Abstractions/IApplicationLifetime.cs b/src/Microsoft.AspNet.Hosting.Abstractions/IApplicationLifetime.cs index 536e24c165..3dd7bcf8aa 100644 --- a/src/Microsoft.AspNet.Hosting.Abstractions/IApplicationLifetime.cs +++ b/src/Microsoft.AspNet.Hosting.Abstractions/IApplicationLifetime.cs @@ -30,5 +30,10 @@ namespace Microsoft.AspNet.Hosting /// /// CancellationToken ApplicationStopped { get; } + + /// + /// Requests termination the current application. + /// + void StopApplication(); } } diff --git a/src/Microsoft.AspNet.Hosting/ApplicationLifetime.cs b/src/Microsoft.AspNet.Hosting/ApplicationLifetime.cs index ced615c889..230b4fd4e3 100644 --- a/src/Microsoft.AspNet.Hosting/ApplicationLifetime.cs +++ b/src/Microsoft.AspNet.Hosting/ApplicationLifetime.cs @@ -19,20 +19,14 @@ namespace Microsoft.AspNet.Hosting /// Triggered when the application host has fully started and is about to wait /// for a graceful shutdown. /// - public CancellationToken ApplicationStarted - { - get { return _startedSource.Token; } - } + public CancellationToken ApplicationStarted => _startedSource.Token; /// /// Triggered when the application host is performing a graceful shutdown. /// Request may still be in flight. Shutdown will block until this event completes. /// /// - public CancellationToken ApplicationStopping - { - get { return _stoppingSource.Token; } - } + public CancellationToken ApplicationStopping => _stoppingSource.Token; /// /// Triggered when the application host is performing a graceful shutdown. @@ -40,9 +34,21 @@ namespace Microsoft.AspNet.Hosting /// until this event completes. /// /// - public CancellationToken ApplicationStopped + public CancellationToken ApplicationStopped => _stoppedSource.Token; + + /// + /// Signals the ApplicationStopping event and blocks until it completes. + /// + public void StopApplication() { - get { return _stoppedSource.Token; } + try + { + _stoppingSource.Cancel(throwOnFirstException: false); + } + catch (Exception) + { + // TODO: LOG + } } /// @@ -60,21 +66,6 @@ namespace Microsoft.AspNet.Hosting } } - /// - /// Signals the ApplicationStopping event and blocks until it completes. - /// - public void NotifyStopping() - { - try - { - _stoppingSource.Cancel(throwOnFirstException: false); - } - catch (Exception) - { - // TODO: LOG - } - } - /// /// Signals the ApplicationStopped event and blocks until it completes. /// diff --git a/src/Microsoft.AspNet.Hosting/Internal/HostingEngine.cs b/src/Microsoft.AspNet.Hosting/Internal/HostingEngine.cs index d0a951849d..cde9a27c1c 100644 --- a/src/Microsoft.AspNet.Hosting/Internal/HostingEngine.cs +++ b/src/Microsoft.AspNet.Hosting/Internal/HostingEngine.cs @@ -135,7 +135,7 @@ namespace Microsoft.AspNet.Hosting.Internal return new Application(ApplicationServices, _serverInstance, new Disposable(() => { - _applicationLifetime.NotifyStopping(); + _applicationLifetime.StopApplication(); server.Dispose(); _applicationLifetime.NotifyStopped(); (_applicationServices as IDisposable)?.Dispose(); diff --git a/src/Microsoft.AspNet.Hosting/Program.cs b/src/Microsoft.AspNet.Hosting/Program.cs index 7c2cbb2127..48a71bbcde 100644 --- a/src/Microsoft.AspNet.Hosting/Program.cs +++ b/src/Microsoft.AspNet.Hosting/Program.cs @@ -54,14 +54,16 @@ namespace Microsoft.AspNet.Hosting Console.WriteLine("Application started. Press Ctrl+C to shut down."); - var appShutdownService = app.Services.GetRequiredService(); + var appLifetime = app.Services.GetRequiredService(); + Console.CancelKeyPress += (sender, eventArgs) => { - appShutdownService.RequestShutdown(); + appLifetime.StopApplication(); // Don't terminate the process immediately, wait for the Main thread to exit gracefully. eventArgs.Cancel = true; }; - appShutdownService.ShutdownRequested.WaitHandle.WaitOne(); + + appLifetime.ApplicationStopping.WaitHandle.WaitOne(); } } } From 5f4f6194b8014ea0f63cd812db3b17143ef07890 Mon Sep 17 00:00:00 2001 From: Kirthi Krishnamraju Date: Fri, 16 Oct 2015 10:19:39 -0700 Subject: [PATCH 395/987] Add logic in test infrastructure to get runtime for coreclr on mac --- .../Deployers/ApplicationDeployer.cs | 29 ++++++++++++++----- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Testing/Deployers/ApplicationDeployer.cs b/src/Microsoft.AspNet.Server.Testing/Deployers/ApplicationDeployer.cs index c7a303affe..a8dfd0e17a 100644 --- a/src/Microsoft.AspNet.Server.Testing/Deployers/ApplicationDeployer.cs +++ b/src/Microsoft.AspNet.Server.Testing/Deployers/ApplicationDeployer.cs @@ -99,16 +99,31 @@ namespace Microsoft.AspNet.Server.Testing protected string PopulateChosenRuntimeInformation() { - // ex: runtimes/dnx-coreclr-win-x64.1.0.0-rc1-15844/bin - var currentRuntimeBinPath = Path.GetDirectoryName(Process.GetCurrentProcess().MainModule.FileName); + string currentRuntimeBinPath = string.Empty; + if (TestPlatformHelper.IsMac && DeploymentParameters.RuntimeFlavor == RuntimeFlavor.CoreClr) + { + var path = Environment.GetEnvironmentVariable("PATH"); + currentRuntimeBinPath = path.Split(new char[] { ':' }, StringSplitOptions.RemoveEmptyEntries). + Where(c => c.Contains("dnx-coreclr-darwin") || c.Contains("dnx-mono")).FirstOrDefault(); + + if (string.IsNullOrWhiteSpace(currentRuntimeBinPath)) + { + throw new Exception("Runtime not detected on the machine."); + } + } + else + { + // ex: runtimes/dnx-coreclr-win-x64.1.0.0-rc1-15844/bin + currentRuntimeBinPath = Path.GetDirectoryName(Process.GetCurrentProcess().MainModule.FileName); + } Logger.LogInformation($"Current runtime path is : {currentRuntimeBinPath}"); var targetRuntimeName = new StringBuilder() - .Append("dnx") - .Append((DeploymentParameters.RuntimeFlavor == RuntimeFlavor.CoreClr) ? "-coreclr" : "-clr") - .Append($"-{OSPrefix}") - .Append((DeploymentParameters.RuntimeArchitecture == RuntimeArchitecture.x86) ? "-x86" : "-x64") - .ToString(); + .Append("dnx") + .Append((DeploymentParameters.RuntimeFlavor == RuntimeFlavor.CoreClr) ? "-coreclr" : "-clr") + .Append($"-{OSPrefix}") + .Append((DeploymentParameters.RuntimeArchitecture == RuntimeArchitecture.x86) ? "-x86" : "-x64") + .ToString(); string targetRuntimeBinPath; // Ex: When current runtime is Mono and the tests are being run for CoreClr From f0438d69eb4792ea27eaa1c401d678413e5ab366 Mon Sep 17 00:00:00 2001 From: Cesar Blum Silveira Date: Fri, 16 Oct 2015 11:33:26 -0700 Subject: [PATCH 396/987] Enable Microsoft.AspNet.TestHost.Tests on CoreCLR. --- test/Microsoft.AspNet.TestHost.Tests/project.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/Microsoft.AspNet.TestHost.Tests/project.json b/test/Microsoft.AspNet.TestHost.Tests/project.json index af78732d7c..7b7222c16e 100644 --- a/test/Microsoft.AspNet.TestHost.Tests/project.json +++ b/test/Microsoft.AspNet.TestHost.Tests/project.json @@ -9,6 +9,7 @@ "test": "xunit.runner.aspnet" }, "frameworks": { - "dnx451": { } + "dnx451": { }, + "dnxcore50": { } } } From 5279786748163e60666a2ead5b1006faef778b46 Mon Sep 17 00:00:00 2001 From: DamianEdwards Date: Mon, 19 Oct 2015 10:51:08 -0700 Subject: [PATCH 397/987] Added doc-comments to IHostingEnvironment - Coherence-Signed#75 --- .../IHostingEnvironment.cs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/Microsoft.AspNet.Hosting.Abstractions/IHostingEnvironment.cs b/src/Microsoft.AspNet.Hosting.Abstractions/IHostingEnvironment.cs index b57ae9a6af..e478c25a6b 100644 --- a/src/Microsoft.AspNet.Hosting.Abstractions/IHostingEnvironment.cs +++ b/src/Microsoft.AspNet.Hosting.Abstractions/IHostingEnvironment.cs @@ -5,14 +5,27 @@ using Microsoft.AspNet.FileProviders; namespace Microsoft.AspNet.Hosting { + /// + /// Provides information about the web hosting environment an application is running in. + /// public interface IHostingEnvironment { + /// + /// Gets or sets the name of the environment. This property is automatically set by the host to the value + /// of the ASPNET_ENV environment variable. + /// // This must be settable! string EnvironmentName { get; set; } + /// + /// Gets or sets the absolute path to the directory that contains the web-servable application content files. + /// // This must be settable! string WebRootPath { get; set; } + /// + /// Gets or sets an pointing at . + /// // This must be settable! IFileProvider WebRootFileProvider { get; set; } } From 585c44536644b67dd071392427b446501bc079d5 Mon Sep 17 00:00:00 2001 From: DamianEdwards Date: Mon, 19 Oct 2015 10:59:39 -0700 Subject: [PATCH 398/987] More doc-comments & added IsStaging --- .../EnvironmentName.cs | 1 + .../HostingEnvironmentExtensions.cs | 39 +++++++++++++------ 2 files changed, 28 insertions(+), 12 deletions(-) diff --git a/src/Microsoft.AspNet.Hosting.Abstractions/EnvironmentName.cs b/src/Microsoft.AspNet.Hosting.Abstractions/EnvironmentName.cs index 664744383c..ec2533be13 100644 --- a/src/Microsoft.AspNet.Hosting.Abstractions/EnvironmentName.cs +++ b/src/Microsoft.AspNet.Hosting.Abstractions/EnvironmentName.cs @@ -6,6 +6,7 @@ namespace Microsoft.AspNet.Hosting public static class EnvironmentName { public static readonly string Development = "Development"; + public static readonly string Staging = "Staging"; public static readonly string Production = "Production"; } } \ No newline at end of file diff --git a/src/Microsoft.AspNet.Hosting.Abstractions/HostingEnvironmentExtensions.cs b/src/Microsoft.AspNet.Hosting.Abstractions/HostingEnvironmentExtensions.cs index 1d62b061dc..ca638841b2 100644 --- a/src/Microsoft.AspNet.Hosting.Abstractions/HostingEnvironmentExtensions.cs +++ b/src/Microsoft.AspNet.Hosting.Abstractions/HostingEnvironmentExtensions.cs @@ -9,10 +9,10 @@ namespace Microsoft.AspNet.Hosting public static class HostingEnvironmentExtensions { /// - /// Checks if the current hosting environment name is development. + /// Checks if the current hosting environment name is "Development". /// - /// An instance of service. - /// True if the environment name is Development, otherwise false. + /// An instance of . + /// True if the environment name is "Development", otherwise false. public static bool IsDevelopment(this IHostingEnvironment hostingEnvironment) { if (hostingEnvironment == null) @@ -24,10 +24,25 @@ namespace Microsoft.AspNet.Hosting } /// - /// Checks if the current hosting environment name is Production. + /// Checks if the current hosting environment name is "Staging". /// - /// An instance of service. - /// True if the environment name is Production, otherwise false. + /// An instance of . + /// True if the environment name is "Staging", otherwise false. + public static bool IsStaging(this IHostingEnvironment hostingEnvironment) + { + if (hostingEnvironment == null) + { + throw new ArgumentNullException(nameof(hostingEnvironment)); + } + + return hostingEnvironment.IsEnvironment(EnvironmentName.Staging); + } + + /// + /// Checks if the current hosting environment name is "Production". + /// + /// An instance of . + /// True if the environment name is "Production", otherwise false. public static bool IsProduction(this IHostingEnvironment hostingEnvironment) { if (hostingEnvironment == null) @@ -41,9 +56,9 @@ namespace Microsoft.AspNet.Hosting /// /// Compares the current hosting environment name against the specified value. /// - /// An instance of service. + /// An instance of . /// Environment name to validate against. - /// True if the specified name is same as the current environment. + /// True if the specified name is the same as the current environment, otherwise false. public static bool IsEnvironment( this IHostingEnvironment hostingEnvironment, string environmentName) @@ -60,11 +75,11 @@ namespace Microsoft.AspNet.Hosting } /// - /// Gives the physical path corresponding to the given virtual path. + /// Determines the physical path corresponding to the given virtual path. /// - /// An instance of service. - /// Path relative to the root. - /// Physical path corresponding to virtual path. + /// An instance of . + /// Path relative to the application root. + /// Physical path corresponding to the virtual path. public static string MapPath( this IHostingEnvironment hostingEnvironment, string virtualPath) From dade325ac84e53c7ce167401873694a3aeeb198b Mon Sep 17 00:00:00 2001 From: DamianEdwards Date: Mon, 19 Oct 2015 14:19:03 -0700 Subject: [PATCH 399/987] CR feedback --- src/Microsoft.AspNet.Hosting.Abstractions/EnvironmentName.cs | 3 +++ .../HostingEnvironmentExtensions.cs | 3 +++ 2 files changed, 6 insertions(+) diff --git a/src/Microsoft.AspNet.Hosting.Abstractions/EnvironmentName.cs b/src/Microsoft.AspNet.Hosting.Abstractions/EnvironmentName.cs index ec2533be13..6ab7b945c1 100644 --- a/src/Microsoft.AspNet.Hosting.Abstractions/EnvironmentName.cs +++ b/src/Microsoft.AspNet.Hosting.Abstractions/EnvironmentName.cs @@ -3,6 +3,9 @@ namespace Microsoft.AspNet.Hosting { + /// + /// Commonly used environment names. + /// public static class EnvironmentName { public static readonly string Development = "Development"; diff --git a/src/Microsoft.AspNet.Hosting.Abstractions/HostingEnvironmentExtensions.cs b/src/Microsoft.AspNet.Hosting.Abstractions/HostingEnvironmentExtensions.cs index ca638841b2..c8bc3993a7 100644 --- a/src/Microsoft.AspNet.Hosting.Abstractions/HostingEnvironmentExtensions.cs +++ b/src/Microsoft.AspNet.Hosting.Abstractions/HostingEnvironmentExtensions.cs @@ -6,6 +6,9 @@ using System.IO; namespace Microsoft.AspNet.Hosting { + /// + /// Extension methods for . + /// public static class HostingEnvironmentExtensions { /// From 8bab053107838b407fb032b493579ad96016221f Mon Sep 17 00:00:00 2001 From: DamianEdwards Date: Mon, 19 Oct 2015 14:32:04 -0700 Subject: [PATCH 400/987] CR feedback --- .../IHostingEnvironment.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Microsoft.AspNet.Hosting.Abstractions/IHostingEnvironment.cs b/src/Microsoft.AspNet.Hosting.Abstractions/IHostingEnvironment.cs index e478c25a6b..6f357d3ca2 100644 --- a/src/Microsoft.AspNet.Hosting.Abstractions/IHostingEnvironment.cs +++ b/src/Microsoft.AspNet.Hosting.Abstractions/IHostingEnvironment.cs @@ -12,7 +12,7 @@ namespace Microsoft.AspNet.Hosting { /// /// Gets or sets the name of the environment. This property is automatically set by the host to the value - /// of the ASPNET_ENV environment variable. + /// of the "Hosting:Environment" (on Windows) or "Hosting__Environment" (on Linux & OS X) environment variable. /// // This must be settable! string EnvironmentName { get; set; } From 828e8d755e101d321678766aa071455b69b61f8e Mon Sep 17 00:00:00 2001 From: John Luo Date: Mon, 19 Oct 2015 12:40:23 -0700 Subject: [PATCH 401/987] reacting to telemetry rename --- global.json | 2 +- .../Internal/HostingEngine.cs | 24 +++++-------- .../WebHostBuilder.cs | 12 +++---- src/Microsoft.AspNet.Hosting/project.json | 2 +- .../TestServerTests.cs | 36 +++++++++---------- .../project.json | 2 +- 6 files changed, 33 insertions(+), 45 deletions(-) diff --git a/global.json b/global.json index dd6bbaf48b..983ba0401e 100644 --- a/global.json +++ b/global.json @@ -1,3 +1,3 @@ { - "projects": ["src","c:/github/testing/src","/home/kiran/github/testing/src"] + "projects": ["src"] } diff --git a/src/Microsoft.AspNet.Hosting/Internal/HostingEngine.cs b/src/Microsoft.AspNet.Hosting/Internal/HostingEngine.cs index cde9a27c1c..213b492f16 100644 --- a/src/Microsoft.AspNet.Hosting/Internal/HostingEngine.cs +++ b/src/Microsoft.AspNet.Hosting/Internal/HostingEngine.cs @@ -3,7 +3,7 @@ using System; using System.Collections.Generic; -using System.Diagnostics.Tracing; +using System.Diagnostics; using System.Linq; using System.Threading; using Microsoft.AspNet.Builder; @@ -88,9 +88,7 @@ namespace Microsoft.AspNet.Hosting.Internal var logger = _applicationServices.GetRequiredService>(); var contextFactory = _applicationServices.GetRequiredService(); var contextAccessor = _applicationServices.GetRequiredService(); -#pragma warning disable 0618 - var telemetrySource = _applicationServices.GetRequiredService(); -#pragma warning restore 0618 + var diagnosticSource = _applicationServices.GetRequiredService(); var server = ServerFactory.Start(_serverInstance, async features => { @@ -98,12 +96,10 @@ namespace Microsoft.AspNet.Hosting.Internal httpContext.ApplicationServices = _applicationServices; var requestIdentifier = GetRequestIdentifier(httpContext); contextAccessor.HttpContext = httpContext; -#pragma warning disable 0618 - if (telemetrySource.IsEnabled("Microsoft.AspNet.Hosting.BeginRequest")) + if (diagnosticSource.IsEnabled("Microsoft.AspNet.Hosting.BeginRequest")) { - telemetrySource.WriteTelemetry("Microsoft.AspNet.Hosting.BeginRequest", new { httpContext = httpContext }); + diagnosticSource.Write("Microsoft.AspNet.Hosting.BeginRequest", new { httpContext = httpContext }); } -#pragma warning restore 0618 try { using (logger.IsEnabled(LogLevel.Critical) @@ -115,20 +111,16 @@ namespace Microsoft.AspNet.Hosting.Internal } catch (Exception ex) { -#pragma warning disable 0618 - if (telemetrySource.IsEnabled("Microsoft.AspNet.Hosting.UnhandledException")) + if (diagnosticSource.IsEnabled("Microsoft.AspNet.Hosting.UnhandledException")) { - telemetrySource.WriteTelemetry("Microsoft.AspNet.Hosting.UnhandledException", new { httpContext = httpContext, exception = ex }); + diagnosticSource.Write("Microsoft.AspNet.Hosting.UnhandledException", new { httpContext = httpContext, exception = ex }); } -#pragma warning restore 0618 throw; } -#pragma warning disable 0618 - if (telemetrySource.IsEnabled("Microsoft.AspNet.Hosting.EndRequest")) + if (diagnosticSource.IsEnabled("Microsoft.AspNet.Hosting.EndRequest")) { - telemetrySource.WriteTelemetry("Microsoft.AspNet.Hosting.EndRequest", new { httpContext = httpContext }); + diagnosticSource.Write("Microsoft.AspNet.Hosting.EndRequest", new { httpContext = httpContext }); } -#pragma warning restore 0618 }); _applicationLifetime.NotifyStarted(); diff --git a/src/Microsoft.AspNet.Hosting/WebHostBuilder.cs b/src/Microsoft.AspNet.Hosting/WebHostBuilder.cs index e3ae6b3517..16c7fb67e4 100644 --- a/src/Microsoft.AspNet.Hosting/WebHostBuilder.cs +++ b/src/Microsoft.AspNet.Hosting/WebHostBuilder.cs @@ -2,7 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using System.Diagnostics.Tracing; +using System.Diagnostics; using Microsoft.AspNet.Builder; using Microsoft.AspNet.Hosting.Builder; using Microsoft.AspNet.Hosting.Internal; @@ -98,12 +98,10 @@ namespace Microsoft.AspNet.Hosting services.AddTransient(); services.AddSingleton(); services.AddLogging(); - -#pragma warning disable 0618 - var telemetrySource = new TelemetryListener("Microsoft.AspNet"); - services.AddInstance(telemetrySource); - services.AddInstance(telemetrySource); -#pragma warning restore 0618 + + var diagnosticSource = new DiagnosticListener("Microsoft.AspNet"); + services.AddInstance(diagnosticSource); + services.AddInstance(diagnosticSource); // Conjure up a RequestServices services.AddTransient(); diff --git a/src/Microsoft.AspNet.Hosting/project.json b/src/Microsoft.AspNet.Hosting/project.json index 18ea116249..83b490ebe0 100644 --- a/src/Microsoft.AspNet.Hosting/project.json +++ b/src/Microsoft.AspNet.Hosting/project.json @@ -24,7 +24,7 @@ "Microsoft.Dnx.Compilation.Abstractions": "1.0.0-*", "Microsoft.Dnx.Runtime.Abstractions": "1.0.0-*", "Newtonsoft.Json": "6.0.6", - "System.Diagnostics.Tracing.Telemetry": "4.0.0-beta-*" + "System.Diagnostics.DiagnosticSource": "4.0.0-beta-*" }, "frameworks": { "dnx451": { diff --git a/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs b/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs index 9bb5cdd9e6..9a1f79124b 100644 --- a/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs +++ b/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs @@ -2,7 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using System.Diagnostics.Tracing; +using System.Diagnostics; using System.IO; using System.Net; using System.Net.Http; @@ -16,7 +16,7 @@ using Microsoft.AspNet.Http.Features.Internal; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; -using Microsoft.Extensions.TelemetryAdapter; +using Microsoft.Extensions.DiagnosticAdapter; using Xunit; namespace Microsoft.AspNet.TestHost @@ -436,22 +436,21 @@ namespace Microsoft.AspNet.TestHost Assert.Equal(HttpStatusCode.OK, result.StatusCode); Assert.Equal("FoundFoo:False", await result.Content.ReadAsStringAsync()); } - -#pragma warning disable 0618 + [Fact] - public async Task BeginEndTelemetryAvailable() + public async Task BeginEndDiagnosticAvailable() { - TelemetryListener telemetryListener = null; + DiagnosticListener diagnosticListener = null; var server = TestServer.Create(app => { - telemetryListener = app.ApplicationServices.GetRequiredService(); + diagnosticListener = app.ApplicationServices.GetRequiredService(); app.Run(context => { return context.Response.WriteAsync("Hello World"); }); }); - var listener = new TestTelemetryListener(); - telemetryListener.SubscribeWithAdapter(listener); + var listener = new TestDiagnosticListener(); + diagnosticListener.SubscribeWithAdapter(listener); var result = await server.CreateClient().GetStringAsync("/path"); Assert.Equal("Hello World", result); @@ -461,19 +460,19 @@ namespace Microsoft.AspNet.TestHost } [Fact] - public async Task ExceptionTelemetryAvailable() + public async Task ExceptionDiagnosticAvailable() { - TelemetryListener telemetryListener = null; + DiagnosticListener diagnosticListener = null; var server = TestServer.Create(app => { - telemetryListener = app.ApplicationServices.GetRequiredService(); + diagnosticListener = app.ApplicationServices.GetRequiredService(); app.Run(context => { throw new Exception("Test exception"); }); }); - var listener = new TestTelemetryListener(); - telemetryListener.SubscribeWithAdapter(listener); + var listener = new TestDiagnosticListener(); + diagnosticListener.SubscribeWithAdapter(listener); await Assert.ThrowsAsync(() => server.CreateClient().GetAsync("/path")); Assert.NotNull(listener.BeginRequest?.HttpContext); @@ -481,9 +480,8 @@ namespace Microsoft.AspNet.TestHost Assert.NotNull(listener.UnhandledException?.HttpContext); Assert.NotNull(listener.UnhandledException?.Exception); } -#pragma warning restore 0618 - public class TestTelemetryListener + public class TestDiagnosticListener { public class OnBeginRequestEventData { @@ -492,7 +490,7 @@ namespace Microsoft.AspNet.TestHost public OnBeginRequestEventData BeginRequest { get; set; } - [TelemetryName("Microsoft.AspNet.Hosting.BeginRequest")] + [DiagnosticName("Microsoft.AspNet.Hosting.BeginRequest")] public virtual void OnBeginRequest(IProxyHttpContext httpContext) { BeginRequest = new OnBeginRequestEventData() @@ -508,7 +506,7 @@ namespace Microsoft.AspNet.TestHost public OnEndRequestEventData EndRequest { get; set; } - [TelemetryName("Microsoft.AspNet.Hosting.EndRequest")] + [DiagnosticName("Microsoft.AspNet.Hosting.EndRequest")] public virtual void OnEndRequest(IProxyHttpContext httpContext) { EndRequest = new OnEndRequestEventData() @@ -525,7 +523,7 @@ namespace Microsoft.AspNet.TestHost public OnUnhandledExceptionEventData UnhandledException { get; set; } - [TelemetryName("Microsoft.AspNet.Hosting.UnhandledException")] + [DiagnosticName("Microsoft.AspNet.Hosting.UnhandledException")] public virtual void OnUnhandledException(IProxyHttpContext httpContext, IProxyException exception) { UnhandledException = new OnUnhandledExceptionEventData() diff --git a/test/Microsoft.AspNet.TestHost.Tests/project.json b/test/Microsoft.AspNet.TestHost.Tests/project.json index 7b7222c16e..ef4d4de144 100644 --- a/test/Microsoft.AspNet.TestHost.Tests/project.json +++ b/test/Microsoft.AspNet.TestHost.Tests/project.json @@ -2,7 +2,7 @@ "dependencies": { "Microsoft.AspNet.Testing": "1.0.0-*", "Microsoft.AspNet.TestHost": "1.0.0-*", - "Microsoft.Extensions.TelemetryAdapter": "1.0.0-*", + "Microsoft.Extensions.DiagnosticAdapter": "1.0.0-*", "xunit.runner.aspnet": "2.0.0-aspnet-*" }, "commands": { From 3774b6055f64e1ce478bce293d8a448a90fe5cc7 Mon Sep 17 00:00:00 2001 From: Pavel Krymets Date: Tue, 20 Oct 2015 09:11:02 -0700 Subject: [PATCH 402/987] React to xnd dependency injection refactorings --- src/Microsoft.AspNet.Hosting/Program.cs | 15 +++---- .../WebHostBuilder.cs | 39 +++++++------------ src/Microsoft.AspNet.TestHost/TestServer.cs | 27 +++++++------ .../HostingEngineTests.cs | 4 +- .../WebHostBuilderTests.cs | 2 +- .../TestServerTests.cs | 13 ------- 6 files changed, 35 insertions(+), 65 deletions(-) diff --git a/src/Microsoft.AspNet.Hosting/Program.cs b/src/Microsoft.AspNet.Hosting/Program.cs index 48a71bbcde..c324b4e9c1 100644 --- a/src/Microsoft.AspNet.Hosting/Program.cs +++ b/src/Microsoft.AspNet.Hosting/Program.cs @@ -4,9 +4,11 @@ using System; using Microsoft.AspNet.Http.Features; using Microsoft.AspNet.Server.Features; +using Microsoft.Dnx.Compilation; using Microsoft.Dnx.Runtime; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.DependencyInjection.Extensions; namespace Microsoft.AspNet.Hosting { @@ -15,21 +17,14 @@ namespace Microsoft.AspNet.Hosting private const string HostingJsonFile = "Microsoft.AspNet.Hosting.json"; private const string ConfigFileKey = "config"; - private readonly IServiceProvider _serviceProvider; - - public Program(IServiceProvider serviceProvider) - { - _serviceProvider = serviceProvider; - } - - public void Main(string[] args) + public static void Main(string[] args) { // Allow the location of the json file to be specified via a --config command line arg var tempBuilder = new ConfigurationBuilder().AddCommandLine(args); var tempConfig = tempBuilder.Build(); var configFilePath = tempConfig[ConfigFileKey] ?? HostingJsonFile; - var appBasePath = _serviceProvider.GetRequiredService().ApplicationBasePath; + var appBasePath = PlatformServices.Default.Application.ApplicationBasePath; var config = new ConfigurationBuilder() .SetBasePath(appBasePath) .AddJsonFile(configFilePath, optional: true) @@ -37,7 +32,7 @@ namespace Microsoft.AspNet.Hosting .AddCommandLine(args) .Build(); - var host = new WebHostBuilder(_serviceProvider, config, captureStartupErrors: true).Build(); + var host = new WebHostBuilder(config, captureStartupErrors: true).Build(); using (var app = host.Start()) { var hostingEnv = app.Services.GetRequiredService(); diff --git a/src/Microsoft.AspNet.Hosting/WebHostBuilder.cs b/src/Microsoft.AspNet.Hosting/WebHostBuilder.cs index 16c7fb67e4..815684d2b9 100644 --- a/src/Microsoft.AspNet.Hosting/WebHostBuilder.cs +++ b/src/Microsoft.AspNet.Hosting/WebHostBuilder.cs @@ -10,9 +10,11 @@ using Microsoft.AspNet.Hosting.Server; using Microsoft.AspNet.Hosting.Startup; using Microsoft.AspNet.Http; using Microsoft.AspNet.Http.Internal; +using Microsoft.Dnx.Compilation; using Microsoft.Dnx.Runtime; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.DependencyInjection.Extensions; using Microsoft.Extensions.Logging; namespace Microsoft.AspNet.Hosting @@ -27,8 +29,7 @@ namespace Microsoft.AspNet.Hosting public const string OldServerKey = "server"; public const string ServerKey = "Hosting:Server"; - - private readonly IServiceProvider _services; + private readonly IHostingEnvironment _hostingEnvironment; private readonly ILoggerFactory _loggerFactory; private readonly IConfiguration _config; @@ -45,23 +46,18 @@ namespace Microsoft.AspNet.Hosting private string _serverFactoryLocation; private IServerFactory _serverFactory; - public WebHostBuilder(IServiceProvider services) - : this(services, config: new ConfigurationBuilder().Build()) + public WebHostBuilder() + : this(config: new ConfigurationBuilder().Build()) { } - public WebHostBuilder(IServiceProvider services, IConfiguration config) - : this(services, config: config, captureStartupErrors: false) + public WebHostBuilder(IConfiguration config) + : this(config: config, captureStartupErrors: false) { } - public WebHostBuilder(IServiceProvider services, IConfiguration config, bool captureStartupErrors) + public WebHostBuilder(IConfiguration config, bool captureStartupErrors) { - if (services == null) - { - throw new ArgumentNullException(nameof(services)); - } - if (config == null) { throw new ArgumentNullException(nameof(config)); @@ -69,7 +65,6 @@ namespace Microsoft.AspNet.Hosting _hostingEnvironment = new HostingEnvironment(); _loggerFactory = new LoggerFactory(); - _services = services; _config = config; _captureStartupErrors = captureStartupErrors; } @@ -77,17 +72,6 @@ namespace Microsoft.AspNet.Hosting private IServiceCollection BuildHostingServices() { var services = new ServiceCollection(); - - // Import from manifest - var manifest = _services.GetService(); - if (manifest != null) - { - foreach (var service in manifest.Services) - { - services.AddTransient(service, sp => _services.GetService(service)); - } - } - services.AddInstance(_hostingEnvironment); services.AddInstance(_loggerFactory); @@ -111,6 +95,13 @@ namespace Microsoft.AspNet.Hosting _configureServices(services); } + services.TryAdd(ServiceDescriptor.Instance(PlatformServices.Default.Application)); + services.TryAdd(ServiceDescriptor.Instance(PlatformServices.Default.Runtime)); + services.TryAdd(ServiceDescriptor.Instance(PlatformServices.Default.AssemblyLoadContextAccessor)); + services.TryAdd(ServiceDescriptor.Instance(PlatformServices.Default.AssemblyLoaderContainer)); + services.TryAdd(ServiceDescriptor.Instance(PlatformServices.Default.LibraryManager)); + services.TryAdd(ServiceDescriptor.Instance(CompilationServices.Default.LibraryExporter)); + return services; } diff --git a/src/Microsoft.AspNet.TestHost/TestServer.cs b/src/Microsoft.AspNet.TestHost/TestServer.cs index 6cdaffc401..331ad7fd76 100644 --- a/src/Microsoft.AspNet.TestHost/TestServer.cs +++ b/src/Microsoft.AspNet.TestHost/TestServer.cs @@ -33,32 +33,32 @@ namespace Microsoft.AspNet.TestHost public static TestServer Create() { - return Create(services: null, config: null, configureApp: null, configureServices: null); + return Create(config: null, configureApp: null, configureServices: null); } public static TestServer Create(Action configureApp) { - return Create(services: null, config: null, configureApp: configureApp, configureServices: null); + return Create(config: null, configureApp: configureApp, configureServices: null); } public static TestServer Create(Action configureApp, Action configureServices) { - return Create(services: null, config: null, configureApp: configureApp, configureServices: configureServices); + return Create(config: null, configureApp: configureApp, configureServices: configureServices); } - public static TestServer Create(IServiceProvider services, Action configureApp, Func configureServices) + public static TestServer Create(Action configureApp, Func configureServices) { - return new TestServer(CreateBuilder(services, config: null, configureApp: configureApp, configureServices: configureServices)); + return new TestServer(CreateBuilder(config: null, configureApp: configureApp, configureServices: configureServices)); } - public static TestServer Create(IServiceProvider services, IConfiguration config, Action configureApp, Action configureServices) + public static TestServer Create(IConfiguration config, Action configureApp, Action configureServices) { - return new TestServer(CreateBuilder(services, config, configureApp, configureServices)); + return new TestServer(CreateBuilder(config, configureApp, configureServices)); } - public static WebHostBuilder CreateBuilder(IServiceProvider services, IConfiguration config, Action configureApp, Action configureServices) + public static WebHostBuilder CreateBuilder(IConfiguration config, Action configureApp, Action configureServices) { - return CreateBuilder(services, config, configureApp, + return CreateBuilder(config, configureApp, s => { if (configureServices != null) @@ -69,21 +69,20 @@ namespace Microsoft.AspNet.TestHost }); } - public static WebHostBuilder CreateBuilder(IServiceProvider services, IConfiguration config, Action configureApp, Func configureServices) + public static WebHostBuilder CreateBuilder(IConfiguration config, Action configureApp, Func configureServices) { - return CreateBuilder(services, config).UseStartup(configureApp, configureServices); + return CreateBuilder(config).UseStartup(configureApp, configureServices); } - public static WebHostBuilder CreateBuilder(IServiceProvider services, IConfiguration config) + public static WebHostBuilder CreateBuilder(IConfiguration config) { return new WebHostBuilder( - services ?? CallContextServiceLocator.Locator.ServiceProvider, config ?? new ConfigurationBuilder().Build()); } public static WebHostBuilder CreateBuilder() { - return CreateBuilder(services: null, config: null); + return CreateBuilder(config: null); } public HttpMessageHandler CreateHandler() diff --git a/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs b/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs index e640180a97..11fa37b5fe 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs @@ -405,9 +405,7 @@ namespace Microsoft.AspNet.Hosting private WebHostBuilder CreateBuilder(IConfiguration config = null) { - return new WebHostBuilder( - CallContextServiceLocator.Locator.ServiceProvider, - config ?? new ConfigurationBuilder().Build()); + return new WebHostBuilder(config ?? new ConfigurationBuilder().Build()); } public IFeatureCollection Initialize(IConfiguration configuration) diff --git a/test/Microsoft.AspNet.Hosting.Tests/WebHostBuilderTests.cs b/test/Microsoft.AspNet.Hosting.Tests/WebHostBuilderTests.cs index 4cd92b967e..078019aff5 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/WebHostBuilderTests.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/WebHostBuilderTests.cs @@ -108,7 +108,7 @@ namespace Microsoft.AspNet.Hosting var builder = new ConfigurationBuilder() .AddInMemoryCollection(vals); var config = builder.Build(); - return new WebHostBuilder(CallContextServiceLocator.Locator.ServiceProvider, config, captureStartupErrors: true); + return new WebHostBuilder(config, captureStartupErrors: true); } private async Task AssertResponseContains(Func app, string expectedText) diff --git a/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs b/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs index 9a1f79124b..626ae24631 100644 --- a/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs +++ b/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs @@ -31,19 +31,6 @@ namespace Microsoft.AspNet.TestHost TestServer.Create(app => { }); } - [Fact] - public void ThrowsIfNoApplicationEnvironmentIsRegisteredWithTheProvider() - { - // Arrange - var services = new ServiceCollection().BuildServiceProvider(); - - // Act & Assert - Assert.Throws( - () => TestServer.Create( - services, - new ConfigurationBuilder().Build(), new Startup().Configure, configureServices: null)); - } - [Fact] public async Task RequestServicesAutoCreated() { From 99f5febc3b43e394325324fc8b4f74f8dba560f7 Mon Sep 17 00:00:00 2001 From: John Luo Date: Tue, 20 Oct 2015 10:05:22 -0700 Subject: [PATCH 403/987] Changing argument type of serverFeatures to IFeatureCollection --- .../Builder/ApplicationBuilderFactory.cs | 5 +++-- .../Builder/IApplicationBuilderFactory.cs | 3 ++- .../Internal/HostingEngine.cs | 14 +++++++------- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/Microsoft.AspNet.Hosting/Builder/ApplicationBuilderFactory.cs b/src/Microsoft.AspNet.Hosting/Builder/ApplicationBuilderFactory.cs index a5b00f5fbf..eaf8d178d4 100644 --- a/src/Microsoft.AspNet.Hosting/Builder/ApplicationBuilderFactory.cs +++ b/src/Microsoft.AspNet.Hosting/Builder/ApplicationBuilderFactory.cs @@ -4,6 +4,7 @@ using System; using Microsoft.AspNet.Builder; using Microsoft.AspNet.Builder.Internal; +using Microsoft.AspNet.Http.Features; namespace Microsoft.AspNet.Hosting.Builder { @@ -16,9 +17,9 @@ namespace Microsoft.AspNet.Hosting.Builder _serviceProvider = serviceProvider; } - public IApplicationBuilder CreateBuilder(object server) + public IApplicationBuilder CreateBuilder(IFeatureCollection serverFeatures) { - return new ApplicationBuilder(_serviceProvider, server); + return new ApplicationBuilder(_serviceProvider, serverFeatures); } } } diff --git a/src/Microsoft.AspNet.Hosting/Builder/IApplicationBuilderFactory.cs b/src/Microsoft.AspNet.Hosting/Builder/IApplicationBuilderFactory.cs index ddcf5807a5..00e64a0a2c 100644 --- a/src/Microsoft.AspNet.Hosting/Builder/IApplicationBuilderFactory.cs +++ b/src/Microsoft.AspNet.Hosting/Builder/IApplicationBuilderFactory.cs @@ -2,11 +2,12 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using Microsoft.AspNet.Builder; +using Microsoft.AspNet.Http.Features; namespace Microsoft.AspNet.Hosting.Builder { public interface IApplicationBuilderFactory { - IApplicationBuilder CreateBuilder(object server); + IApplicationBuilder CreateBuilder(IFeatureCollection serverFeatures); } } \ No newline at end of file diff --git a/src/Microsoft.AspNet.Hosting/Internal/HostingEngine.cs b/src/Microsoft.AspNet.Hosting/Internal/HostingEngine.cs index 213b492f16..8c603b6e3c 100644 --- a/src/Microsoft.AspNet.Hosting/Internal/HostingEngine.cs +++ b/src/Microsoft.AspNet.Hosting/Internal/HostingEngine.cs @@ -42,7 +42,7 @@ namespace Microsoft.AspNet.Hosting.Internal // Only one of these should be set internal IServerFactory ServerFactory { get; set; } internal string ServerFactoryLocation { get; set; } - private IFeatureCollection _serverInstance; + private IFeatureCollection _serverFeatures; public HostingEngine( IServiceCollection appServices, @@ -89,7 +89,7 @@ namespace Microsoft.AspNet.Hosting.Internal var contextFactory = _applicationServices.GetRequiredService(); var contextAccessor = _applicationServices.GetRequiredService(); var diagnosticSource = _applicationServices.GetRequiredService(); - var server = ServerFactory.Start(_serverInstance, + var server = ServerFactory.Start(_serverFeatures, async features => { var httpContext = contextFactory.CreateHttpContext(features); @@ -125,7 +125,7 @@ namespace Microsoft.AspNet.Hosting.Internal _applicationLifetime.NotifyStarted(); - return new Application(ApplicationServices, _serverInstance, new Disposable(() => + return new Application(ApplicationServices, _serverFeatures, new Disposable(() => { _applicationLifetime.StopApplication(); server.Dispose(); @@ -181,7 +181,7 @@ namespace Microsoft.AspNet.Hosting.Internal EnsureServer(); var builderFactory = _applicationServices.GetRequiredService(); - var builder = builderFactory.CreateBuilder(_serverInstance); + var builder = builderFactory.CreateBuilder(_serverFeatures); builder.ApplicationServices = _applicationServices; var startupFilters = _applicationServices.GetService>(); @@ -247,10 +247,10 @@ namespace Microsoft.AspNet.Hosting.Internal ServerFactory = _applicationServices.GetRequiredService().LoadServerFactory(ServerFactoryLocation); } - if (_serverInstance == null) + if (_serverFeatures == null) { - _serverInstance = ServerFactory.Initialize(_config); - var addresses = _serverInstance?.Get()?.Addresses; + _serverFeatures = ServerFactory.Initialize(_config); + var addresses = _serverFeatures?.Get()?.Addresses; if (addresses != null && !addresses.IsReadOnly) { var port = _config[ServerPort]; From 7cc3e11a9e11341046828203fe8cd74d24852d7f Mon Sep 17 00:00:00 2001 From: Pavel Krymets Date: Wed, 21 Oct 2015 14:12:23 -0700 Subject: [PATCH 404/987] Add compiler configuration to services and another overload for test server creation .. to alow host service configuration --- src/Microsoft.AspNet.Hosting/WebHostBuilder.cs | 1 + src/Microsoft.AspNet.TestHost/TestServer.cs | 16 ++++++++++++---- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/Microsoft.AspNet.Hosting/WebHostBuilder.cs b/src/Microsoft.AspNet.Hosting/WebHostBuilder.cs index 815684d2b9..ef7aeb0ecb 100644 --- a/src/Microsoft.AspNet.Hosting/WebHostBuilder.cs +++ b/src/Microsoft.AspNet.Hosting/WebHostBuilder.cs @@ -101,6 +101,7 @@ namespace Microsoft.AspNet.Hosting services.TryAdd(ServiceDescriptor.Instance(PlatformServices.Default.AssemblyLoaderContainer)); services.TryAdd(ServiceDescriptor.Instance(PlatformServices.Default.LibraryManager)); services.TryAdd(ServiceDescriptor.Instance(CompilationServices.Default.LibraryExporter)); + services.TryAdd(ServiceDescriptor.Instance(CompilationServices.Default.CompilerOptionsProvider)); return services; } diff --git a/src/Microsoft.AspNet.TestHost/TestServer.cs b/src/Microsoft.AspNet.TestHost/TestServer.cs index 331ad7fd76..56dce2e74c 100644 --- a/src/Microsoft.AspNet.TestHost/TestServer.cs +++ b/src/Microsoft.AspNet.TestHost/TestServer.cs @@ -48,7 +48,11 @@ namespace Microsoft.AspNet.TestHost public static TestServer Create(Action configureApp, Func configureServices) { - return new TestServer(CreateBuilder(config: null, configureApp: configureApp, configureServices: configureServices)); + return new TestServer(CreateBuilder(config: null, configureApp: configureApp, configureServices: configureServices, configureHostServices: null)); + } + public static TestServer Create(Action configureApp, Func configureServices, Action configureHostServices) + { + return new TestServer(CreateBuilder(config: null, configureApp: configureApp, configureServices: configureServices, configureHostServices: configureHostServices)); } public static TestServer Create(IConfiguration config, Action configureApp, Action configureServices) @@ -66,12 +70,16 @@ namespace Microsoft.AspNet.TestHost configureServices(s); } return s.BuildServiceProvider(); - }); + }, null); } - public static WebHostBuilder CreateBuilder(IConfiguration config, Action configureApp, Func configureServices) { - return CreateBuilder(config).UseStartup(configureApp, configureServices); + return CreateBuilder(config, configureApp, configureServices, null); + } + + public static WebHostBuilder CreateBuilder(IConfiguration config, Action configureApp, Func configureServices, Action configureHostServices) + { + return CreateBuilder(config).UseStartup(configureApp, configureServices).UseServices(configureHostServices); } public static WebHostBuilder CreateBuilder(IConfiguration config) From 39c355002b3afa7eaa901a5654b5eaddfcf62c94 Mon Sep 17 00:00:00 2001 From: Pranav K Date: Wed, 21 Oct 2015 21:37:42 -0700 Subject: [PATCH 405/987] Switching to using generations TFM --- .../project.json | 28 +++---- .../project.json | 31 ++++---- src/Microsoft.AspNet.Hosting/project.json | 77 ++++++++++--------- 3 files changed, 68 insertions(+), 68 deletions(-) diff --git a/src/Microsoft.AspNet.Hosting.Abstractions/project.json b/src/Microsoft.AspNet.Hosting.Abstractions/project.json index daaa329df3..0bc206ff72 100644 --- a/src/Microsoft.AspNet.Hosting.Abstractions/project.json +++ b/src/Microsoft.AspNet.Hosting.Abstractions/project.json @@ -1,16 +1,16 @@ { - "version": "1.0.0-*", - "description": "ASP.NET 5 Hosting abstractions.", - "repository": { - "type": "git", - "url": "git://github.com/aspnet/hosting" - }, - "dependencies": { - "Microsoft.AspNet.Http.Abstractions": "1.0.0-*", - "Microsoft.AspNet.FileProviders.Abstractions": "1.0.0-*" - }, - "frameworks": { - "dnx451": {}, - "dnxcore50": {} - } + "version": "1.0.0-*", + "description": "ASP.NET 5 Hosting abstractions.", + "repository": { + "type": "git", + "url": "git://github.com/aspnet/hosting" + }, + "dependencies": { + "Microsoft.AspNet.Http.Abstractions": "1.0.0-*", + "Microsoft.AspNet.FileProviders.Abstractions": "1.0.0-*" + }, + "frameworks": { + "net451": {}, + "dotnet5.4": {} + } } \ No newline at end of file diff --git a/src/Microsoft.AspNet.Hosting.Server.Abstractions/project.json b/src/Microsoft.AspNet.Hosting.Server.Abstractions/project.json index c36c180620..a3ccdf94bb 100644 --- a/src/Microsoft.AspNet.Hosting.Server.Abstractions/project.json +++ b/src/Microsoft.AspNet.Hosting.Server.Abstractions/project.json @@ -1,17 +1,16 @@ { - "version": "1.0.0-*", - "description": "ASP.NET 5 Hosting server abstractions.", - "repository": { - "type": "git", - "url": "git://github.com/aspnet/hosting" - }, - "dependencies": { - "Microsoft.AspNet.Http.Features": "1.0.0-*", - "Microsoft.Extensions.Configuration.Abstractions": "1.0.0-*" - }, - - "frameworks": { - "dnx451": { }, - "dnxcore50": { } - } -} + "version": "1.0.0-*", + "description": "ASP.NET 5 Hosting server abstractions.", + "repository": { + "type": "git", + "url": "git://github.com/aspnet/hosting" + }, + "dependencies": { + "Microsoft.AspNet.Http.Features": "1.0.0-*", + "Microsoft.Extensions.Configuration.Abstractions": "1.0.0-*" + }, + "frameworks": { + "net451": {}, + "dotnet5.4": {} + } +} \ No newline at end of file diff --git a/src/Microsoft.AspNet.Hosting/project.json b/src/Microsoft.AspNet.Hosting/project.json index 83b490ebe0..01bf705d81 100644 --- a/src/Microsoft.AspNet.Hosting/project.json +++ b/src/Microsoft.AspNet.Hosting/project.json @@ -1,42 +1,43 @@ { - "version": "1.0.0-*", - "description": "ASP.NET 5 core hosting infrastructure and startup logic for web applications.", - "repository": { - "type": "git", - "url": "git://github.com/aspnet/hosting" + "version": "1.0.0-*", + "description": "ASP.NET 5 core hosting infrastructure and startup logic for web applications.", + "repository": { + "type": "git", + "url": "git://github.com/aspnet/hosting" + }, + "compilationOptions": { + "warningsAsErrors": true, + "allowUnsafe": true + }, + "dependencies": { + "Microsoft.AspNet.FileProviders.Physical": "1.0.0-*", + "Microsoft.AspNet.Hosting.Abstractions": "1.0.0-*", + "Microsoft.AspNet.Hosting.Server.Abstractions": "1.0.0-*", + "Microsoft.AspNet.Http": "1.0.0-*", + "Microsoft.AspNet.Http.Extensions": "1.0.0-*", + "Microsoft.Extensions.Configuration": "1.0.0-*", + "Microsoft.Extensions.Configuration.CommandLine": "1.0.0-*", + "Microsoft.Extensions.Configuration.EnvironmentVariables": "1.0.0-*", + "Microsoft.Extensions.Configuration.Json": "1.0.0-*", + "Microsoft.Extensions.DependencyInjection": "1.0.0-*", + "Microsoft.Extensions.Logging": "1.0.0-*", + "Microsoft.Dnx.Compilation.Abstractions": "1.0.0-*", + "Microsoft.Dnx.Runtime.Abstractions": "1.0.0-*", + "Newtonsoft.Json": "6.0.6", + "System.Diagnostics.DiagnosticSource": "4.0.0-beta-*" + }, + "frameworks": { + "dnx451": { + "frameworkAssemblies": { + "System.Runtime": "" + } }, - "compilationOptions": { - "warningsAsErrors": true, - "allowUnsafe": true - }, - "dependencies": { - "Microsoft.AspNet.FileProviders.Physical": "1.0.0-*", - "Microsoft.AspNet.Hosting.Abstractions": "1.0.0-*", - "Microsoft.AspNet.Hosting.Server.Abstractions": "1.0.0-*", - "Microsoft.AspNet.Http": "1.0.0-*", - "Microsoft.AspNet.Http.Extensions": "1.0.0-*", - "Microsoft.Extensions.Configuration": "1.0.0-*", - "Microsoft.Extensions.Configuration.CommandLine": "1.0.0-*", - "Microsoft.Extensions.Configuration.EnvironmentVariables": "1.0.0-*", - "Microsoft.Extensions.Configuration.Json": "1.0.0-*", - "Microsoft.Extensions.DependencyInjection": "1.0.0-*", - "Microsoft.Extensions.Logging": "1.0.0-*", - "Microsoft.Dnx.Compilation.Abstractions": "1.0.0-*", - "Microsoft.Dnx.Runtime.Abstractions": "1.0.0-*", - "Newtonsoft.Json": "6.0.6", - "System.Diagnostics.DiagnosticSource": "4.0.0-beta-*" - }, - "frameworks": { - "dnx451": { - "frameworkAssemblies": { - "System.Runtime": "" - } - }, - "dnxcore50": { - "dependencies": { - "System.Console": "4.0.0-beta-*", - "System.Diagnostics.StackTrace": "4.0.1-beta-*" - } - } + "dnxcore50": { + "dependencies": { + "System.Console": "4.0.0-beta-*", + "System.Diagnostics.StackTrace": "4.0.1-beta-*", + "System.Reflection.Extensions": "4.0.1-beta-*" + } } + } } From 10822b3b4f4a7343cbf9eec6773f611e443e07b2 Mon Sep 17 00:00:00 2001 From: Chris R Date: Tue, 20 Oct 2015 16:59:26 -0700 Subject: [PATCH 406/987] #411 Move webroot from project.json to config. --- .../HostingEnvironmentExtensions.cs | 14 +++++++-- .../Internal/HostingUtilities.cs | 31 ------------------- .../WebHostBuilder.cs | 5 +-- src/Microsoft.AspNet.Hosting/project.json | 1 - .../HostingEngineTests.cs | 13 ++++++-- .../HostingUtilitiesTests.cs | 18 ----------- .../project.json | 3 +- .../TestServerTests.cs | 2 +- 8 files changed, 25 insertions(+), 62 deletions(-) delete mode 100644 src/Microsoft.AspNet.Hosting/Internal/HostingUtilities.cs delete mode 100644 test/Microsoft.AspNet.Hosting.Tests/HostingUtilitiesTests.cs diff --git a/src/Microsoft.AspNet.Hosting/HostingEnvironmentExtensions.cs b/src/Microsoft.AspNet.Hosting/HostingEnvironmentExtensions.cs index 98a839afdc..59aae860dc 100644 --- a/src/Microsoft.AspNet.Hosting/HostingEnvironmentExtensions.cs +++ b/src/Microsoft.AspNet.Hosting/HostingEnvironmentExtensions.cs @@ -3,20 +3,28 @@ using System.IO; using Microsoft.AspNet.FileProviders; -using Microsoft.AspNet.Hosting.Internal; +using Microsoft.Extensions.Configuration; namespace Microsoft.AspNet.Hosting { public static class HostingEnvironmentExtensions { - public static void Initialize(this IHostingEnvironment hostingEnvironment, string applicationBasePath, string environmentName) + private const string OldEnvironmentKey = "ASPNET_ENV"; + private const string EnvironmentKey = "Hosting:Environment"; + + private const string WebRootKey = "Hosting:WebRoot"; + + public static void Initialize(this IHostingEnvironment hostingEnvironment, string applicationBasePath, IConfiguration config) { - hostingEnvironment.WebRootPath = HostingUtilities.GetWebRoot(applicationBasePath); + var webRoot = config?[WebRootKey] ?? string.Empty; + hostingEnvironment.WebRootPath = Path.Combine(applicationBasePath, webRoot); if (!Directory.Exists(hostingEnvironment.WebRootPath)) { Directory.CreateDirectory(hostingEnvironment.WebRootPath); } hostingEnvironment.WebRootFileProvider = new PhysicalFileProvider(hostingEnvironment.WebRootPath); + + var environmentName = config?[EnvironmentKey] ?? config?[OldEnvironmentKey]; hostingEnvironment.EnvironmentName = environmentName ?? hostingEnvironment.EnvironmentName; } } diff --git a/src/Microsoft.AspNet.Hosting/Internal/HostingUtilities.cs b/src/Microsoft.AspNet.Hosting/Internal/HostingUtilities.cs deleted file mode 100644 index 305888997d..0000000000 --- a/src/Microsoft.AspNet.Hosting/Internal/HostingUtilities.cs +++ /dev/null @@ -1,31 +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; -using System.IO; -using Newtonsoft.Json; -using Newtonsoft.Json.Linq; - -namespace Microsoft.AspNet.Hosting.Internal -{ - public static class HostingUtilities - { - public static string GetWebRoot(string applicationBasePath) - { - var webroot = applicationBasePath; - using (var stream = File.OpenRead(Path.Combine(applicationBasePath, "project.json"))) - { - using (var reader = new JsonTextReader(new StreamReader(stream))) - { - var project = JObject.Load(reader); - JToken token; - if (project.TryGetValue("webroot", out token)) - { - webroot = Path.Combine(applicationBasePath, token.ToString()); - } - } - } - return Path.GetFullPath(webroot); - } - } -} diff --git a/src/Microsoft.AspNet.Hosting/WebHostBuilder.cs b/src/Microsoft.AspNet.Hosting/WebHostBuilder.cs index ef7aeb0ecb..d19ca7668b 100644 --- a/src/Microsoft.AspNet.Hosting/WebHostBuilder.cs +++ b/src/Microsoft.AspNet.Hosting/WebHostBuilder.cs @@ -21,9 +21,6 @@ namespace Microsoft.AspNet.Hosting { public class WebHostBuilder { - public const string OldEnvironmentKey = "ASPNET_ENV"; - public const string EnvironmentKey = "Hosting:Environment"; - public const string OldApplicationKey = "app"; public const string ApplicationKey = "Hosting:Application"; @@ -115,7 +112,7 @@ namespace Microsoft.AspNet.Hosting var appEnvironment = hostingContainer.GetRequiredService(); var startupLoader = hostingContainer.GetRequiredService(); - _hostingEnvironment.Initialize(appEnvironment.ApplicationBasePath, _config?[EnvironmentKey] ?? _config?[OldEnvironmentKey]); + _hostingEnvironment.Initialize(appEnvironment.ApplicationBasePath, _config); var engine = new HostingEngine(hostingServices, startupLoader, _config, _captureStartupErrors); // Only one of these should be set, but they are used in priority diff --git a/src/Microsoft.AspNet.Hosting/project.json b/src/Microsoft.AspNet.Hosting/project.json index 01bf705d81..148bec393f 100644 --- a/src/Microsoft.AspNet.Hosting/project.json +++ b/src/Microsoft.AspNet.Hosting/project.json @@ -23,7 +23,6 @@ "Microsoft.Extensions.Logging": "1.0.0-*", "Microsoft.Dnx.Compilation.Abstractions": "1.0.0-*", "Microsoft.Dnx.Runtime.Abstractions": "1.0.0-*", - "Newtonsoft.Json": "6.0.6", "System.Diagnostics.DiagnosticSource": "4.0.0-beta-*" }, "frameworks": { diff --git a/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs b/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs index 11fa37b5fe..afd3a1fc94 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs @@ -248,9 +248,18 @@ namespace Microsoft.AspNet.Hosting } [Fact] - public void WebRootCanBeResolvedFromTheProjectJson() + public void WebRootCanBeResolvedFromTheConfig() { - var engine = CreateBuilder().UseServer(this).Build(); + var vals = new Dictionary + { + { "Hosting:WebRoot", "testroot" } + }; + + var builder = new ConfigurationBuilder() + .AddInMemoryCollection(vals); + var config = builder.Build(); + + var engine = CreateBuilder(config).UseServer(this).Build(); var env = engine.ApplicationServices.GetRequiredService(); Assert.Equal(Path.GetFullPath("testroot"), env.WebRootPath); Assert.True(env.WebRootFileProvider.GetFileInfo("TextFile.txt").Exists); diff --git a/test/Microsoft.AspNet.Hosting.Tests/HostingUtilitiesTests.cs b/test/Microsoft.AspNet.Hosting.Tests/HostingUtilitiesTests.cs deleted file mode 100644 index 86de386a1e..0000000000 --- a/test/Microsoft.AspNet.Hosting.Tests/HostingUtilitiesTests.cs +++ /dev/null @@ -1,18 +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.Hosting.Internal; -using Xunit; - -namespace Microsoft.AspNet.Hosting.Tests -{ - public class HostingUtilitiesTests - { - [Fact] - public void ReadWebRootFromProjectJson() - { - var root = HostingUtilities.GetWebRoot("."); - Assert.True(root.EndsWith("testroot")); - } - } -} \ No newline at end of file diff --git a/test/Microsoft.AspNet.Hosting.Tests/project.json b/test/Microsoft.AspNet.Hosting.Tests/project.json index f4cb38366d..935b44acbd 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/project.json +++ b/test/Microsoft.AspNet.Hosting.Tests/project.json @@ -13,6 +13,5 @@ }, "commands": { "test": "xunit.runner.aspnet" - }, - "webroot": "testroot" + } } diff --git a/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs b/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs index 626ae24631..ffbdb0c470 100644 --- a/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs +++ b/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs @@ -344,7 +344,7 @@ namespace Microsoft.AspNet.TestHost } [Fact] - public void WebRootCanBeResolvedWhenNotInTheProjectJson() + public void WebRootCanBeResolvedWhenNotInTheConfig() { TestServer server = TestServer.Create(app => { From f2e7c49c36f2172b90f8a905293365bcc175490c Mon Sep 17 00:00:00 2001 From: David Fowler Date: Thu, 22 Oct 2015 06:13:25 -0700 Subject: [PATCH 407/987] Don't add platforms services if no available --- .../WebHostBuilder.cs | 22 +++++++++++++------ 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/src/Microsoft.AspNet.Hosting/WebHostBuilder.cs b/src/Microsoft.AspNet.Hosting/WebHostBuilder.cs index d19ca7668b..8938b79333 100644 --- a/src/Microsoft.AspNet.Hosting/WebHostBuilder.cs +++ b/src/Microsoft.AspNet.Hosting/WebHostBuilder.cs @@ -92,13 +92,21 @@ namespace Microsoft.AspNet.Hosting _configureServices(services); } - services.TryAdd(ServiceDescriptor.Instance(PlatformServices.Default.Application)); - services.TryAdd(ServiceDescriptor.Instance(PlatformServices.Default.Runtime)); - services.TryAdd(ServiceDescriptor.Instance(PlatformServices.Default.AssemblyLoadContextAccessor)); - services.TryAdd(ServiceDescriptor.Instance(PlatformServices.Default.AssemblyLoaderContainer)); - services.TryAdd(ServiceDescriptor.Instance(PlatformServices.Default.LibraryManager)); - services.TryAdd(ServiceDescriptor.Instance(CompilationServices.Default.LibraryExporter)); - services.TryAdd(ServiceDescriptor.Instance(CompilationServices.Default.CompilerOptionsProvider)); + if (PlatformServices.Default != null) + { + services.TryAdd(ServiceDescriptor.Instance(PlatformServices.Default.Application)); + services.TryAdd(ServiceDescriptor.Instance(PlatformServices.Default.Runtime)); + services.TryAdd(ServiceDescriptor.Instance(PlatformServices.Default.AssemblyLoadContextAccessor)); + services.TryAdd(ServiceDescriptor.Instance(PlatformServices.Default.AssemblyLoaderContainer)); + services.TryAdd(ServiceDescriptor.Instance(PlatformServices.Default.LibraryManager)); + } + + // TODO: Remove this + if (CompilationServices.Default != null) + { + services.TryAdd(ServiceDescriptor.Instance(CompilationServices.Default.LibraryExporter)); + services.TryAdd(ServiceDescriptor.Instance(CompilationServices.Default.CompilerOptionsProvider)); + } return services; } From 4702752384ca4fbd447f34fcdb4385a8b1947ff4 Mon Sep 17 00:00:00 2001 From: Chris R Date: Thu, 22 Oct 2015 09:27:53 -0700 Subject: [PATCH 408/987] #411 Default webroot to wwwroot if the directory exists. --- .../HostingEnvironmentExtensions.cs | 23 +++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/src/Microsoft.AspNet.Hosting/HostingEnvironmentExtensions.cs b/src/Microsoft.AspNet.Hosting/HostingEnvironmentExtensions.cs index 59aae860dc..4ff521aefb 100644 --- a/src/Microsoft.AspNet.Hosting/HostingEnvironmentExtensions.cs +++ b/src/Microsoft.AspNet.Hosting/HostingEnvironmentExtensions.cs @@ -16,8 +16,27 @@ namespace Microsoft.AspNet.Hosting public static void Initialize(this IHostingEnvironment hostingEnvironment, string applicationBasePath, IConfiguration config) { - var webRoot = config?[WebRootKey] ?? string.Empty; - hostingEnvironment.WebRootPath = Path.Combine(applicationBasePath, webRoot); + var webRoot = config?[WebRootKey]; + if (webRoot == null) + { + // Default to /wwwroot if it exists. + var wwwroot = Path.Combine(applicationBasePath, "wwwroot"); + if (Directory.Exists(wwwroot)) + { + hostingEnvironment.WebRootPath = wwwroot; + } + else + { + hostingEnvironment.WebRootPath = applicationBasePath; + } + } + else + { + hostingEnvironment.WebRootPath = Path.Combine(applicationBasePath, webRoot); + } + + hostingEnvironment.WebRootPath = Path.GetFullPath(hostingEnvironment.WebRootPath); + if (!Directory.Exists(hostingEnvironment.WebRootPath)) { Directory.CreateDirectory(hostingEnvironment.WebRootPath); From 8e946798a1f8bec8a063a1940b80fa45327cd1b1 Mon Sep 17 00:00:00 2001 From: "N. Taylor Mullen" Date: Thu, 22 Oct 2015 11:01:51 -0700 Subject: [PATCH 409/987] Remove compilation options from services. - This was a temporary work around to allow MVC to build. - Reacts to aspnet/Mvc#3383 --- src/Microsoft.AspNet.Hosting/WebHostBuilder.cs | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/src/Microsoft.AspNet.Hosting/WebHostBuilder.cs b/src/Microsoft.AspNet.Hosting/WebHostBuilder.cs index 8938b79333..9467721720 100644 --- a/src/Microsoft.AspNet.Hosting/WebHostBuilder.cs +++ b/src/Microsoft.AspNet.Hosting/WebHostBuilder.cs @@ -26,7 +26,7 @@ namespace Microsoft.AspNet.Hosting public const string OldServerKey = "server"; public const string ServerKey = "Hosting:Server"; - + private readonly IHostingEnvironment _hostingEnvironment; private readonly ILoggerFactory _loggerFactory; private readonly IConfiguration _config; @@ -79,7 +79,7 @@ namespace Microsoft.AspNet.Hosting services.AddTransient(); services.AddSingleton(); services.AddLogging(); - + var diagnosticSource = new DiagnosticListener("Microsoft.AspNet"); services.AddInstance(diagnosticSource); services.AddInstance(diagnosticSource); @@ -101,13 +101,6 @@ namespace Microsoft.AspNet.Hosting services.TryAdd(ServiceDescriptor.Instance(PlatformServices.Default.LibraryManager)); } - // TODO: Remove this - if (CompilationServices.Default != null) - { - services.TryAdd(ServiceDescriptor.Instance(CompilationServices.Default.LibraryExporter)); - services.TryAdd(ServiceDescriptor.Instance(CompilationServices.Default.CompilerOptionsProvider)); - } - return services; } From 47365e421f5374c51566b3d2a5704d61dab6f15e Mon Sep 17 00:00:00 2001 From: Pranav K Date: Thu, 22 Oct 2015 08:52:05 -0700 Subject: [PATCH 410/987] Add generations TFMs to Hosting packages --- .../Startup/StartupExceptionPage.cs | 2 +- src/Microsoft.AspNet.Hosting/project.json | 12 ++++ .../Common/RetryHelper.cs | 2 +- .../Deployers/ApplicationDeployer.cs | 8 +-- .../Deployers/ApplicationDeployerFactory.cs | 2 +- .../Deployers/IISDeployer.cs | 2 +- .../Deployers/IISExpressDeployer.cs | 4 +- .../project.json | 66 +++++++++---------- .../ResponseStream.cs | 4 +- src/Microsoft.AspNet.TestHost/TestServer.cs | 1 - src/Microsoft.AspNet.TestHost/project.json | 42 ++++++------ 11 files changed, 78 insertions(+), 67 deletions(-) diff --git a/src/Microsoft.AspNet.Hosting/Startup/StartupExceptionPage.cs b/src/Microsoft.AspNet.Hosting/Startup/StartupExceptionPage.cs index bf3125e834..0f663b231e 100644 --- a/src/Microsoft.AspNet.Hosting/Startup/StartupExceptionPage.cs +++ b/src/Microsoft.AspNet.Hosting/Startup/StartupExceptionPage.cs @@ -379,7 +379,7 @@ namespace Microsoft.AspNet.Hosting.Startup private static string GenerateFooterEncoded(IRuntimeEnvironment environment) { var runtimeType = HtmlEncodeAndReplaceLineBreaks(environment.RuntimeType); -#if DNXCORE50 +#if DNXCORE50 || DOTNET5_4 var systemRuntimeAssembly = typeof(System.ComponentModel.DefaultValueAttribute).GetTypeInfo().Assembly; var assemblyVersion = new AssemblyName(systemRuntimeAssembly.FullName).Version.ToString(); var clrVersion = HtmlEncodeAndReplaceLineBreaks(assemblyVersion); diff --git a/src/Microsoft.AspNet.Hosting/project.json b/src/Microsoft.AspNet.Hosting/project.json index 148bec393f..01d2233836 100644 --- a/src/Microsoft.AspNet.Hosting/project.json +++ b/src/Microsoft.AspNet.Hosting/project.json @@ -31,12 +31,24 @@ "System.Runtime": "" } }, + "net451": { + "frameworkAssemblies": { + "System.Runtime": "" + } + }, "dnxcore50": { "dependencies": { "System.Console": "4.0.0-beta-*", "System.Diagnostics.StackTrace": "4.0.1-beta-*", "System.Reflection.Extensions": "4.0.1-beta-*" } + }, + "dotnet5.4": { + "dependencies": { + "System.Console": "4.0.0-beta-*", + "System.Diagnostics.StackTrace": "4.0.1-beta-*", + "System.Reflection.Extensions": "4.0.1-beta-*" + } } } } diff --git a/src/Microsoft.AspNet.Server.Testing/Common/RetryHelper.cs b/src/Microsoft.AspNet.Server.Testing/Common/RetryHelper.cs index e6f9038725..6ece35a2db 100644 --- a/src/Microsoft.AspNet.Server.Testing/Common/RetryHelper.cs +++ b/src/Microsoft.AspNet.Server.Testing/Common/RetryHelper.cs @@ -57,7 +57,7 @@ namespace Microsoft.AspNet.Server.Testing else { if (exception is HttpRequestException -#if DNX451 +#if DNX451 || NET451 || exception is System.Net.WebException #endif ) diff --git a/src/Microsoft.AspNet.Server.Testing/Deployers/ApplicationDeployer.cs b/src/Microsoft.AspNet.Server.Testing/Deployers/ApplicationDeployer.cs index a8dfd0e17a..8e9541199b 100644 --- a/src/Microsoft.AspNet.Server.Testing/Deployers/ApplicationDeployer.cs +++ b/src/Microsoft.AspNet.Server.Testing/Deployers/ApplicationDeployer.cs @@ -238,9 +238,9 @@ namespace Microsoft.AspNet.Server.Testing protected void AddEnvironmentVariablesToProcess(ProcessStartInfo startInfo) { var environment = -#if DNX451 +#if NET451 startInfo.EnvironmentVariables; -#elif DNXCORE50 +#elif DOTNET5_4 startInfo.Environment; #endif @@ -260,10 +260,10 @@ namespace Microsoft.AspNet.Server.Testing } } -#if DNX451 +#if DNX451 || NET451 protected void SetEnvironmentVariable(System.Collections.Specialized.StringDictionary environment, string name, string value) { -#elif DNXCORE50 +#elif DNXCORE50 || DOTNET5_4 protected void SetEnvironmentVariable(System.Collections.Generic.IDictionary environment, string name, string value) { #endif diff --git a/src/Microsoft.AspNet.Server.Testing/Deployers/ApplicationDeployerFactory.cs b/src/Microsoft.AspNet.Server.Testing/Deployers/ApplicationDeployerFactory.cs index 3bdcd17684..2ceaa03eed 100644 --- a/src/Microsoft.AspNet.Server.Testing/Deployers/ApplicationDeployerFactory.cs +++ b/src/Microsoft.AspNet.Server.Testing/Deployers/ApplicationDeployerFactory.cs @@ -38,7 +38,7 @@ namespace Microsoft.AspNet.Server.Testing { case ServerType.IISExpress: return new IISExpressDeployer(deploymentParameters, logger); -#if DNX451 +#if NET451 case ServerType.IIS: return new IISDeployer(deploymentParameters, logger); #endif diff --git a/src/Microsoft.AspNet.Server.Testing/Deployers/IISDeployer.cs b/src/Microsoft.AspNet.Server.Testing/Deployers/IISDeployer.cs index 744c216dfd..db2fd224d4 100644 --- a/src/Microsoft.AspNet.Server.Testing/Deployers/IISDeployer.cs +++ b/src/Microsoft.AspNet.Server.Testing/Deployers/IISDeployer.cs @@ -1,7 +1,7 @@ // 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. -#if DNX451 +#if NET451 using System; using System.IO; using System.Linq; diff --git a/src/Microsoft.AspNet.Server.Testing/Deployers/IISExpressDeployer.cs b/src/Microsoft.AspNet.Server.Testing/Deployers/IISExpressDeployer.cs index a9aaea2a35..96f69b2b7f 100644 --- a/src/Microsoft.AspNet.Server.Testing/Deployers/IISExpressDeployer.cs +++ b/src/Microsoft.AspNet.Server.Testing/Deployers/IISExpressDeployer.cs @@ -92,10 +92,10 @@ namespace Microsoft.AspNet.Server.Testing AddEnvironmentVariablesToProcess(startInfo); // IIS express figures out the DNX from %PATH%. -#if DNX451 +#if NET451 SetEnvironmentVariable(startInfo.EnvironmentVariables, "PATH", ChosenRuntimePath + ";" + startInfo.EnvironmentVariables["PATH"]); SetEnvironmentVariable(startInfo.EnvironmentVariables, "DNX_APPBASE", DeploymentParameters.ApplicationPath); -#elif DNXCORE50 +#elif DOTNET5_4 SetEnvironmentVariable(startInfo.Environment, "PATH", ChosenRuntimePath + ";" + startInfo.Environment["PATH"]); SetEnvironmentVariable(startInfo.Environment, "DNX_APPBASE", DeploymentParameters.ApplicationPath); #endif diff --git a/src/Microsoft.AspNet.Server.Testing/project.json b/src/Microsoft.AspNet.Server.Testing/project.json index 90279d5ecf..e3c02cd77b 100644 --- a/src/Microsoft.AspNet.Server.Testing/project.json +++ b/src/Microsoft.AspNet.Server.Testing/project.json @@ -1,36 +1,36 @@ { - "version": "1.0.0-*", - "description": "ASP.NET 5 helpers to deploy applications to IIS Express, IIS, WebListener and Kestrel for testing.", - "repository": { - "type": "git", - "url": "git://github.com/aspnet/hosting" + "version": "1.0.0-*", + "description": "ASP.NET 5 helpers to deploy applications to IIS Express, IIS, WebListener and Kestrel for testing.", + "repository": { + "type": "git", + "url": "git://github.com/aspnet/hosting" + }, + "dependencies": { + "Microsoft.AspNet.Testing": "1.0.0-*", + "Microsoft.Extensions.Logging.Abstractions": "1.0.0-*", + "Microsoft.Dnx.Runtime.Abstractions": "1.0.0-*" + }, + "frameworks": { + "net451": { + "dependencies": { + "Microsoft.Web.Administration": "7.0.0" + }, + "frameworkAssemblies": { + "System.Net.Http": "", + "System.Xml": "" + } }, - "dependencies": { - "Microsoft.AspNet.Testing": "1.0.0-*", - "Microsoft.Extensions.Logging.Abstractions": "1.0.0-*", - "Microsoft.Dnx.Runtime.Abstractions": "1.0.0-*" - }, - "frameworks": { - "dnx451": { - "dependencies": { - "Microsoft.Web.Administration": "7.0.0" - }, - "frameworkAssemblies": { - "System.Net.Http": "", - "System.Xml": "" - } - }, - "dnxcore50": { - "dependencies": { - "System.Diagnostics.Process": "4.0.0-beta-*", - "System.IO.FileSystem": "4.0.1-beta-*", - "System.Net.Http": "4.0.1-beta-*", - "System.Net.Primitives": "4.0.11-beta-*", - "System.Runtime.Extensions": "4.0.11-beta-*", - "System.Text.RegularExpressions": "4.0.11-beta-*", - "System.Threading": "4.0.11-beta-*", - "System.Threading.Thread": "4.0.0-*" - } - } + "dotnet5.4": { + "dependencies": { + "System.Diagnostics.Process": "4.0.0-beta-*", + "System.IO.FileSystem": "4.0.1-beta-*", + "System.Net.Http": "4.0.1-beta-*", + "System.Net.Primitives": "4.0.11-beta-*", + "System.Runtime.Extensions": "4.0.11-beta-*", + "System.Text.RegularExpressions": "4.0.11-beta-*", + "System.Threading": "4.0.11-beta-*", + "System.Threading.Thread": "4.0.0-*" + } } -} + } +} \ No newline at end of file diff --git a/src/Microsoft.AspNet.TestHost/ResponseStream.cs b/src/Microsoft.AspNet.TestHost/ResponseStream.cs index a1dd0df091..314bbec048 100644 --- a/src/Microsoft.AspNet.TestHost/ResponseStream.cs +++ b/src/Microsoft.AspNet.TestHost/ResponseStream.cs @@ -169,7 +169,7 @@ namespace Microsoft.AspNet.TestHost _readLock.Release(); } } -#if DNX451 +#if NET451 public override IAsyncResult BeginRead(byte[] buffer, int offset, int count, AsyncCallback callback, object state) { // TODO: This option doesn't preserve the state object. @@ -266,7 +266,7 @@ namespace Microsoft.AspNet.TestHost _writeLock.Release(); } } -#if DNX451 +#if NET451 public override IAsyncResult BeginWrite(byte[] buffer, int offset, int count, AsyncCallback callback, object state) { Write(buffer, offset, count); diff --git a/src/Microsoft.AspNet.TestHost/TestServer.cs b/src/Microsoft.AspNet.TestHost/TestServer.cs index 56dce2e74c..176431060c 100644 --- a/src/Microsoft.AspNet.TestHost/TestServer.cs +++ b/src/Microsoft.AspNet.TestHost/TestServer.cs @@ -9,7 +9,6 @@ using Microsoft.AspNet.Hosting; using Microsoft.AspNet.Hosting.Server; using Microsoft.AspNet.Http; using Microsoft.AspNet.Http.Features; -using Microsoft.Dnx.Runtime.Infrastructure; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; diff --git a/src/Microsoft.AspNet.TestHost/project.json b/src/Microsoft.AspNet.TestHost/project.json index 34769e53cd..20bd0b4016 100644 --- a/src/Microsoft.AspNet.TestHost/project.json +++ b/src/Microsoft.AspNet.TestHost/project.json @@ -1,24 +1,24 @@ { - "version": "1.0.0-*", - "description": "ASP.NET 5 web server for writing and running tests.", - "repository": { - "type": "git", - "url": "git://github.com/aspnet/hosting" + "version": "1.0.0-*", + "description": "ASP.NET 5 web server for writing and running tests.", + "repository": { + "type": "git", + "url": "git://github.com/aspnet/hosting" + }, + "dependencies": { + "Microsoft.AspNet.Hosting": "1.0.0-*" + }, + "frameworks": { + "net451": { + "frameworkAssemblies": { + "System.Net.Http": "" + } }, - "dependencies": { - "Microsoft.AspNet.Hosting": "1.0.0-*" - }, - "frameworks": { - "dnx451": { - "frameworkAssemblies": { - "System.Net.Http": "" - } - }, - "dnxcore50": { - "dependencies": { - "System.Diagnostics.Contracts": "4.0.1-beta-*", - "System.Net.Http": "4.0.1-beta-*" - } - } + "dotnet5.4": { + "dependencies": { + "System.Diagnostics.Contracts": "4.0.1-beta-*", + "System.Net.Http": "4.0.1-beta-*" + } } -} + } +} \ No newline at end of file From 77f29142aa3649fec9246591acb9546cc8e7f105 Mon Sep 17 00:00:00 2001 From: Cesar Blum Silveira Date: Mon, 19 Oct 2015 23:54:49 -0700 Subject: [PATCH 411/987] Disable tests that randomly hang on Linux (#442). --- test/Microsoft.AspNet.TestHost.Tests/ClientHandlerTests.cs | 2 +- test/Microsoft.AspNet.TestHost.Tests/TestClientTests.cs | 4 +++- test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs | 4 +++- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/test/Microsoft.AspNet.TestHost.Tests/ClientHandlerTests.cs b/test/Microsoft.AspNet.TestHost.Tests/ClientHandlerTests.cs index d4092e5ea2..ec7976d685 100644 --- a/test/Microsoft.AspNet.TestHost.Tests/ClientHandlerTests.cs +++ b/test/Microsoft.AspNet.TestHost.Tests/ClientHandlerTests.cs @@ -223,7 +223,7 @@ namespace Microsoft.AspNet.TestHost } [ConditionalFact] - [FrameworkSkipCondition(RuntimeFrameworks.Mono)] + [OSSkipCondition(OperatingSystems.Linux, SkipReason = "Hangs randomly (issue #422).")] public async Task ExceptionAfterFirstWriteIsReported() { ManualResetEvent block = new ManualResetEvent(false); diff --git a/test/Microsoft.AspNet.TestHost.Tests/TestClientTests.cs b/test/Microsoft.AspNet.TestHost.Tests/TestClientTests.cs index e2ed03d89c..0d19dd88ef 100644 --- a/test/Microsoft.AspNet.TestHost.Tests/TestClientTests.cs +++ b/test/Microsoft.AspNet.TestHost.Tests/TestClientTests.cs @@ -11,6 +11,7 @@ using System.Threading; using System.Threading.Tasks; using Microsoft.AspNet.Builder; using Microsoft.AspNet.Http; +using Microsoft.AspNet.Testing.xunit; using Xunit; namespace Microsoft.AspNet.TestHost @@ -280,7 +281,8 @@ namespace Microsoft.AspNet.TestHost var exception = await Assert.ThrowsAnyAsync(async () => await tcs.Task); } - [Fact] + [ConditionalFact] + [FrameworkSkipCondition(RuntimeFrameworks.CoreCLR, SkipReason = "Hangs randomly (issue #422).")] public async Task ClientCancellationAbortsRequest() { // Arrange diff --git a/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs b/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs index ffbdb0c470..a422818802 100644 --- a/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs +++ b/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs @@ -13,6 +13,7 @@ using Microsoft.AspNet.Hosting.Startup; using Microsoft.AspNet.Http; using Microsoft.AspNet.Http.Features; using Microsoft.AspNet.Http.Features.Internal; +using Microsoft.AspNet.Testing.xunit; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; @@ -388,7 +389,8 @@ namespace Microsoft.AspNet.TestHost await Assert.ThrowsAsync(() => server.CreateClient().GetAsync("/")); } - [Fact] + [ConditionalFact] + [FrameworkSkipCondition(RuntimeFrameworks.CoreCLR, SkipReason = "Hangs randomly (issue #422).")] public void CancelAborts() { TestServer server = TestServer.Create(app => From 0394987271383c5934395fa299f662991143b4fe Mon Sep 17 00:00:00 2001 From: John Luo Date: Tue, 20 Oct 2015 10:43:43 -0700 Subject: [PATCH 412/987] Adding more specific error for private configure --- .../Startup/StartupLoader.cs | 2 +- .../Fakes/StartupPrivateConfigure.cs | 25 +++++++++++++++++++ .../StartupManagerTests.cs | 18 ++++++++++++- 3 files changed, 43 insertions(+), 2 deletions(-) create mode 100644 test/Microsoft.AspNet.Hosting.Tests/Fakes/StartupPrivateConfigure.cs diff --git a/src/Microsoft.AspNet.Hosting/Startup/StartupLoader.cs b/src/Microsoft.AspNet.Hosting/Startup/StartupLoader.cs index f97b024bec..1898dd818a 100644 --- a/src/Microsoft.AspNet.Hosting/Startup/StartupLoader.cs +++ b/src/Microsoft.AspNet.Hosting/Startup/StartupLoader.cs @@ -126,7 +126,7 @@ namespace Microsoft.AspNet.Hosting.Startup { if (required) { - throw new InvalidOperationException(string.Format("A method named '{0}' or '{1}' in the type '{2}' could not be found.", + throw new InvalidOperationException(string.Format("A public method named '{0}' or '{1}' could not be found in the '{2}' type.", methodNameWithEnv, methodNameWithNoEnv, startupType.FullName)); diff --git a/test/Microsoft.AspNet.Hosting.Tests/Fakes/StartupPrivateConfigure.cs b/test/Microsoft.AspNet.Hosting.Tests/Fakes/StartupPrivateConfigure.cs new file mode 100644 index 0000000000..b06efe81da --- /dev/null +++ b/test/Microsoft.AspNet.Hosting.Tests/Fakes/StartupPrivateConfigure.cs @@ -0,0 +1,25 @@ +// 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.Builder; +using Microsoft.Extensions.DependencyInjection; + +namespace Microsoft.AspNet.Hosting.Fakes +{ + public class StartupPrivateConfigure + { + public StartupPrivateConfigure() + { + } + + public void ConfigureServices(IServiceCollection services) + { + + } + + private void Configure(IApplicationBuilder builder) + { + + } + } +} \ No newline at end of file diff --git a/test/Microsoft.AspNet.Hosting.Tests/StartupManagerTests.cs b/test/Microsoft.AspNet.Hosting.Tests/StartupManagerTests.cs index e186469f0b..f7d835cd87 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/StartupManagerTests.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/StartupManagerTests.cs @@ -80,7 +80,7 @@ namespace Microsoft.AspNet.Hosting.Tests var type = loader.FindStartupType("Microsoft.AspNet.Hosting.Tests", diagnosticMessages); var ex = Assert.Throws(() => loader.LoadMethods(type, diagnosticMessages)); - Assert.Equal("A method named 'ConfigureBoom' or 'Configure' in the type 'Microsoft.AspNet.Hosting.Fakes.StartupBoom' could not be found.", ex.Message); + Assert.Equal("A public method named 'ConfigureBoom' or 'Configure' could not be found in the 'Microsoft.AspNet.Hosting.Fakes.StartupBoom' type.", ex.Message); } [Fact] @@ -98,6 +98,22 @@ namespace Microsoft.AspNet.Hosting.Tests var ex = Assert.Throws(() => loader.LoadMethods(type, diagnosticMessages)); Assert.Equal("Having multiple overloads of method 'Configure' is not supported.", ex.Message); } + + [Fact] + public void StartupWithPrivateConfiguresThrows() + { + var serviceCollection = new ServiceCollection(); + serviceCollection.AddInstance(this); + var services = serviceCollection.BuildServiceProvider(); + + var diagnosticMessages = new List(); + var hostingEnv = new HostingEnvironment { EnvironmentName = "PrivateConfigure" }; + var loader = new StartupLoader(services, hostingEnv); + var type = loader.FindStartupType("Microsoft.AspNet.Hosting.Tests", diagnosticMessages); + + var ex = Assert.Throws(() => loader.LoadMethods(type, diagnosticMessages)); + Assert.Equal("A public method named 'ConfigurePrivateConfigure' or 'Configure' could not be found in the 'Microsoft.AspNet.Hosting.Fakes.StartupPrivateConfigure' type.", ex.Message); + } [Fact] public void StartupWithTwoConfigureServicesThrows() From b72f95bdb5ed53578c8b4640ac3d31ce51e133b6 Mon Sep 17 00:00:00 2001 From: John Luo Date: Wed, 21 Oct 2015 16:14:01 -0700 Subject: [PATCH 413/987] Setting IHttpContextAccessor in CreateHttpContext #405 --- .../Builder/HttpContextFactory.cs | 11 ++++++++++- .../Internal/HostingEngine.cs | 2 -- .../HttpContextFactoryFacts.cs | 19 +++++++++++++++++-- 3 files changed, 27 insertions(+), 5 deletions(-) diff --git a/src/Microsoft.AspNet.Hosting/Builder/HttpContextFactory.cs b/src/Microsoft.AspNet.Hosting/Builder/HttpContextFactory.cs index d24250405b..c86cf451b5 100644 --- a/src/Microsoft.AspNet.Hosting/Builder/HttpContextFactory.cs +++ b/src/Microsoft.AspNet.Hosting/Builder/HttpContextFactory.cs @@ -9,9 +9,18 @@ namespace Microsoft.AspNet.Hosting.Builder { public class HttpContextFactory : IHttpContextFactory { + private IHttpContextAccessor _httpContextAccessor; + + public HttpContextFactory(IHttpContextAccessor httpContextAccessor) + { + _httpContextAccessor = httpContextAccessor; + } + public HttpContext CreateHttpContext(IFeatureCollection featureCollection) { - return new DefaultHttpContext(featureCollection); + var httpContext = new DefaultHttpContext(featureCollection); + _httpContextAccessor.HttpContext = httpContext; + return httpContext; } } } \ No newline at end of file diff --git a/src/Microsoft.AspNet.Hosting/Internal/HostingEngine.cs b/src/Microsoft.AspNet.Hosting/Internal/HostingEngine.cs index 8c603b6e3c..4e175806e8 100644 --- a/src/Microsoft.AspNet.Hosting/Internal/HostingEngine.cs +++ b/src/Microsoft.AspNet.Hosting/Internal/HostingEngine.cs @@ -87,7 +87,6 @@ namespace Microsoft.AspNet.Hosting.Internal var logger = _applicationServices.GetRequiredService>(); var contextFactory = _applicationServices.GetRequiredService(); - var contextAccessor = _applicationServices.GetRequiredService(); var diagnosticSource = _applicationServices.GetRequiredService(); var server = ServerFactory.Start(_serverFeatures, async features => @@ -95,7 +94,6 @@ namespace Microsoft.AspNet.Hosting.Internal var httpContext = contextFactory.CreateHttpContext(features); httpContext.ApplicationServices = _applicationServices; var requestIdentifier = GetRequestIdentifier(httpContext); - contextAccessor.HttpContext = httpContext; if (diagnosticSource.IsEnabled("Microsoft.AspNet.Hosting.BeginRequest")) { diagnosticSource.Write("Microsoft.AspNet.Hosting.BeginRequest", new { httpContext = httpContext }); diff --git a/test/Microsoft.AspNet.Hosting.Tests/HttpContextFactoryFacts.cs b/test/Microsoft.AspNet.Hosting.Tests/HttpContextFactoryFacts.cs index a355ca0842..02f3a2cc2c 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/HttpContextFactoryFacts.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/HttpContextFactoryFacts.cs @@ -4,6 +4,7 @@ using System.Collections.Generic; using Microsoft.AspNet.Hosting.Builder; using Microsoft.AspNet.Http.Features; +using Microsoft.AspNet.Http.Internal; using Microsoft.AspNet.Owin; using Xunit; @@ -11,13 +12,27 @@ namespace Microsoft.AspNet.Hosting.Tests { public class HttpContextFactoryFacts { + [Fact] + public void CreateHttpContextSetsHttpContextAccessor() + { + // Arrange + var accessor = new HttpContextAccessor(); + var contextFactory = new HttpContextFactory(accessor); + + // Act + var context = contextFactory.CreateHttpContext(new FeatureCollection()); + + // Assert + Assert.True(ReferenceEquals(context, accessor.HttpContext)); + } + [Fact] public void Mutable_FeatureCollection_Wrapped_For_OwinFeatureCollection() { var env = new Dictionary(); - var contextFactory = new HttpContextFactory(); + var contextFactory = new HttpContextFactory(new HttpContextAccessor()); var context = contextFactory.CreateHttpContext(new FeatureCollection(new OwinFeatureCollection(env))); - + // Setting a feature will throw if the above feature collection is not wrapped in a mutable feature collection. context.Features.Set(new CustomFeature(100)); Assert.Equal(100, context.Features.Get().Value); From ea0abd82932b4a6734542306b2db7c182528edb8 Mon Sep 17 00:00:00 2001 From: Pavel Krymets Date: Thu, 22 Oct 2015 16:53:04 -0700 Subject: [PATCH 414/987] Rename Microsoft.Runtime.Abstractions to Microsoft.Extensions.PlatformAbstractions --- src/Microsoft.AspNet.Hosting/Internal/HostingEngine.cs | 2 +- src/Microsoft.AspNet.Hosting/Program.cs | 2 +- src/Microsoft.AspNet.Hosting/Startup/StartupExceptionPage.cs | 2 +- src/Microsoft.AspNet.Hosting/WebHostBuilder.cs | 2 +- test/Microsoft.AspNet.Hosting.Tests/Fakes/RuntimeEnvironment.cs | 2 +- test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs | 1 - test/Microsoft.AspNet.Hosting.Tests/WebHostBuilderTests.cs | 1 - test/Microsoft.AspNet.Hosting.Tests/project.json | 2 +- 8 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/Microsoft.AspNet.Hosting/Internal/HostingEngine.cs b/src/Microsoft.AspNet.Hosting/Internal/HostingEngine.cs index 4e175806e8..7bcad0328c 100644 --- a/src/Microsoft.AspNet.Hosting/Internal/HostingEngine.cs +++ b/src/Microsoft.AspNet.Hosting/Internal/HostingEngine.cs @@ -13,10 +13,10 @@ using Microsoft.AspNet.Hosting.Startup; using Microsoft.AspNet.Http; using Microsoft.AspNet.Http.Features; using Microsoft.AspNet.Server.Features; -using Microsoft.Dnx.Runtime; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; +using Microsoft.Extensions.PlatformAbstractions; namespace Microsoft.AspNet.Hosting.Internal { diff --git a/src/Microsoft.AspNet.Hosting/Program.cs b/src/Microsoft.AspNet.Hosting/Program.cs index c324b4e9c1..4715f818d5 100644 --- a/src/Microsoft.AspNet.Hosting/Program.cs +++ b/src/Microsoft.AspNet.Hosting/Program.cs @@ -5,10 +5,10 @@ using System; using Microsoft.AspNet.Http.Features; using Microsoft.AspNet.Server.Features; using Microsoft.Dnx.Compilation; -using Microsoft.Dnx.Runtime; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection.Extensions; +using Microsoft.Extensions.PlatformAbstractions; namespace Microsoft.AspNet.Hosting { diff --git a/src/Microsoft.AspNet.Hosting/Startup/StartupExceptionPage.cs b/src/Microsoft.AspNet.Hosting/Startup/StartupExceptionPage.cs index 0f663b231e..adc9656f89 100644 --- a/src/Microsoft.AspNet.Hosting/Startup/StartupExceptionPage.cs +++ b/src/Microsoft.AspNet.Hosting/Startup/StartupExceptionPage.cs @@ -12,7 +12,7 @@ using System.Runtime.CompilerServices; using System.Runtime.ExceptionServices; using System.Text; using Microsoft.Dnx.Compilation; -using Microsoft.Dnx.Runtime; +using Microsoft.Extensions.PlatformAbstractions; using Microsoft.Extensions.WebEncoders; namespace Microsoft.AspNet.Hosting.Startup diff --git a/src/Microsoft.AspNet.Hosting/WebHostBuilder.cs b/src/Microsoft.AspNet.Hosting/WebHostBuilder.cs index 9467721720..55126d83b7 100644 --- a/src/Microsoft.AspNet.Hosting/WebHostBuilder.cs +++ b/src/Microsoft.AspNet.Hosting/WebHostBuilder.cs @@ -11,11 +11,11 @@ using Microsoft.AspNet.Hosting.Startup; using Microsoft.AspNet.Http; using Microsoft.AspNet.Http.Internal; using Microsoft.Dnx.Compilation; -using Microsoft.Dnx.Runtime; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection.Extensions; using Microsoft.Extensions.Logging; +using Microsoft.Extensions.PlatformAbstractions; namespace Microsoft.AspNet.Hosting { diff --git a/test/Microsoft.AspNet.Hosting.Tests/Fakes/RuntimeEnvironment.cs b/test/Microsoft.AspNet.Hosting.Tests/Fakes/RuntimeEnvironment.cs index 330ff30c29..ee180c4f01 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/Fakes/RuntimeEnvironment.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/Fakes/RuntimeEnvironment.cs @@ -1,7 +1,7 @@ // 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.Dnx.Runtime; +using Microsoft.Extensions.PlatformAbstractions; namespace Microsoft.AspNet.Hosting.Fakes { diff --git a/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs b/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs index afd3a1fc94..9467dba265 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs @@ -17,7 +17,6 @@ using Microsoft.AspNet.Http.Features; using Microsoft.AspNet.Http.Features.Internal; using Microsoft.AspNet.Server.Features; using Microsoft.AspNet.Testing.xunit; -using Microsoft.Dnx.Runtime.Infrastructure; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Internal; diff --git a/test/Microsoft.AspNet.Hosting.Tests/WebHostBuilderTests.cs b/test/Microsoft.AspNet.Hosting.Tests/WebHostBuilderTests.cs index 078019aff5..d558dd40e3 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/WebHostBuilderTests.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/WebHostBuilderTests.cs @@ -10,7 +10,6 @@ using Microsoft.AspNet.Hosting.Internal; using Microsoft.AspNet.Hosting.Server; using Microsoft.AspNet.Http.Features; using Microsoft.AspNet.Http.Internal; -using Microsoft.Dnx.Runtime.Infrastructure; using Microsoft.Extensions.Configuration; using Xunit; diff --git a/test/Microsoft.AspNet.Hosting.Tests/project.json b/test/Microsoft.AspNet.Hosting.Tests/project.json index 935b44acbd..504a10b0b4 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/project.json +++ b/test/Microsoft.AspNet.Hosting.Tests/project.json @@ -4,7 +4,7 @@ "Microsoft.AspNet.Owin": "1.0.0-*", "Microsoft.AspNet.Testing": "1.0.0-*", "Microsoft.Extensions.OptionsModel": "1.0.0-*", - "Microsoft.Dnx.Runtime.Abstractions": "1.0.0-*", + "Microsoft.Extensions.PlatformAbstractions": "1.0.0-*", "Moq": "4.2.1312.1622", "xunit.runner.aspnet": "2.0.0-aspnet-*" }, From 02de506c28f1b1c2889d2ddc128bbbdc4739e9d6 Mon Sep 17 00:00:00 2001 From: David Fowler Date: Fri, 23 Oct 2015 00:33:48 -0700 Subject: [PATCH 415/987] React to rename of DNX abstractions --- src/Microsoft.AspNet.Hosting/project.json | 2 +- src/Microsoft.AspNet.Server.Testing/project.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Microsoft.AspNet.Hosting/project.json b/src/Microsoft.AspNet.Hosting/project.json index 01d2233836..b2e9e33799 100644 --- a/src/Microsoft.AspNet.Hosting/project.json +++ b/src/Microsoft.AspNet.Hosting/project.json @@ -22,7 +22,7 @@ "Microsoft.Extensions.DependencyInjection": "1.0.0-*", "Microsoft.Extensions.Logging": "1.0.0-*", "Microsoft.Dnx.Compilation.Abstractions": "1.0.0-*", - "Microsoft.Dnx.Runtime.Abstractions": "1.0.0-*", + "Microsoft.Extensions.PlatformAbstractions": "1.0.0-*", "System.Diagnostics.DiagnosticSource": "4.0.0-beta-*" }, "frameworks": { diff --git a/src/Microsoft.AspNet.Server.Testing/project.json b/src/Microsoft.AspNet.Server.Testing/project.json index e3c02cd77b..4d3ddd3fd1 100644 --- a/src/Microsoft.AspNet.Server.Testing/project.json +++ b/src/Microsoft.AspNet.Server.Testing/project.json @@ -8,7 +8,7 @@ "dependencies": { "Microsoft.AspNet.Testing": "1.0.0-*", "Microsoft.Extensions.Logging.Abstractions": "1.0.0-*", - "Microsoft.Dnx.Runtime.Abstractions": "1.0.0-*" + "Microsoft.Extensions.PlatformAbstractions": "1.0.0-*" }, "frameworks": { "net451": { From fa72b35883dccc39d6d3e9d66e738185f7e3f2f0 Mon Sep 17 00:00:00 2001 From: David Fowler Date: Fri, 23 Oct 2015 02:59:50 -0700 Subject: [PATCH 416/987] More granualr null checks for platform services --- src/Microsoft.AspNet.Hosting/WebHostBuilder.cs | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/Microsoft.AspNet.Hosting/WebHostBuilder.cs b/src/Microsoft.AspNet.Hosting/WebHostBuilder.cs index 55126d83b7..d3cb534555 100644 --- a/src/Microsoft.AspNet.Hosting/WebHostBuilder.cs +++ b/src/Microsoft.AspNet.Hosting/WebHostBuilder.cs @@ -92,12 +92,28 @@ namespace Microsoft.AspNet.Hosting _configureServices(services); } - if (PlatformServices.Default != null) + if (PlatformServices.Default?.Application != null) { services.TryAdd(ServiceDescriptor.Instance(PlatformServices.Default.Application)); + } + + if (PlatformServices.Default?.Runtime != null) + { services.TryAdd(ServiceDescriptor.Instance(PlatformServices.Default.Runtime)); + } + + if (PlatformServices.Default?.AssemblyLoadContextAccessor != null) + { services.TryAdd(ServiceDescriptor.Instance(PlatformServices.Default.AssemblyLoadContextAccessor)); + } + + if (PlatformServices.Default?.AssemblyLoaderContainer != null) + { services.TryAdd(ServiceDescriptor.Instance(PlatformServices.Default.AssemblyLoaderContainer)); + } + + if (PlatformServices.Default?.LibraryManager != null) + { services.TryAdd(ServiceDescriptor.Instance(PlatformServices.Default.LibraryManager)); } From d56e2fe59b226b43dc0ce676d5f9fd8786d6f94c Mon Sep 17 00:00:00 2001 From: David Fowler Date: Fri, 23 Oct 2015 03:11:50 -0700 Subject: [PATCH 417/987] Removed whitespace --- src/Microsoft.AspNet.Hosting/WebHostBuilder.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Microsoft.AspNet.Hosting/WebHostBuilder.cs b/src/Microsoft.AspNet.Hosting/WebHostBuilder.cs index d3cb534555..8d5c5648e6 100644 --- a/src/Microsoft.AspNet.Hosting/WebHostBuilder.cs +++ b/src/Microsoft.AspNet.Hosting/WebHostBuilder.cs @@ -96,22 +96,22 @@ namespace Microsoft.AspNet.Hosting { services.TryAdd(ServiceDescriptor.Instance(PlatformServices.Default.Application)); } - + if (PlatformServices.Default?.Runtime != null) { services.TryAdd(ServiceDescriptor.Instance(PlatformServices.Default.Runtime)); } - + if (PlatformServices.Default?.AssemblyLoadContextAccessor != null) { services.TryAdd(ServiceDescriptor.Instance(PlatformServices.Default.AssemblyLoadContextAccessor)); } - + if (PlatformServices.Default?.AssemblyLoaderContainer != null) { services.TryAdd(ServiceDescriptor.Instance(PlatformServices.Default.AssemblyLoaderContainer)); } - + if (PlatformServices.Default?.LibraryManager != null) { services.TryAdd(ServiceDescriptor.Instance(PlatformServices.Default.LibraryManager)); From 460b9bcac162ab90c40ad13b448695dc2cf5ce39 Mon Sep 17 00:00:00 2001 From: David Fowler Date: Fri, 23 Oct 2015 05:04:51 -0700 Subject: [PATCH 418/987] Exclude facade from .NET 4.5.1 target --- src/Microsoft.AspNet.Hosting/project.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Microsoft.AspNet.Hosting/project.json b/src/Microsoft.AspNet.Hosting/project.json index b2e9e33799..c5801b914d 100644 --- a/src/Microsoft.AspNet.Hosting/project.json +++ b/src/Microsoft.AspNet.Hosting/project.json @@ -33,7 +33,7 @@ }, "net451": { "frameworkAssemblies": { - "System.Runtime": "" + "System.Runtime": { "type": "build" } } }, "dnxcore50": { From 56256a013bf2acb5b47212c3e2d6ba4acc3828b5 Mon Sep 17 00:00:00 2001 From: Chris R Date: Fri, 23 Oct 2015 09:43:59 -0700 Subject: [PATCH 419/987] #430 Move Program.Main into WebApplication.Run. --- src/Microsoft.AspNet.Hosting/Program.cs | 54 +----------- .../WebApplication.cs | 85 +++++++++++++++++++ 2 files changed, 86 insertions(+), 53 deletions(-) create mode 100644 src/Microsoft.AspNet.Hosting/WebApplication.cs diff --git a/src/Microsoft.AspNet.Hosting/Program.cs b/src/Microsoft.AspNet.Hosting/Program.cs index 4715f818d5..80fa43f73f 100644 --- a/src/Microsoft.AspNet.Hosting/Program.cs +++ b/src/Microsoft.AspNet.Hosting/Program.cs @@ -1,65 +1,13 @@ // 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; -using Microsoft.AspNet.Http.Features; -using Microsoft.AspNet.Server.Features; -using Microsoft.Dnx.Compilation; -using Microsoft.Extensions.Configuration; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.DependencyInjection.Extensions; -using Microsoft.Extensions.PlatformAbstractions; - namespace Microsoft.AspNet.Hosting { public class Program { - private const string HostingJsonFile = "Microsoft.AspNet.Hosting.json"; - private const string ConfigFileKey = "config"; - public static void Main(string[] args) { - // Allow the location of the json file to be specified via a --config command line arg - var tempBuilder = new ConfigurationBuilder().AddCommandLine(args); - var tempConfig = tempBuilder.Build(); - var configFilePath = tempConfig[ConfigFileKey] ?? HostingJsonFile; - - var appBasePath = PlatformServices.Default.Application.ApplicationBasePath; - var config = new ConfigurationBuilder() - .SetBasePath(appBasePath) - .AddJsonFile(configFilePath, optional: true) - .AddEnvironmentVariables() - .AddCommandLine(args) - .Build(); - - var host = new WebHostBuilder(config, captureStartupErrors: true).Build(); - using (var app = host.Start()) - { - var hostingEnv = app.Services.GetRequiredService(); - Console.WriteLine("Hosting environment: " + hostingEnv.EnvironmentName); - - var serverAddresses = app.ServerFeatures.Get(); - if (serverAddresses != null) - { - foreach (var address in serverAddresses.Addresses) - { - Console.WriteLine("Now listening on: " + address); - } - } - - Console.WriteLine("Application started. Press Ctrl+C to shut down."); - - var appLifetime = app.Services.GetRequiredService(); - - Console.CancelKeyPress += (sender, eventArgs) => - { - appLifetime.StopApplication(); - // Don't terminate the process immediately, wait for the Main thread to exit gracefully. - eventArgs.Cancel = true; - }; - - appLifetime.ApplicationStopping.WaitHandle.WaitOne(); - } + WebApplication.Run(args); } } } diff --git a/src/Microsoft.AspNet.Hosting/WebApplication.cs b/src/Microsoft.AspNet.Hosting/WebApplication.cs new file mode 100644 index 0000000000..fea0d58353 --- /dev/null +++ b/src/Microsoft.AspNet.Hosting/WebApplication.cs @@ -0,0 +1,85 @@ +// 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; +using Microsoft.AspNet.Http.Features; +using Microsoft.AspNet.Server.Features; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; + +namespace Microsoft.AspNet.Hosting +{ + public class WebApplication + { + private const string HostingJsonFile = "Microsoft.AspNet.Hosting.json"; + private const string ConfigFileKey = "config"; + + public static void Run(string[] args) + { + Run(startupType: null, args: args); + } + + public static void Run() + { + Run(typeof(TStartup), null); + } + + public static void Run(string[] args) + { + Run(typeof(TStartup), args); + } + + public static void Run(Type startupType) + { + Run(startupType, null); + } + + public static void Run(Type startupType, string[] args) + { + // Allow the location of the json file to be specified via a --config command line arg + var tempBuilder = new ConfigurationBuilder().AddCommandLine(args); + var tempConfig = tempBuilder.Build(); + var configFilePath = tempConfig[ConfigFileKey] ?? HostingJsonFile; + + var config = new ConfigurationBuilder() + .AddJsonFile(configFilePath, optional: true) + .AddEnvironmentVariables() + .AddCommandLine(args) + .Build(); + + var hostBuilder = new WebHostBuilder(config, captureStartupErrors: true); + if (startupType != null) + { + hostBuilder.UseStartup(startupType); + } + var host = hostBuilder.Build(); + using (var app = host.Start()) + { + var hostingEnv = app.Services.GetRequiredService(); + Console.WriteLine("Hosting environment: " + hostingEnv.EnvironmentName); + + var serverAddresses = app.ServerFeatures.Get(); + if (serverAddresses != null) + { + foreach (var address in serverAddresses.Addresses) + { + Console.WriteLine("Now listening on: " + address); + } + } + + Console.WriteLine("Application started. Press Ctrl+C to shut down."); + + var appLifetime = app.Services.GetRequiredService(); + + Console.CancelKeyPress += (sender, eventArgs) => + { + appLifetime.StopApplication(); + // Don't terminate the process immediately, wait for the Main thread to exit gracefully. + eventArgs.Cancel = true; + }; + + appLifetime.ApplicationStopping.WaitHandle.WaitOne(); + } + } + } +} From a20b3e6e377b738360d796bd0479a0d51d3703fc Mon Sep 17 00:00:00 2001 From: Pranav K Date: Fri, 23 Oct 2015 14:10:52 -0700 Subject: [PATCH 420/987] React to Testing changes --- .../Deployers/ApplicationDeployer.cs | 8 ++++---- src/Microsoft.AspNet.Server.Testing/project.json | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Testing/Deployers/ApplicationDeployer.cs b/src/Microsoft.AspNet.Server.Testing/Deployers/ApplicationDeployer.cs index 8e9541199b..a8dfd0e17a 100644 --- a/src/Microsoft.AspNet.Server.Testing/Deployers/ApplicationDeployer.cs +++ b/src/Microsoft.AspNet.Server.Testing/Deployers/ApplicationDeployer.cs @@ -238,9 +238,9 @@ namespace Microsoft.AspNet.Server.Testing protected void AddEnvironmentVariablesToProcess(ProcessStartInfo startInfo) { var environment = -#if NET451 +#if DNX451 startInfo.EnvironmentVariables; -#elif DOTNET5_4 +#elif DNXCORE50 startInfo.Environment; #endif @@ -260,10 +260,10 @@ namespace Microsoft.AspNet.Server.Testing } } -#if DNX451 || NET451 +#if DNX451 protected void SetEnvironmentVariable(System.Collections.Specialized.StringDictionary environment, string name, string value) { -#elif DNXCORE50 || DOTNET5_4 +#elif DNXCORE50 protected void SetEnvironmentVariable(System.Collections.Generic.IDictionary environment, string name, string value) { #endif diff --git a/src/Microsoft.AspNet.Server.Testing/project.json b/src/Microsoft.AspNet.Server.Testing/project.json index 4d3ddd3fd1..66ee97d55c 100644 --- a/src/Microsoft.AspNet.Server.Testing/project.json +++ b/src/Microsoft.AspNet.Server.Testing/project.json @@ -11,7 +11,7 @@ "Microsoft.Extensions.PlatformAbstractions": "1.0.0-*" }, "frameworks": { - "net451": { + "dnx451": { "dependencies": { "Microsoft.Web.Administration": "7.0.0" }, @@ -20,7 +20,7 @@ "System.Xml": "" } }, - "dotnet5.4": { + "dnxcore50": { "dependencies": { "System.Diagnostics.Process": "4.0.0-beta-*", "System.IO.FileSystem": "4.0.1-beta-*", From f37375f43cd9e49ebcd61b62130d3455c8d41944 Mon Sep 17 00:00:00 2001 From: Louis DeJardin Date: Tue, 13 Oct 2015 14:10:26 -0700 Subject: [PATCH 421/987] Reduce logging overhead in hosting * TraceIdentifier is done at the last moment, or not at all * Request starting and finished messages are added * This pair provide many of the top-level values that you would have found in server log files. --- .../FastHttpRequestIdentifierFeature.cs | 65 ------ .../Internal/HostingEngine.cs | 41 ++-- .../Internal/HostingLoggerExtensions.cs | 189 ++++++++++++++++++ src/Microsoft.AspNet.Hosting/project.json | 3 +- .../HostingEngineTests.cs | 121 ++++++++++- .../FastHttpRequestIdentifierFeatureTests.cs | 44 ---- 6 files changed, 324 insertions(+), 139 deletions(-) delete mode 100644 src/Microsoft.AspNet.Hosting/Internal/FastHttpRequestIdentifierFeature.cs create mode 100644 src/Microsoft.AspNet.Hosting/Internal/HostingLoggerExtensions.cs delete mode 100644 test/Microsoft.AspNet.Hosting.Tests/Internal/FastHttpRequestIdentifierFeatureTests.cs diff --git a/src/Microsoft.AspNet.Hosting/Internal/FastHttpRequestIdentifierFeature.cs b/src/Microsoft.AspNet.Hosting/Internal/FastHttpRequestIdentifierFeature.cs deleted file mode 100644 index 95e7806557..0000000000 --- a/src/Microsoft.AspNet.Hosting/Internal/FastHttpRequestIdentifierFeature.cs +++ /dev/null @@ -1,65 +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; -using System.Threading; -using Microsoft.AspNet.Http.Features; - -namespace Microsoft.AspNet.Hosting.Internal -{ - public class FastHttpRequestIdentifierFeature : IHttpRequestIdentifierFeature - { - // Base64 encoding - but in ascii sort order for easy text based sorting - private static readonly string _encode32Chars = "0123456789ABCDEFGHIJKLMNOPQRSTUV"; - // Seed the _requestId for this application instance with - // the number of 100-nanosecond intervals that have elapsed since 12:00:00 midnight, January 1, 0001 - // for a roughly increasing _requestId over restarts - private static long _requestId = DateTime.UtcNow.Ticks; - - private string _id = null; - - public string TraceIdentifier - { - get - { - // Don't incur the cost of generating the request ID until it's asked for - if (_id == null) - { - _id = GenerateRequestId(Interlocked.Increment(ref _requestId)); - } - return _id; - } - set - { - _id = value; - } - } - - private static unsafe string GenerateRequestId(long id) - { - // The following routine is ~310% faster than calling long.ToString() on x64 - // and ~600% faster than calling long.ToString() on x86 in tight loops of 1 million+ iterations - // See: https://github.com/aspnet/Hosting/pull/385 - - // stackalloc to allocate array on stack rather than heap - char* charBuffer = stackalloc char[13]; - - charBuffer[0] = _encode32Chars[(int)(id >> 60) & 31]; - charBuffer[1] = _encode32Chars[(int)(id >> 55) & 31]; - charBuffer[2] = _encode32Chars[(int)(id >> 50) & 31]; - charBuffer[3] = _encode32Chars[(int)(id >> 45) & 31]; - charBuffer[4] = _encode32Chars[(int)(id >> 40) & 31]; - charBuffer[5] = _encode32Chars[(int)(id >> 35) & 31]; - charBuffer[6] = _encode32Chars[(int)(id >> 30) & 31]; - charBuffer[7] = _encode32Chars[(int)(id >> 25) & 31]; - charBuffer[8] = _encode32Chars[(int)(id >> 20) & 31]; - charBuffer[9] = _encode32Chars[(int)(id >> 15) & 31]; - charBuffer[10] = _encode32Chars[(int)(id >> 10) & 31]; - charBuffer[11] = _encode32Chars[(int)(id >> 5) & 31]; - charBuffer[12] = _encode32Chars[(int)id & 31]; - - // string ctor overload that takes char* - return new string(charBuffer, 0, 13); - } - } -} diff --git a/src/Microsoft.AspNet.Hosting/Internal/HostingEngine.cs b/src/Microsoft.AspNet.Hosting/Internal/HostingEngine.cs index 7bcad0328c..b68e2f7c9b 100644 --- a/src/Microsoft.AspNet.Hosting/Internal/HostingEngine.cs +++ b/src/Microsoft.AspNet.Hosting/Internal/HostingEngine.cs @@ -93,27 +93,34 @@ namespace Microsoft.AspNet.Hosting.Internal { var httpContext = contextFactory.CreateHttpContext(features); httpContext.ApplicationServices = _applicationServices; - var requestIdentifier = GetRequestIdentifier(httpContext); + if (diagnosticSource.IsEnabled("Microsoft.AspNet.Hosting.BeginRequest")) { diagnosticSource.Write("Microsoft.AspNet.Hosting.BeginRequest", new { httpContext = httpContext }); } - try + + using (logger.RequestScope(httpContext)) { - using (logger.IsEnabled(LogLevel.Critical) - ? logger.BeginScope("Request Id: {RequestId}", requestIdentifier) - : null) + int startTime = 0; + try { + logger.RequestStarting(httpContext); + + startTime = Environment.TickCount; await application(httpContext); + + logger.RequestFinished(httpContext, startTime); } - } - catch (Exception ex) - { - if (diagnosticSource.IsEnabled("Microsoft.AspNet.Hosting.UnhandledException")) + catch (Exception ex) { - diagnosticSource.Write("Microsoft.AspNet.Hosting.UnhandledException", new { httpContext = httpContext, exception = ex }); + logger.RequestFailed(httpContext, startTime); + + if (diagnosticSource.IsEnabled("Microsoft.AspNet.Hosting.UnhandledException")) + { + diagnosticSource.Write("Microsoft.AspNet.Hosting.UnhandledException", new { httpContext = httpContext, exception = ex }); + } + throw; } - throw; } if (diagnosticSource.IsEnabled("Microsoft.AspNet.Hosting.EndRequest")) { @@ -266,18 +273,6 @@ namespace Microsoft.AspNet.Hosting.Internal } } - private string GetRequestIdentifier(HttpContext httpContext) - { - var requestIdentifierFeature = httpContext.Features.Get(); - if (requestIdentifierFeature == null) - { - requestIdentifierFeature = new FastHttpRequestIdentifierFeature(); - httpContext.Features.Set(requestIdentifierFeature); - } - - return requestIdentifierFeature.TraceIdentifier; - } - private class Disposable : IDisposable { private Action _dispose; diff --git a/src/Microsoft.AspNet.Hosting/Internal/HostingLoggerExtensions.cs b/src/Microsoft.AspNet.Hosting/Internal/HostingLoggerExtensions.cs new file mode 100644 index 0000000000..3f6b109c81 --- /dev/null +++ b/src/Microsoft.AspNet.Hosting/Internal/HostingLoggerExtensions.cs @@ -0,0 +1,189 @@ +// 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; +using System.Collections.Generic; +using System.Threading; +using Microsoft.AspNet.Http; +using Microsoft.Extensions.Logging; + +namespace Microsoft.AspNet.Hosting.Internal +{ + internal static class HostingLoggerExtensions + { + public static IDisposable RequestScope(this ILogger logger, HttpContext httpContext) + { + return logger.BeginScopeImpl(new HostingLogScope(httpContext)); + } + + public static void RequestStarting(this ILogger logger, HttpContext httpContext) + { + if (logger.IsEnabled(LogLevel.Information)) + { + logger.Log( + logLevel: LogLevel.Information, + eventId: 1, + state: new HostingRequestStarting(httpContext), + exception: null, + formatter: HostingRequestStarting.Callback); + } + } + + public static void RequestFinished(this ILogger logger, HttpContext httpContext, int startTimeInTicks) + { + if (logger.IsEnabled(LogLevel.Information)) + { + var elapsed = new TimeSpan(Environment.TickCount - startTimeInTicks); + logger.Log( + logLevel: LogLevel.Information, + eventId: 2, + state: new HostingRequestFinished(httpContext, elapsed), + exception: null, + formatter: HostingRequestFinished.Callback); + } + } + + public static void RequestFailed(this ILogger logger, HttpContext httpContext, int startTimeInTicks) + { + if (logger.IsEnabled(LogLevel.Information)) + { + var elapsed = new TimeSpan(Environment.TickCount - startTimeInTicks); + logger.Log( + logLevel: LogLevel.Information, + eventId: 2, + state: new HostingRequestFailed(httpContext, elapsed), + exception: null, + formatter: HostingRequestFailed.Callback); + } + } + + + private class HostingLogScope : ILogValues + { + private readonly HttpContext _httpContext; + + private string _cachedToString; + private IEnumerable> _cachedGetValues; + + public HostingLogScope(HttpContext httpContext) + { + _httpContext = httpContext; + } + + public override string ToString() => _cachedToString ?? Interlocked.CompareExchange( + ref _cachedToString, + $"RequestId:{_httpContext.TraceIdentifier} RequestPath:{_httpContext.Request.Path}", + null); + + public IEnumerable> GetValues() => _cachedGetValues ?? Interlocked.CompareExchange( + ref _cachedGetValues, + new[] + { + new KeyValuePair("RequestId", _httpContext.TraceIdentifier), + new KeyValuePair("RequestPath", _httpContext.Request.Path.ToString()), + }, + null); + } + + private class HostingRequestStarting : ILogValues + { + internal static readonly Func Callback = (state, exception) => ((HostingRequestStarting)state).ToString(); + + private readonly HttpContext _httpContext; + + private string _cachedToString; + private IEnumerable> _cachedGetValues; + + public HostingRequestStarting(HttpContext httpContext) + { + _httpContext = httpContext; + } + + public override string ToString() => _cachedToString ?? Interlocked.CompareExchange( + ref _cachedToString, + $"Request starting {_httpContext.Request.Protocol} {_httpContext.Request.Method} {_httpContext.Request.Scheme}://{_httpContext.Request.Host}{_httpContext.Request.PathBase}{_httpContext.Request.Path}{_httpContext.Request.QueryString} {_httpContext.Request.ContentType} {_httpContext.Request.ContentLength}", + null); + + public IEnumerable> GetValues() => _cachedGetValues ?? Interlocked.CompareExchange( + ref _cachedGetValues, + new[] + { + new KeyValuePair("Protocol", _httpContext.Request.Protocol), + new KeyValuePair("Method", _httpContext.Request.Method), + new KeyValuePair("ContentType", _httpContext.Request.ContentType), + new KeyValuePair("ContentLength", _httpContext.Request.ContentLength), + new KeyValuePair("Scheme", _httpContext.Request.Scheme.ToString()), + new KeyValuePair("Host", _httpContext.Request.Host.ToString()), + new KeyValuePair("PathBase", _httpContext.Request.PathBase.ToString()), + new KeyValuePair("Path", _httpContext.Request.Path.ToString()), + new KeyValuePair("QueryString", _httpContext.Request.QueryString.ToString()), + }, + null); + } + + private class HostingRequestFinished + { + internal static readonly Func Callback = (state, exception) => ((HostingRequestFinished)state).ToString(); + + private readonly HttpContext _httpContext; + private readonly TimeSpan _elapsed; + + private IEnumerable> _cachedGetValues; + private string _cachedToString; + + public HostingRequestFinished(HttpContext httpContext, TimeSpan elapsed) + { + _httpContext = httpContext; + _elapsed = elapsed; + } + + public override string ToString() => _cachedToString ?? Interlocked.CompareExchange( + ref _cachedToString, + $"Request finished in {_elapsed.TotalMilliseconds}ms {_httpContext.Response.StatusCode} {_httpContext.Response.ContentType}", + null); + + public IEnumerable> GetValues() => _cachedGetValues ?? Interlocked.CompareExchange( + ref _cachedGetValues, + new[] + { + new KeyValuePair("ElapsedMilliseconds", _elapsed.TotalMilliseconds), + new KeyValuePair("StatusCode", _httpContext.Response.StatusCode), + new KeyValuePair("ContentType", _httpContext.Response.ContentType), + }, + null); + } + + private class HostingRequestFailed + { + internal static readonly Func Callback = (state, exception) => ((HostingRequestFailed)state).ToString(); + + private readonly HttpContext _httpContext; + private readonly TimeSpan _elapsed; + + private IEnumerable> _cachedGetValues; + private string _cachedToString; + + public HostingRequestFailed(HttpContext httpContext, TimeSpan elapsed) + { + _httpContext = httpContext; + _elapsed = elapsed; + } + + public override string ToString() => _cachedToString ?? Interlocked.CompareExchange( + ref _cachedToString, + $"Request finished in {_elapsed.TotalMilliseconds}ms 500", + null); + + public IEnumerable> GetValues() => _cachedGetValues ?? Interlocked.CompareExchange( + ref _cachedGetValues, + new[] + { + new KeyValuePair("ElapsedMilliseconds", _elapsed.TotalMilliseconds), + new KeyValuePair("StatusCode", 500), + new KeyValuePair("ContentType", null), + }, + null); + } + } +} + diff --git a/src/Microsoft.AspNet.Hosting/project.json b/src/Microsoft.AspNet.Hosting/project.json index c5801b914d..edd34b5469 100644 --- a/src/Microsoft.AspNet.Hosting/project.json +++ b/src/Microsoft.AspNet.Hosting/project.json @@ -6,8 +6,7 @@ "url": "git://github.com/aspnet/hosting" }, "compilationOptions": { - "warningsAsErrors": true, - "allowUnsafe": true + "warningsAsErrors": true }, "dependencies": { "Microsoft.AspNet.FileProviders.Physical": "1.0.0-*", diff --git a/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs b/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs index 9467dba265..1d9ababa9d 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs @@ -14,13 +14,13 @@ using Microsoft.AspNet.Hosting.Server; using Microsoft.AspNet.Hosting.Startup; using Microsoft.AspNet.Http; using Microsoft.AspNet.Http.Features; -using Microsoft.AspNet.Http.Features.Internal; using Microsoft.AspNet.Server.Features; using Microsoft.AspNet.Testing.xunit; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Internal; +using Microsoft.Extensions.Logging; using Microsoft.Extensions.OptionsModel; +using Microsoft.Extensions.Primitives; using Moq; using Xunit; @@ -29,7 +29,16 @@ namespace Microsoft.AspNet.Hosting public class HostingEngineTests : IServerFactory { private readonly IList _startInstances = new List(); - private IFeatureCollection _featuresSupportedByThisHost = new FeatureCollection(); + private IFeatureCollection _featuresSupportedByThisHost = NewFeatureCollection(); + + static IFeatureCollection NewFeatureCollection() + { + var stub = new StubFeatures(); + var features = new FeatureCollection(); + features[typeof(IHttpRequestFeature)] = stub; + features[typeof(IHttpResponseFeature)] = stub; + return features; + } [Fact] public void HostingEngineThrowsWithNoServer() @@ -314,7 +323,9 @@ namespace Microsoft.AspNet.Hosting // Assert Assert.NotNull(httpContext); - Assert.IsType(httpContext.Features.Get()); + var featuresTraceIdentifier = httpContext.Features.Get().TraceIdentifier; + Assert.False(string.IsNullOrWhiteSpace(httpContext.TraceIdentifier)); + Assert.Same(httpContext.TraceIdentifier, featuresTraceIdentifier); } [Fact] @@ -393,7 +404,11 @@ namespace Microsoft.AspNet.Hosting var host = CreateBuilder() .UseServer(this) .UseStartup( - appBuilder => { appBuilder.Run(requestDelegate); }, + appBuilder => + { + appBuilder.ApplicationServices.GetRequiredService().AddProvider(new AllMessagesAreNeeded()); + appBuilder.Run(requestDelegate); + }, configureServices => configureServices.BuildServiceProvider()); return host.Build(); } @@ -498,5 +513,101 @@ namespace Microsoft.AspNet.Hosting { public ICollection Addresses { get; } = new List(); } + + private class AllMessagesAreNeeded : ILoggerProvider, ILogger + { + public bool IsEnabled(LogLevel logLevel) => true; + + public ILogger CreateLogger(string name) => this; + + public IDisposable BeginScopeImpl(object state) + { + var stringified = state.ToString(); + return this; + } + public void Log(LogLevel logLevel, int eventId, object state, Exception exception, Func formatter) + { + var stringified = formatter(state, exception); + } + + public void Dispose() + { + } + } + + private class StubFeatures : IHttpRequestFeature, IHttpResponseFeature, IHeaderDictionary + { + public StubFeatures() + { + Headers = this; + Body = new MemoryStream(); + } + + public StringValues this[string key] + { + get { return StringValues.Empty; } + set { } + } + + public Stream Body { get; set; } + + public int Count => 0; + + public bool HasStarted { get; set; } + + public IHeaderDictionary Headers { get; set; } + + public bool IsReadOnly => false; + + public ICollection Keys => null; + + public string Method { get; set; } + + public string Path { get; set; } + + public string PathBase { get; set; } + + public string Protocol { get; set; } + + public string QueryString { get; set; } + + public string ReasonPhrase { get; set; } + + public string Scheme { get; set; } + + public int StatusCode { get; set; } + + public ICollection Values => null; + + public void Add(KeyValuePair item) { } + + public void Add(string key, StringValues value) { } + + public void Clear() { } + + public bool Contains(KeyValuePair item) => false; + + public bool ContainsKey(string key) => false; + + public void CopyTo(KeyValuePair[] array, int arrayIndex) { } + + public IEnumerator> GetEnumerator() => null; + + public void OnCompleted(Func callback, object state) { } + + public void OnStarting(Func callback, object state) { } + + public bool Remove(KeyValuePair item) => false; + + public bool Remove(string key) => false; + + public bool TryGetValue(string key, out StringValues value) + { + value = StringValues.Empty; + return false; + } + + IEnumerator IEnumerable.GetEnumerator() => null; + } } } diff --git a/test/Microsoft.AspNet.Hosting.Tests/Internal/FastHttpRequestIdentifierFeatureTests.cs b/test/Microsoft.AspNet.Hosting.Tests/Internal/FastHttpRequestIdentifierFeatureTests.cs deleted file mode 100644 index fff0fb603a..0000000000 --- a/test/Microsoft.AspNet.Hosting.Tests/Internal/FastHttpRequestIdentifierFeatureTests.cs +++ /dev/null @@ -1,44 +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.Hosting.Internal; -using Xunit; - -namespace Microsoft.AspNet.Hosting.Tests.Internal -{ - public class FastHttpRequestIdentifierFeatureTests - { - [Fact] - public void TraceIdentifier_ReturnsId() - { - var feature = new FastHttpRequestIdentifierFeature(); - - var id = feature.TraceIdentifier; - - Assert.NotNull(id); - } - - [Fact] - public void TraceIdentifier_ReturnsStableId() - { - var feature = new FastHttpRequestIdentifierFeature(); - - var id1 = feature.TraceIdentifier; - var id2 = feature.TraceIdentifier; - - Assert.Equal(id1, id2); - } - - [Fact] - public void TraceIdentifier_ReturnsUniqueIdForDifferentInstances() - { - var feature1 = new FastHttpRequestIdentifierFeature(); - var feature2 = new FastHttpRequestIdentifierFeature(); - - var id1 = feature1.TraceIdentifier; - var id2 = feature2.TraceIdentifier; - - Assert.NotEqual(id1, id2); - } - } -} From 8e1a0768db01d56d9f1510def3a1e5666d68eba8 Mon Sep 17 00:00:00 2001 From: Chris R Date: Sun, 25 Oct 2015 09:12:33 -0700 Subject: [PATCH 422/987] Remove IHttpContextFactory, it was moved to HttpAbstractions. --- .../Builder/HttpContextFactory.cs | 26 -------- .../Builder/IHttpContextFactory.cs | 13 ---- .../HttpContextFactoryFacts.cs | 60 ------------------- 3 files changed, 99 deletions(-) delete mode 100644 src/Microsoft.AspNet.Hosting/Builder/HttpContextFactory.cs delete mode 100644 src/Microsoft.AspNet.Hosting/Builder/IHttpContextFactory.cs delete mode 100644 test/Microsoft.AspNet.Hosting.Tests/HttpContextFactoryFacts.cs diff --git a/src/Microsoft.AspNet.Hosting/Builder/HttpContextFactory.cs b/src/Microsoft.AspNet.Hosting/Builder/HttpContextFactory.cs deleted file mode 100644 index c86cf451b5..0000000000 --- a/src/Microsoft.AspNet.Hosting/Builder/HttpContextFactory.cs +++ /dev/null @@ -1,26 +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; -using Microsoft.AspNet.Http.Features; -using Microsoft.AspNet.Http.Internal; - -namespace Microsoft.AspNet.Hosting.Builder -{ - public class HttpContextFactory : IHttpContextFactory - { - private IHttpContextAccessor _httpContextAccessor; - - public HttpContextFactory(IHttpContextAccessor httpContextAccessor) - { - _httpContextAccessor = httpContextAccessor; - } - - public HttpContext CreateHttpContext(IFeatureCollection featureCollection) - { - var httpContext = new DefaultHttpContext(featureCollection); - _httpContextAccessor.HttpContext = httpContext; - return httpContext; - } - } -} \ No newline at end of file diff --git a/src/Microsoft.AspNet.Hosting/Builder/IHttpContextFactory.cs b/src/Microsoft.AspNet.Hosting/Builder/IHttpContextFactory.cs deleted file mode 100644 index ed1d9f4cc3..0000000000 --- a/src/Microsoft.AspNet.Hosting/Builder/IHttpContextFactory.cs +++ /dev/null @@ -1,13 +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; -using Microsoft.AspNet.Http.Features; - -namespace Microsoft.AspNet.Hosting.Builder -{ - public interface IHttpContextFactory - { - HttpContext CreateHttpContext(IFeatureCollection featureCollection); - } -} \ No newline at end of file diff --git a/test/Microsoft.AspNet.Hosting.Tests/HttpContextFactoryFacts.cs b/test/Microsoft.AspNet.Hosting.Tests/HttpContextFactoryFacts.cs deleted file mode 100644 index 02f3a2cc2c..0000000000 --- a/test/Microsoft.AspNet.Hosting.Tests/HttpContextFactoryFacts.cs +++ /dev/null @@ -1,60 +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.Collections.Generic; -using Microsoft.AspNet.Hosting.Builder; -using Microsoft.AspNet.Http.Features; -using Microsoft.AspNet.Http.Internal; -using Microsoft.AspNet.Owin; -using Xunit; - -namespace Microsoft.AspNet.Hosting.Tests -{ - public class HttpContextFactoryFacts - { - [Fact] - public void CreateHttpContextSetsHttpContextAccessor() - { - // Arrange - var accessor = new HttpContextAccessor(); - var contextFactory = new HttpContextFactory(accessor); - - // Act - var context = contextFactory.CreateHttpContext(new FeatureCollection()); - - // Assert - Assert.True(ReferenceEquals(context, accessor.HttpContext)); - } - - [Fact] - public void Mutable_FeatureCollection_Wrapped_For_OwinFeatureCollection() - { - var env = new Dictionary(); - var contextFactory = new HttpContextFactory(new HttpContextAccessor()); - var context = contextFactory.CreateHttpContext(new FeatureCollection(new OwinFeatureCollection(env))); - - // Setting a feature will throw if the above feature collection is not wrapped in a mutable feature collection. - context.Features.Set(new CustomFeature(100)); - Assert.Equal(100, context.Features.Get().Value); - } - - private interface ICustomFeature - { - int Value { get; } - } - - private class CustomFeature : ICustomFeature - { - private readonly int _value; - public CustomFeature(int value) - { - _value = value; - } - - public int Value - { - get { return _value; } - } - } - } -} \ No newline at end of file From 0107ba005b0a1a7f3b2aaee422aab167139437cf Mon Sep 17 00:00:00 2001 From: Chris R Date: Sun, 25 Oct 2015 09:12:55 -0700 Subject: [PATCH 423/987] One more line. --- src/Microsoft.AspNet.Hosting/Internal/HostingEngine.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Microsoft.AspNet.Hosting/Internal/HostingEngine.cs b/src/Microsoft.AspNet.Hosting/Internal/HostingEngine.cs index b68e2f7c9b..6c0ad5eedd 100644 --- a/src/Microsoft.AspNet.Hosting/Internal/HostingEngine.cs +++ b/src/Microsoft.AspNet.Hosting/Internal/HostingEngine.cs @@ -91,7 +91,7 @@ namespace Microsoft.AspNet.Hosting.Internal var server = ServerFactory.Start(_serverFeatures, async features => { - var httpContext = contextFactory.CreateHttpContext(features); + var httpContext = contextFactory.Create(features); httpContext.ApplicationServices = _applicationServices; if (diagnosticSource.IsEnabled("Microsoft.AspNet.Hosting.BeginRequest")) From 52796a09a209985b3967d1122dc05bd76f71aa8d Mon Sep 17 00:00:00 2001 From: Chris R Date: Mon, 26 Oct 2015 08:59:47 -0700 Subject: [PATCH 424/987] #434 Make sure IApplicationLifetime gets added even if startup throws. --- .../Internal/HostingEngine.cs | 2 +- .../WebHostBuilderTests.cs | 25 +++++++++++++++---- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/src/Microsoft.AspNet.Hosting/Internal/HostingEngine.cs b/src/Microsoft.AspNet.Hosting/Internal/HostingEngine.cs index 6c0ad5eedd..6126d712ec 100644 --- a/src/Microsoft.AspNet.Hosting/Internal/HostingEngine.cs +++ b/src/Microsoft.AspNet.Hosting/Internal/HostingEngine.cs @@ -70,6 +70,7 @@ namespace Microsoft.AspNet.Hosting.Internal _startupLoader = startupLoader; _captureStartupErrors = captureStartupErrors; _applicationLifetime = new ApplicationLifetime(); + _applicationServiceCollection.AddInstance(_applicationLifetime); } public IServiceProvider ApplicationServices @@ -144,7 +145,6 @@ namespace Microsoft.AspNet.Hosting.Internal if (_applicationServices == null) { EnsureStartup(); - _applicationServiceCollection.AddInstance(_applicationLifetime); _applicationServices = Startup.ConfigureServicesDelegate(_applicationServiceCollection); } } diff --git a/test/Microsoft.AspNet.Hosting.Tests/WebHostBuilderTests.cs b/test/Microsoft.AspNet.Hosting.Tests/WebHostBuilderTests.cs index d558dd40e3..b8aa7c6e6c 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/WebHostBuilderTests.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/WebHostBuilderTests.cs @@ -11,6 +11,7 @@ using Microsoft.AspNet.Hosting.Server; using Microsoft.AspNet.Http.Features; using Microsoft.AspNet.Http.Internal; using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; using Xunit; namespace Microsoft.AspNet.Hosting @@ -42,7 +43,7 @@ namespace Microsoft.AspNet.Hosting { var builder = CreateWebHostBuilder(); var serverFactory = new TestServerFactory(); - var engine = (HostingEngine)builder.UseServer(serverFactory).UseStartup("MissingStartupAssembly").Build(); + var engine = builder.UseServer(serverFactory).UseStartup("MissingStartupAssembly").Build(); using (engine.Start()) { await AssertResponseContains(serverFactory.Application, "MissingStartupAssembly"); @@ -54,7 +55,7 @@ namespace Microsoft.AspNet.Hosting { var builder = CreateWebHostBuilder(); var serverFactory = new TestServerFactory(); - var engine = (HostingEngine)builder.UseServer(serverFactory).UseStartup().Build(); + var engine = builder.UseServer(serverFactory).UseStartup().Build(); using (engine.Start()) { await AssertResponseContains(serverFactory.Application, "Exception from static constructor"); @@ -66,19 +67,33 @@ namespace Microsoft.AspNet.Hosting { var builder = CreateWebHostBuilder(); var serverFactory = new TestServerFactory(); - var engine = (HostingEngine)builder.UseServer(serverFactory).UseStartup().Build(); + var engine = builder.UseServer(serverFactory).UseStartup().Build(); using (engine.Start()) { await AssertResponseContains(serverFactory.Application, "Exception from constructor"); } } + [Fact] + public async Task IApplicationLifetimeRegisteredEvenWhenStartupCtorThrows_Fallback() + { + var builder = CreateWebHostBuilder(); + var serverFactory = new TestServerFactory(); + var engine = builder.UseServer(serverFactory).UseStartup().Build(); + using (engine.Start()) + { + var service = engine.ApplicationServices.GetService(); + Assert.NotNull(service); + await AssertResponseContains(serverFactory.Application, "Exception from constructor"); + } + } + [Fact] public async Task StartupConfigureServicesThrows_Fallback() { var builder = CreateWebHostBuilder(); var serverFactory = new TestServerFactory(); - var engine = (HostingEngine)builder.UseServer(serverFactory).UseStartup().Build(); + var engine = builder.UseServer(serverFactory).UseStartup().Build(); using (engine.Start()) { await AssertResponseContains(serverFactory.Application, "Exception from ConfigureServices"); @@ -90,7 +105,7 @@ namespace Microsoft.AspNet.Hosting { var builder = CreateWebHostBuilder(); var serverFactory = new TestServerFactory(); - var engine = (HostingEngine)builder.UseServer(serverFactory).UseStartup().Build(); + var engine = builder.UseServer(serverFactory).UseStartup().Build(); using (engine.Start()) { await AssertResponseContains(serverFactory.Application, "Exception from Configure"); From 2f4c34476bc01b5a69863272f9c947e41b4e586c Mon Sep 17 00:00:00 2001 From: Chris R Date: Mon, 26 Oct 2015 13:43:00 -0700 Subject: [PATCH 425/987] #411 Use "webroot" instead of "hosting:webroot" --- src/Microsoft.AspNet.Hosting/HostingEnvironmentExtensions.cs | 2 +- test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Microsoft.AspNet.Hosting/HostingEnvironmentExtensions.cs b/src/Microsoft.AspNet.Hosting/HostingEnvironmentExtensions.cs index 4ff521aefb..74cf50ec74 100644 --- a/src/Microsoft.AspNet.Hosting/HostingEnvironmentExtensions.cs +++ b/src/Microsoft.AspNet.Hosting/HostingEnvironmentExtensions.cs @@ -12,7 +12,7 @@ namespace Microsoft.AspNet.Hosting private const string OldEnvironmentKey = "ASPNET_ENV"; private const string EnvironmentKey = "Hosting:Environment"; - private const string WebRootKey = "Hosting:WebRoot"; + private const string WebRootKey = "webroot"; public static void Initialize(this IHostingEnvironment hostingEnvironment, string applicationBasePath, IConfiguration config) { diff --git a/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs b/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs index 1d9ababa9d..928cd5bb35 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs @@ -260,7 +260,7 @@ namespace Microsoft.AspNet.Hosting { var vals = new Dictionary { - { "Hosting:WebRoot", "testroot" } + { "webroot", "testroot" } }; var builder = new ConfigurationBuilder() From 9be0758c4d1da87aa5afe931e030d59636d33cb6 Mon Sep 17 00:00:00 2001 From: Victor Hurdugaci Date: Mon, 26 Oct 2015 13:19:32 -0700 Subject: [PATCH 426/987] Event ids and more logging --- .../Internal/HostingEngine.cs | 7 ++- .../Internal/HostingLoggerExtensions.cs | 44 +++++++++++++++++-- .../Internal/LoggerEventIds.cs | 16 +++++++ 3 files changed, 63 insertions(+), 4 deletions(-) create mode 100644 src/Microsoft.AspNet.Hosting/Internal/LoggerEventIds.cs diff --git a/src/Microsoft.AspNet.Hosting/Internal/HostingEngine.cs b/src/Microsoft.AspNet.Hosting/Internal/HostingEngine.cs index 6126d712ec..55e2cd589c 100644 --- a/src/Microsoft.AspNet.Hosting/Internal/HostingEngine.cs +++ b/src/Microsoft.AspNet.Hosting/Internal/HostingEngine.cs @@ -89,6 +89,9 @@ namespace Microsoft.AspNet.Hosting.Internal var logger = _applicationServices.GetRequiredService>(); var contextFactory = _applicationServices.GetRequiredService(); var diagnosticSource = _applicationServices.GetRequiredService(); + + logger.Starting(); + var server = ServerFactory.Start(_serverFeatures, async features => { @@ -130,9 +133,11 @@ namespace Microsoft.AspNet.Hosting.Internal }); _applicationLifetime.NotifyStarted(); + logger.Started(); return new Application(ApplicationServices, _serverFeatures, new Disposable(() => { + logger.Shutdown(); _applicationLifetime.StopApplication(); server.Dispose(); _applicationLifetime.NotifyStopped(); @@ -218,7 +223,7 @@ namespace Microsoft.AspNet.Hosting.Internal // Write errors to standard out so they can be retrieved when not in development mode. Console.Out.WriteLine("Application startup exception: " + ex.ToString()); var logger = _applicationServices.GetRequiredService>(); - logger.LogError("Application startup exception", ex); + logger.ApplicationError(ex); // Generate an HTML error page. var runtimeEnv = _applicationServices.GetRequiredService(); diff --git a/src/Microsoft.AspNet.Hosting/Internal/HostingLoggerExtensions.cs b/src/Microsoft.AspNet.Hosting/Internal/HostingLoggerExtensions.cs index 3f6b109c81..0d79f7ae63 100644 --- a/src/Microsoft.AspNet.Hosting/Internal/HostingLoggerExtensions.cs +++ b/src/Microsoft.AspNet.Hosting/Internal/HostingLoggerExtensions.cs @@ -22,7 +22,7 @@ namespace Microsoft.AspNet.Hosting.Internal { logger.Log( logLevel: LogLevel.Information, - eventId: 1, + eventId: LoggerEventIds.RequestStarting, state: new HostingRequestStarting(httpContext), exception: null, formatter: HostingRequestStarting.Callback); @@ -36,7 +36,7 @@ namespace Microsoft.AspNet.Hosting.Internal var elapsed = new TimeSpan(Environment.TickCount - startTimeInTicks); logger.Log( logLevel: LogLevel.Information, - eventId: 2, + eventId: LoggerEventIds.RequestFinished, state: new HostingRequestFinished(httpContext, elapsed), exception: null, formatter: HostingRequestFinished.Callback); @@ -50,13 +50,51 @@ namespace Microsoft.AspNet.Hosting.Internal var elapsed = new TimeSpan(Environment.TickCount - startTimeInTicks); logger.Log( logLevel: LogLevel.Information, - eventId: 2, + eventId: LoggerEventIds.RequestFailed, state: new HostingRequestFailed(httpContext, elapsed), exception: null, formatter: HostingRequestFailed.Callback); } } + public static void ApplicationError(this ILogger logger, Exception exception) + { + logger.LogError( + eventId: LoggerEventIds.ApplicationStartupException, + message: "Application startup exception", + error: exception); + } + + public static void Starting(this ILogger logger) + { + if (logger.IsEnabled(LogLevel.Verbose)) + { + logger.LogVerbose( + eventId: LoggerEventIds.Starting, + data: "Hosting starting"); + } + } + + public static void Started(this ILogger logger) + { + if (logger.IsEnabled(LogLevel.Verbose)) + { + logger.LogVerbose( + eventId: LoggerEventIds.Started, + data: "Hosting started"); + } + } + + public static void Shutdown(this ILogger logger) + { + if (logger.IsEnabled(LogLevel.Verbose)) + { + logger.LogVerbose( + eventId: LoggerEventIds.Shutdown, + data: "Hosting shutdown"); + } + } + private class HostingLogScope : ILogValues { diff --git a/src/Microsoft.AspNet.Hosting/Internal/LoggerEventIds.cs b/src/Microsoft.AspNet.Hosting/Internal/LoggerEventIds.cs new file mode 100644 index 0000000000..9bc4a4affe --- /dev/null +++ b/src/Microsoft.AspNet.Hosting/Internal/LoggerEventIds.cs @@ -0,0 +1,16 @@ +// 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. + +namespace Microsoft.AspNet.Hosting.Internal +{ + internal static class LoggerEventIds + { + public const int RequestStarting = 1; + public const int RequestFinished = 2; + public const int RequestFailed = 3; + public const int Starting = 4; + public const int Started = 5; + public const int Shutdown = 6; + public const int ApplicationStartupException = 7; + } +} From de35fba9c95da3df6020a33ca28af014704dc39c Mon Sep 17 00:00:00 2001 From: Pranav K Date: Wed, 28 Oct 2015 12:43:06 -0700 Subject: [PATCH 427/987] Updating to release NuGet.config. --- NuGet.config | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/NuGet.config b/NuGet.config index 03704957e8..9db87a421e 100644 --- a/NuGet.config +++ b/NuGet.config @@ -1,7 +1,7 @@ - + - + \ No newline at end of file From 2bb2f955327ea52c4b0536732d85b4a42f16e1a5 Mon Sep 17 00:00:00 2001 From: Kiran Challa Date: Wed, 28 Oct 2015 12:10:07 -0700 Subject: [PATCH 428/987] Log messages from HostingEngine are sometimes null #454 --- .../Internal/HostingLoggerExtensions.cs | 159 +++++++++++------- 1 file changed, 99 insertions(+), 60 deletions(-) diff --git a/src/Microsoft.AspNet.Hosting/Internal/HostingLoggerExtensions.cs b/src/Microsoft.AspNet.Hosting/Internal/HostingLoggerExtensions.cs index 0d79f7ae63..a92eac1444 100644 --- a/src/Microsoft.AspNet.Hosting/Internal/HostingLoggerExtensions.cs +++ b/src/Microsoft.AspNet.Hosting/Internal/HostingLoggerExtensions.cs @@ -3,7 +3,6 @@ using System; using System.Collections.Generic; -using System.Threading; using Microsoft.AspNet.Http; using Microsoft.Extensions.Logging; @@ -108,55 +107,75 @@ namespace Microsoft.AspNet.Hosting.Internal _httpContext = httpContext; } - public override string ToString() => _cachedToString ?? Interlocked.CompareExchange( - ref _cachedToString, - $"RequestId:{_httpContext.TraceIdentifier} RequestPath:{_httpContext.Request.Path}", - null); - - public IEnumerable> GetValues() => _cachedGetValues ?? Interlocked.CompareExchange( - ref _cachedGetValues, - new[] + public override string ToString() + { + if (_cachedToString == null) { - new KeyValuePair("RequestId", _httpContext.TraceIdentifier), - new KeyValuePair("RequestPath", _httpContext.Request.Path.ToString()), - }, - null); + _cachedToString = $"RequestId:{_httpContext.TraceIdentifier} RequestPath:{_httpContext.Request.Path}"; + } + + return _cachedToString; + } + + public IEnumerable> GetValues() + { + if (_cachedGetValues == null) + { + _cachedGetValues = new[] + { + new KeyValuePair("RequestId", _httpContext.TraceIdentifier), + new KeyValuePair("RequestPath", _httpContext.Request.Path.ToString()), + }; + } + + return _cachedGetValues; + } } private class HostingRequestStarting : ILogValues { internal static readonly Func Callback = (state, exception) => ((HostingRequestStarting)state).ToString(); - private readonly HttpContext _httpContext; + private readonly HttpRequest _request; private string _cachedToString; private IEnumerable> _cachedGetValues; public HostingRequestStarting(HttpContext httpContext) { - _httpContext = httpContext; + _request = httpContext.Request; } - public override string ToString() => _cachedToString ?? Interlocked.CompareExchange( - ref _cachedToString, - $"Request starting {_httpContext.Request.Protocol} {_httpContext.Request.Method} {_httpContext.Request.Scheme}://{_httpContext.Request.Host}{_httpContext.Request.PathBase}{_httpContext.Request.Path}{_httpContext.Request.QueryString} {_httpContext.Request.ContentType} {_httpContext.Request.ContentLength}", - null); - - public IEnumerable> GetValues() => _cachedGetValues ?? Interlocked.CompareExchange( - ref _cachedGetValues, - new[] + public override string ToString() + { + if (_cachedToString == null) { - new KeyValuePair("Protocol", _httpContext.Request.Protocol), - new KeyValuePair("Method", _httpContext.Request.Method), - new KeyValuePair("ContentType", _httpContext.Request.ContentType), - new KeyValuePair("ContentLength", _httpContext.Request.ContentLength), - new KeyValuePair("Scheme", _httpContext.Request.Scheme.ToString()), - new KeyValuePair("Host", _httpContext.Request.Host.ToString()), - new KeyValuePair("PathBase", _httpContext.Request.PathBase.ToString()), - new KeyValuePair("Path", _httpContext.Request.Path.ToString()), - new KeyValuePair("QueryString", _httpContext.Request.QueryString.ToString()), - }, - null); + _cachedToString = $"Request starting {_request.Protocol} {_request.Method} {_request.Scheme}://{_request.Host}{_request.PathBase}{_request.Path}{_request.QueryString} {_request.ContentType} {_request.ContentLength}"; + } + + return _cachedToString; + } + + public IEnumerable> GetValues() + { + if (_cachedGetValues == null) + { + _cachedGetValues = new[] + { + new KeyValuePair("Protocol", _request.Protocol), + new KeyValuePair("Method", _request.Method), + new KeyValuePair("ContentType", _request.ContentType), + new KeyValuePair("ContentLength", _request.ContentLength), + new KeyValuePair("Scheme", _request.Scheme.ToString()), + new KeyValuePair("Host", _request.Host.ToString()), + new KeyValuePair("PathBase", _request.PathBase.ToString()), + new KeyValuePair("Path", _request.Path.ToString()), + new KeyValuePair("QueryString", _request.QueryString.ToString()), + }; + } + + return _cachedGetValues; + } } private class HostingRequestFinished @@ -175,20 +194,30 @@ namespace Microsoft.AspNet.Hosting.Internal _elapsed = elapsed; } - public override string ToString() => _cachedToString ?? Interlocked.CompareExchange( - ref _cachedToString, - $"Request finished in {_elapsed.TotalMilliseconds}ms {_httpContext.Response.StatusCode} {_httpContext.Response.ContentType}", - null); - - public IEnumerable> GetValues() => _cachedGetValues ?? Interlocked.CompareExchange( - ref _cachedGetValues, - new[] + public override string ToString() + { + if (_cachedToString == null) { - new KeyValuePair("ElapsedMilliseconds", _elapsed.TotalMilliseconds), - new KeyValuePair("StatusCode", _httpContext.Response.StatusCode), - new KeyValuePair("ContentType", _httpContext.Response.ContentType), - }, - null); + _cachedToString = $"Request finished in {_elapsed.TotalMilliseconds}ms {_httpContext.Response.StatusCode} {_httpContext.Response.ContentType}"; + } + + return _cachedToString; + } + + public IEnumerable> GetValues() + { + if (_cachedGetValues == null) + { + _cachedGetValues = new[] + { + new KeyValuePair("ElapsedMilliseconds", _elapsed.TotalMilliseconds), + new KeyValuePair("StatusCode", _httpContext.Response.StatusCode), + new KeyValuePair("ContentType", _httpContext.Response.ContentType), + }; + } + + return _cachedGetValues; + } } private class HostingRequestFailed @@ -207,20 +236,30 @@ namespace Microsoft.AspNet.Hosting.Internal _elapsed = elapsed; } - public override string ToString() => _cachedToString ?? Interlocked.CompareExchange( - ref _cachedToString, - $"Request finished in {_elapsed.TotalMilliseconds}ms 500", - null); - - public IEnumerable> GetValues() => _cachedGetValues ?? Interlocked.CompareExchange( - ref _cachedGetValues, - new[] + public override string ToString() + { + if (_cachedToString == null) { - new KeyValuePair("ElapsedMilliseconds", _elapsed.TotalMilliseconds), - new KeyValuePair("StatusCode", 500), - new KeyValuePair("ContentType", null), - }, - null); + _cachedToString = $"Request finished in {_elapsed.TotalMilliseconds}ms 500"; + } + + return _cachedToString; + } + + public IEnumerable> GetValues() + { + if (_cachedGetValues == null) + { + _cachedGetValues = new[] + { + new KeyValuePair("ElapsedMilliseconds", _elapsed.TotalMilliseconds), + new KeyValuePair("StatusCode", 500), + new KeyValuePair("ContentType", null), + }; + } + + return _cachedGetValues; + } } } } From 995f0ca92fe4c85f01ef00df787f669a9882109c Mon Sep 17 00:00:00 2001 From: Chris R Date: Wed, 28 Oct 2015 14:07:22 -0700 Subject: [PATCH 429/987] #452 Rename Microsoft.AspNet.Hosting.json to hosting.json. --- src/Microsoft.AspNet.Hosting/WebApplication.cs | 2 +- .../Deployers/IISDeployer.cs | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Microsoft.AspNet.Hosting/WebApplication.cs b/src/Microsoft.AspNet.Hosting/WebApplication.cs index fea0d58353..7d77a911db 100644 --- a/src/Microsoft.AspNet.Hosting/WebApplication.cs +++ b/src/Microsoft.AspNet.Hosting/WebApplication.cs @@ -11,7 +11,7 @@ namespace Microsoft.AspNet.Hosting { public class WebApplication { - private const string HostingJsonFile = "Microsoft.AspNet.Hosting.json"; + private const string HostingJsonFile = "hosting.json"; private const string ConfigFileKey = "config"; public static void Run(string[] args) diff --git a/src/Microsoft.AspNet.Server.Testing/Deployers/IISDeployer.cs b/src/Microsoft.AspNet.Server.Testing/Deployers/IISDeployer.cs index db2fd224d4..5403dbc1df 100644 --- a/src/Microsoft.AspNet.Server.Testing/Deployers/IISDeployer.cs +++ b/src/Microsoft.AspNet.Server.Testing/Deployers/IISDeployer.cs @@ -66,9 +66,9 @@ namespace Microsoft.AspNet.Server.Testing private void SetAspEnvironmentWithJson() { - // Drop a Microsoft.AspNet.Hosting.json with Hosting:Environment information. - Logger.LogInformation("Creating Microsoft.AspNet.Hosting.json file with Hosting:Environment."); - var jsonFile = Path.Combine(DeploymentParameters.ApplicationPath, "Microsoft.AspNet.Hosting.json"); + // Drop a hosting.json with Hosting:Environment information. + Logger.LogInformation("Creating hosting.json file with Hosting:Environment."); + var jsonFile = Path.Combine(DeploymentParameters.ApplicationPath, "hosting.json"); File.WriteAllText(jsonFile, string.Format("{ \"Hosting:Environment\":\"{0}\" }", DeploymentParameters.EnvironmentName)); } From 0b14bc135badce4d39f0c90432e3120b63212ae8 Mon Sep 17 00:00:00 2001 From: Victor Hurdugaci Date: Wed, 28 Oct 2015 12:12:37 -0700 Subject: [PATCH 430/987] Show type load exception on the startup error page --- .../Startup/StartupExceptionPage.cs | 15 +++++++++++ .../Fakes/StartupThrowTypeLoadException.cs | 25 +++++++++++++++++++ .../WebHostBuilderTests.cs | 12 +++++++++ 3 files changed, 52 insertions(+) create mode 100644 test/Microsoft.AspNet.Hosting.Tests/Fakes/StartupThrowTypeLoadException.cs diff --git a/src/Microsoft.AspNet.Hosting/Startup/StartupExceptionPage.cs b/src/Microsoft.AspNet.Hosting/Startup/StartupExceptionPage.cs index adc9656f89..8e15772526 100644 --- a/src/Microsoft.AspNet.Hosting/Startup/StartupExceptionPage.cs +++ b/src/Microsoft.AspNet.Hosting/Startup/StartupExceptionPage.cs @@ -508,6 +508,21 @@ namespace Microsoft.AspNet.Hosting.Startup private static IEnumerable FlattenAndReverseExceptionTree(Exception ex) { + // ReflectionTypeLoadException is special because the details are in + // a the LoaderExceptions property + var typeLoadException = ex as ReflectionTypeLoadException; + if (typeLoadException != null) + { + var typeLoadExceptions = new List(); + foreach (Exception loadException in typeLoadException.LoaderExceptions) + { + typeLoadExceptions.AddRange(FlattenAndReverseExceptionTree(loadException)); + } + + typeLoadExceptions.Add(ex); + return typeLoadExceptions; + } + var list = new List(); while (ex != null) { diff --git a/test/Microsoft.AspNet.Hosting.Tests/Fakes/StartupThrowTypeLoadException.cs b/test/Microsoft.AspNet.Hosting.Tests/Fakes/StartupThrowTypeLoadException.cs new file mode 100644 index 0000000000..fdfbc6a24e --- /dev/null +++ b/test/Microsoft.AspNet.Hosting.Tests/Fakes/StartupThrowTypeLoadException.cs @@ -0,0 +1,25 @@ +// 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; +using System.IO; +using System.Reflection; + +namespace Microsoft.AspNet.Hosting.Fakes +{ + public class StartupThrowTypeLoadException + { + public StartupThrowTypeLoadException() + { + // For this exception, the error page should contain details of the LoaderExceptions + throw new ReflectionTypeLoadException( + classes: new Type[] { GetType() }, + exceptions: new Exception[] { new FileNotFoundException("Message from the LoaderException") }, + message: "This should not be in the output"); + } + + public void Configure() + { + } + } +} \ No newline at end of file diff --git a/test/Microsoft.AspNet.Hosting.Tests/WebHostBuilderTests.cs b/test/Microsoft.AspNet.Hosting.Tests/WebHostBuilderTests.cs index b8aa7c6e6c..988194f0a3 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/WebHostBuilderTests.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/WebHostBuilderTests.cs @@ -74,6 +74,18 @@ namespace Microsoft.AspNet.Hosting } } + [Fact] + public async Task StartupCtorThrows_TypeLoadException() + { + var builder = CreateWebHostBuilder(); + var serverFactory = new TestServerFactory(); + var engine = builder.UseServer(serverFactory).UseStartup().Build(); + using (engine.Start()) + { + await AssertResponseContains(serverFactory.Application, "Message from the LoaderException"); + } + } + [Fact] public async Task IApplicationLifetimeRegisteredEvenWhenStartupCtorThrows_Fallback() { From 4ad38625c776dbc636394cb912b890423efd4a2c Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Wed, 28 Oct 2015 15:45:33 -0700 Subject: [PATCH 431/987] Get the current runtime path via PlatformServices.Default - This fixes an issue whith ApplicationDeployer on Mono. Instead of giving the dnx path, Process.GetCurrentProcess().MainModule.FileName would give the path to the Mono executable. --- .../Deployers/ApplicationDeployer.cs | 19 ++----------------- 1 file changed, 2 insertions(+), 17 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Testing/Deployers/ApplicationDeployer.cs b/src/Microsoft.AspNet.Server.Testing/Deployers/ApplicationDeployer.cs index a8dfd0e17a..477348f7af 100644 --- a/src/Microsoft.AspNet.Server.Testing/Deployers/ApplicationDeployer.cs +++ b/src/Microsoft.AspNet.Server.Testing/Deployers/ApplicationDeployer.cs @@ -10,6 +10,7 @@ using System.Text.RegularExpressions; using System.Threading; using Microsoft.AspNet.Testing; using Microsoft.Extensions.Logging; +using Microsoft.Extensions.PlatformAbstractions; namespace Microsoft.AspNet.Server.Testing { @@ -99,23 +100,7 @@ namespace Microsoft.AspNet.Server.Testing protected string PopulateChosenRuntimeInformation() { - string currentRuntimeBinPath = string.Empty; - if (TestPlatformHelper.IsMac && DeploymentParameters.RuntimeFlavor == RuntimeFlavor.CoreClr) - { - var path = Environment.GetEnvironmentVariable("PATH"); - currentRuntimeBinPath = path.Split(new char[] { ':' }, StringSplitOptions.RemoveEmptyEntries). - Where(c => c.Contains("dnx-coreclr-darwin") || c.Contains("dnx-mono")).FirstOrDefault(); - - if (string.IsNullOrWhiteSpace(currentRuntimeBinPath)) - { - throw new Exception("Runtime not detected on the machine."); - } - } - else - { - // ex: runtimes/dnx-coreclr-win-x64.1.0.0-rc1-15844/bin - currentRuntimeBinPath = Path.GetDirectoryName(Process.GetCurrentProcess().MainModule.FileName); - } + string currentRuntimeBinPath = PlatformServices.Default.Runtime.RuntimePath; Logger.LogInformation($"Current runtime path is : {currentRuntimeBinPath}"); var targetRuntimeName = new StringBuilder() From 21373740c7791f5384ed360f1b9df68afe376b48 Mon Sep 17 00:00:00 2001 From: Chris R Date: Fri, 30 Oct 2015 10:39:39 -0700 Subject: [PATCH 432/987] React to WebEncoders change. --- src/Microsoft.AspNet.Hosting/Startup/StartupExceptionPage.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Microsoft.AspNet.Hosting/Startup/StartupExceptionPage.cs b/src/Microsoft.AspNet.Hosting/Startup/StartupExceptionPage.cs index 8e15772526..1ffcf7a001 100644 --- a/src/Microsoft.AspNet.Hosting/Startup/StartupExceptionPage.cs +++ b/src/Microsoft.AspNet.Hosting/Startup/StartupExceptionPage.cs @@ -11,9 +11,9 @@ using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.ExceptionServices; using System.Text; +using System.Text.Encodings.Web; using Microsoft.Dnx.Compilation; using Microsoft.Extensions.PlatformAbstractions; -using Microsoft.Extensions.WebEncoders; namespace Microsoft.AspNet.Hosting.Startup { @@ -411,7 +411,7 @@ namespace Microsoft.AspNet.Hosting.Startup return string.Join("
" + Environment.NewLine, input.Split(new[] { "\r\n" }, StringSplitOptions.None) .SelectMany(s => s.Split(new[] { '\r', '\n' }, StringSplitOptions.None)) - .Select(HtmlEncoder.Default.HtmlEncode)); + .Select(HtmlEncoder.Default.Encode)); } private static void WriteException(Exception ex, StringBuilder builder, ref bool wasFailingCallSiteSourceWritten) From 3933a1904e68e338b0f69c8cb6be5971cb4e29a4 Mon Sep 17 00:00:00 2001 From: John Luo Date: Tue, 20 Oct 2015 15:43:01 -0700 Subject: [PATCH 433/987] Refactoring IServerFactory #395 --- .../IServer.cs | 26 +++++++ .../IServerFactory.cs | 14 ++-- .../project.json | 4 +- .../Internal/HostingEngine.cs | 36 +++++----- .../WebHostBuilder.cs | 22 +++++- .../ClientHandler.cs | 30 ++++++-- src/Microsoft.AspNet.TestHost/TestServer.cs | 39 +++++----- .../WebSocketClient.cs | 28 +++++--- .../HostingEngineTests.cs | 64 +++++++++++++---- .../WebHostBuilderTests.cs | 71 +++++++++---------- .../ClientHandlerTests.cs | 57 +++++++-------- 11 files changed, 240 insertions(+), 151 deletions(-) create mode 100644 src/Microsoft.AspNet.Hosting.Server.Abstractions/IServer.cs diff --git a/src/Microsoft.AspNet.Hosting.Server.Abstractions/IServer.cs b/src/Microsoft.AspNet.Hosting.Server.Abstractions/IServer.cs new file mode 100644 index 0000000000..c6909990d0 --- /dev/null +++ b/src/Microsoft.AspNet.Hosting.Server.Abstractions/IServer.cs @@ -0,0 +1,26 @@ +// 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; +using Microsoft.AspNet.Http; +using Microsoft.AspNet.Http.Features; + +namespace Microsoft.AspNet.Hosting.Server +{ + /// + /// Represents a server. + /// + public interface IServer : IDisposable + { + /// + /// A collection of HTTP features of the server. + /// + IFeatureCollection Features { get; } + + /// + /// Start the server with the given function that processes an HTTP request. + /// + /// A function that processes an HTTP request. + void Start(RequestDelegate requestDelegate); + } +} diff --git a/src/Microsoft.AspNet.Hosting.Server.Abstractions/IServerFactory.cs b/src/Microsoft.AspNet.Hosting.Server.Abstractions/IServerFactory.cs index c685ff8570..163d39f1c0 100644 --- a/src/Microsoft.AspNet.Hosting.Server.Abstractions/IServerFactory.cs +++ b/src/Microsoft.AspNet.Hosting.Server.Abstractions/IServerFactory.cs @@ -1,16 +1,20 @@ // 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; -using System.Threading.Tasks; -using Microsoft.AspNet.Http.Features; using Microsoft.Extensions.Configuration; namespace Microsoft.AspNet.Hosting.Server { + /// + /// Represents a factory for creating servers. + /// public interface IServerFactory { - IFeatureCollection Initialize(IConfiguration configuration); - IDisposable Start(IFeatureCollection serverFeatures, Func application); + /// + /// Creates based on the given configuration. + /// + /// An instance of . + /// The created server. + IServer CreateServer(IConfiguration configuration); } } diff --git a/src/Microsoft.AspNet.Hosting.Server.Abstractions/project.json b/src/Microsoft.AspNet.Hosting.Server.Abstractions/project.json index a3ccdf94bb..315af28c3f 100644 --- a/src/Microsoft.AspNet.Hosting.Server.Abstractions/project.json +++ b/src/Microsoft.AspNet.Hosting.Server.Abstractions/project.json @@ -6,11 +6,11 @@ "url": "git://github.com/aspnet/hosting" }, "dependencies": { - "Microsoft.AspNet.Http.Features": "1.0.0-*", + "Microsoft.AspNet.Http.Abstractions": "1.0.0-*", "Microsoft.Extensions.Configuration.Abstractions": "1.0.0-*" }, "frameworks": { "net451": {}, "dotnet5.4": {} } -} \ No newline at end of file +} diff --git a/src/Microsoft.AspNet.Hosting/Internal/HostingEngine.cs b/src/Microsoft.AspNet.Hosting/Internal/HostingEngine.cs index 55e2cd589c..c504e6d0e3 100644 --- a/src/Microsoft.AspNet.Hosting/Internal/HostingEngine.cs +++ b/src/Microsoft.AspNet.Hosting/Internal/HostingEngine.cs @@ -42,7 +42,7 @@ namespace Microsoft.AspNet.Hosting.Internal // Only one of these should be set internal IServerFactory ServerFactory { get; set; } internal string ServerFactoryLocation { get; set; } - private IFeatureCollection _serverFeatures; + internal IServer Server { get; set; } public HostingEngine( IServiceCollection appServices, @@ -87,15 +87,13 @@ namespace Microsoft.AspNet.Hosting.Internal var application = BuildApplication(); var logger = _applicationServices.GetRequiredService>(); - var contextFactory = _applicationServices.GetRequiredService(); var diagnosticSource = _applicationServices.GetRequiredService(); logger.Starting(); - var server = ServerFactory.Start(_serverFeatures, - async features => + Server.Start( + async httpContext => { - var httpContext = contextFactory.Create(features); httpContext.ApplicationServices = _applicationServices; if (diagnosticSource.IsEnabled("Microsoft.AspNet.Hosting.BeginRequest")) @@ -135,11 +133,11 @@ namespace Microsoft.AspNet.Hosting.Internal _applicationLifetime.NotifyStarted(); logger.Started(); - return new Application(ApplicationServices, _serverFeatures, new Disposable(() => + return new Application(ApplicationServices, Server.Features, new Disposable(() => { logger.Shutdown(); _applicationLifetime.StopApplication(); - server.Dispose(); + Server.Dispose(); _applicationLifetime.NotifyStopped(); (_applicationServices as IDisposable)?.Dispose(); })); @@ -191,7 +189,7 @@ namespace Microsoft.AspNet.Hosting.Internal EnsureServer(); var builderFactory = _applicationServices.GetRequiredService(); - var builder = builderFactory.CreateBuilder(_serverFeatures); + var builder = builderFactory.CreateBuilder(Server.Features); builder.ApplicationServices = _applicationServices; var startupFilters = _applicationServices.GetService>(); @@ -246,21 +244,21 @@ namespace Microsoft.AspNet.Hosting.Internal private void EnsureServer() { - if (ServerFactory == null) + if (Server == null) { - // Blow up if we don't have a server set at this point - if (ServerFactoryLocation == null) + if (ServerFactory == null) { - throw new InvalidOperationException("IHostingBuilder.UseServer() is required for " + nameof(Start) + "()"); + // Blow up if we don't have a server set at this point + if (ServerFactoryLocation == null) + { + throw new InvalidOperationException("IHostingBuilder.UseServer() is required for " + nameof(Start) + "()"); + } + + ServerFactory = _applicationServices.GetRequiredService().LoadServerFactory(ServerFactoryLocation); } - ServerFactory = _applicationServices.GetRequiredService().LoadServerFactory(ServerFactoryLocation); - } - - if (_serverFeatures == null) - { - _serverFeatures = ServerFactory.Initialize(_config); - var addresses = _serverFeatures?.Get()?.Addresses; + Server = ServerFactory.CreateServer(_config); + var addresses = Server.Features?.Get()?.Addresses; if (addresses != null && !addresses.IsReadOnly) { var port = _config[ServerPort]; diff --git a/src/Microsoft.AspNet.Hosting/WebHostBuilder.cs b/src/Microsoft.AspNet.Hosting/WebHostBuilder.cs index 8d5c5648e6..ddff824f21 100644 --- a/src/Microsoft.AspNet.Hosting/WebHostBuilder.cs +++ b/src/Microsoft.AspNet.Hosting/WebHostBuilder.cs @@ -42,6 +42,7 @@ namespace Microsoft.AspNet.Hosting // Only one of these should be set private string _serverFactoryLocation; private IServerFactory _serverFactory; + private IServer _server; public WebHostBuilder() : this(config: new ConfigurationBuilder().Build()) @@ -133,6 +134,7 @@ namespace Microsoft.AspNet.Hosting var engine = new HostingEngine(hostingServices, startupLoader, _config, _captureStartupErrors); // Only one of these should be set, but they are used in priority + engine.Server = _server; engine.ServerFactory = _serverFactory; engine.ServerFactoryLocation = _config[ServerKey] ?? _config[OldServerKey] ?? _serverFactoryLocation; @@ -161,7 +163,18 @@ namespace Microsoft.AspNet.Hosting return this; } - public WebHostBuilder UseServer(string assemblyName) + public WebHostBuilder UseServer(IServer server) + { + if (server == null) + { + throw new ArgumentNullException(nameof(server)); + } + + _server = server; + return this; + } + + public WebHostBuilder UseServerFactory(string assemblyName) { if (assemblyName == null) { @@ -172,8 +185,13 @@ namespace Microsoft.AspNet.Hosting return this; } - public WebHostBuilder UseServer(IServerFactory factory) + public WebHostBuilder UseServerFactory(IServerFactory factory) { + if (factory == null) + { + throw new ArgumentNullException(nameof(factory)); + } + _serverFactory = factory; return this; } diff --git a/src/Microsoft.AspNet.TestHost/ClientHandler.cs b/src/Microsoft.AspNet.TestHost/ClientHandler.cs index efcb5dc06e..78e3463bc6 100644 --- a/src/Microsoft.AspNet.TestHost/ClientHandler.cs +++ b/src/Microsoft.AspNet.TestHost/ClientHandler.cs @@ -23,21 +23,27 @@ namespace Microsoft.AspNet.TestHost ///
public class ClientHandler : HttpMessageHandler { - private readonly Func _next; + private readonly RequestDelegate _next; private readonly PathString _pathBase; + private readonly IHttpContextFactory _factory; /// /// Create a new handler. /// /// The pipeline entry point. - public ClientHandler(Func next, PathString pathBase) + public ClientHandler(RequestDelegate next, PathString pathBase, IHttpContextFactory httpContextFactory) { if (next == null) { throw new ArgumentNullException(nameof(next)); } + if (httpContextFactory == null) + { + throw new ArgumentNullException(nameof(httpContextFactory)); + } _next = next; + _factory = httpContextFactory; // PathString.StartsWithSegments that we use below requires the base path to not end in a slash. if (pathBase.HasValue && pathBase.Value.EndsWith("/")) @@ -63,7 +69,7 @@ namespace Microsoft.AspNet.TestHost throw new ArgumentNullException(nameof(request)); } - var state = new RequestState(request, _pathBase); + var state = new RequestState(request, _pathBase, _factory); var requestContent = request.Content ?? new StreamContent(Stream.Null); var body = await requestContent.ReadAsStreamAsync(); if (body.CanSeek) @@ -79,7 +85,7 @@ namespace Microsoft.AspNet.TestHost { try { - await _next(state.HttpContext.Features); + await _next(state.HttpContext); state.CompleteResponse(); } catch (Exception ex) @@ -88,6 +94,7 @@ namespace Microsoft.AspNet.TestHost } finally { + state.ServerCleanup(); registration.Dispose(); } }); @@ -102,14 +109,16 @@ namespace Microsoft.AspNet.TestHost private ResponseStream _responseStream; private ResponseFeature _responseFeature; private CancellationTokenSource _requestAbortedSource; + private IHttpContextFactory _factory; private bool _pipelineFinished; - internal RequestState(HttpRequestMessage request, PathString pathBase) + internal RequestState(HttpRequestMessage request, PathString pathBase, IHttpContextFactory factory) { _request = request; _responseTcs = new TaskCompletionSource(); _requestAbortedSource = new CancellationTokenSource(); _pipelineFinished = false; + _factory = factory; if (request.RequestUri.IsDefaultPort) { @@ -120,7 +129,8 @@ namespace Microsoft.AspNet.TestHost request.Headers.Host = request.RequestUri.GetComponents(UriComponents.HostAndPort, UriFormat.UriEscaped); } - HttpContext = new DefaultHttpContext(); + HttpContext = _factory.Create(new FeatureCollection()); + HttpContext.Features.Set(new RequestFeature()); _responseFeature = new ResponseFeature(); HttpContext.Features.Set(_responseFeature); @@ -228,6 +238,14 @@ namespace Microsoft.AspNet.TestHost _responseStream.Abort(exception); _responseTcs.TrySetException(exception); } + + internal void ServerCleanup() + { + if (HttpContext != null) + { + _factory.Dispose(HttpContext); + } + } } } } diff --git a/src/Microsoft.AspNet.TestHost/TestServer.cs b/src/Microsoft.AspNet.TestHost/TestServer.cs index 176431060c..cd354c3eba 100644 --- a/src/Microsoft.AspNet.TestHost/TestServer.cs +++ b/src/Microsoft.AspNet.TestHost/TestServer.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// 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; @@ -14,22 +14,26 @@ using Microsoft.Extensions.DependencyInjection; namespace Microsoft.AspNet.TestHost { - public class TestServer : IServerFactory, IDisposable + public class TestServer : IServer { private const string DefaultEnvironmentName = "Development"; private const string ServerName = nameof(TestServer); - private static readonly IFeatureCollection ServerInfo = new FeatureCollection(); - private Func _appDelegate; + private RequestDelegate _appDelegate; private IDisposable _appInstance; private bool _disposed = false; + private IHttpContextFactory _httpContextFactory; public TestServer(WebHostBuilder builder) { - _appInstance = builder.UseServer(this).Build().Start(); + var hostingEngine = builder.UseServer(this).Build(); + _httpContextFactory = hostingEngine.ApplicationServices.GetService(); + _appInstance = hostingEngine.Start(); } public Uri BaseAddress { get; set; } = new Uri("http://localhost/"); + IFeatureCollection IServer.Features { get; } + public static TestServer Create() { return Create(config: null, configureApp: null, configureServices: null); @@ -95,7 +99,7 @@ namespace Microsoft.AspNet.TestHost public HttpMessageHandler CreateHandler() { var pathBase = BaseAddress == null ? PathString.Empty : PathString.FromUriComponent(BaseAddress); - return new ClientHandler(Invoke, pathBase); + return new ClientHandler(Invoke, pathBase, _httpContextFactory); } public HttpClient CreateClient() @@ -106,7 +110,7 @@ namespace Microsoft.AspNet.TestHost public WebSocketClient CreateWebSocketClient() { var pathBase = BaseAddress == null ? PathString.Empty : PathString.FromUriComponent(BaseAddress); - return new WebSocketClient(Invoke, pathBase); + return new WebSocketClient(Invoke, pathBase, _httpContextFactory); } /// @@ -119,25 +123,13 @@ namespace Microsoft.AspNet.TestHost return new RequestBuilder(this, path); } - public IFeatureCollection Initialize(IConfiguration configuration) - { - return ServerInfo; - } - - public IDisposable Start(IFeatureCollection serverInformation, Func application) - { - _appDelegate = application; - - return this; - } - - public Task Invoke(IFeatureCollection featureCollection) + public Task Invoke(HttpContext context) { if (_disposed) { throw new ObjectDisposedException(GetType().FullName); } - return _appDelegate(featureCollection); + return _appDelegate(context); } public void Dispose() @@ -145,5 +137,10 @@ namespace Microsoft.AspNet.TestHost _disposed = true; _appInstance.Dispose(); } + + void IServer.Start(RequestDelegate requestDelegate) + { + _appDelegate = requestDelegate; + } } } \ No newline at end of file diff --git a/src/Microsoft.AspNet.TestHost/WebSocketClient.cs b/src/Microsoft.AspNet.TestHost/WebSocketClient.cs index 9946d5e4bd..320f43afe8 100644 --- a/src/Microsoft.AspNet.TestHost/WebSocketClient.cs +++ b/src/Microsoft.AspNet.TestHost/WebSocketClient.cs @@ -8,25 +8,31 @@ using System.Net.WebSockets; using System.Security.Cryptography; using System.Threading; using System.Threading.Tasks; -using Microsoft.AspNet.Http.Features; using Microsoft.AspNet.Http; +using Microsoft.AspNet.Http.Features; using Microsoft.AspNet.Http.Internal; namespace Microsoft.AspNet.TestHost { public class WebSocketClient { - private readonly Func _next; + private readonly RequestDelegate _next; private readonly PathString _pathBase; + private readonly IHttpContextFactory _httpContextFactory; - internal WebSocketClient(Func next, PathString pathBase) + internal WebSocketClient(RequestDelegate next, PathString pathBase, IHttpContextFactory httpContextFactory) { if (next == null) { throw new ArgumentNullException(nameof(next)); } + if (httpContextFactory == null) + { + throw new ArgumentNullException(nameof(httpContextFactory)); + } _next = next; + _httpContextFactory = httpContextFactory; // PathString.StartsWithSegments that we use below requires the base path to not end in a slash. if (pathBase.HasValue && pathBase.Value.EndsWith("/")) @@ -52,7 +58,7 @@ namespace Microsoft.AspNet.TestHost public async Task ConnectAsync(Uri uri, CancellationToken cancellationToken) { - var state = new RequestState(uri, _pathBase, cancellationToken); + var state = new RequestState(uri, _pathBase, cancellationToken, _httpContextFactory); if (ConfigureRequest != null) { @@ -64,7 +70,7 @@ namespace Microsoft.AspNet.TestHost { try { - await _next(state.FeatureCollection); + await _next(state.HttpContext); state.PipelineComplete(); } catch (Exception ex) @@ -84,18 +90,18 @@ namespace Microsoft.AspNet.TestHost { private TaskCompletionSource _clientWebSocketTcs; private WebSocket _serverWebSocket; + private IHttpContextFactory _factory; - public IFeatureCollection FeatureCollection { get; private set; } public HttpContext HttpContext { get; private set; } public Task WebSocketTask { get { return _clientWebSocketTcs.Task; } } - public RequestState(Uri uri, PathString pathBase, CancellationToken cancellationToken) + public RequestState(Uri uri, PathString pathBase, CancellationToken cancellationToken, IHttpContextFactory factory) { + _factory = factory; _clientWebSocketTcs = new TaskCompletionSource(); // HttpContext - FeatureCollection = new FeatureCollection(); - HttpContext = new DefaultHttpContext(FeatureCollection); + HttpContext = _factory.Create(new FeatureCollection()); // Request HttpContext.Features.Set(new RequestFeature()); @@ -147,6 +153,10 @@ namespace Microsoft.AspNet.TestHost public void Dispose() { + if (HttpContext != null) + { + _factory.Dispose(HttpContext); + } if (_serverWebSocket != null) { _serverWebSocket.Dispose(); diff --git a/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs b/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs index 928cd5bb35..0e0655ecac 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs @@ -14,6 +14,7 @@ using Microsoft.AspNet.Hosting.Server; using Microsoft.AspNet.Hosting.Startup; using Microsoft.AspNet.Http; using Microsoft.AspNet.Http.Features; +using Microsoft.AspNet.Http.Internal; using Microsoft.AspNet.Server.Features; using Microsoft.AspNet.Testing.xunit; using Microsoft.Extensions.Configuration; @@ -26,10 +27,33 @@ using Xunit; namespace Microsoft.AspNet.Hosting { - public class HostingEngineTests : IServerFactory + public class HostingEngineTests : IServerFactory, IServer { private readonly IList _startInstances = new List(); private IFeatureCollection _featuresSupportedByThisHost = NewFeatureCollection(); + private IFeatureCollection _instanceFeaturesSupportedByThisHost; + + public IFeatureCollection Features { + get + { + var features = new FeatureCollection(); + + foreach (var feature in _featuresSupportedByThisHost) + { + features[feature.Key] = feature.Value; + } + + if (_instanceFeaturesSupportedByThisHost != null) + { + foreach (var feature in _instanceFeaturesSupportedByThisHost) + { + features[feature.Key] = feature.Value; + } + } + + return features; + } + } static IFeatureCollection NewFeatureCollection() { @@ -431,26 +455,36 @@ namespace Microsoft.AspNet.Hosting return new WebHostBuilder(config ?? new ConfigurationBuilder().Build()); } - public IFeatureCollection Initialize(IConfiguration configuration) + public void Start(RequestDelegate requestDelegate) { - var features = new FeatureCollection(); - features.Set(new ServerAddressesFeature()); - return features; - } - - public IDisposable Start(IFeatureCollection serverFeatures, Func application) - { - var startInstance = new StartInstance(application); + var startInstance = new StartInstance(requestDelegate); _startInstances.Add(startInstance); - application(_featuresSupportedByThisHost); - return startInstance; + requestDelegate(new DefaultHttpContext(Features)); } - public class StartInstance : IDisposable + public void Dispose() { - private readonly Func _application; + if (_startInstances != null) + { + foreach (var startInstance in _startInstances) + { + startInstance.Dispose(); + } + } + } - public StartInstance(Func application) + public IServer CreateServer(IConfiguration configuration) + { + _instanceFeaturesSupportedByThisHost = new FeatureCollection(); + _instanceFeaturesSupportedByThisHost.Set(new ServerAddressesFeature()); + return this; + } + + private class StartInstance : IDisposable + { + private readonly RequestDelegate _application; + + public StartInstance(RequestDelegate application) { _application = application; } diff --git a/test/Microsoft.AspNet.Hosting.Tests/WebHostBuilderTests.cs b/test/Microsoft.AspNet.Hosting.Tests/WebHostBuilderTests.cs index 988194f0a3..3ab61daf96 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/WebHostBuilderTests.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/WebHostBuilderTests.cs @@ -1,13 +1,13 @@ // 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; using System.Collections.Generic; using System.IO; using System.Threading.Tasks; using Microsoft.AspNet.Hosting.Fakes; using Microsoft.AspNet.Hosting.Internal; using Microsoft.AspNet.Hosting.Server; +using Microsoft.AspNet.Http; using Microsoft.AspNet.Http.Features; using Microsoft.AspNet.Http.Internal; using Microsoft.Extensions.Configuration; @@ -42,11 +42,11 @@ namespace Microsoft.AspNet.Hosting public async Task StartupMissing_Fallback() { var builder = CreateWebHostBuilder(); - var serverFactory = new TestServerFactory(); - var engine = builder.UseServer(serverFactory).UseStartup("MissingStartupAssembly").Build(); + var server = new TestServer(); + var engine = builder.UseServer(server).UseStartup("MissingStartupAssembly").Build(); using (engine.Start()) { - await AssertResponseContains(serverFactory.Application, "MissingStartupAssembly"); + await AssertResponseContains(server.RequestDelegate, "MissingStartupAssembly"); } } @@ -54,11 +54,11 @@ namespace Microsoft.AspNet.Hosting public async Task StartupStaticCtorThrows_Fallback() { var builder = CreateWebHostBuilder(); - var serverFactory = new TestServerFactory(); - var engine = builder.UseServer(serverFactory).UseStartup().Build(); + var server = new TestServer(); + var engine = builder.UseServer(server).UseStartup().Build(); using (engine.Start()) { - await AssertResponseContains(serverFactory.Application, "Exception from static constructor"); + await AssertResponseContains(server.RequestDelegate, "Exception from static constructor"); } } @@ -66,11 +66,11 @@ namespace Microsoft.AspNet.Hosting public async Task StartupCtorThrows_Fallback() { var builder = CreateWebHostBuilder(); - var serverFactory = new TestServerFactory(); - var engine = builder.UseServer(serverFactory).UseStartup().Build(); + var server = new TestServer(); + var engine = builder.UseServer(server).UseStartup().Build(); using (engine.Start()) { - await AssertResponseContains(serverFactory.Application, "Exception from constructor"); + await AssertResponseContains(server.RequestDelegate, "Exception from constructor"); } } @@ -78,11 +78,11 @@ namespace Microsoft.AspNet.Hosting public async Task StartupCtorThrows_TypeLoadException() { var builder = CreateWebHostBuilder(); - var serverFactory = new TestServerFactory(); - var engine = builder.UseServer(serverFactory).UseStartup().Build(); + var server = new TestServer(); + var engine = builder.UseServer(server).UseStartup().Build(); using (engine.Start()) { - await AssertResponseContains(serverFactory.Application, "Message from the LoaderException"); + await AssertResponseContains(server.RequestDelegate, "Message from the LoaderException"); } } @@ -90,13 +90,13 @@ namespace Microsoft.AspNet.Hosting public async Task IApplicationLifetimeRegisteredEvenWhenStartupCtorThrows_Fallback() { var builder = CreateWebHostBuilder(); - var serverFactory = new TestServerFactory(); - var engine = builder.UseServer(serverFactory).UseStartup().Build(); + var server = new TestServer(); + var engine = builder.UseServer(server).UseStartup().Build(); using (engine.Start()) { - var service = engine.ApplicationServices.GetService(); + var service = engine.ApplicationServices.GetServices(); Assert.NotNull(service); - await AssertResponseContains(serverFactory.Application, "Exception from constructor"); + await AssertResponseContains(server.RequestDelegate, "Exception from constructor"); } } @@ -104,11 +104,11 @@ namespace Microsoft.AspNet.Hosting public async Task StartupConfigureServicesThrows_Fallback() { var builder = CreateWebHostBuilder(); - var serverFactory = new TestServerFactory(); - var engine = builder.UseServer(serverFactory).UseStartup().Build(); + var server = new TestServer(); + var engine = builder.UseServer(server).UseStartup().Build(); using (engine.Start()) { - await AssertResponseContains(serverFactory.Application, "Exception from ConfigureServices"); + await AssertResponseContains(server.RequestDelegate, "Exception from ConfigureServices"); } } @@ -116,11 +116,11 @@ namespace Microsoft.AspNet.Hosting public async Task StartupConfigureThrows_Fallback() { var builder = CreateWebHostBuilder(); - var serverFactory = new TestServerFactory(); - var engine = builder.UseServer(serverFactory).UseStartup().Build(); + var server = new TestServer(); + var engine = builder.UseServer(server).UseStartup().Build(); using (engine.Start()) { - await AssertResponseContains(serverFactory.Application, "Exception from Configure"); + await AssertResponseContains(server.RequestDelegate, "Exception from Configure"); } } @@ -137,36 +137,29 @@ namespace Microsoft.AspNet.Hosting return new WebHostBuilder(config, captureStartupErrors: true); } - private async Task AssertResponseContains(Func app, string expectedText) + private async Task AssertResponseContains(RequestDelegate app, string expectedText) { var httpContext = new DefaultHttpContext(); httpContext.Response.Body = new MemoryStream(); - await app(httpContext.Features); + await app(httpContext); httpContext.Response.Body.Seek(0, SeekOrigin.Begin); var bodyText = new StreamReader(httpContext.Response.Body).ReadToEnd(); Assert.Contains(expectedText, bodyText); } - private class TestServerFactory : IServerFactory + private class TestServer : IServer { - public Func Application { get; set; } + IFeatureCollection IServer.Features { get; } + public RequestDelegate RequestDelegate { get; private set; } - public IFeatureCollection Initialize(IConfiguration configuration) + public void Dispose() { - return new FeatureCollection(); + } - public IDisposable Start(IFeatureCollection serverFeatures, Func application) + public void Start(RequestDelegate requestDelegate) { - Application = application; - return new Disposable(); - } - - private class Disposable : IDisposable - { - public void Dispose() - { - } + RequestDelegate = requestDelegate; } } } diff --git a/test/Microsoft.AspNet.TestHost.Tests/ClientHandlerTests.cs b/test/Microsoft.AspNet.TestHost.Tests/ClientHandlerTests.cs index ec7976d685..adacdd9d8e 100644 --- a/test/Microsoft.AspNet.TestHost.Tests/ClientHandlerTests.cs +++ b/test/Microsoft.AspNet.TestHost.Tests/ClientHandlerTests.cs @@ -17,13 +17,13 @@ namespace Microsoft.AspNet.TestHost { public class ClientHandlerTests { + private IHttpContextFactory _httpContextFactory = new HttpContextFactory(new HttpContextAccessor()); + [Fact] public Task ExpectedKeysAreAvailable() { - var handler = new ClientHandler(env => + var handler = new ClientHandler(context => { - var context = new DefaultHttpContext((IFeatureCollection)env); - // TODO: Assert.True(context.RequestAborted.CanBeCanceled); Assert.Equal("HTTP/1.1", context.Request.Protocol); Assert.Equal("GET", context.Request.Method); @@ -40,7 +40,7 @@ namespace Microsoft.AspNet.TestHost Assert.Equal("example.com", context.Request.Host.Value); return Task.FromResult(0); - }, new PathString("/A/Path/")); + }, new PathString("/A/Path/"), _httpContextFactory); var httpClient = new HttpClient(handler); return httpClient.GetAsync("https://example.com/A/Path/and/file.txt?and=query"); } @@ -48,14 +48,13 @@ namespace Microsoft.AspNet.TestHost [Fact] public Task SingleSlashNotMovedToPathBase() { - var handler = new ClientHandler(env => + var handler = new ClientHandler(context => { - var context = new DefaultHttpContext((IFeatureCollection)env); Assert.Equal("", context.Request.PathBase.Value); Assert.Equal("/", context.Request.Path.Value); return Task.FromResult(0); - }, new PathString("")); + }, new PathString(""), _httpContextFactory); var httpClient = new HttpClient(handler); return httpClient.GetAsync("https://example.com/"); } @@ -64,15 +63,14 @@ namespace Microsoft.AspNet.TestHost public async Task ResubmitRequestWorks() { int requestCount = 1; - var handler = new ClientHandler(env => + var handler = new ClientHandler(context => { - var context = new DefaultHttpContext((IFeatureCollection)env); int read = context.Request.Body.Read(new byte[100], 0, 100); Assert.Equal(11, read); context.Response.Headers["TestHeader"] = "TestValue:" + requestCount++; return Task.FromResult(0); - }, PathString.Empty); + }, PathString.Empty, _httpContextFactory); HttpMessageInvoker invoker = new HttpMessageInvoker(handler); HttpRequestMessage message = new HttpRequestMessage(HttpMethod.Post, "https://example.com/"); @@ -88,13 +86,11 @@ namespace Microsoft.AspNet.TestHost [Fact] public async Task MiddlewareOnlySetsHeaders() { - var handler = new ClientHandler(env => + var handler = new ClientHandler(context => { - var context = new DefaultHttpContext((IFeatureCollection)env); - context.Response.Headers["TestHeader"] = "TestValue"; return Task.FromResult(0); - }, PathString.Empty); + }, PathString.Empty, _httpContextFactory); var httpClient = new HttpClient(handler); HttpResponseMessage response = await httpClient.GetAsync("https://example.com/"); Assert.Equal("TestValue", response.Headers.GetValues("TestHeader").First()); @@ -104,11 +100,11 @@ namespace Microsoft.AspNet.TestHost public async Task BlockingMiddlewareShouldNotBlockClient() { ManualResetEvent block = new ManualResetEvent(false); - var handler = new ClientHandler(env => + var handler = new ClientHandler(context => { block.WaitOne(); return Task.FromResult(0); - }, PathString.Empty); + }, PathString.Empty, _httpContextFactory); var httpClient = new HttpClient(handler); Task task = httpClient.GetAsync("https://example.com/"); Assert.False(task.IsCompleted); @@ -121,14 +117,13 @@ namespace Microsoft.AspNet.TestHost public async Task HeadersAvailableBeforeBodyFinished() { ManualResetEvent block = new ManualResetEvent(false); - var handler = new ClientHandler(async env => + var handler = new ClientHandler(async context => { - var context = new DefaultHttpContext((IFeatureCollection)env); context.Response.Headers["TestHeader"] = "TestValue"; await context.Response.WriteAsync("BodyStarted,"); block.WaitOne(); await context.Response.WriteAsync("BodyFinished"); - }, PathString.Empty); + }, PathString.Empty, _httpContextFactory); var httpClient = new HttpClient(handler); HttpResponseMessage response = await httpClient.GetAsync("https://example.com/", HttpCompletionOption.ResponseHeadersRead); @@ -141,14 +136,13 @@ namespace Microsoft.AspNet.TestHost public async Task FlushSendsHeaders() { ManualResetEvent block = new ManualResetEvent(false); - var handler = new ClientHandler(async env => + var handler = new ClientHandler(async context => { - var context = new DefaultHttpContext((IFeatureCollection)env); context.Response.Headers["TestHeader"] = "TestValue"; context.Response.Body.Flush(); block.WaitOne(); await context.Response.WriteAsync("BodyFinished"); - }, PathString.Empty); + }, PathString.Empty, _httpContextFactory); var httpClient = new HttpClient(handler); HttpResponseMessage response = await httpClient.GetAsync("https://example.com/", HttpCompletionOption.ResponseHeadersRead); @@ -161,14 +155,13 @@ namespace Microsoft.AspNet.TestHost public async Task ClientDisposalCloses() { ManualResetEvent block = new ManualResetEvent(false); - var handler = new ClientHandler(env => + var handler = new ClientHandler(context => { - var context = new DefaultHttpContext((IFeatureCollection)env); context.Response.Headers["TestHeader"] = "TestValue"; context.Response.Body.Flush(); block.WaitOne(); return Task.FromResult(0); - }, PathString.Empty); + }, PathString.Empty, _httpContextFactory); var httpClient = new HttpClient(handler); HttpResponseMessage response = await httpClient.GetAsync("https://example.com/", HttpCompletionOption.ResponseHeadersRead); @@ -187,14 +180,13 @@ namespace Microsoft.AspNet.TestHost public async Task ClientCancellationAborts() { ManualResetEvent block = new ManualResetEvent(false); - var handler = new ClientHandler(env => + var handler = new ClientHandler(context => { - var context = new DefaultHttpContext((IFeatureCollection)env); context.Response.Headers["TestHeader"] = "TestValue"; context.Response.Body.Flush(); block.WaitOne(); return Task.FromResult(0); - }, PathString.Empty); + }, PathString.Empty, _httpContextFactory); var httpClient = new HttpClient(handler); HttpResponseMessage response = await httpClient.GetAsync("https://example.com/", HttpCompletionOption.ResponseHeadersRead); @@ -213,10 +205,10 @@ namespace Microsoft.AspNet.TestHost [Fact] public Task ExceptionBeforeFirstWriteIsReported() { - var handler = new ClientHandler(env => + var handler = new ClientHandler(context => { throw new InvalidOperationException("Test Exception"); - }, PathString.Empty); + }, PathString.Empty, _httpContextFactory); var httpClient = new HttpClient(handler); return Assert.ThrowsAsync(() => httpClient.GetAsync("https://example.com/", HttpCompletionOption.ResponseHeadersRead)); @@ -227,14 +219,13 @@ namespace Microsoft.AspNet.TestHost public async Task ExceptionAfterFirstWriteIsReported() { ManualResetEvent block = new ManualResetEvent(false); - var handler = new ClientHandler(async env => + var handler = new ClientHandler(async context => { - var context = new DefaultHttpContext((IFeatureCollection)env); context.Response.Headers["TestHeader"] = "TestValue"; await context.Response.WriteAsync("BodyStarted"); block.WaitOne(); throw new InvalidOperationException("Test Exception"); - }, PathString.Empty); + }, PathString.Empty, _httpContextFactory); var httpClient = new HttpClient(handler); HttpResponseMessage response = await httpClient.GetAsync("https://example.com/", HttpCompletionOption.ResponseHeadersRead); From 2ed9ae8586c1c33d6e5927ef20347dc33897f705 Mon Sep 17 00:00:00 2001 From: Pavel Krymets Date: Mon, 2 Nov 2015 15:24:06 -0800 Subject: [PATCH 434/987] Rename Microsoft.Dnx.Compilation.Abstractions to Microsoft.Extensions.Compilation.Abstractions --- src/Microsoft.AspNet.Hosting/project.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Microsoft.AspNet.Hosting/project.json b/src/Microsoft.AspNet.Hosting/project.json index edd34b5469..72350a67ae 100644 --- a/src/Microsoft.AspNet.Hosting/project.json +++ b/src/Microsoft.AspNet.Hosting/project.json @@ -20,7 +20,7 @@ "Microsoft.Extensions.Configuration.Json": "1.0.0-*", "Microsoft.Extensions.DependencyInjection": "1.0.0-*", "Microsoft.Extensions.Logging": "1.0.0-*", - "Microsoft.Dnx.Compilation.Abstractions": "1.0.0-*", + "Microsoft.Extensions.Compilation.Abstractions": "1.0.0-*", "Microsoft.Extensions.PlatformAbstractions": "1.0.0-*", "System.Diagnostics.DiagnosticSource": "4.0.0-beta-*" }, From 201e3d325a24f8e7d08af41b7637db785023fe54 Mon Sep 17 00:00:00 2001 From: Cesar Blum Silveira Date: Mon, 2 Nov 2015 15:50:03 -0800 Subject: [PATCH 435/987] Strong name everything. --- .../project.json | 4 ++++ .../project.json | 4 ++++ .../Properties/AssemblyInfo.cs | 2 +- src/Microsoft.AspNet.Hosting/project.json | 3 ++- src/Microsoft.AspNet.Server.Testing/project.json | 4 ++++ test/Microsoft.AspNet.Hosting.Tests/project.json | 4 ++++ tools/Key.snk | Bin 0 -> 596 bytes 7 files changed, 19 insertions(+), 2 deletions(-) create mode 100644 tools/Key.snk diff --git a/src/Microsoft.AspNet.Hosting.Abstractions/project.json b/src/Microsoft.AspNet.Hosting.Abstractions/project.json index 0bc206ff72..d8764590da 100644 --- a/src/Microsoft.AspNet.Hosting.Abstractions/project.json +++ b/src/Microsoft.AspNet.Hosting.Abstractions/project.json @@ -1,5 +1,9 @@ { "version": "1.0.0-*", + "compilationOptions": { + "warningsAsErrors": true, + "keyFile": "../../tools/Key.snk" + }, "description": "ASP.NET 5 Hosting abstractions.", "repository": { "type": "git", diff --git a/src/Microsoft.AspNet.Hosting.Server.Abstractions/project.json b/src/Microsoft.AspNet.Hosting.Server.Abstractions/project.json index a3ccdf94bb..be15de9ea4 100644 --- a/src/Microsoft.AspNet.Hosting.Server.Abstractions/project.json +++ b/src/Microsoft.AspNet.Hosting.Server.Abstractions/project.json @@ -1,5 +1,9 @@ { "version": "1.0.0-*", + "compilationOptions": { + "warningsAsErrors": true, + "keyFile": "../../tools/Key.snk" + }, "description": "ASP.NET 5 Hosting server abstractions.", "repository": { "type": "git", diff --git a/src/Microsoft.AspNet.Hosting/Properties/AssemblyInfo.cs b/src/Microsoft.AspNet.Hosting/Properties/AssemblyInfo.cs index 1ee4059c80..4f51e0868a 100644 --- a/src/Microsoft.AspNet.Hosting/Properties/AssemblyInfo.cs +++ b/src/Microsoft.AspNet.Hosting/Properties/AssemblyInfo.cs @@ -6,5 +6,5 @@ using System.Resources; using System.Runtime.CompilerServices; [assembly: AssemblyMetadata("Serviceable", "True")] -[assembly: InternalsVisibleTo("Microsoft.AspNet.Hosting.Tests")] +[assembly: InternalsVisibleTo("Microsoft.AspNet.Hosting.Tests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f33a29044fa9d740c9b3213a93e57c84b472c84e0b8a0e1ae48e67a9f8f6de9d5f7f3d52ac23e48ac51801f1dc950abe901da34d2a9e3baadb141a17c77ef3c565dd5ee5054b91cf63bb3c6ab83f72ab3aafe93d0fc3c2348b764fafb0b1c0733de51459aeab46580384bf9d74c4e28164b7cde247f891ba07891c9d872ad2bb")] [assembly: NeutralResourcesLanguage("en-us")] diff --git a/src/Microsoft.AspNet.Hosting/project.json b/src/Microsoft.AspNet.Hosting/project.json index edd34b5469..8bfda6e2d9 100644 --- a/src/Microsoft.AspNet.Hosting/project.json +++ b/src/Microsoft.AspNet.Hosting/project.json @@ -6,7 +6,8 @@ "url": "git://github.com/aspnet/hosting" }, "compilationOptions": { - "warningsAsErrors": true + "warningsAsErrors": true, + "keyFile": "../../tools/Key.snk" }, "dependencies": { "Microsoft.AspNet.FileProviders.Physical": "1.0.0-*", diff --git a/src/Microsoft.AspNet.Server.Testing/project.json b/src/Microsoft.AspNet.Server.Testing/project.json index 66ee97d55c..833e0f0a62 100644 --- a/src/Microsoft.AspNet.Server.Testing/project.json +++ b/src/Microsoft.AspNet.Server.Testing/project.json @@ -1,5 +1,9 @@ { "version": "1.0.0-*", + "compilationOptions": { + "warningsAsErrors": true, + "keyFile": "../../tools/Key.snk" + }, "description": "ASP.NET 5 helpers to deploy applications to IIS Express, IIS, WebListener and Kestrel for testing.", "repository": { "type": "git", diff --git a/test/Microsoft.AspNet.Hosting.Tests/project.json b/test/Microsoft.AspNet.Hosting.Tests/project.json index 504a10b0b4..f00e2281e0 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/project.json +++ b/test/Microsoft.AspNet.Hosting.Tests/project.json @@ -1,4 +1,8 @@ { + "compilationOptions": { + "warningsAsErrors": true, + "keyFile": "../../tools/Key.snk" + }, "dependencies": { "Microsoft.AspNet.Hosting": "1.0.0-*", "Microsoft.AspNet.Owin": "1.0.0-*", diff --git a/tools/Key.snk b/tools/Key.snk new file mode 100644 index 0000000000000000000000000000000000000000..e10e4889c125d3120cd9e81582243d70f7cbb806 GIT binary patch literal 596 zcmV-a0;~N80ssI2Bme+XQ$aES1ONa50098=Iw=HCsnz~#iVhm& zj%TU(_THUee?3yHBjk$37ysB?i5#7WD$={H zV4B!OxRPrb|8)HPg~A}8P>^=#y<)56#=E&NzcjOtPK~<4n6GHt=K$ro*T(lhby_@U zEk(hLzk1H)0yXj{A_5>fk-TgNoP|q6(tP2xo8zt8i%212CWM#AeCd?`hS|4~L({h~Moo(~vy&3Z z1uI}`fd^*>o=rwbAGymj6RM^pZm(*Kfhs+Y1#`-2JPWZMK8@;ZWCk2+9bX4YP);~fj-BU*R zQPvWv$89!{Rl9wM+zR>_TSkn^voYxA?2G iKnV#iZ6Ah`K>b=@=IjYJXrxL124zR(38)nxe+&q_$QXwJ literal 0 HcmV?d00001 From 79eed1807ee4edae574dc4d60b93be438ff544bc Mon Sep 17 00:00:00 2001 From: Cesar Blum Silveira Date: Tue, 3 Nov 2015 12:42:26 -0800 Subject: [PATCH 436/987] Strong name Microsoft.AspNet.TestHost. --- src/Microsoft.AspNet.TestHost/Properties/AssemblyInfo.cs | 2 +- src/Microsoft.AspNet.TestHost/project.json | 4 ++++ test/Microsoft.AspNet.TestHost.Tests/project.json | 4 ++++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/Microsoft.AspNet.TestHost/Properties/AssemblyInfo.cs b/src/Microsoft.AspNet.TestHost/Properties/AssemblyInfo.cs index 726e557599..23d1e15e16 100644 --- a/src/Microsoft.AspNet.TestHost/Properties/AssemblyInfo.cs +++ b/src/Microsoft.AspNet.TestHost/Properties/AssemblyInfo.cs @@ -36,7 +36,7 @@ using System.Runtime.InteropServices; // The following GUID is for the ID of the typelib if this project is exposed to COM [assembly: Guid("12A3EDBB-65B6-4D47-98FC-2B80CEC71E51")] -[assembly: InternalsVisibleTo("Microsoft.AspNet.TestHost.Tests")] +[assembly: InternalsVisibleTo("Microsoft.AspNet.TestHost.Tests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f33a29044fa9d740c9b3213a93e57c84b472c84e0b8a0e1ae48e67a9f8f6de9d5f7f3d52ac23e48ac51801f1dc950abe901da34d2a9e3baadb141a17c77ef3c565dd5ee5054b91cf63bb3c6ab83f72ab3aafe93d0fc3c2348b764fafb0b1c0733de51459aeab46580384bf9d74c4e28164b7cde247f891ba07891c9d872ad2bb")] [assembly: AssemblyMetadata("Serviceable", "True")] [assembly: NeutralResourcesLanguage("en-us")] diff --git a/src/Microsoft.AspNet.TestHost/project.json b/src/Microsoft.AspNet.TestHost/project.json index 20bd0b4016..7f32b07622 100644 --- a/src/Microsoft.AspNet.TestHost/project.json +++ b/src/Microsoft.AspNet.TestHost/project.json @@ -1,5 +1,9 @@ { "version": "1.0.0-*", + "compilationOptions": { + "warningsAsErrors": true, + "keyFile": "../../tools/Key.snk" + }, "description": "ASP.NET 5 web server for writing and running tests.", "repository": { "type": "git", diff --git a/test/Microsoft.AspNet.TestHost.Tests/project.json b/test/Microsoft.AspNet.TestHost.Tests/project.json index ef4d4de144..661f7c8602 100644 --- a/test/Microsoft.AspNet.TestHost.Tests/project.json +++ b/test/Microsoft.AspNet.TestHost.Tests/project.json @@ -1,4 +1,8 @@ { + "compilationOptions": { + "warningsAsErrors": true, + "keyFile": "../../tools/Key.snk" + }, "dependencies": { "Microsoft.AspNet.Testing": "1.0.0-*", "Microsoft.AspNet.TestHost": "1.0.0-*", From c1311f903e2ed948e15acc6a65142ad2516303b2 Mon Sep 17 00:00:00 2001 From: Pavel Krymets Date: Tue, 3 Nov 2015 12:52:01 -0800 Subject: [PATCH 437/987] Rename Microsoft.Dnx.Compilation.Abstractions to Microsoft.Extensions.Compilation.Abstractions --- src/Microsoft.AspNet.Hosting/Startup/StartupExceptionPage.cs | 2 +- src/Microsoft.AspNet.Hosting/WebHostBuilder.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Microsoft.AspNet.Hosting/Startup/StartupExceptionPage.cs b/src/Microsoft.AspNet.Hosting/Startup/StartupExceptionPage.cs index 1ffcf7a001..f80b1d99fc 100644 --- a/src/Microsoft.AspNet.Hosting/Startup/StartupExceptionPage.cs +++ b/src/Microsoft.AspNet.Hosting/Startup/StartupExceptionPage.cs @@ -12,7 +12,7 @@ using System.Runtime.CompilerServices; using System.Runtime.ExceptionServices; using System.Text; using System.Text.Encodings.Web; -using Microsoft.Dnx.Compilation; +using Microsoft.Extensions.Compilation; using Microsoft.Extensions.PlatformAbstractions; namespace Microsoft.AspNet.Hosting.Startup diff --git a/src/Microsoft.AspNet.Hosting/WebHostBuilder.cs b/src/Microsoft.AspNet.Hosting/WebHostBuilder.cs index ddff824f21..01434eaa10 100644 --- a/src/Microsoft.AspNet.Hosting/WebHostBuilder.cs +++ b/src/Microsoft.AspNet.Hosting/WebHostBuilder.cs @@ -10,7 +10,7 @@ using Microsoft.AspNet.Hosting.Server; using Microsoft.AspNet.Hosting.Startup; using Microsoft.AspNet.Http; using Microsoft.AspNet.Http.Internal; -using Microsoft.Dnx.Compilation; +using Microsoft.Extensions.Compilation; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection.Extensions; From 5bb737b6ad24edb8d9f77aa3b48b17b24b4dfc0d Mon Sep 17 00:00:00 2001 From: Pavel Krymets Date: Fri, 6 Nov 2015 15:10:11 -0800 Subject: [PATCH 438/987] Make Compilation Abstractions naming consistent with Platform Abstractions --- src/Microsoft.AspNet.Hosting/Startup/StartupExceptionPage.cs | 2 +- src/Microsoft.AspNet.Hosting/WebHostBuilder.cs | 2 +- src/Microsoft.AspNet.Hosting/project.json | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Microsoft.AspNet.Hosting/Startup/StartupExceptionPage.cs b/src/Microsoft.AspNet.Hosting/Startup/StartupExceptionPage.cs index f80b1d99fc..1419c5d427 100644 --- a/src/Microsoft.AspNet.Hosting/Startup/StartupExceptionPage.cs +++ b/src/Microsoft.AspNet.Hosting/Startup/StartupExceptionPage.cs @@ -12,7 +12,7 @@ using System.Runtime.CompilerServices; using System.Runtime.ExceptionServices; using System.Text; using System.Text.Encodings.Web; -using Microsoft.Extensions.Compilation; +using Microsoft.Extensions.CompilationAbstractions; using Microsoft.Extensions.PlatformAbstractions; namespace Microsoft.AspNet.Hosting.Startup diff --git a/src/Microsoft.AspNet.Hosting/WebHostBuilder.cs b/src/Microsoft.AspNet.Hosting/WebHostBuilder.cs index 01434eaa10..26f5938eba 100644 --- a/src/Microsoft.AspNet.Hosting/WebHostBuilder.cs +++ b/src/Microsoft.AspNet.Hosting/WebHostBuilder.cs @@ -10,7 +10,7 @@ using Microsoft.AspNet.Hosting.Server; using Microsoft.AspNet.Hosting.Startup; using Microsoft.AspNet.Http; using Microsoft.AspNet.Http.Internal; -using Microsoft.Extensions.Compilation; +using Microsoft.Extensions.CompilationAbstractions; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection.Extensions; diff --git a/src/Microsoft.AspNet.Hosting/project.json b/src/Microsoft.AspNet.Hosting/project.json index 0db69b3e7c..823b1cc372 100644 --- a/src/Microsoft.AspNet.Hosting/project.json +++ b/src/Microsoft.AspNet.Hosting/project.json @@ -21,7 +21,7 @@ "Microsoft.Extensions.Configuration.Json": "1.0.0-*", "Microsoft.Extensions.DependencyInjection": "1.0.0-*", "Microsoft.Extensions.Logging": "1.0.0-*", - "Microsoft.Extensions.Compilation.Abstractions": "1.0.0-*", + "Microsoft.Extensions.CompilationAbstractions": "1.0.0-*", "Microsoft.Extensions.PlatformAbstractions": "1.0.0-*", "System.Diagnostics.DiagnosticSource": "4.0.0-beta-*" }, From 660f1cad10b7c3e08e9267b7f5967fbcdbd6c18f Mon Sep 17 00:00:00 2001 From: Pavel Krymets Date: Mon, 9 Nov 2015 10:54:15 -0800 Subject: [PATCH 439/987] Make hosting configuration consistent --- .../HostingEnvironmentExtensions.cs | 17 ++--- .../Internal/HostingEngine.cs | 8 +-- .../WebApplication.cs | 17 +++-- .../WebHostBuilder.cs | 16 ++--- .../WebHostOptions.cs | 47 ++++++++++++++ .../HostingEngineTests.cs | 12 ++-- .../WebHostBuilderTests.cs | 2 +- .../WebHostConfigurationsTests.cs | 63 +++++++++++++++++++ 8 files changed, 148 insertions(+), 34 deletions(-) create mode 100644 src/Microsoft.AspNet.Hosting/WebHostOptions.cs create mode 100644 test/Microsoft.AspNet.Hosting.Tests/WebHostConfigurationsTests.cs diff --git a/src/Microsoft.AspNet.Hosting/HostingEnvironmentExtensions.cs b/src/Microsoft.AspNet.Hosting/HostingEnvironmentExtensions.cs index 74cf50ec74..b6e5e8071a 100644 --- a/src/Microsoft.AspNet.Hosting/HostingEnvironmentExtensions.cs +++ b/src/Microsoft.AspNet.Hosting/HostingEnvironmentExtensions.cs @@ -1,6 +1,7 @@ // 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; using System.IO; using Microsoft.AspNet.FileProviders; using Microsoft.Extensions.Configuration; @@ -9,14 +10,14 @@ namespace Microsoft.AspNet.Hosting { public static class HostingEnvironmentExtensions { - private const string OldEnvironmentKey = "ASPNET_ENV"; - private const string EnvironmentKey = "Hosting:Environment"; - - private const string WebRootKey = "webroot"; - - public static void Initialize(this IHostingEnvironment hostingEnvironment, string applicationBasePath, IConfiguration config) + public static void Initialize(this IHostingEnvironment hostingEnvironment, string applicationBasePath, WebHostOptions options) { - var webRoot = config?[WebRootKey]; + if (options == null) + { + throw new ArgumentNullException(nameof(options)); + } + + var webRoot = options.WebRoot; if (webRoot == null) { // Default to /wwwroot if it exists. @@ -43,7 +44,7 @@ namespace Microsoft.AspNet.Hosting } hostingEnvironment.WebRootFileProvider = new PhysicalFileProvider(hostingEnvironment.WebRootPath); - var environmentName = config?[EnvironmentKey] ?? config?[OldEnvironmentKey]; + var environmentName = options.Environment; hostingEnvironment.EnvironmentName = environmentName ?? hostingEnvironment.EnvironmentName; } } diff --git a/src/Microsoft.AspNet.Hosting/Internal/HostingEngine.cs b/src/Microsoft.AspNet.Hosting/Internal/HostingEngine.cs index c504e6d0e3..4b304c152a 100644 --- a/src/Microsoft.AspNet.Hosting/Internal/HostingEngine.cs +++ b/src/Microsoft.AspNet.Hosting/Internal/HostingEngine.cs @@ -24,11 +24,11 @@ namespace Microsoft.AspNet.Hosting.Internal { // This is defined by IIS's HttpPlatformHandler. private static readonly string ServerPort = "HTTP_PLATFORM_PORT"; - private static readonly string DetailedErrors = "Hosting:DetailedErrors"; private readonly IServiceCollection _applicationServiceCollection; private readonly IStartupLoader _startupLoader; private readonly ApplicationLifetime _applicationLifetime; + private readonly WebHostOptions _options; private readonly IConfiguration _config; private readonly bool _captureStartupErrors; @@ -47,6 +47,7 @@ namespace Microsoft.AspNet.Hosting.Internal public HostingEngine( IServiceCollection appServices, IStartupLoader startupLoader, + WebHostOptions options, IConfiguration config, bool captureStartupErrors) { @@ -66,6 +67,7 @@ namespace Microsoft.AspNet.Hosting.Internal } _config = config; + _options = options; _applicationServiceCollection = appServices; _startupLoader = startupLoader; _captureStartupErrors = captureStartupErrors; @@ -226,9 +228,7 @@ namespace Microsoft.AspNet.Hosting.Internal // Generate an HTML error page. var runtimeEnv = _applicationServices.GetRequiredService(); var hostingEnv = _applicationServices.GetRequiredService(); - var showDetailedErrors = hostingEnv.IsDevelopment() - || string.Equals("true", _config[DetailedErrors], StringComparison.OrdinalIgnoreCase) - || string.Equals("1", _config[DetailedErrors], StringComparison.OrdinalIgnoreCase); + var showDetailedErrors = hostingEnv.IsDevelopment() || _options.DetailedErrors; var errorBytes = StartupExceptionPage.GenerateErrorHtml(showDetailedErrors, runtimeEnv, ex); return context => diff --git a/src/Microsoft.AspNet.Hosting/WebApplication.cs b/src/Microsoft.AspNet.Hosting/WebApplication.cs index 7d77a911db..33a834b183 100644 --- a/src/Microsoft.AspNet.Hosting/WebApplication.cs +++ b/src/Microsoft.AspNet.Hosting/WebApplication.cs @@ -12,6 +12,7 @@ namespace Microsoft.AspNet.Hosting public class WebApplication { private const string HostingJsonFile = "hosting.json"; + private const string EnvironmentVariablesPrefix = "ASPNET_"; private const string ConfigFileKey = "config"; public static void Run(string[] args) @@ -40,12 +41,7 @@ namespace Microsoft.AspNet.Hosting var tempBuilder = new ConfigurationBuilder().AddCommandLine(args); var tempConfig = tempBuilder.Build(); var configFilePath = tempConfig[ConfigFileKey] ?? HostingJsonFile; - - var config = new ConfigurationBuilder() - .AddJsonFile(configFilePath, optional: true) - .AddEnvironmentVariables() - .AddCommandLine(args) - .Build(); + var config = LoadHostingConfiguration(configFilePath, args); var hostBuilder = new WebHostBuilder(config, captureStartupErrors: true); if (startupType != null) @@ -81,5 +77,14 @@ namespace Microsoft.AspNet.Hosting appLifetime.ApplicationStopping.WaitHandle.WaitOne(); } } + + internal static IConfiguration LoadHostingConfiguration(string configJsonPath, string[] args) + { + return new ConfigurationBuilder() + .AddJsonFile(configJsonPath, optional: true) + .AddEnvironmentVariables(prefix: EnvironmentVariablesPrefix) + .AddCommandLine(args) + .Build(); + } } } diff --git a/src/Microsoft.AspNet.Hosting/WebHostBuilder.cs b/src/Microsoft.AspNet.Hosting/WebHostBuilder.cs index 26f5938eba..a26796412f 100644 --- a/src/Microsoft.AspNet.Hosting/WebHostBuilder.cs +++ b/src/Microsoft.AspNet.Hosting/WebHostBuilder.cs @@ -21,15 +21,10 @@ namespace Microsoft.AspNet.Hosting { public class WebHostBuilder { - public const string OldApplicationKey = "app"; - public const string ApplicationKey = "Hosting:Application"; - - public const string OldServerKey = "server"; - public const string ServerKey = "Hosting:Server"; - private readonly IHostingEnvironment _hostingEnvironment; private readonly ILoggerFactory _loggerFactory; private readonly IConfiguration _config; + private readonly WebHostOptions _options; private Action _configureServices; @@ -64,6 +59,7 @@ namespace Microsoft.AspNet.Hosting _hostingEnvironment = new HostingEnvironment(); _loggerFactory = new LoggerFactory(); _config = config; + _options = new WebHostOptions(config); _captureStartupErrors = captureStartupErrors; } @@ -130,18 +126,18 @@ namespace Microsoft.AspNet.Hosting var appEnvironment = hostingContainer.GetRequiredService(); var startupLoader = hostingContainer.GetRequiredService(); - _hostingEnvironment.Initialize(appEnvironment.ApplicationBasePath, _config); - var engine = new HostingEngine(hostingServices, startupLoader, _config, _captureStartupErrors); + _hostingEnvironment.Initialize(appEnvironment.ApplicationBasePath, _options); + var engine = new HostingEngine(hostingServices, startupLoader, _options, _config, _captureStartupErrors); // Only one of these should be set, but they are used in priority engine.Server = _server; engine.ServerFactory = _serverFactory; - engine.ServerFactoryLocation = _config[ServerKey] ?? _config[OldServerKey] ?? _serverFactoryLocation; + engine.ServerFactoryLocation = _options.Server ?? _serverFactoryLocation; // Only one of these should be set, but they are used in priority engine.Startup = _startup; engine.StartupType = _startupType; - engine.StartupAssemblyName = _startupAssemblyName ?? _config[ApplicationKey] ?? _config[OldApplicationKey] ?? appEnvironment.ApplicationName; + engine.StartupAssemblyName = _startupAssemblyName ?? _options.Application ?? appEnvironment.ApplicationName; return engine; } diff --git a/src/Microsoft.AspNet.Hosting/WebHostOptions.cs b/src/Microsoft.AspNet.Hosting/WebHostOptions.cs new file mode 100644 index 0000000000..89a0aad6bc --- /dev/null +++ b/src/Microsoft.AspNet.Hosting/WebHostOptions.cs @@ -0,0 +1,47 @@ +// 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; +using Microsoft.Extensions.Configuration; + +namespace Microsoft.AspNet.Hosting +{ + public class WebHostOptions + { + private const string ApplicationKey = "app"; + private const string DetailedErrorsKey = "detailedErrors"; + private const string EnvironmentKey = "environment"; + private const string ServerKey = "server"; + private const string WebRootKey = "webroot"; + private const string OldEnvironmentKey = "ENV"; + + public WebHostOptions() + { + } + + public WebHostOptions(IConfiguration configuration) + { + if (configuration == null) + { + throw new ArgumentNullException(nameof(configuration)); + } + + Application = configuration[ApplicationKey]; + DetailedErrors = string.Equals("true", configuration[DetailedErrorsKey], StringComparison.OrdinalIgnoreCase) + || string.Equals("1", configuration[DetailedErrorsKey], StringComparison.OrdinalIgnoreCase); + Environment = configuration[EnvironmentKey] ?? configuration[OldEnvironmentKey]; + Server = configuration[ServerKey]; + WebRoot = configuration[WebRootKey]; + } + + public string Application { get; set; } + + public bool DetailedErrors { get; set; } + + public string Environment { get; set; } + + public string Server { get; set; } + + public string WebRoot { get; set; } + } +} \ No newline at end of file diff --git a/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs b/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs index 0e0655ecac..a31fbd5d43 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs @@ -98,7 +98,7 @@ namespace Microsoft.AspNet.Hosting { var vals = new Dictionary { - { "Hosting:Server", "Microsoft.AspNet.Hosting.Tests" } + { "Server", "Microsoft.AspNet.Hosting.Tests" } }; var builder = new ConfigurationBuilder() @@ -114,7 +114,7 @@ namespace Microsoft.AspNet.Hosting { var vals = new Dictionary { - { "Hosting:Server", "Microsoft.AspNet.Hosting.Tests" }, + { "Server", "Microsoft.AspNet.Hosting.Tests" }, { "HTTP_PLATFORM_PORT", "abc123" } }; @@ -132,7 +132,7 @@ namespace Microsoft.AspNet.Hosting { var vals = new Dictionary { - { "Hosting:Server", "Microsoft.AspNet.Hosting.Tests" } + { "Server", "Microsoft.AspNet.Hosting.Tests" } }; var builder = new ConfigurationBuilder() @@ -250,7 +250,9 @@ namespace Microsoft.AspNet.Hosting { var vals = new Dictionary { - { "ASPNET_ENV", "Staging" } + // Old key is actualy ASPNET_ENV but WebHostConfiguration expects environment + // variable names stripped from ASPNET_ prefix so using just ENV here + { "ENV", "Staging" } }; var builder = new ConfigurationBuilder() @@ -267,7 +269,7 @@ namespace Microsoft.AspNet.Hosting { var vals = new Dictionary { - { "Hosting:Environment", "Staging" } + { "Environment", "Staging" } }; var builder = new ConfigurationBuilder() diff --git a/test/Microsoft.AspNet.Hosting.Tests/WebHostBuilderTests.cs b/test/Microsoft.AspNet.Hosting.Tests/WebHostBuilderTests.cs index 3ab61daf96..db801c2f4d 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/WebHostBuilderTests.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/WebHostBuilderTests.cs @@ -129,7 +129,7 @@ namespace Microsoft.AspNet.Hosting var vals = new Dictionary { { "server", "Microsoft.AspNet.Hosting.Tests" }, - { "Hosting:DetailedErrors", "true" }, + { "DetailedErrors", "true" }, }; var builder = new ConfigurationBuilder() .AddInMemoryCollection(vals); diff --git a/test/Microsoft.AspNet.Hosting.Tests/WebHostConfigurationsTests.cs b/test/Microsoft.AspNet.Hosting.Tests/WebHostConfigurationsTests.cs new file mode 100644 index 0000000000..ea3b314bbd --- /dev/null +++ b/test/Microsoft.AspNet.Hosting.Tests/WebHostConfigurationsTests.cs @@ -0,0 +1,63 @@ +// 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; +using System.Collections; +using System.Collections.Generic; +using System.IO; +using System.Reflection; +using Microsoft.AspNet.Builder; +using Microsoft.AspNet.Builder.Internal; +using Microsoft.AspNet.Hosting.Fakes; +using Microsoft.AspNet.Hosting.Startup; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.OptionsModel; +using Xunit; + +namespace Microsoft.AspNet.Hosting.Tests +{ + public class WebHostConfigurationTests + { + [Fact] + public void ReadsParametersCorrectly() + { + var parameters = new Dictionary() + { + {"webroot", "wwwroot"}, + {"server", "Microsoft.AspNet.Server.Kestrel"}, + {"app", "MyProjectReference"}, + {"environment", "Development"}, + {"detailederrors", "true"}, + }; + + var config = new WebHostOptions(new ConfigurationBuilder().AddInMemoryCollection(parameters).Build()); + + Assert.Equal("wwwroot", config.WebRoot); + Assert.Equal("Microsoft.AspNet.Server.Kestrel", config.Server); + Assert.Equal("MyProjectReference", config.Application); + Assert.Equal("Development", config.Environment); + Assert.Equal(true, config.DetailedErrors); + } + + [Fact] + public void ReadsOldEnvKey() + { + var parameters = new Dictionary() { { "ENV", "Development" } }; + var config = new WebHostOptions(new ConfigurationBuilder().AddInMemoryCollection(parameters).Build()); + + Assert.Equal("Development", config.Environment); + } + + [Theory] + [InlineData("1", true)] + [InlineData("0", false)] + public void AllowsNumberForDetailedErrors(string value, bool expected) + { + var parameters = new Dictionary() { { "detailedErrors", value } }; + var config = new WebHostOptions(new ConfigurationBuilder().AddInMemoryCollection(parameters).Build()); + + Assert.Equal(expected, config.DetailedErrors); + } + } +} From b2edb0d4848c53ffe1ebf568ee9f997d42f493d6 Mon Sep 17 00:00:00 2001 From: Pavel Krymets Date: Tue, 10 Nov 2015 12:12:06 -0800 Subject: [PATCH 440/987] Fix environment variable loading in hosting #470 --- src/Microsoft.AspNet.Hosting/WebApplication.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/Microsoft.AspNet.Hosting/WebApplication.cs b/src/Microsoft.AspNet.Hosting/WebApplication.cs index 33a834b183..f819fcec7a 100644 --- a/src/Microsoft.AspNet.Hosting/WebApplication.cs +++ b/src/Microsoft.AspNet.Hosting/WebApplication.cs @@ -80,8 +80,11 @@ namespace Microsoft.AspNet.Hosting internal static IConfiguration LoadHostingConfiguration(string configJsonPath, string[] args) { + // We are adding all environment variables first and then adding the ASPNET_ ones + // with the prefix removed to unify with the command line and config file formats return new ConfigurationBuilder() .AddJsonFile(configJsonPath, optional: true) + .AddEnvironmentVariables() .AddEnvironmentVariables(prefix: EnvironmentVariablesPrefix) .AddCommandLine(args) .Build(); From ecb7e697d15033918147e286dc198865261beefc Mon Sep 17 00:00:00 2001 From: Pavel Krymets Date: Tue, 10 Nov 2015 16:48:16 -0800 Subject: [PATCH 441/987] Fix bug with environment name beeng overwritten After being set using UseEnvironment --- src/Microsoft.AspNet.Hosting/WebHostBuilder.cs | 7 ++++++- .../WebHostBuilderTests.cs | 17 +++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/Microsoft.AspNet.Hosting/WebHostBuilder.cs b/src/Microsoft.AspNet.Hosting/WebHostBuilder.cs index a26796412f..f60c32fb32 100644 --- a/src/Microsoft.AspNet.Hosting/WebHostBuilder.cs +++ b/src/Microsoft.AspNet.Hosting/WebHostBuilder.cs @@ -27,6 +27,7 @@ namespace Microsoft.AspNet.Hosting private readonly WebHostOptions _options; private Action _configureServices; + private string _environmentName; // Only one of these should be set private StartupMethods _startup; @@ -127,6 +128,10 @@ namespace Microsoft.AspNet.Hosting var startupLoader = hostingContainer.GetRequiredService(); _hostingEnvironment.Initialize(appEnvironment.ApplicationBasePath, _options); + if (!string.IsNullOrEmpty(_environmentName)) + { + _hostingEnvironment.EnvironmentName = _environmentName; + } var engine = new HostingEngine(hostingServices, startupLoader, _options, _config, _captureStartupErrors); // Only one of these should be set, but they are used in priority @@ -155,7 +160,7 @@ namespace Microsoft.AspNet.Hosting throw new ArgumentNullException(nameof(environment)); } - _hostingEnvironment.EnvironmentName = environment; + _environmentName = environment; return this; } diff --git a/test/Microsoft.AspNet.Hosting.Tests/WebHostBuilderTests.cs b/test/Microsoft.AspNet.Hosting.Tests/WebHostBuilderTests.cs index db801c2f4d..7b3bdf7f82 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/WebHostBuilderTests.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/WebHostBuilderTests.cs @@ -124,6 +124,23 @@ namespace Microsoft.AspNet.Hosting } } + [Fact] + public void UseEnvironmentIsNotOverriden() + { + var vals = new Dictionary + { + { "ENV", "Dev" }, + }; + var builder = new ConfigurationBuilder() + .AddInMemoryCollection(vals); + var config = builder.Build(); + + var expected = "MY_TEST_ENVIRONMENT"; + var webHost = new WebHostBuilder(config, captureStartupErrors: true).UseEnvironment(expected).Build(); + + Assert.Equal(expected, webHost.ApplicationServices.GetService().EnvironmentName); + } + private WebHostBuilder CreateWebHostBuilder() { var vals = new Dictionary From 0692ebe628b8089bfc18dabef42697bc8b362c20 Mon Sep 17 00:00:00 2001 From: "N. Taylor Mullen" Date: Thu, 12 Nov 2015 12:23:29 -0800 Subject: [PATCH 442/987] Remove System beta tag in project.json for coreclr packages. --- src/Microsoft.AspNet.Hosting/project.json | 14 +++++++------- src/Microsoft.AspNet.Server.Testing/project.json | 16 ++++++++-------- src/Microsoft.AspNet.TestHost/project.json | 6 +++--- 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/Microsoft.AspNet.Hosting/project.json b/src/Microsoft.AspNet.Hosting/project.json index 823b1cc372..c34f9fd752 100644 --- a/src/Microsoft.AspNet.Hosting/project.json +++ b/src/Microsoft.AspNet.Hosting/project.json @@ -23,7 +23,7 @@ "Microsoft.Extensions.Logging": "1.0.0-*", "Microsoft.Extensions.CompilationAbstractions": "1.0.0-*", "Microsoft.Extensions.PlatformAbstractions": "1.0.0-*", - "System.Diagnostics.DiagnosticSource": "4.0.0-beta-*" + "System.Diagnostics.DiagnosticSource": "4.0.0-*" }, "frameworks": { "dnx451": { @@ -38,16 +38,16 @@ }, "dnxcore50": { "dependencies": { - "System.Console": "4.0.0-beta-*", - "System.Diagnostics.StackTrace": "4.0.1-beta-*", - "System.Reflection.Extensions": "4.0.1-beta-*" + "System.Console": "4.0.0-*", + "System.Diagnostics.StackTrace": "4.0.1-*", + "System.Reflection.Extensions": "4.0.1-*" } }, "dotnet5.4": { "dependencies": { - "System.Console": "4.0.0-beta-*", - "System.Diagnostics.StackTrace": "4.0.1-beta-*", - "System.Reflection.Extensions": "4.0.1-beta-*" + "System.Console": "4.0.0-*", + "System.Diagnostics.StackTrace": "4.0.1-*", + "System.Reflection.Extensions": "4.0.1-*" } } } diff --git a/src/Microsoft.AspNet.Server.Testing/project.json b/src/Microsoft.AspNet.Server.Testing/project.json index 833e0f0a62..77079ef4f8 100644 --- a/src/Microsoft.AspNet.Server.Testing/project.json +++ b/src/Microsoft.AspNet.Server.Testing/project.json @@ -26,15 +26,15 @@ }, "dnxcore50": { "dependencies": { - "System.Diagnostics.Process": "4.0.0-beta-*", - "System.IO.FileSystem": "4.0.1-beta-*", - "System.Net.Http": "4.0.1-beta-*", - "System.Net.Primitives": "4.0.11-beta-*", - "System.Runtime.Extensions": "4.0.11-beta-*", - "System.Text.RegularExpressions": "4.0.11-beta-*", - "System.Threading": "4.0.11-beta-*", + "System.Diagnostics.Process": "4.0.0-*", + "System.IO.FileSystem": "4.0.1-*", + "System.Net.Http": "4.0.1-*", + "System.Net.Primitives": "4.0.11-*", + "System.Runtime.Extensions": "4.0.11-*", + "System.Text.RegularExpressions": "4.0.11-*", + "System.Threading": "4.0.11-*", "System.Threading.Thread": "4.0.0-*" } } } -} \ No newline at end of file +} diff --git a/src/Microsoft.AspNet.TestHost/project.json b/src/Microsoft.AspNet.TestHost/project.json index 7f32b07622..bdadfda68b 100644 --- a/src/Microsoft.AspNet.TestHost/project.json +++ b/src/Microsoft.AspNet.TestHost/project.json @@ -20,9 +20,9 @@ }, "dotnet5.4": { "dependencies": { - "System.Diagnostics.Contracts": "4.0.1-beta-*", - "System.Net.Http": "4.0.1-beta-*" + "System.Diagnostics.Contracts": "4.0.1-*", + "System.Net.Http": "4.0.1-*" } } } -} \ No newline at end of file +} From 8341c6a944326c95485670f72e4de52423721eac Mon Sep 17 00:00:00 2001 From: Pranav K Date: Fri, 13 Nov 2015 11:04:43 -0800 Subject: [PATCH 443/987] Reacting to DependencyInjection changes --- src/Microsoft.AspNet.Hosting/Internal/HostingEngine.cs | 2 +- src/Microsoft.AspNet.Hosting/WebHostBuilder.cs | 8 ++++---- .../StartupManagerTests.cs | 10 +++++----- .../Microsoft.AspNet.TestHost.Tests/TestServerTests.cs | 2 +- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/Microsoft.AspNet.Hosting/Internal/HostingEngine.cs b/src/Microsoft.AspNet.Hosting/Internal/HostingEngine.cs index 4b304c152a..2a5ef5f534 100644 --- a/src/Microsoft.AspNet.Hosting/Internal/HostingEngine.cs +++ b/src/Microsoft.AspNet.Hosting/Internal/HostingEngine.cs @@ -72,7 +72,7 @@ namespace Microsoft.AspNet.Hosting.Internal _startupLoader = startupLoader; _captureStartupErrors = captureStartupErrors; _applicationLifetime = new ApplicationLifetime(); - _applicationServiceCollection.AddInstance(_applicationLifetime); + _applicationServiceCollection.AddSingleton(_applicationLifetime); } public IServiceProvider ApplicationServices diff --git a/src/Microsoft.AspNet.Hosting/WebHostBuilder.cs b/src/Microsoft.AspNet.Hosting/WebHostBuilder.cs index f60c32fb32..ca52616b35 100644 --- a/src/Microsoft.AspNet.Hosting/WebHostBuilder.cs +++ b/src/Microsoft.AspNet.Hosting/WebHostBuilder.cs @@ -67,8 +67,8 @@ namespace Microsoft.AspNet.Hosting private IServiceCollection BuildHostingServices() { var services = new ServiceCollection(); - services.AddInstance(_hostingEnvironment); - services.AddInstance(_loggerFactory); + services.AddSingleton(_hostingEnvironment); + services.AddSingleton(_loggerFactory); services.AddTransient(); @@ -79,8 +79,8 @@ namespace Microsoft.AspNet.Hosting services.AddLogging(); var diagnosticSource = new DiagnosticListener("Microsoft.AspNet"); - services.AddInstance(diagnosticSource); - services.AddInstance(diagnosticSource); + services.AddSingleton(diagnosticSource); + services.AddSingleton(diagnosticSource); // Conjure up a RequestServices services.AddTransient(); diff --git a/test/Microsoft.AspNet.Hosting.Tests/StartupManagerTests.cs b/test/Microsoft.AspNet.Hosting.Tests/StartupManagerTests.cs index f7d835cd87..0272e66a81 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/StartupManagerTests.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/StartupManagerTests.cs @@ -22,7 +22,7 @@ namespace Microsoft.AspNet.Hosting.Tests public void StartupClassMayHaveHostingServicesInjected() { var serviceCollection = new ServiceCollection(); - serviceCollection.AddInstance(this); + serviceCollection.AddSingleton(this); var services = serviceCollection.BuildServiceProvider(); var diagnosticMessages = new List(); @@ -71,7 +71,7 @@ namespace Microsoft.AspNet.Hosting.Tests public void StartupWithNoConfigureThrows() { var serviceCollection = new ServiceCollection(); - serviceCollection.AddInstance(this); + serviceCollection.AddSingleton(this); var services = serviceCollection.BuildServiceProvider(); var diagnosticMessages = new List(); @@ -87,7 +87,7 @@ namespace Microsoft.AspNet.Hosting.Tests public void StartupWithTwoConfiguresThrows() { var serviceCollection = new ServiceCollection(); - serviceCollection.AddInstance(this); + serviceCollection.AddSingleton(this); var services = serviceCollection.BuildServiceProvider(); var diagnosticMessages = new List(); @@ -103,7 +103,7 @@ namespace Microsoft.AspNet.Hosting.Tests public void StartupWithPrivateConfiguresThrows() { var serviceCollection = new ServiceCollection(); - serviceCollection.AddInstance(this); + serviceCollection.AddSingleton(this); var services = serviceCollection.BuildServiceProvider(); var diagnosticMessages = new List(); @@ -119,7 +119,7 @@ namespace Microsoft.AspNet.Hosting.Tests public void StartupWithTwoConfigureServicesThrows() { var serviceCollection = new ServiceCollection(); - serviceCollection.AddInstance(this); + serviceCollection.AddSingleton(this); var services = serviceCollection.BuildServiceProvider(); var diagnosticMessages = new List(); diff --git a/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs b/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs index a422818802..06c21fc3f8 100644 --- a/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs +++ b/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs @@ -203,7 +203,7 @@ namespace Microsoft.AspNet.TestHost return context.Response.WriteAsync("Success"); }); }, - services => services.AddInstance(new ReplaceServiceProvidersFeatureFilter(appServices, appServices))); + services => services.AddSingleton(new ReplaceServiceProvidersFeatureFilter(appServices, appServices))); var result = await server.CreateClient().GetStringAsync("/path"); Assert.Equal("Success", result); } From 861b8b75e8bbeda02bb675bcd74ac48106719a0f Mon Sep 17 00:00:00 2001 From: Doug Bunting Date: Tue, 17 Nov 2015 10:59:38 -0800 Subject: [PATCH 444/987] Explicitly choose Mono 4.0.5 - avoids future problems related to aspnet/External#48 - e.g. when Travis updates default Mono version in `csharp` bundle --- .travis.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.travis.yml b/.travis.yml index 947bf868ee..dc44c0f660 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,4 +1,6 @@ language: csharp sudo: false +mono: + - 4.0.5 script: - ./build.sh --quiet verify \ No newline at end of file From d867d2555b98995f332a8fe74c58f48d009c7461 Mon Sep 17 00:00:00 2001 From: Doug Bunting Date: Tue, 17 Nov 2015 12:44:12 -0800 Subject: [PATCH 445/987] Move Travis to supported Linux distribution - use Ubuntu 14.04 (Trusty) - Travis support for Trusty is in Beta and currently requires `sudo` - run `dnu restore` with DNX Core since aspnet/External#49 is not fixed in Mono versions we can use - add required dependencies for DNX Core to `.travis.yml` - addresses part of aspnet/Universe#290 --- .travis.yml | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index dc44c0f660..2fc624899f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,18 @@ language: csharp -sudo: false +sudo: required +dist: trusty +addons: + apt: + packages: + - gettext + - libcurl4-openssl-dev + - libicu-dev + - libssl-dev + - libunwind8 + - zlib1g +env: + - KOREBUILD_DNU_RESTORE_CORECLR=true mono: - 4.0.5 script: - - ./build.sh --quiet verify \ No newline at end of file + - ./build.sh --quiet verify From 3c1b7597504b39b0c0bcbf9915e60adfa7bee853 Mon Sep 17 00:00:00 2001 From: Master T Date: Tue, 17 Nov 2015 20:26:41 +0100 Subject: [PATCH 446/987] Merge pull request #485 from tmds:dev Convert Environment Ticks to TimeSpan Ticks --- .../Internal/HostingLoggerExtensions.cs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Microsoft.AspNet.Hosting/Internal/HostingLoggerExtensions.cs b/src/Microsoft.AspNet.Hosting/Internal/HostingLoggerExtensions.cs index a92eac1444..67f9f114ff 100644 --- a/src/Microsoft.AspNet.Hosting/Internal/HostingLoggerExtensions.cs +++ b/src/Microsoft.AspNet.Hosting/Internal/HostingLoggerExtensions.cs @@ -10,6 +10,8 @@ namespace Microsoft.AspNet.Hosting.Internal { internal static class HostingLoggerExtensions { + private const long TicksPerMillisecond = 10000; + public static IDisposable RequestScope(this ILogger logger, HttpContext httpContext) { return logger.BeginScopeImpl(new HostingLogScope(httpContext)); @@ -32,7 +34,7 @@ namespace Microsoft.AspNet.Hosting.Internal { if (logger.IsEnabled(LogLevel.Information)) { - var elapsed = new TimeSpan(Environment.TickCount - startTimeInTicks); + var elapsed = new TimeSpan(TicksPerMillisecond * (Environment.TickCount - startTimeInTicks)); logger.Log( logLevel: LogLevel.Information, eventId: LoggerEventIds.RequestFinished, @@ -46,7 +48,7 @@ namespace Microsoft.AspNet.Hosting.Internal { if (logger.IsEnabled(LogLevel.Information)) { - var elapsed = new TimeSpan(Environment.TickCount - startTimeInTicks); + var elapsed = new TimeSpan(TicksPerMillisecond * (Environment.TickCount - startTimeInTicks)); logger.Log( logLevel: LogLevel.Information, eventId: LoggerEventIds.RequestFailed, From 2f2ca234a56b8d7367049f11b9a8d4a815177fea Mon Sep 17 00:00:00 2001 From: Chris R Date: Wed, 18 Nov 2015 12:44:08 -0800 Subject: [PATCH 447/987] Enable detailed startup errors by default. --- .../Common/DeploymentParameters.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Microsoft.AspNet.Server.Testing/Common/DeploymentParameters.cs b/src/Microsoft.AspNet.Server.Testing/Common/DeploymentParameters.cs index 842e65b70f..f4b64df53f 100644 --- a/src/Microsoft.AspNet.Server.Testing/Common/DeploymentParameters.cs +++ b/src/Microsoft.AspNet.Server.Testing/Common/DeploymentParameters.cs @@ -39,6 +39,7 @@ namespace Microsoft.AspNet.Server.Testing ServerType = serverType; RuntimeFlavor = runtimeFlavor; RuntimeArchitecture = runtimeArchitecture; + EnvironmentVariables.Add(new KeyValuePair("ASPNET_DETAILEDERRORS", "true")); } public ServerType ServerType { get; private set; } From 7c8b37bcc726895d12724ba2d7f657c8400c6c4d Mon Sep 17 00:00:00 2001 From: Pavel Krymets Date: Wed, 11 Nov 2015 14:23:59 -0800 Subject: [PATCH 448/987] Do not add IHttpContextAccessor to DI by default --- src/Microsoft.AspNet.Hosting/WebHostBuilder.cs | 1 - .../TestServerTests.cs | 15 ++++++++++++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/Microsoft.AspNet.Hosting/WebHostBuilder.cs b/src/Microsoft.AspNet.Hosting/WebHostBuilder.cs index ca52616b35..9ad73e964a 100644 --- a/src/Microsoft.AspNet.Hosting/WebHostBuilder.cs +++ b/src/Microsoft.AspNet.Hosting/WebHostBuilder.cs @@ -75,7 +75,6 @@ namespace Microsoft.AspNet.Hosting services.AddTransient(); services.AddTransient(); services.AddTransient(); - services.AddSingleton(); services.AddLogging(); var diagnosticSource = new DiagnosticListener("Microsoft.AspNet"); diff --git a/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs b/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs index 06c21fc3f8..d34bc4f447 100644 --- a/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs +++ b/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs @@ -13,6 +13,7 @@ using Microsoft.AspNet.Hosting.Startup; using Microsoft.AspNet.Http; using Microsoft.AspNet.Http.Features; using Microsoft.AspNet.Http.Features.Internal; +using Microsoft.AspNet.Http.Internal; using Microsoft.AspNet.Testing.xunit; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; @@ -289,6 +290,10 @@ namespace Microsoft.AspNet.TestHost [Fact] public async Task CanAccessHttpContext() { + Action configureServices = services => + { + services.AddSingleton(); + }; TestServer server = TestServer.Create(app => { app.Run(context => @@ -296,7 +301,7 @@ namespace Microsoft.AspNet.TestHost var accessor = app.ApplicationServices.GetRequiredService(); return context.Response.WriteAsync("HasContext:"+(accessor.HttpContext != null)); }); - }); + }, configureServices); string result = await server.CreateClient().GetStringAsync("/path"); Assert.Equal("HasContext:True", result); @@ -315,6 +320,11 @@ namespace Microsoft.AspNet.TestHost [Fact] public async Task CanAddNewHostServices() { + Action configureServices = services => + { + services.AddSingleton(); + services.AddSingleton(); + }; TestServer server = TestServer.Create(app => { app.Run(context => @@ -322,8 +332,7 @@ namespace Microsoft.AspNet.TestHost var accessor = app.ApplicationServices.GetRequiredService(); return context.Response.WriteAsync("HasContext:" + (accessor.Accessor.HttpContext != null)); }); - }, - services => services.AddSingleton()); + }, configureServices); string result = await server.CreateClient().GetStringAsync("/path"); Assert.Equal("HasContext:True", result); From 04c30c8bb769aa5aea9fc7e63b0f8d47b81bdb72 Mon Sep 17 00:00:00 2001 From: Pavel Krymets Date: Thu, 19 Nov 2015 10:43:08 -0800 Subject: [PATCH 449/987] Flow configuration via IHostingEnvironment --- .../IHostingEnvironment.cs | 6 ++++++ .../project.json | 3 ++- .../HostingEnvironment.cs | 4 +++- .../HostingEnvironmentExtensions.cs | 4 +++- src/Microsoft.AspNet.Hosting/WebHostBuilder.cs | 2 +- .../HostingEngineTests.cs | 18 ++++++++++++++++++ 6 files changed, 33 insertions(+), 4 deletions(-) diff --git a/src/Microsoft.AspNet.Hosting.Abstractions/IHostingEnvironment.cs b/src/Microsoft.AspNet.Hosting.Abstractions/IHostingEnvironment.cs index 6f357d3ca2..cfc96be02f 100644 --- a/src/Microsoft.AspNet.Hosting.Abstractions/IHostingEnvironment.cs +++ b/src/Microsoft.AspNet.Hosting.Abstractions/IHostingEnvironment.cs @@ -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.FileProviders; +using Microsoft.Extensions.Configuration; namespace Microsoft.AspNet.Hosting { @@ -28,5 +29,10 @@ namespace Microsoft.AspNet.Hosting /// // This must be settable! IFileProvider WebRootFileProvider { get; set; } + + /// + /// Gets or sets the configuration object used by hosting environment. + /// + IConfiguration Configuration { get; set; } } } \ No newline at end of file diff --git a/src/Microsoft.AspNet.Hosting.Abstractions/project.json b/src/Microsoft.AspNet.Hosting.Abstractions/project.json index d8764590da..087bc75058 100644 --- a/src/Microsoft.AspNet.Hosting.Abstractions/project.json +++ b/src/Microsoft.AspNet.Hosting.Abstractions/project.json @@ -11,7 +11,8 @@ }, "dependencies": { "Microsoft.AspNet.Http.Abstractions": "1.0.0-*", - "Microsoft.AspNet.FileProviders.Abstractions": "1.0.0-*" + "Microsoft.AspNet.FileProviders.Abstractions": "1.0.0-*", + "Microsoft.Extensions.Configuration.Abstractions": "1.0.0-*" }, "frameworks": { "net451": {}, diff --git a/src/Microsoft.AspNet.Hosting/HostingEnvironment.cs b/src/Microsoft.AspNet.Hosting/HostingEnvironment.cs index 57617c2893..e7254247a2 100644 --- a/src/Microsoft.AspNet.Hosting/HostingEnvironment.cs +++ b/src/Microsoft.AspNet.Hosting/HostingEnvironment.cs @@ -2,7 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using Microsoft.AspNet.FileProviders; -using Microsoft.AspNet.Hosting.Internal; +using Microsoft.Extensions.Configuration; namespace Microsoft.AspNet.Hosting { @@ -13,5 +13,7 @@ namespace Microsoft.AspNet.Hosting public string WebRootPath { get; set; } public IFileProvider WebRootFileProvider { get; set; } + + public IConfiguration Configuration { get; set; } } } \ No newline at end of file diff --git a/src/Microsoft.AspNet.Hosting/HostingEnvironmentExtensions.cs b/src/Microsoft.AspNet.Hosting/HostingEnvironmentExtensions.cs index b6e5e8071a..6b1fd8c346 100644 --- a/src/Microsoft.AspNet.Hosting/HostingEnvironmentExtensions.cs +++ b/src/Microsoft.AspNet.Hosting/HostingEnvironmentExtensions.cs @@ -10,7 +10,7 @@ namespace Microsoft.AspNet.Hosting { public static class HostingEnvironmentExtensions { - public static void Initialize(this IHostingEnvironment hostingEnvironment, string applicationBasePath, WebHostOptions options) + public static void Initialize(this IHostingEnvironment hostingEnvironment, string applicationBasePath, WebHostOptions options, IConfiguration configuration) { if (options == null) { @@ -46,6 +46,8 @@ namespace Microsoft.AspNet.Hosting var environmentName = options.Environment; hostingEnvironment.EnvironmentName = environmentName ?? hostingEnvironment.EnvironmentName; + + hostingEnvironment.Configuration = configuration; } } } \ No newline at end of file diff --git a/src/Microsoft.AspNet.Hosting/WebHostBuilder.cs b/src/Microsoft.AspNet.Hosting/WebHostBuilder.cs index 9ad73e964a..bc7e0c7883 100644 --- a/src/Microsoft.AspNet.Hosting/WebHostBuilder.cs +++ b/src/Microsoft.AspNet.Hosting/WebHostBuilder.cs @@ -126,7 +126,7 @@ namespace Microsoft.AspNet.Hosting var appEnvironment = hostingContainer.GetRequiredService(); var startupLoader = hostingContainer.GetRequiredService(); - _hostingEnvironment.Initialize(appEnvironment.ApplicationBasePath, _options); + _hostingEnvironment.Initialize(appEnvironment.ApplicationBasePath, _options, _config); if (!string.IsNullOrEmpty(_environmentName)) { _hostingEnvironment.EnvironmentName = _environmentName; diff --git a/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs b/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs index a31fbd5d43..1268e981fe 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs @@ -144,6 +144,24 @@ namespace Microsoft.AspNet.Hosting Assert.Equal("http://localhost:5000", app.ServerFeatures.Get().Addresses.First()); } + [Fact] + public void FlowsConfig() + { + var vals = new Dictionary + { + { "Server", "Microsoft.AspNet.Hosting.Tests" } + }; + + var builder = new ConfigurationBuilder() + .AddInMemoryCollection(vals); + var config = builder.Build(); + var host = CreateBuilder(config).Build(); + var app = host.Start(); + var hostingEnvironment = host.ApplicationServices.GetRequiredService(); + Assert.NotNull(hostingEnvironment.Configuration); + Assert.Equal("Microsoft.AspNet.Hosting.Tests", hostingEnvironment.Configuration["Server"]); + } + [Fact] public void HostingEngineCanBeStarted() { From 73fd257844b6177680f1ccb3dcf3317caf813632 Mon Sep 17 00:00:00 2001 From: John Luo Date: Thu, 19 Nov 2015 09:35:23 -0800 Subject: [PATCH 450/987] Reacting to ApplicationServices removal from HttpContext --- .../Internal/HostingEngine.cs | 2 - .../RequestServicesContainerFeature.cs | 20 +------ .../TestServerTests.cs | 58 ++----------------- 3 files changed, 7 insertions(+), 73 deletions(-) diff --git a/src/Microsoft.AspNet.Hosting/Internal/HostingEngine.cs b/src/Microsoft.AspNet.Hosting/Internal/HostingEngine.cs index 2a5ef5f534..4a796b6e6f 100644 --- a/src/Microsoft.AspNet.Hosting/Internal/HostingEngine.cs +++ b/src/Microsoft.AspNet.Hosting/Internal/HostingEngine.cs @@ -96,8 +96,6 @@ namespace Microsoft.AspNet.Hosting.Internal Server.Start( async httpContext => { - httpContext.ApplicationServices = _applicationServices; - if (diagnosticSource.IsEnabled("Microsoft.AspNet.Hosting.BeginRequest")) { diagnosticSource.Write("Microsoft.AspNet.Hosting.BeginRequest", new { httpContext = httpContext }); diff --git a/src/Microsoft.AspNet.Hosting/Internal/RequestServicesContainerFeature.cs b/src/Microsoft.AspNet.Hosting/Internal/RequestServicesContainerFeature.cs index 0de3d46ac6..455be554b4 100644 --- a/src/Microsoft.AspNet.Hosting/Internal/RequestServicesContainerFeature.cs +++ b/src/Microsoft.AspNet.Hosting/Internal/RequestServicesContainerFeature.cs @@ -21,23 +21,7 @@ namespace Microsoft.AspNet.Hosting.Internal throw new ArgumentNullException(nameof(applicationServices)); } - ApplicationServices = applicationServices; - } - - public IServiceProvider ApplicationServices - { - get - { - return _appServices; - } - set - { - if (value == null) - { - throw new ArgumentNullException(nameof(value)); - } - _appServices = value; - } + _appServices = applicationServices; } public IServiceProvider RequestServices @@ -46,7 +30,7 @@ namespace Microsoft.AspNet.Hosting.Internal { if (!_requestServicesSet) { - _scope = ApplicationServices.GetRequiredService().CreateScope(); + _scope = _appServices.GetRequiredService().CreateScope(); _requestServices = _scope.ServiceProvider; _requestServicesSet = true; } diff --git a/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs b/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs index d34bc4f447..3116e549fa 100644 --- a/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs +++ b/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs @@ -15,7 +15,6 @@ using Microsoft.AspNet.Http.Features; using Microsoft.AspNet.Http.Features.Internal; using Microsoft.AspNet.Http.Internal; using Microsoft.AspNet.Testing.xunit; -using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using Microsoft.Extensions.DiagnosticAdapter; @@ -59,16 +58,17 @@ namespace Microsoft.AspNet.TestHost public void Configure(IApplicationBuilder app) { + var applicationServices = app.ApplicationServices; app.Run(async context => { - await context.Response.WriteAsync("ApplicationServicesEqual:" + (context.ApplicationServices == Services)); + await context.Response.WriteAsync("ApplicationServicesEqual:" + (applicationServices == Services)); }); } } [Fact] - public async Task CustomServiceProviderReplacesApplicationServices() + public async Task CustomServiceProviderSetsApplicationServices() { var server = new TestServer(TestServer.CreateBuilder().UseStartup()); string result = await server.CreateClient().GetStringAsync("/path"); @@ -124,22 +124,6 @@ namespace Microsoft.AspNet.TestHost Assert.Equal("Found:True", result); } - [Fact] - public async Task SettingApplicationServicesOnFeatureToNullThrows() - { - var server = TestServer.Create(app => - { - app.Run(context => - { - var feature = context.Features.Get(); - Assert.Throws(() => feature.ApplicationServices = null); - return context.Response.WriteAsync("Success"); - }); - }); - string result = await server.CreateClient().GetStringAsync("/path"); - Assert.Equal("Success", result); - } - [Fact] public async Task CanSetCustomServiceProvider() { @@ -147,16 +131,11 @@ namespace Microsoft.AspNet.TestHost { app.Run(context => { - context.ApplicationServices = new ServiceCollection() - .AddTransient() - .BuildServiceProvider(); - context.RequestServices = new ServiceCollection() .AddTransient() .BuildServiceProvider(); - - var s1 = context.ApplicationServices.GetRequiredService(); - var s2 = context.RequestServices.GetRequiredService(); + + var s = context.RequestServices.GetRequiredService(); return context.Response.WriteAsync("Success"); }); @@ -199,7 +178,6 @@ namespace Microsoft.AspNet.TestHost { app.Run(context => { - Assert.Equal(appServices, context.ApplicationServices); Assert.Equal(appServices, context.RequestServices); return context.Response.WriteAsync("Success"); }); @@ -236,7 +214,6 @@ namespace Microsoft.AspNet.TestHost { app.Run(context => { - Assert.NotNull(context.ApplicationServices); Assert.NotNull(context.RequestServices); return context.Response.WriteAsync("Success"); }); @@ -246,31 +223,6 @@ namespace Microsoft.AspNet.TestHost Assert.Equal("Success", result); } - - public class EnsureApplicationServicesFilter : IStartupFilter - { - public Action Configure(Action next) - { - return builder => - { - builder.Run(context => { - Assert.NotNull(context.ApplicationServices); - return context.Response.WriteAsync("Done"); - }); - }; - } - } - - [Fact] - public async Task ApplicationServicesShouldSetBeforeStatupFilters() - { - var server = TestServer.Create(app => { }, - services => services.AddTransient()); - string result = await server.CreateClient().GetStringAsync("/path"); - Assert.Equal("Done", result); - } - - [Fact] public async Task CanAccessLogger() { From 6a719ab95d292b55a7d5713de322c2097e818752 Mon Sep 17 00:00:00 2001 From: Pavel Krymets Date: Fri, 20 Nov 2015 09:30:00 -0800 Subject: [PATCH 451/987] Remove webroot fallback to approot --- .../HostingEnvironmentExtensions.cs | 5 +- .../HostingEnvironmentExtensions.cs | 23 +++--- .../Internal/NullFileProvider.cs | 82 +++++++++++++++++++ .../HostingEngineTests.cs | 3 + .../HostingEnvironmentExtensionsTests.cs | 71 ++++++++++++++++ .../testroot/wwwroot/README | 1 + .../TestServerTests.cs | 10 --- 7 files changed, 173 insertions(+), 22 deletions(-) create mode 100644 src/Microsoft.AspNet.Hosting/Internal/NullFileProvider.cs create mode 100644 test/Microsoft.AspNet.Hosting.Tests/HostingEnvironmentExtensionsTests.cs create mode 100644 test/Microsoft.AspNet.Hosting.Tests/testroot/wwwroot/README diff --git a/src/Microsoft.AspNet.Hosting.Abstractions/HostingEnvironmentExtensions.cs b/src/Microsoft.AspNet.Hosting.Abstractions/HostingEnvironmentExtensions.cs index c8bc3993a7..d42b40e644 100644 --- a/src/Microsoft.AspNet.Hosting.Abstractions/HostingEnvironmentExtensions.cs +++ b/src/Microsoft.AspNet.Hosting.Abstractions/HostingEnvironmentExtensions.cs @@ -91,7 +91,10 @@ namespace Microsoft.AspNet.Hosting { throw new ArgumentNullException(nameof(hostingEnvironment)); } - + if (string.IsNullOrEmpty(hostingEnvironment.WebRootPath)) + { + throw new InvalidOperationException("Can not map path because webroot path is not set"); + } if (virtualPath == null) { return hostingEnvironment.WebRootPath; diff --git a/src/Microsoft.AspNet.Hosting/HostingEnvironmentExtensions.cs b/src/Microsoft.AspNet.Hosting/HostingEnvironmentExtensions.cs index 6b1fd8c346..6b46ba7214 100644 --- a/src/Microsoft.AspNet.Hosting/HostingEnvironmentExtensions.cs +++ b/src/Microsoft.AspNet.Hosting/HostingEnvironmentExtensions.cs @@ -4,6 +4,7 @@ using System; using System.IO; using Microsoft.AspNet.FileProviders; +using Microsoft.AspNet.Hosting.Internal; using Microsoft.Extensions.Configuration; namespace Microsoft.AspNet.Hosting @@ -26,24 +27,24 @@ namespace Microsoft.AspNet.Hosting { hostingEnvironment.WebRootPath = wwwroot; } - else - { - hostingEnvironment.WebRootPath = applicationBasePath; - } } else { hostingEnvironment.WebRootPath = Path.Combine(applicationBasePath, webRoot); } - - hostingEnvironment.WebRootPath = Path.GetFullPath(hostingEnvironment.WebRootPath); - - if (!Directory.Exists(hostingEnvironment.WebRootPath)) + if (!string.IsNullOrEmpty(hostingEnvironment.WebRootPath)) { - Directory.CreateDirectory(hostingEnvironment.WebRootPath); + hostingEnvironment.WebRootPath = Path.GetFullPath(hostingEnvironment.WebRootPath); + if (!Directory.Exists(hostingEnvironment.WebRootPath)) + { + Directory.CreateDirectory(hostingEnvironment.WebRootPath); + } + hostingEnvironment.WebRootFileProvider = new PhysicalFileProvider(hostingEnvironment.WebRootPath); + } + else + { + hostingEnvironment.WebRootFileProvider = new NullFileProvider(); } - hostingEnvironment.WebRootFileProvider = new PhysicalFileProvider(hostingEnvironment.WebRootPath); - var environmentName = options.Environment; hostingEnvironment.EnvironmentName = environmentName ?? hostingEnvironment.EnvironmentName; diff --git a/src/Microsoft.AspNet.Hosting/Internal/NullFileProvider.cs b/src/Microsoft.AspNet.Hosting/Internal/NullFileProvider.cs new file mode 100644 index 0000000000..73f0bebc93 --- /dev/null +++ b/src/Microsoft.AspNet.Hosting/Internal/NullFileProvider.cs @@ -0,0 +1,82 @@ +// 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; +using System.Collections; +using System.Collections.Generic; +using System.IO; +using Microsoft.AspNet.FileProviders; +using Microsoft.Extensions.Primitives; + +namespace Microsoft.AspNet.Hosting.Internal +{ + internal class NullFileProvider : IFileProvider + { + public IDirectoryContents GetDirectoryContents(string subpath) + { + return new NullDirectoryContents(); + } + + public IFileInfo GetFileInfo(string subpath) + { + return new NullFileInfo(subpath); + } + + public IChangeToken Watch(string filter) + { + return new NullChangeToken(); + } + + private class NullDirectoryContents : IDirectoryContents + { + public bool Exists => false; + + public IEnumerator GetEnumerator() + { + yield break; + } + + IEnumerator IEnumerable.GetEnumerator() + { + return GetEnumerator(); + } + } + + internal class NullFileInfo : IFileInfo + { + public NullFileInfo(string name) + { + Name = name; + } + + public bool Exists => false; + + public bool IsDirectory => false; + + public DateTimeOffset LastModified => DateTimeOffset.MinValue; + + public long Length => -1; + + public string Name { get; } + + public string PhysicalPath => null; + + public Stream CreateReadStream() + { + throw new FileNotFoundException(string.Format($"{nameof(NullFileProvider)} does not support reading files.", Name)); + } + } + + private class NullChangeToken : IChangeToken + { + public bool HasChanged => false; + + public bool ActiveChangeCallbacks => false; + + public IDisposable RegisterChangeCallback(Action callback, object state) + { + throw new NotSupportedException($"{nameof(NullFileProvider)} does not support registering change notifications."); + } + } + } +} diff --git a/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs b/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs index 1268e981fe..2017193a16 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs @@ -464,6 +464,9 @@ namespace Microsoft.AspNet.Hosting using (engine.Start()) { var env = engine.ApplicationServices.GetRequiredService(); + // MapPath requires webroot to be set, we don't care + // about file provider so just set it here + env.WebRootPath = ""; var mappedPath = env.MapPath(virtualPath); expectedSuffix = expectedSuffix.Replace('/', Path.DirectorySeparatorChar); Assert.Equal(Path.Combine(env.WebRootPath, expectedSuffix), mappedPath); diff --git a/test/Microsoft.AspNet.Hosting.Tests/HostingEnvironmentExtensionsTests.cs b/test/Microsoft.AspNet.Hosting.Tests/HostingEnvironmentExtensionsTests.cs new file mode 100644 index 0000000000..44ab8996e2 --- /dev/null +++ b/test/Microsoft.AspNet.Hosting.Tests/HostingEnvironmentExtensionsTests.cs @@ -0,0 +1,71 @@ +// 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.IO; +using Microsoft.AspNet.FileProviders; +using Microsoft.AspNet.Hosting; +using Microsoft.AspNet.Hosting.Internal; +using Microsoft.Extensions.Configuration; +using Xunit; + +namespace Microsoft.AspNet.Hosting.Tests +{ + public class HostingEnvironmentExtensionsTests + { + [Fact] + public void SetsFullPathToWwwroot() + { + var env = new HostingEnvironment(); + + env.Initialize(".", new WebHostOptions() {WebRoot = "testroot"}, null); + + Assert.Equal(Path.GetFullPath("testroot"), env.WebRootPath); + Assert.IsAssignableFrom(env.WebRootFileProvider); + } + + [Fact] + public void DefaultsToWwwrootSubdir() + { + var env = new HostingEnvironment(); + + env.Initialize("testroot", new WebHostOptions(), null); + + Assert.Equal(Path.GetFullPath(Path.Combine("testroot","wwwroot")), env.WebRootPath); + Assert.IsAssignableFrom(env.WebRootFileProvider); + } + + [Fact] + public void DefaultsToNullFileProvider() + { + var env = new HostingEnvironment(); + + env.Initialize(Path.Combine("testroot", "wwwroot"), new WebHostOptions(), null); + + Assert.Null(env.WebRootPath); + Assert.IsAssignableFrom(env.WebRootFileProvider); + } + + [Fact] + public void SetsConfiguration() + { + var config = new ConfigurationBuilder().Build(); + var env = new HostingEnvironment(); + + env.Initialize(".", new WebHostOptions(), config); + + Assert.Same(config, env.Configuration); + } + + [Fact] + public void OverridesEnvironmentFromConfig() + { + var env = new HostingEnvironment(); + env.EnvironmentName = "SomeName"; + + env.Initialize(".", new WebHostOptions() { Environment = "NewName" }, null); + + Assert.Equal("NewName", env.EnvironmentName); + } + + } +} diff --git a/test/Microsoft.AspNet.Hosting.Tests/testroot/wwwroot/README b/test/Microsoft.AspNet.Hosting.Tests/testroot/wwwroot/README new file mode 100644 index 0000000000..4b906ff4a8 --- /dev/null +++ b/test/Microsoft.AspNet.Hosting.Tests/testroot/wwwroot/README @@ -0,0 +1 @@ +This file is here to keep directories needed by tests. Do no remove it. \ No newline at end of file diff --git a/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs b/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs index 3116e549fa..9ca048c9e0 100644 --- a/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs +++ b/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs @@ -305,16 +305,6 @@ namespace Microsoft.AspNet.TestHost Assert.Equal("CreateInvokesApp", result); } - [Fact] - public void WebRootCanBeResolvedWhenNotInTheConfig() - { - TestServer server = TestServer.Create(app => - { - var env = app.ApplicationServices.GetRequiredService(); - Assert.Equal(Directory.GetCurrentDirectory(), env.WebRootPath); - }); - } - [Fact] public async Task DisposeStreamIgnored() { From 6ee745f7f5f0c5c663717bfc250a546d00079298 Mon Sep 17 00:00:00 2001 From: Pavel Krymets Date: Fri, 20 Nov 2015 13:59:05 -0800 Subject: [PATCH 452/987] Fix tests --- test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs b/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs index 2017193a16..13921ba022 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs @@ -466,7 +466,7 @@ namespace Microsoft.AspNet.Hosting var env = engine.ApplicationServices.GetRequiredService(); // MapPath requires webroot to be set, we don't care // about file provider so just set it here - env.WebRootPath = ""; + env.WebRootPath = "."; var mappedPath = env.MapPath(virtualPath); expectedSuffix = expectedSuffix.Replace('/', Path.DirectorySeparatorChar); Assert.Equal(Path.Combine(env.WebRootPath, expectedSuffix), mappedPath); From 9d19a27b6b988abbd225688f1e808565a766824d Mon Sep 17 00:00:00 2001 From: Chris R Date: Fri, 20 Nov 2015 15:44:51 -0800 Subject: [PATCH 453/987] #481 Add the DNX runtime to the path when lanching test processes. --- .../Deployers/ApplicationDeployer.cs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Microsoft.AspNet.Server.Testing/Deployers/ApplicationDeployer.cs b/src/Microsoft.AspNet.Server.Testing/Deployers/ApplicationDeployer.cs index 477348f7af..df1d0bcbe3 100644 --- a/src/Microsoft.AspNet.Server.Testing/Deployers/ApplicationDeployer.cs +++ b/src/Microsoft.AspNet.Server.Testing/Deployers/ApplicationDeployer.cs @@ -2,8 +2,8 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.Collections.Generic; using System.Diagnostics; -using System.Linq; using System.IO; using System.Text; using System.Text.RegularExpressions; @@ -137,6 +137,10 @@ namespace Microsoft.AspNet.Server.Testing Logger.LogInformation($"Chosen runtime path is {ChosenRuntimePath}"); + // Work around win7 search path issues. + var newPath = ChosenRuntimePath + Path.PathSeparator + Environment.GetEnvironmentVariable("PATH"); + DeploymentParameters.EnvironmentVariables.Add(new KeyValuePair("PATH", newPath)); + return ChosenRuntimeName; } From d01c8bb1cf1433faf42f3aec61fb7cb5758e376f Mon Sep 17 00:00:00 2001 From: Chris R Date: Sat, 21 Nov 2015 21:56:34 -0800 Subject: [PATCH 454/987] #318 Move IStartupFilter to Hosting.Abstractions. --- .../IStartupFilter.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename src/{Microsoft.AspNet.Hosting/Startup => Microsoft.AspNet.Hosting.Abstractions}/IStartupFilter.cs (89%) diff --git a/src/Microsoft.AspNet.Hosting/Startup/IStartupFilter.cs b/src/Microsoft.AspNet.Hosting.Abstractions/IStartupFilter.cs similarity index 89% rename from src/Microsoft.AspNet.Hosting/Startup/IStartupFilter.cs rename to src/Microsoft.AspNet.Hosting.Abstractions/IStartupFilter.cs index 79bf34401e..f89fba525c 100644 --- a/src/Microsoft.AspNet.Hosting/Startup/IStartupFilter.cs +++ b/src/Microsoft.AspNet.Hosting.Abstractions/IStartupFilter.cs @@ -4,7 +4,7 @@ using System; using Microsoft.AspNet.Builder; -namespace Microsoft.AspNet.Hosting.Startup +namespace Microsoft.AspNet.Hosting { public interface IStartupFilter { From 82ed1a4eeede502b76c59e2f6a1e999332b99db7 Mon Sep 17 00:00:00 2001 From: Pavel Krymets Date: Mon, 23 Nov 2015 14:20:16 -0800 Subject: [PATCH 455/987] Remove single moq usage --- test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs | 8 ++++++-- test/Microsoft.AspNet.Hosting.Tests/project.json | 4 ++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs b/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs index 13921ba022..18640d122d 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs @@ -22,7 +22,6 @@ using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using Microsoft.Extensions.OptionsModel; using Microsoft.Extensions.Primitives; -using Moq; using Xunit; namespace Microsoft.AspNet.Hosting @@ -382,7 +381,7 @@ namespace Microsoft.AspNet.Hosting httpContext = innerHttpContext; return Task.FromResult(0); }); - var requestIdentifierFeature = new Mock().Object; + var requestIdentifierFeature = new StubHttpRequestIdentifierFeature(); _featuresSupportedByThisHost[typeof(IHttpRequestIdentifierFeature)] = requestIdentifierFeature; var hostingEngine = CreateHostingEngine(requestDelegate); @@ -666,5 +665,10 @@ namespace Microsoft.AspNet.Hosting IEnumerator IEnumerable.GetEnumerator() => null; } + + private class StubHttpRequestIdentifierFeature : IHttpRequestIdentifierFeature + { + public string TraceIdentifier { get; set; } + } } } diff --git a/test/Microsoft.AspNet.Hosting.Tests/project.json b/test/Microsoft.AspNet.Hosting.Tests/project.json index f00e2281e0..07b3452630 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/project.json +++ b/test/Microsoft.AspNet.Hosting.Tests/project.json @@ -9,11 +9,11 @@ "Microsoft.AspNet.Testing": "1.0.0-*", "Microsoft.Extensions.OptionsModel": "1.0.0-*", "Microsoft.Extensions.PlatformAbstractions": "1.0.0-*", - "Moq": "4.2.1312.1622", "xunit.runner.aspnet": "2.0.0-aspnet-*" }, "frameworks": { - "dnx451": {} + "dnx451": { }, + "dnxcore50": { } }, "commands": { "test": "xunit.runner.aspnet" From f600604140e048df7671fa6e196791492ecacbe1 Mon Sep 17 00:00:00 2001 From: Pavel Krymets Date: Mon, 30 Nov 2015 10:49:59 -0800 Subject: [PATCH 456/987] Add tests for map path without wwwroot, and typos --- .../HostingEnvironmentExtensions.cs | 2 +- .../HostingEnvironmentExtensionsTests.cs | 11 +++++++++++ .../testroot/wwwroot/README | 2 +- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/Microsoft.AspNet.Hosting.Abstractions/HostingEnvironmentExtensions.cs b/src/Microsoft.AspNet.Hosting.Abstractions/HostingEnvironmentExtensions.cs index d42b40e644..05cf2c9ceb 100644 --- a/src/Microsoft.AspNet.Hosting.Abstractions/HostingEnvironmentExtensions.cs +++ b/src/Microsoft.AspNet.Hosting.Abstractions/HostingEnvironmentExtensions.cs @@ -93,7 +93,7 @@ namespace Microsoft.AspNet.Hosting } if (string.IsNullOrEmpty(hostingEnvironment.WebRootPath)) { - throw new InvalidOperationException("Can not map path because webroot path is not set"); + throw new InvalidOperationException("Cannot map path because webroot path is not set"); } if (virtualPath == null) { diff --git a/test/Microsoft.AspNet.Hosting.Tests/HostingEnvironmentExtensionsTests.cs b/test/Microsoft.AspNet.Hosting.Tests/HostingEnvironmentExtensionsTests.cs index 44ab8996e2..727130ded8 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/HostingEnvironmentExtensionsTests.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/HostingEnvironmentExtensionsTests.cs @@ -1,6 +1,7 @@ // 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; using System.IO; using Microsoft.AspNet.FileProviders; using Microsoft.AspNet.Hosting; @@ -67,5 +68,15 @@ namespace Microsoft.AspNet.Hosting.Tests Assert.Equal("NewName", env.EnvironmentName); } + [Fact] + public void MapPathThrowsWithNoWwwroot() + { + var env = new HostingEnvironment(); + + env.Initialize(".", new WebHostOptions(), null); + + Assert.Throws(() => env.MapPath("file.txt")); + } + } } diff --git a/test/Microsoft.AspNet.Hosting.Tests/testroot/wwwroot/README b/test/Microsoft.AspNet.Hosting.Tests/testroot/wwwroot/README index 4b906ff4a8..d3415c9f70 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/testroot/wwwroot/README +++ b/test/Microsoft.AspNet.Hosting.Tests/testroot/wwwroot/README @@ -1 +1 @@ -This file is here to keep directories needed by tests. Do no remove it. \ No newline at end of file +This file is here to keep directories needed by tests. Do not remove it. \ No newline at end of file From 8c256a0d8718a1adccc2e6af283a232b4b6bcfc5 Mon Sep 17 00:00:00 2001 From: John Luo Date: Mon, 2 Nov 2015 13:55:44 -0800 Subject: [PATCH 457/987] New IServer design with IHttpApplication added #395 --- .../IHttpApplication.cs | 35 +++++++ .../IServer.cs | 7 +- .../Internal/HostingApplication.cs | 91 +++++++++++++++++++ .../Internal/HostingEngine.cs | 39 +------- .../Internal/HostingLoggerExtensions.cs | 63 +------------ .../Internal/LoggerEventIds.cs | 9 +- .../WebHostBuilder.cs | 1 - .../ClientHandler.cs | 69 +++++++------- src/Microsoft.AspNet.TestHost/TestServer.cs | 56 ++++++++---- .../WebSocketClient.cs | 63 +++++++------ .../HostingEngineTests.cs | 24 ++--- .../WebHostBuilderTests.cs | 18 +++- .../ClientHandlerTests.cs | 78 +++++++++++----- .../TestServerTests.cs | 9 +- 14 files changed, 332 insertions(+), 230 deletions(-) create mode 100644 src/Microsoft.AspNet.Hosting.Server.Abstractions/IHttpApplication.cs create mode 100644 src/Microsoft.AspNet.Hosting/Internal/HostingApplication.cs diff --git a/src/Microsoft.AspNet.Hosting.Server.Abstractions/IHttpApplication.cs b/src/Microsoft.AspNet.Hosting.Server.Abstractions/IHttpApplication.cs new file mode 100644 index 0000000000..07cbe53f82 --- /dev/null +++ b/src/Microsoft.AspNet.Hosting.Server.Abstractions/IHttpApplication.cs @@ -0,0 +1,35 @@ +// 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; +using System.Threading.Tasks; +using Microsoft.AspNet.Http.Features; + +namespace Microsoft.AspNet.Hosting.Server +{ + /// + /// Represents an HttpApplication. + /// + public interface IHttpApplication + { + /// + /// Create a TContext given a collection of HTTP features. + /// + /// A collection of HTTP features to be used for creating the TContext. + /// The created TContext. + TContext CreateContext(IFeatureCollection contextFeatures); + + /// + /// Asynchronously processes an TContext. + /// + /// The TContext that the operation will process. + Task ProcessRequestAsync(TContext context); + + /// + /// Dispose a given TContext. + /// + /// The TContext to be disposed. + /// The Exception thrown when processing did not complete successfully, otherwise null. + void DisposeContext(TContext context, Exception exception); + } +} diff --git a/src/Microsoft.AspNet.Hosting.Server.Abstractions/IServer.cs b/src/Microsoft.AspNet.Hosting.Server.Abstractions/IServer.cs index c6909990d0..cc1a88d519 100644 --- a/src/Microsoft.AspNet.Hosting.Server.Abstractions/IServer.cs +++ b/src/Microsoft.AspNet.Hosting.Server.Abstractions/IServer.cs @@ -2,7 +2,6 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using Microsoft.AspNet.Http; using Microsoft.AspNet.Http.Features; namespace Microsoft.AspNet.Hosting.Server @@ -18,9 +17,9 @@ namespace Microsoft.AspNet.Hosting.Server IFeatureCollection Features { get; } /// - /// Start the server with the given function that processes an HTTP request. + /// Start the server with an HttpApplication. /// - /// A function that processes an HTTP request. - void Start(RequestDelegate requestDelegate); + /// An instance of . + void Start(IHttpApplication application); } } diff --git a/src/Microsoft.AspNet.Hosting/Internal/HostingApplication.cs b/src/Microsoft.AspNet.Hosting/Internal/HostingApplication.cs new file mode 100644 index 0000000000..c5b74dca72 --- /dev/null +++ b/src/Microsoft.AspNet.Hosting/Internal/HostingApplication.cs @@ -0,0 +1,91 @@ +// 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; +using System.Diagnostics; +using System.Threading.Tasks; +using Microsoft.AspNet.Hosting.Server; +using Microsoft.AspNet.Http; +using Microsoft.AspNet.Http.Features; +using Microsoft.Extensions.Logging; + +namespace Microsoft.AspNet.Hosting.Internal +{ + public class HostingApplication : IHttpApplication + { + private readonly RequestDelegate _application; + private readonly ILogger _logger; + private readonly DiagnosticSource _diagnosticSource; + private readonly IHttpContextFactory _httpContextFactory; + + public HostingApplication( + RequestDelegate application, + ILogger logger, + DiagnosticSource diagnosticSource, + IHttpContextFactory httpContextFactory) + { + _application = application; + _logger = logger; + _diagnosticSource = diagnosticSource; + _httpContextFactory = httpContextFactory; + } + + public Context CreateContext(IFeatureCollection contextFeatures) + { + var httpContext = _httpContextFactory.Create(contextFeatures); + var startTick = Environment.TickCount; + + var scope = _logger.RequestScope(httpContext); + _logger.RequestStarting(httpContext); + if (_diagnosticSource.IsEnabled("Microsoft.AspNet.Hosting.BeginRequest")) + { + _diagnosticSource.Write("Microsoft.AspNet.Hosting.BeginRequest", new { httpContext = httpContext, tickCount = startTick }); + } + + return new Context + { + HttpContext = httpContext, + Scope = scope, + StartTick = startTick, + }; + } + + public void DisposeContext(Context context, Exception exception) + { + var httpContext = context.HttpContext; + var currentTick = Environment.TickCount; + _logger.RequestFinished(httpContext, context.StartTick, currentTick); + + if (exception == null) + { + if (_diagnosticSource.IsEnabled("Microsoft.AspNet.Hosting.EndRequest")) + { + _diagnosticSource.Write("Microsoft.AspNet.Hosting.EndRequest", new { httpContext = httpContext, tickCount = currentTick }); + } + } + else + { + if (_diagnosticSource.IsEnabled("Microsoft.AspNet.Hosting.UnhandledException")) + { + _diagnosticSource.Write("Microsoft.AspNet.Hosting.UnhandledException", new { httpContext = httpContext, tickCount = currentTick, exception = exception }); + } + } + + context.Scope.Dispose(); + + _httpContextFactory.Dispose(httpContext); + } + + public async Task ProcessRequestAsync(Context context) + { + await _application(context.HttpContext); + } + + public struct Context + { + public HttpContext HttpContext { get; set; } + public IDisposable Scope { get; set; } + public int StartTick { get; set; } + } + } +} diff --git a/src/Microsoft.AspNet.Hosting/Internal/HostingEngine.cs b/src/Microsoft.AspNet.Hosting/Internal/HostingEngine.cs index 4a796b6e6f..2d232995ee 100644 --- a/src/Microsoft.AspNet.Hosting/Internal/HostingEngine.cs +++ b/src/Microsoft.AspNet.Hosting/Internal/HostingEngine.cs @@ -6,7 +6,6 @@ using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Threading; -using Microsoft.AspNet.Builder; using Microsoft.AspNet.Hosting.Builder; using Microsoft.AspNet.Hosting.Server; using Microsoft.AspNet.Hosting.Startup; @@ -90,45 +89,11 @@ namespace Microsoft.AspNet.Hosting.Internal var logger = _applicationServices.GetRequiredService>(); var diagnosticSource = _applicationServices.GetRequiredService(); + var httpContextFactory = _applicationServices.GetRequiredService(); logger.Starting(); - Server.Start( - async httpContext => - { - if (diagnosticSource.IsEnabled("Microsoft.AspNet.Hosting.BeginRequest")) - { - diagnosticSource.Write("Microsoft.AspNet.Hosting.BeginRequest", new { httpContext = httpContext }); - } - - using (logger.RequestScope(httpContext)) - { - int startTime = 0; - try - { - logger.RequestStarting(httpContext); - - startTime = Environment.TickCount; - await application(httpContext); - - logger.RequestFinished(httpContext, startTime); - } - catch (Exception ex) - { - logger.RequestFailed(httpContext, startTime); - - if (diagnosticSource.IsEnabled("Microsoft.AspNet.Hosting.UnhandledException")) - { - diagnosticSource.Write("Microsoft.AspNet.Hosting.UnhandledException", new { httpContext = httpContext, exception = ex }); - } - throw; - } - } - if (diagnosticSource.IsEnabled("Microsoft.AspNet.Hosting.EndRequest")) - { - diagnosticSource.Write("Microsoft.AspNet.Hosting.EndRequest", new { httpContext = httpContext }); - } - }); + Server.Start(new HostingApplication(application, logger, diagnosticSource, httpContextFactory)); _applicationLifetime.NotifyStarted(); logger.Started(); diff --git a/src/Microsoft.AspNet.Hosting/Internal/HostingLoggerExtensions.cs b/src/Microsoft.AspNet.Hosting/Internal/HostingLoggerExtensions.cs index 67f9f114ff..3730736d0b 100644 --- a/src/Microsoft.AspNet.Hosting/Internal/HostingLoggerExtensions.cs +++ b/src/Microsoft.AspNet.Hosting/Internal/HostingLoggerExtensions.cs @@ -30,11 +30,14 @@ namespace Microsoft.AspNet.Hosting.Internal } } - public static void RequestFinished(this ILogger logger, HttpContext httpContext, int startTimeInTicks) + public static void RequestFinished(this ILogger logger, HttpContext httpContext, int startTimeInTicks, int currentTick) { if (logger.IsEnabled(LogLevel.Information)) { - var elapsed = new TimeSpan(TicksPerMillisecond * (Environment.TickCount - startTimeInTicks)); + var elapsed = new TimeSpan(TicksPerMillisecond * (currentTick < startTimeInTicks ? + (int.MaxValue - startTimeInTicks) + (currentTick - int.MinValue) : + currentTick - startTimeInTicks)); + logger.Log( logLevel: LogLevel.Information, eventId: LoggerEventIds.RequestFinished, @@ -44,20 +47,6 @@ namespace Microsoft.AspNet.Hosting.Internal } } - public static void RequestFailed(this ILogger logger, HttpContext httpContext, int startTimeInTicks) - { - if (logger.IsEnabled(LogLevel.Information)) - { - var elapsed = new TimeSpan(TicksPerMillisecond * (Environment.TickCount - startTimeInTicks)); - logger.Log( - logLevel: LogLevel.Information, - eventId: LoggerEventIds.RequestFailed, - state: new HostingRequestFailed(httpContext, elapsed), - exception: null, - formatter: HostingRequestFailed.Callback); - } - } - public static void ApplicationError(this ILogger logger, Exception exception) { logger.LogError( @@ -221,48 +210,6 @@ namespace Microsoft.AspNet.Hosting.Internal return _cachedGetValues; } } - - private class HostingRequestFailed - { - internal static readonly Func Callback = (state, exception) => ((HostingRequestFailed)state).ToString(); - - private readonly HttpContext _httpContext; - private readonly TimeSpan _elapsed; - - private IEnumerable> _cachedGetValues; - private string _cachedToString; - - public HostingRequestFailed(HttpContext httpContext, TimeSpan elapsed) - { - _httpContext = httpContext; - _elapsed = elapsed; - } - - public override string ToString() - { - if (_cachedToString == null) - { - _cachedToString = $"Request finished in {_elapsed.TotalMilliseconds}ms 500"; - } - - return _cachedToString; - } - - public IEnumerable> GetValues() - { - if (_cachedGetValues == null) - { - _cachedGetValues = new[] - { - new KeyValuePair("ElapsedMilliseconds", _elapsed.TotalMilliseconds), - new KeyValuePair("StatusCode", 500), - new KeyValuePair("ContentType", null), - }; - } - - return _cachedGetValues; - } - } } } diff --git a/src/Microsoft.AspNet.Hosting/Internal/LoggerEventIds.cs b/src/Microsoft.AspNet.Hosting/Internal/LoggerEventIds.cs index 9bc4a4affe..0b23c81e2a 100644 --- a/src/Microsoft.AspNet.Hosting/Internal/LoggerEventIds.cs +++ b/src/Microsoft.AspNet.Hosting/Internal/LoggerEventIds.cs @@ -7,10 +7,9 @@ namespace Microsoft.AspNet.Hosting.Internal { public const int RequestStarting = 1; public const int RequestFinished = 2; - public const int RequestFailed = 3; - public const int Starting = 4; - public const int Started = 5; - public const int Shutdown = 6; - public const int ApplicationStartupException = 7; + public const int Starting = 3; + public const int Started = 4; + public const int Shutdown = 5; + public const int ApplicationStartupException = 6; } } diff --git a/src/Microsoft.AspNet.Hosting/WebHostBuilder.cs b/src/Microsoft.AspNet.Hosting/WebHostBuilder.cs index bc7e0c7883..309d9eff71 100644 --- a/src/Microsoft.AspNet.Hosting/WebHostBuilder.cs +++ b/src/Microsoft.AspNet.Hosting/WebHostBuilder.cs @@ -10,7 +10,6 @@ using Microsoft.AspNet.Hosting.Server; using Microsoft.AspNet.Hosting.Startup; using Microsoft.AspNet.Http; using Microsoft.AspNet.Http.Internal; -using Microsoft.Extensions.CompilationAbstractions; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection.Extensions; diff --git a/src/Microsoft.AspNet.TestHost/ClientHandler.cs b/src/Microsoft.AspNet.TestHost/ClientHandler.cs index 78e3463bc6..200dc5db9a 100644 --- a/src/Microsoft.AspNet.TestHost/ClientHandler.cs +++ b/src/Microsoft.AspNet.TestHost/ClientHandler.cs @@ -11,9 +11,10 @@ using System.Net; using System.Net.Http; using System.Threading; using System.Threading.Tasks; +using Microsoft.AspNet.Hosting.Server; using Microsoft.AspNet.Http; using Microsoft.AspNet.Http.Features; -using Microsoft.AspNet.Http.Internal; +using Context = Microsoft.AspNet.Hosting.Internal.HostingApplication.Context; namespace Microsoft.AspNet.TestHost { @@ -23,27 +24,21 @@ namespace Microsoft.AspNet.TestHost /// public class ClientHandler : HttpMessageHandler { - private readonly RequestDelegate _next; + private readonly IHttpApplication _application; private readonly PathString _pathBase; - private readonly IHttpContextFactory _factory; /// /// Create a new handler. /// /// The pipeline entry point. - public ClientHandler(RequestDelegate next, PathString pathBase, IHttpContextFactory httpContextFactory) + public ClientHandler(PathString pathBase, IHttpApplication application) { - if (next == null) + if (application == null) { - throw new ArgumentNullException(nameof(next)); + throw new ArgumentNullException(nameof(application)); } - if (httpContextFactory == null) - { - throw new ArgumentNullException(nameof(httpContextFactory)); - } - - _next = next; - _factory = httpContextFactory; + + _application = application; // PathString.StartsWithSegments that we use below requires the base path to not end in a slash. if (pathBase.HasValue && pathBase.Value.EndsWith("/")) @@ -69,7 +64,7 @@ namespace Microsoft.AspNet.TestHost throw new ArgumentNullException(nameof(request)); } - var state = new RequestState(request, _pathBase, _factory); + var state = new RequestState(request, _pathBase, _application); var requestContent = request.Content ?? new StreamContent(Stream.Null); var body = await requestContent.ReadAsStreamAsync(); if (body.CanSeek) @@ -77,7 +72,7 @@ namespace Microsoft.AspNet.TestHost // This body may have been consumed before, rewind it. body.Seek(0, SeekOrigin.Begin); } - state.HttpContext.Request.Body = body; + state.Context.HttpContext.Request.Body = body; var registration = cancellationToken.Register(state.AbortRequest); // Async offload, don't let the test code block the caller. @@ -85,16 +80,17 @@ namespace Microsoft.AspNet.TestHost { try { - await _next(state.HttpContext); + await _application.ProcessRequestAsync(state.Context); state.CompleteResponse(); + state.ServerCleanup(exception: null); } catch (Exception ex) { state.Abort(ex); + state.ServerCleanup(ex); } finally { - state.ServerCleanup(); registration.Dispose(); } }); @@ -105,20 +101,20 @@ namespace Microsoft.AspNet.TestHost private class RequestState { private readonly HttpRequestMessage _request; + private readonly IHttpApplication _application; private TaskCompletionSource _responseTcs; private ResponseStream _responseStream; private ResponseFeature _responseFeature; private CancellationTokenSource _requestAbortedSource; - private IHttpContextFactory _factory; private bool _pipelineFinished; - internal RequestState(HttpRequestMessage request, PathString pathBase, IHttpContextFactory factory) + internal RequestState(HttpRequestMessage request, PathString pathBase, IHttpApplication application) { _request = request; + _application = application; _responseTcs = new TaskCompletionSource(); _requestAbortedSource = new CancellationTokenSource(); _pipelineFinished = false; - _factory = factory; if (request.RequestUri.IsDefaultPort) { @@ -129,12 +125,13 @@ namespace Microsoft.AspNet.TestHost request.Headers.Host = request.RequestUri.GetComponents(UriComponents.HostAndPort, UriFormat.UriEscaped); } - HttpContext = _factory.Create(new FeatureCollection()); - - HttpContext.Features.Set(new RequestFeature()); + Context = application.CreateContext(new FeatureCollection()); + var httpContext = Context.HttpContext; + + httpContext.Features.Set(new RequestFeature()); _responseFeature = new ResponseFeature(); - HttpContext.Features.Set(_responseFeature); - var serverRequest = HttpContext.Request; + httpContext.Features.Set(_responseFeature); + var serverRequest = httpContext.Request; serverRequest.Protocol = "HTTP/" + request.Version.ToString(2); serverRequest.Scheme = request.RequestUri.Scheme; serverRequest.Method = request.Method.ToString(); @@ -168,12 +165,12 @@ namespace Microsoft.AspNet.TestHost } _responseStream = new ResponseStream(ReturnResponseMessage, AbortRequest); - HttpContext.Response.Body = _responseStream; - HttpContext.Response.StatusCode = 200; - HttpContext.RequestAborted = _requestAbortedSource.Token; + httpContext.Response.Body = _responseStream; + httpContext.Response.StatusCode = 200; + httpContext.RequestAborted = _requestAbortedSource.Token; } - public HttpContext HttpContext { get; private set; } + public Context Context { get; private set; } public Task ResponseTask { @@ -212,16 +209,17 @@ namespace Microsoft.AspNet.TestHost private HttpResponseMessage GenerateResponse() { _responseFeature.FireOnSendingHeaders(); + var httpContext = Context.HttpContext; var response = new HttpResponseMessage(); - response.StatusCode = (HttpStatusCode)HttpContext.Response.StatusCode; - response.ReasonPhrase = HttpContext.Features.Get().ReasonPhrase; + response.StatusCode = (HttpStatusCode)httpContext.Response.StatusCode; + response.ReasonPhrase = httpContext.Features.Get().ReasonPhrase; response.RequestMessage = _request; // response.Version = owinResponse.Protocol; response.Content = new StreamContent(_responseStream); - foreach (var header in HttpContext.Response.Headers) + foreach (var header in httpContext.Response.Headers) { if (!response.Headers.TryAddWithoutValidation(header.Key, (IEnumerable)header.Value)) { @@ -239,12 +237,9 @@ namespace Microsoft.AspNet.TestHost _responseTcs.TrySetException(exception); } - internal void ServerCleanup() + internal void ServerCleanup(Exception exception) { - if (HttpContext != null) - { - _factory.Dispose(HttpContext); - } + _application.DisposeContext(Context, exception); } } } diff --git a/src/Microsoft.AspNet.TestHost/TestServer.cs b/src/Microsoft.AspNet.TestHost/TestServer.cs index cd354c3eba..efeefac128 100644 --- a/src/Microsoft.AspNet.TestHost/TestServer.cs +++ b/src/Microsoft.AspNet.TestHost/TestServer.cs @@ -11,6 +11,7 @@ using Microsoft.AspNet.Http; using Microsoft.AspNet.Http.Features; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; +using Context = Microsoft.AspNet.Hosting.Internal.HostingApplication.Context; namespace Microsoft.AspNet.TestHost { @@ -18,15 +19,13 @@ namespace Microsoft.AspNet.TestHost { private const string DefaultEnvironmentName = "Development"; private const string ServerName = nameof(TestServer); - private RequestDelegate _appDelegate; private IDisposable _appInstance; private bool _disposed = false; - private IHttpContextFactory _httpContextFactory; + private IHttpApplication _application; public TestServer(WebHostBuilder builder) { var hostingEngine = builder.UseServer(this).Build(); - _httpContextFactory = hostingEngine.ApplicationServices.GetService(); _appInstance = hostingEngine.Start(); } @@ -99,7 +98,7 @@ namespace Microsoft.AspNet.TestHost public HttpMessageHandler CreateHandler() { var pathBase = BaseAddress == null ? PathString.Empty : PathString.FromUriComponent(BaseAddress); - return new ClientHandler(Invoke, pathBase, _httpContextFactory); + return new ClientHandler(pathBase, _application); } public HttpClient CreateClient() @@ -110,7 +109,7 @@ namespace Microsoft.AspNet.TestHost public WebSocketClient CreateWebSocketClient() { var pathBase = BaseAddress == null ? PathString.Empty : PathString.FromUriComponent(BaseAddress); - return new WebSocketClient(Invoke, pathBase, _httpContextFactory); + return new WebSocketClient(pathBase, _application); } /// @@ -123,24 +122,49 @@ namespace Microsoft.AspNet.TestHost return new RequestBuilder(this, path); } - public Task Invoke(HttpContext context) - { - if (_disposed) - { - throw new ObjectDisposedException(GetType().FullName); - } - return _appDelegate(context); - } - public void Dispose() { _disposed = true; _appInstance.Dispose(); } - void IServer.Start(RequestDelegate requestDelegate) + void IServer.Start(IHttpApplication application) { - _appDelegate = requestDelegate; + _application = new ApplicationWrapper((IHttpApplication)application, () => + { + if (_disposed) + { + throw new ObjectDisposedException(GetType().FullName); + } + }); + } + + private class ApplicationWrapper : IHttpApplication + { + IHttpApplication _application; + Action _preProcessRequestAsync; + + public ApplicationWrapper(IHttpApplication application, Action preProcessRequestAsync) + { + _application = application; + _preProcessRequestAsync = preProcessRequestAsync; + } + + public TContext CreateContext(IFeatureCollection contextFeatures) + { + return _application.CreateContext(contextFeatures); + } + + public void DisposeContext(TContext context, Exception exception) + { + _application.DisposeContext(context, exception); + } + + public Task ProcessRequestAsync(TContext context) + { + _preProcessRequestAsync(); + return _application.ProcessRequestAsync(context); + } } } } \ No newline at end of file diff --git a/src/Microsoft.AspNet.TestHost/WebSocketClient.cs b/src/Microsoft.AspNet.TestHost/WebSocketClient.cs index 320f43afe8..8c9da7e11b 100644 --- a/src/Microsoft.AspNet.TestHost/WebSocketClient.cs +++ b/src/Microsoft.AspNet.TestHost/WebSocketClient.cs @@ -8,31 +8,26 @@ using System.Net.WebSockets; using System.Security.Cryptography; using System.Threading; using System.Threading.Tasks; +using Microsoft.AspNet.Hosting.Server; using Microsoft.AspNet.Http; using Microsoft.AspNet.Http.Features; -using Microsoft.AspNet.Http.Internal; +using Context = Microsoft.AspNet.Hosting.Internal.HostingApplication.Context; namespace Microsoft.AspNet.TestHost { public class WebSocketClient { - private readonly RequestDelegate _next; + private readonly IHttpApplication _application; private readonly PathString _pathBase; - private readonly IHttpContextFactory _httpContextFactory; - internal WebSocketClient(RequestDelegate next, PathString pathBase, IHttpContextFactory httpContextFactory) + internal WebSocketClient(PathString pathBase, IHttpApplication application) { - if (next == null) + if (application == null) { - throw new ArgumentNullException(nameof(next)); + throw new ArgumentNullException(nameof(application)); } - if (httpContextFactory == null) - { - throw new ArgumentNullException(nameof(httpContextFactory)); - } - - _next = next; - _httpContextFactory = httpContextFactory; + + _application = application; // PathString.StartsWithSegments that we use below requires the base path to not end in a slash. if (pathBase.HasValue && pathBase.Value.EndsWith("/")) @@ -58,11 +53,11 @@ namespace Microsoft.AspNet.TestHost public async Task ConnectAsync(Uri uri, CancellationToken cancellationToken) { - var state = new RequestState(uri, _pathBase, cancellationToken, _httpContextFactory); + var state = new RequestState(uri, _pathBase, cancellationToken, _application); if (ConfigureRequest != null) { - ConfigureRequest(state.HttpContext.Request); + ConfigureRequest(state.Context.HttpContext.Request); } // Async offload, don't let the test code block the caller. @@ -70,12 +65,14 @@ namespace Microsoft.AspNet.TestHost { try { - await _next(state.HttpContext); + await _application.ProcessRequestAsync(state.Context); state.PipelineComplete(); + state.ServerCleanup(exception: null); } catch (Exception ex) { state.PipelineFailed(ex); + state.ServerCleanup(ex); } finally { @@ -88,24 +85,25 @@ namespace Microsoft.AspNet.TestHost private class RequestState : IDisposable, IHttpWebSocketFeature { + private readonly IHttpApplication _application; private TaskCompletionSource _clientWebSocketTcs; private WebSocket _serverWebSocket; - private IHttpContextFactory _factory; - public HttpContext HttpContext { get; private set; } + public Context Context { get; private set; } public Task WebSocketTask { get { return _clientWebSocketTcs.Task; } } - public RequestState(Uri uri, PathString pathBase, CancellationToken cancellationToken, IHttpContextFactory factory) + public RequestState(Uri uri, PathString pathBase, CancellationToken cancellationToken, IHttpApplication application) { - _factory = factory; _clientWebSocketTcs = new TaskCompletionSource(); + _application = application; // HttpContext - HttpContext = _factory.Create(new FeatureCollection()); + Context = _application.CreateContext(new FeatureCollection()); + var httpContext = Context.HttpContext; // Request - HttpContext.Features.Set(new RequestFeature()); - var request = HttpContext.Request; + httpContext.Features.Set(new RequestFeature()); + var request = httpContext.Request; request.Protocol = "HTTP/1.1"; var scheme = uri.Scheme; scheme = (scheme == "ws") ? "http" : scheme; @@ -132,18 +130,18 @@ namespace Microsoft.AspNet.TestHost request.Body = Stream.Null; // Response - HttpContext.Features.Set(new ResponseFeature()); - var response = HttpContext.Response; + httpContext.Features.Set(new ResponseFeature()); + var response = httpContext.Response; response.Body = Stream.Null; response.StatusCode = 200; // WebSocket - HttpContext.Features.Set(this); + httpContext.Features.Set(this); } public void PipelineComplete() { - PipelineFailed(new InvalidOperationException("Incomplete handshake, status code: " + HttpContext.Response.StatusCode)); + PipelineFailed(new InvalidOperationException("Incomplete handshake, status code: " + Context.HttpContext.Response.StatusCode)); } public void PipelineFailed(Exception ex) @@ -153,16 +151,17 @@ namespace Microsoft.AspNet.TestHost public void Dispose() { - if (HttpContext != null) - { - _factory.Dispose(HttpContext); - } if (_serverWebSocket != null) { _serverWebSocket.Dispose(); } } + internal void ServerCleanup(Exception exception) + { + _application.DisposeContext(Context, exception); + } + private string CreateRequestKey() { byte[] data = new byte[16]; @@ -181,7 +180,7 @@ namespace Microsoft.AspNet.TestHost Task IHttpWebSocketFeature.AcceptAsync(WebSocketAcceptContext context) { - HttpContext.Response.StatusCode = 101; // Switching Protocols + Context.HttpContext.Response.StatusCode = 101; // Switching Protocols var websockets = TestWebSocket.CreatePair(context.SubProtocol); _clientWebSocketTcs.SetResult(websockets.Item1); diff --git a/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs b/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs index 18640d122d..da2dd15336 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs @@ -14,7 +14,6 @@ using Microsoft.AspNet.Hosting.Server; using Microsoft.AspNet.Hosting.Startup; using Microsoft.AspNet.Http; using Microsoft.AspNet.Http.Features; -using Microsoft.AspNet.Http.Internal; using Microsoft.AspNet.Server.Features; using Microsoft.AspNet.Testing.xunit; using Microsoft.Extensions.Configuration; @@ -477,11 +476,21 @@ namespace Microsoft.AspNet.Hosting return new WebHostBuilder(config ?? new ConfigurationBuilder().Build()); } - public void Start(RequestDelegate requestDelegate) + public void Start(IHttpApplication application) { - var startInstance = new StartInstance(requestDelegate); + var startInstance = new StartInstance(); _startInstances.Add(startInstance); - requestDelegate(new DefaultHttpContext(Features)); + var context = application.CreateContext(Features); + try + { + application.ProcessRequestAsync(context); + } + catch (Exception ex) + { + application.DisposeContext(context, ex); + throw; + } + application.DisposeContext(context, null); } public void Dispose() @@ -504,13 +513,6 @@ namespace Microsoft.AspNet.Hosting private class StartInstance : IDisposable { - private readonly RequestDelegate _application; - - public StartInstance(RequestDelegate application) - { - _application = application; - } - public int DisposeCalls { get; set; } public void Dispose() diff --git a/test/Microsoft.AspNet.Hosting.Tests/WebHostBuilderTests.cs b/test/Microsoft.AspNet.Hosting.Tests/WebHostBuilderTests.cs index 7b3bdf7f82..cd7c1ee3b4 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/WebHostBuilderTests.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/WebHostBuilderTests.cs @@ -1,6 +1,7 @@ // 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; using System.Collections.Generic; using System.IO; using System.Threading.Tasks; @@ -174,9 +175,22 @@ namespace Microsoft.AspNet.Hosting } - public void Start(RequestDelegate requestDelegate) + public void Start(IHttpApplication application) { - RequestDelegate = requestDelegate; + RequestDelegate = async ctx => + { + var httpContext = application.CreateContext(ctx.Features); + try + { + await application.ProcessRequestAsync(httpContext); + } + catch (Exception ex) + { + application.DisposeContext(httpContext, ex); + throw; + } + application.DisposeContext(httpContext, null); + }; } } } diff --git a/test/Microsoft.AspNet.TestHost.Tests/ClientHandlerTests.cs b/test/Microsoft.AspNet.TestHost.Tests/ClientHandlerTests.cs index adacdd9d8e..3108810ff9 100644 --- a/test/Microsoft.AspNet.TestHost.Tests/ClientHandlerTests.cs +++ b/test/Microsoft.AspNet.TestHost.Tests/ClientHandlerTests.cs @@ -7,22 +7,22 @@ using System.Linq; using System.Net.Http; using System.Threading; using System.Threading.Tasks; +using Microsoft.AspNet.Hosting.Server; using Microsoft.AspNet.Http; -using Microsoft.AspNet.Http.Features; using Microsoft.AspNet.Http.Internal; +using Microsoft.AspNet.Http.Features; using Microsoft.AspNet.Testing.xunit; using Xunit; +using Context = Microsoft.AspNet.Hosting.Internal.HostingApplication.Context; namespace Microsoft.AspNet.TestHost { public class ClientHandlerTests { - private IHttpContextFactory _httpContextFactory = new HttpContextFactory(new HttpContextAccessor()); - [Fact] public Task ExpectedKeysAreAvailable() { - var handler = new ClientHandler(context => + var handler = new ClientHandler(new PathString("/A/Path/"), new DummyApplication(context => { // TODO: Assert.True(context.RequestAborted.CanBeCanceled); Assert.Equal("HTTP/1.1", context.Request.Protocol); @@ -40,7 +40,7 @@ namespace Microsoft.AspNet.TestHost Assert.Equal("example.com", context.Request.Host.Value); return Task.FromResult(0); - }, new PathString("/A/Path/"), _httpContextFactory); + })); var httpClient = new HttpClient(handler); return httpClient.GetAsync("https://example.com/A/Path/and/file.txt?and=query"); } @@ -48,13 +48,13 @@ namespace Microsoft.AspNet.TestHost [Fact] public Task SingleSlashNotMovedToPathBase() { - var handler = new ClientHandler(context => + var handler = new ClientHandler(new PathString(""), new DummyApplication(context => { Assert.Equal("", context.Request.PathBase.Value); Assert.Equal("/", context.Request.Path.Value); return Task.FromResult(0); - }, new PathString(""), _httpContextFactory); + })); var httpClient = new HttpClient(handler); return httpClient.GetAsync("https://example.com/"); } @@ -63,14 +63,14 @@ namespace Microsoft.AspNet.TestHost public async Task ResubmitRequestWorks() { int requestCount = 1; - var handler = new ClientHandler(context => + var handler = new ClientHandler(PathString.Empty, new DummyApplication(context => { int read = context.Request.Body.Read(new byte[100], 0, 100); Assert.Equal(11, read); context.Response.Headers["TestHeader"] = "TestValue:" + requestCount++; return Task.FromResult(0); - }, PathString.Empty, _httpContextFactory); + })); HttpMessageInvoker invoker = new HttpMessageInvoker(handler); HttpRequestMessage message = new HttpRequestMessage(HttpMethod.Post, "https://example.com/"); @@ -86,11 +86,11 @@ namespace Microsoft.AspNet.TestHost [Fact] public async Task MiddlewareOnlySetsHeaders() { - var handler = new ClientHandler(context => + var handler = new ClientHandler(PathString.Empty, new DummyApplication(context => { context.Response.Headers["TestHeader"] = "TestValue"; return Task.FromResult(0); - }, PathString.Empty, _httpContextFactory); + })); var httpClient = new HttpClient(handler); HttpResponseMessage response = await httpClient.GetAsync("https://example.com/"); Assert.Equal("TestValue", response.Headers.GetValues("TestHeader").First()); @@ -100,11 +100,11 @@ namespace Microsoft.AspNet.TestHost public async Task BlockingMiddlewareShouldNotBlockClient() { ManualResetEvent block = new ManualResetEvent(false); - var handler = new ClientHandler(context => + var handler = new ClientHandler(PathString.Empty, new DummyApplication(context => { block.WaitOne(); return Task.FromResult(0); - }, PathString.Empty, _httpContextFactory); + })); var httpClient = new HttpClient(handler); Task task = httpClient.GetAsync("https://example.com/"); Assert.False(task.IsCompleted); @@ -117,13 +117,13 @@ namespace Microsoft.AspNet.TestHost public async Task HeadersAvailableBeforeBodyFinished() { ManualResetEvent block = new ManualResetEvent(false); - var handler = new ClientHandler(async context => + var handler = new ClientHandler(PathString.Empty, new DummyApplication(async context => { context.Response.Headers["TestHeader"] = "TestValue"; await context.Response.WriteAsync("BodyStarted,"); block.WaitOne(); await context.Response.WriteAsync("BodyFinished"); - }, PathString.Empty, _httpContextFactory); + })); var httpClient = new HttpClient(handler); HttpResponseMessage response = await httpClient.GetAsync("https://example.com/", HttpCompletionOption.ResponseHeadersRead); @@ -136,13 +136,13 @@ namespace Microsoft.AspNet.TestHost public async Task FlushSendsHeaders() { ManualResetEvent block = new ManualResetEvent(false); - var handler = new ClientHandler(async context => + var handler = new ClientHandler(PathString.Empty, new DummyApplication(async context => { context.Response.Headers["TestHeader"] = "TestValue"; context.Response.Body.Flush(); block.WaitOne(); await context.Response.WriteAsync("BodyFinished"); - }, PathString.Empty, _httpContextFactory); + })); var httpClient = new HttpClient(handler); HttpResponseMessage response = await httpClient.GetAsync("https://example.com/", HttpCompletionOption.ResponseHeadersRead); @@ -155,13 +155,13 @@ namespace Microsoft.AspNet.TestHost public async Task ClientDisposalCloses() { ManualResetEvent block = new ManualResetEvent(false); - var handler = new ClientHandler(context => + var handler = new ClientHandler(PathString.Empty, new DummyApplication(context => { context.Response.Headers["TestHeader"] = "TestValue"; context.Response.Body.Flush(); block.WaitOne(); return Task.FromResult(0); - }, PathString.Empty, _httpContextFactory); + })); var httpClient = new HttpClient(handler); HttpResponseMessage response = await httpClient.GetAsync("https://example.com/", HttpCompletionOption.ResponseHeadersRead); @@ -180,13 +180,13 @@ namespace Microsoft.AspNet.TestHost public async Task ClientCancellationAborts() { ManualResetEvent block = new ManualResetEvent(false); - var handler = new ClientHandler(context => + var handler = new ClientHandler(PathString.Empty, new DummyApplication(context => { context.Response.Headers["TestHeader"] = "TestValue"; context.Response.Body.Flush(); block.WaitOne(); return Task.FromResult(0); - }, PathString.Empty, _httpContextFactory); + })); var httpClient = new HttpClient(handler); HttpResponseMessage response = await httpClient.GetAsync("https://example.com/", HttpCompletionOption.ResponseHeadersRead); @@ -205,10 +205,10 @@ namespace Microsoft.AspNet.TestHost [Fact] public Task ExceptionBeforeFirstWriteIsReported() { - var handler = new ClientHandler(context => + var handler = new ClientHandler(PathString.Empty, new DummyApplication(context => { throw new InvalidOperationException("Test Exception"); - }, PathString.Empty, _httpContextFactory); + })); var httpClient = new HttpClient(handler); return Assert.ThrowsAsync(() => httpClient.GetAsync("https://example.com/", HttpCompletionOption.ResponseHeadersRead)); @@ -219,13 +219,13 @@ namespace Microsoft.AspNet.TestHost public async Task ExceptionAfterFirstWriteIsReported() { ManualResetEvent block = new ManualResetEvent(false); - var handler = new ClientHandler(async context => + var handler = new ClientHandler(PathString.Empty, new DummyApplication(async context => { context.Response.Headers["TestHeader"] = "TestValue"; await context.Response.WriteAsync("BodyStarted"); block.WaitOne(); throw new InvalidOperationException("Test Exception"); - }, PathString.Empty, _httpContextFactory); + })); var httpClient = new HttpClient(handler); HttpResponseMessage response = await httpClient.GetAsync("https://example.com/", HttpCompletionOption.ResponseHeadersRead); @@ -234,5 +234,33 @@ namespace Microsoft.AspNet.TestHost var ex = await Assert.ThrowsAsync(() => response.Content.ReadAsStringAsync()); Assert.IsType(ex.GetBaseException()); } + + private class DummyApplication : IHttpApplication + { + RequestDelegate _application; + + public DummyApplication(RequestDelegate application) + { + _application = application; + } + + public Context CreateContext(IFeatureCollection contextFeatures) + { + return new Context() + { + HttpContext = new DefaultHttpContext(contextFeatures) + }; + } + + public void DisposeContext(Context context, Exception exception) + { + + } + + public Task ProcessRequestAsync(Context context) + { + return _application(context.HttpContext); + } + } } } diff --git a/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs b/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs index 9ca048c9e0..ad55d2ee69 100644 --- a/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs +++ b/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs @@ -3,13 +3,12 @@ using System; using System.Diagnostics; -using System.IO; using System.Net; using System.Net.Http; +using System.Threading; using System.Threading.Tasks; using Microsoft.AspNet.Builder; using Microsoft.AspNet.Hosting; -using Microsoft.AspNet.Hosting.Startup; using Microsoft.AspNet.Http; using Microsoft.AspNet.Http.Features; using Microsoft.AspNet.Http.Features.Internal; @@ -393,6 +392,9 @@ namespace Microsoft.AspNet.TestHost diagnosticListener.SubscribeWithAdapter(listener); var result = await server.CreateClient().GetStringAsync("/path"); + // This ensures that all diagnostics are completely written to the diagnostic listener + Thread.Sleep(1000); + Assert.Equal("Hello World", result); Assert.NotNull(listener.BeginRequest?.HttpContext); Assert.NotNull(listener.EndRequest?.HttpContext); @@ -414,6 +416,9 @@ namespace Microsoft.AspNet.TestHost var listener = new TestDiagnosticListener(); diagnosticListener.SubscribeWithAdapter(listener); await Assert.ThrowsAsync(() => server.CreateClient().GetAsync("/path")); + + // This ensures that all diagnostics are completely written to the diagnostic listener + Thread.Sleep(1000); Assert.NotNull(listener.BeginRequest?.HttpContext); Assert.Null(listener.EndRequest?.HttpContext); From bae9771a811b958fc408f21ba7a11661e55b6663 Mon Sep 17 00:00:00 2001 From: John Luo Date: Thu, 3 Dec 2015 11:03:13 -0800 Subject: [PATCH 458/987] Diabling async TestHost.Tests on Mono #507 --- .../ClientHandlerTests.cs | 23 +++++--- .../TestClientTests.cs | 29 +++++++---- .../TestServerTests.cs | 52 ++++++++++++------- 3 files changed, 68 insertions(+), 36 deletions(-) diff --git a/test/Microsoft.AspNet.TestHost.Tests/ClientHandlerTests.cs b/test/Microsoft.AspNet.TestHost.Tests/ClientHandlerTests.cs index 3108810ff9..820f98d1fb 100644 --- a/test/Microsoft.AspNet.TestHost.Tests/ClientHandlerTests.cs +++ b/test/Microsoft.AspNet.TestHost.Tests/ClientHandlerTests.cs @@ -59,7 +59,8 @@ namespace Microsoft.AspNet.TestHost return httpClient.GetAsync("https://example.com/"); } - [Fact] + [ConditionalFact] + [FrameworkSkipCondition(RuntimeFrameworks.Mono, SkipReason = "Hangs randomly (issue #507)")] public async Task ResubmitRequestWorks() { int requestCount = 1; @@ -83,7 +84,8 @@ namespace Microsoft.AspNet.TestHost Assert.Equal("TestValue:2", response.Headers.GetValues("TestHeader").First()); } - [Fact] + [ConditionalFact] + [FrameworkSkipCondition(RuntimeFrameworks.Mono, SkipReason = "Hangs randomly (issue #507)")] public async Task MiddlewareOnlySetsHeaders() { var handler = new ClientHandler(PathString.Empty, new DummyApplication(context => @@ -96,7 +98,8 @@ namespace Microsoft.AspNet.TestHost Assert.Equal("TestValue", response.Headers.GetValues("TestHeader").First()); } - [Fact] + [ConditionalFact] + [FrameworkSkipCondition(RuntimeFrameworks.Mono, SkipReason = "Hangs randomly (issue #507)")] public async Task BlockingMiddlewareShouldNotBlockClient() { ManualResetEvent block = new ManualResetEvent(false); @@ -113,7 +116,8 @@ namespace Microsoft.AspNet.TestHost HttpResponseMessage response = await task; } - [Fact] + [ConditionalFact] + [FrameworkSkipCondition(RuntimeFrameworks.Mono, SkipReason = "Hangs randomly (issue #507)")] public async Task HeadersAvailableBeforeBodyFinished() { ManualResetEvent block = new ManualResetEvent(false); @@ -132,7 +136,8 @@ namespace Microsoft.AspNet.TestHost Assert.Equal("BodyStarted,BodyFinished", await response.Content.ReadAsStringAsync()); } - [Fact] + [ConditionalFact] + [FrameworkSkipCondition(RuntimeFrameworks.Mono, SkipReason = "Hangs randomly (issue #507)")] public async Task FlushSendsHeaders() { ManualResetEvent block = new ManualResetEvent(false); @@ -151,7 +156,8 @@ namespace Microsoft.AspNet.TestHost Assert.Equal("BodyFinished", await response.Content.ReadAsStringAsync()); } - [Fact] + [ConditionalFact] + [FrameworkSkipCondition(RuntimeFrameworks.Mono, SkipReason = "Hangs randomly (issue #507)")] public async Task ClientDisposalCloses() { ManualResetEvent block = new ManualResetEvent(false); @@ -176,7 +182,8 @@ namespace Microsoft.AspNet.TestHost block.Set(); } - [Fact] + [ConditionalFact] + [FrameworkSkipCondition(RuntimeFrameworks.Mono, SkipReason = "Hangs randomly (issue #507)")] public async Task ClientCancellationAborts() { ManualResetEvent block = new ManualResetEvent(false); @@ -215,7 +222,7 @@ namespace Microsoft.AspNet.TestHost } [ConditionalFact] - [OSSkipCondition(OperatingSystems.Linux, SkipReason = "Hangs randomly (issue #422).")] + [FrameworkSkipCondition(RuntimeFrameworks.Mono, SkipReason = "Hangs randomly (issue #507)")] public async Task ExceptionAfterFirstWriteIsReported() { ManualResetEvent block = new ManualResetEvent(false); diff --git a/test/Microsoft.AspNet.TestHost.Tests/TestClientTests.cs b/test/Microsoft.AspNet.TestHost.Tests/TestClientTests.cs index 0d19dd88ef..61e0f2b9d7 100644 --- a/test/Microsoft.AspNet.TestHost.Tests/TestClientTests.cs +++ b/test/Microsoft.AspNet.TestHost.Tests/TestClientTests.cs @@ -25,7 +25,8 @@ namespace Microsoft.AspNet.TestHost _server = TestServer.Create(app => app.Run(ctx => Task.FromResult(0))); } - [Fact] + [ConditionalFact] + [FrameworkSkipCondition(RuntimeFrameworks.Mono, SkipReason = "Hangs randomly (issue #507)")] public async Task GetAsyncWorks() { // Arrange @@ -42,7 +43,8 @@ namespace Microsoft.AspNet.TestHost Assert.Equal(expected, actual); } - [Fact] + [ConditionalFact] + [FrameworkSkipCondition(RuntimeFrameworks.Mono, SkipReason = "Hangs randomly (issue #507)")] public async Task NoTrailingSlash_NoPathBase() { // Arrange @@ -63,7 +65,8 @@ namespace Microsoft.AspNet.TestHost Assert.Equal(expected, actual); } - [Fact] + [ConditionalFact] + [FrameworkSkipCondition(RuntimeFrameworks.Mono, SkipReason = "Hangs randomly (issue #507)")] public async Task SingleTrailingSlash_NoPathBase() { // Arrange @@ -84,7 +87,8 @@ namespace Microsoft.AspNet.TestHost Assert.Equal(expected, actual); } - [Fact] + [ConditionalFact] + [FrameworkSkipCondition(RuntimeFrameworks.Mono, SkipReason = "Hangs randomly (issue #507)")] public async Task PutAsyncWorks() { // Arrange @@ -101,7 +105,8 @@ namespace Microsoft.AspNet.TestHost Assert.Equal("Hello world PUT Response", await response.Content.ReadAsStringAsync()); } - [Fact] + [ConditionalFact] + [FrameworkSkipCondition(RuntimeFrameworks.Mono, SkipReason = "Hangs randomly (issue #507)")] public async Task PostAsyncWorks() { // Arrange @@ -118,7 +123,8 @@ namespace Microsoft.AspNet.TestHost Assert.Equal("Hello world POST Response", await response.Content.ReadAsStringAsync()); } - [Fact] + [ConditionalFact] + [FrameworkSkipCondition(RuntimeFrameworks.Mono, SkipReason = "Hangs randomly (issue #507)")] public async Task WebSocketWorks() { // Arrange @@ -179,7 +185,8 @@ namespace Microsoft.AspNet.TestHost clientSocket.Dispose(); } - [Fact] + [ConditionalFact] + [FrameworkSkipCondition(RuntimeFrameworks.Mono, SkipReason = "Hangs randomly (issue #507)")] public async Task WebSocketDisposalThrowsOnPeer() { // Arrange @@ -205,7 +212,8 @@ namespace Microsoft.AspNet.TestHost clientSocket.Dispose(); } - [Fact] + [ConditionalFact] + [FrameworkSkipCondition(RuntimeFrameworks.Mono, SkipReason = "Hangs randomly (issue #507)")] public async Task WebSocketTinyReceiveGeneratesEndOfMessage() { // Arrange @@ -248,7 +256,8 @@ namespace Microsoft.AspNet.TestHost clientSocket.Dispose(); } - [Fact] + [ConditionalFact] + [FrameworkSkipCondition(RuntimeFrameworks.Mono, SkipReason = "Hangs randomly (issue #507)")] public async Task ClientDisposalAbortsRequest() { // Arrange @@ -282,7 +291,7 @@ namespace Microsoft.AspNet.TestHost } [ConditionalFact] - [FrameworkSkipCondition(RuntimeFrameworks.CoreCLR, SkipReason = "Hangs randomly (issue #422).")] + [FrameworkSkipCondition(RuntimeFrameworks.Mono, SkipReason = "Hangs randomly (issue #507)")] public async Task ClientCancellationAbortsRequest() { // Arrange diff --git a/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs b/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs index ad55d2ee69..80e0e44f0f 100644 --- a/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs +++ b/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs @@ -31,7 +31,8 @@ namespace Microsoft.AspNet.TestHost TestServer.Create(app => { }); } - [Fact] + [ConditionalFact] + [FrameworkSkipCondition(RuntimeFrameworks.Mono, SkipReason = "Hangs randomly (issue #507)")] public async Task RequestServicesAutoCreated() { var server = TestServer.Create(app => @@ -66,7 +67,8 @@ namespace Microsoft.AspNet.TestHost } - [Fact] + [ConditionalFact] + [FrameworkSkipCondition(RuntimeFrameworks.Mono, SkipReason = "Hangs randomly (issue #507)")] public async Task CustomServiceProviderSetsApplicationServices() { var server = new TestServer(TestServer.CreateBuilder().UseStartup()); @@ -107,7 +109,8 @@ namespace Microsoft.AspNet.TestHost } } - [Fact] + [ConditionalFact] + [FrameworkSkipCondition(RuntimeFrameworks.Mono, SkipReason = "Hangs randomly (issue #507)")] public async Task ExistingRequestServicesWillNotBeReplaced() { var server = TestServer.Create(app => @@ -123,7 +126,8 @@ namespace Microsoft.AspNet.TestHost Assert.Equal("Found:True", result); } - [Fact] + [ConditionalFact] + [FrameworkSkipCondition(RuntimeFrameworks.Mono, SkipReason = "Hangs randomly (issue #507)")] public async Task CanSetCustomServiceProvider() { var server = TestServer.Create(app => @@ -169,7 +173,8 @@ namespace Microsoft.AspNet.TestHost } } - [Fact] + [ConditionalFact] + [FrameworkSkipCondition(RuntimeFrameworks.Mono, SkipReason = "Hangs randomly (issue #507)")] public async Task ExistingServiceProviderFeatureWillNotBeReplaced() { var appServices = new ServiceCollection().BuildServiceProvider(); @@ -206,7 +211,8 @@ namespace Microsoft.AspNet.TestHost } } - [Fact] + [ConditionalFact] + [FrameworkSkipCondition(RuntimeFrameworks.Mono, SkipReason = "Hangs randomly (issue #507)")] public async Task WillReplaceServiceProviderFeatureWithNullRequestServices() { var server = TestServer.Create(app => @@ -222,7 +228,8 @@ namespace Microsoft.AspNet.TestHost Assert.Equal("Success", result); } - [Fact] + [ConditionalFact] + [FrameworkSkipCondition(RuntimeFrameworks.Mono, SkipReason = "Hangs randomly (issue #507)")] public async Task CanAccessLogger() { var server = TestServer.Create(app => @@ -238,7 +245,8 @@ namespace Microsoft.AspNet.TestHost Assert.Equal("FoundLogger:True", result); } - [Fact] + [ConditionalFact] + [FrameworkSkipCondition(RuntimeFrameworks.Mono, SkipReason = "Hangs randomly (issue #507)")] public async Task CanAccessHttpContext() { Action configureServices = services => @@ -268,7 +276,8 @@ namespace Microsoft.AspNet.TestHost public IHttpContextAccessor Accessor { get; set; } } - [Fact] + [ConditionalFact] + [FrameworkSkipCondition(RuntimeFrameworks.Mono, SkipReason = "Hangs randomly (issue #507)")] public async Task CanAddNewHostServices() { Action configureServices = services => @@ -289,7 +298,8 @@ namespace Microsoft.AspNet.TestHost Assert.Equal("HasContext:True", result); } - [Fact] + [ConditionalFact] + [FrameworkSkipCondition(RuntimeFrameworks.Mono, SkipReason = "Hangs randomly (issue #507)")] public async Task CreateInvokesApp() { TestServer server = TestServer.Create(app => @@ -304,7 +314,8 @@ namespace Microsoft.AspNet.TestHost Assert.Equal("CreateInvokesApp", result); } - [Fact] + [ConditionalFact] + [FrameworkSkipCondition(RuntimeFrameworks.Mono, SkipReason = "Hangs randomly (issue #507)")] public async Task DisposeStreamIgnored() { TestServer server = TestServer.Create(app => @@ -321,7 +332,8 @@ namespace Microsoft.AspNet.TestHost Assert.Equal("Response", await result.Content.ReadAsStringAsync()); } - [Fact] + [ConditionalFact] + [FrameworkSkipCondition(RuntimeFrameworks.Mono, SkipReason = "Hangs randomly (issue #507)")] public async Task DisposedServerThrows() { TestServer server = TestServer.Create(app => @@ -340,7 +352,7 @@ namespace Microsoft.AspNet.TestHost } [ConditionalFact] - [FrameworkSkipCondition(RuntimeFrameworks.CoreCLR, SkipReason = "Hangs randomly (issue #422).")] + [FrameworkSkipCondition(RuntimeFrameworks.Mono, SkipReason = "Hangs randomly (issue #507)")] public void CancelAborts() { TestServer server = TestServer.Create(app => @@ -356,7 +368,8 @@ namespace Microsoft.AspNet.TestHost Assert.Throws(() => { string result = server.CreateClient().GetStringAsync("/path").Result; }); } - [Fact] + [ConditionalFact] + [FrameworkSkipCondition(RuntimeFrameworks.Mono, SkipReason = "Hangs randomly (issue #507)")] public async Task CanCreateViaStartupType() { TestServer server = new TestServer(TestServer.CreateBuilder().UseStartup()); @@ -365,7 +378,8 @@ namespace Microsoft.AspNet.TestHost Assert.Equal("FoundService:True", await result.Content.ReadAsStringAsync()); } - [Fact] + [ConditionalFact] + [FrameworkSkipCondition(RuntimeFrameworks.Mono, SkipReason = "Hangs randomly (issue #507)")] public async Task CanCreateViaStartupTypeAndSpecifyEnv() { TestServer server = new TestServer(TestServer.CreateBuilder() @@ -375,8 +389,9 @@ namespace Microsoft.AspNet.TestHost Assert.Equal(HttpStatusCode.OK, result.StatusCode); Assert.Equal("FoundFoo:False", await result.Content.ReadAsStringAsync()); } - - [Fact] + + [ConditionalFact] + [FrameworkSkipCondition(RuntimeFrameworks.Mono, SkipReason = "Hangs randomly (issue #507)")] public async Task BeginEndDiagnosticAvailable() { DiagnosticListener diagnosticListener = null; @@ -401,7 +416,8 @@ namespace Microsoft.AspNet.TestHost Assert.Null(listener.UnhandledException); } - [Fact] + [ConditionalFact] + [FrameworkSkipCondition(RuntimeFrameworks.Mono, SkipReason = "Hangs randomly (issue #507)")] public async Task ExceptionDiagnosticAvailable() { DiagnosticListener diagnosticListener = null; From 0f0999161d5dfb12feba90f26bbc05795fdf00b3 Mon Sep 17 00:00:00 2001 From: John Luo Date: Wed, 2 Dec 2015 17:20:28 -0800 Subject: [PATCH 459/987] Reacting to verbose rename --- .../Internal/HostingLoggerExtensions.cs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Microsoft.AspNet.Hosting/Internal/HostingLoggerExtensions.cs b/src/Microsoft.AspNet.Hosting/Internal/HostingLoggerExtensions.cs index 3730736d0b..4f149d5b44 100644 --- a/src/Microsoft.AspNet.Hosting/Internal/HostingLoggerExtensions.cs +++ b/src/Microsoft.AspNet.Hosting/Internal/HostingLoggerExtensions.cs @@ -57,9 +57,9 @@ namespace Microsoft.AspNet.Hosting.Internal public static void Starting(this ILogger logger) { - if (logger.IsEnabled(LogLevel.Verbose)) + if (logger.IsEnabled(LogLevel.Debug)) { - logger.LogVerbose( + logger.LogDebug( eventId: LoggerEventIds.Starting, data: "Hosting starting"); } @@ -67,9 +67,9 @@ namespace Microsoft.AspNet.Hosting.Internal public static void Started(this ILogger logger) { - if (logger.IsEnabled(LogLevel.Verbose)) + if (logger.IsEnabled(LogLevel.Debug)) { - logger.LogVerbose( + logger.LogDebug( eventId: LoggerEventIds.Started, data: "Hosting started"); } @@ -77,9 +77,9 @@ namespace Microsoft.AspNet.Hosting.Internal public static void Shutdown(this ILogger logger) { - if (logger.IsEnabled(LogLevel.Verbose)) + if (logger.IsEnabled(LogLevel.Debug)) { - logger.LogVerbose( + logger.LogDebug( eventId: LoggerEventIds.Shutdown, data: "Hosting shutdown"); } From 3f9c23a6eeca10cfd31db0fba47bb0408ce0453e Mon Sep 17 00:00:00 2001 From: Doug Bunting Date: Mon, 7 Dec 2015 20:15:37 -0800 Subject: [PATCH 460/987] Remove `[SuppressMessage]`s - build break --- src/Microsoft.AspNet.TestHost/ClientHandler.cs | 5 +---- src/Microsoft.AspNet.TestHost/RequestBuilder.cs | 5 ----- src/Microsoft.AspNet.TestHost/ResponseStream.cs | 3 --- 3 files changed, 1 insertion(+), 12 deletions(-) diff --git a/src/Microsoft.AspNet.TestHost/ClientHandler.cs b/src/Microsoft.AspNet.TestHost/ClientHandler.cs index 200dc5db9a..30a48d38aa 100644 --- a/src/Microsoft.AspNet.TestHost/ClientHandler.cs +++ b/src/Microsoft.AspNet.TestHost/ClientHandler.cs @@ -3,7 +3,6 @@ using System; using System.Collections.Generic; -using System.Diagnostics.CodeAnalysis; using System.Diagnostics.Contracts; using System.IO; using System.Linq; @@ -37,7 +36,7 @@ namespace Microsoft.AspNet.TestHost { throw new ArgumentNullException(nameof(application)); } - + _application = application; // PathString.StartsWithSegments that we use below requires the base path to not end in a slash. @@ -204,8 +203,6 @@ namespace Microsoft.AspNet.TestHost } } - [SuppressMessage("Microsoft.Reliability", "CA2000:DisposeObjectsBeforeLosingScope", - Justification = "HttpResposneMessage must be returned to the caller.")] private HttpResponseMessage GenerateResponse() { _responseFeature.FireOnSendingHeaders(); diff --git a/src/Microsoft.AspNet.TestHost/RequestBuilder.cs b/src/Microsoft.AspNet.TestHost/RequestBuilder.cs index 2de21ead03..51b93fade0 100644 --- a/src/Microsoft.AspNet.TestHost/RequestBuilder.cs +++ b/src/Microsoft.AspNet.TestHost/RequestBuilder.cs @@ -2,7 +2,6 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using System.Diagnostics.CodeAnalysis; using System.IO; using System.Net.Http; using System.Threading.Tasks; @@ -12,8 +11,6 @@ namespace Microsoft.AspNet.TestHost /// /// Used to construct a HttpRequestMessage object. /// - [SuppressMessage("Microsoft.Design", "CA1001:TypesThatOwnDisposableFieldsShouldBeDisposable", - Justification = "HttpRequestMessage is disposed by HttpClient in SendAsync")] public class RequestBuilder { private readonly TestServer _server; @@ -24,7 +21,6 @@ namespace Microsoft.AspNet.TestHost /// /// /// - [SuppressMessage("Microsoft.Usage", "CA2234:PassSystemUriObjectsInsteadOfStrings", Justification = "Not a full URI")] public RequestBuilder(TestServer server, string path) { if (server == null) @@ -90,7 +86,6 @@ namespace Microsoft.AspNet.TestHost /// Set the request method to GET and start processing the request. /// /// - [SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate", Justification = "GET is an HTTP verb.")] public Task GetAsync() { _req.Method = HttpMethod.Get; diff --git a/src/Microsoft.AspNet.TestHost/ResponseStream.cs b/src/Microsoft.AspNet.TestHost/ResponseStream.cs index 314bbec048..55b318309a 100644 --- a/src/Microsoft.AspNet.TestHost/ResponseStream.cs +++ b/src/Microsoft.AspNet.TestHost/ResponseStream.cs @@ -3,7 +3,6 @@ using System; using System.Collections.Concurrent; -using System.Diagnostics.CodeAnalysis; using System.Diagnostics.Contracts; using System.IO; using System.Threading; @@ -370,8 +369,6 @@ namespace Microsoft.AspNet.TestHost } } - [SuppressMessage("Microsoft.Usage", "CA2213:DisposableFieldsShouldBeDisposed", MessageId = "_writeLock", Justification = "ODEs from the locks would mask IOEs from abort.")] - [SuppressMessage("Microsoft.Usage", "CA2213:DisposableFieldsShouldBeDisposed", MessageId = "_readLock", Justification = "Data can still be read unless we get aborted.")] protected override void Dispose(bool disposing) { if (disposing) From 29a4f302d893cc87b79bba7c5426cc00438e009f Mon Sep 17 00:00:00 2001 From: David Fowler Date: Sun, 6 Dec 2015 01:51:38 -0800 Subject: [PATCH 461/987] Remove non-essential platform services - Remove services that can be registered by the application itself. - These services use to come from the DNX but now they are stand alone implementations that can be registered by applications if they choose. #501 --- src/Microsoft.AspNet.Hosting/WebHostBuilder.cs | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/src/Microsoft.AspNet.Hosting/WebHostBuilder.cs b/src/Microsoft.AspNet.Hosting/WebHostBuilder.cs index 309d9eff71..5c96962fb2 100644 --- a/src/Microsoft.AspNet.Hosting/WebHostBuilder.cs +++ b/src/Microsoft.AspNet.Hosting/WebHostBuilder.cs @@ -98,21 +98,6 @@ namespace Microsoft.AspNet.Hosting services.TryAdd(ServiceDescriptor.Instance(PlatformServices.Default.Runtime)); } - if (PlatformServices.Default?.AssemblyLoadContextAccessor != null) - { - services.TryAdd(ServiceDescriptor.Instance(PlatformServices.Default.AssemblyLoadContextAccessor)); - } - - if (PlatformServices.Default?.AssemblyLoaderContainer != null) - { - services.TryAdd(ServiceDescriptor.Instance(PlatformServices.Default.AssemblyLoaderContainer)); - } - - if (PlatformServices.Default?.LibraryManager != null) - { - services.TryAdd(ServiceDescriptor.Instance(PlatformServices.Default.LibraryManager)); - } - return services; } From b966ed0ba3021e1c4b3a2cfac1dc43a104fcc04c Mon Sep 17 00:00:00 2001 From: Pranav K Date: Tue, 8 Dec 2015 17:15:40 -0800 Subject: [PATCH 462/987] Fixing CoreCLR package versions --- src/Microsoft.AspNet.Server.Testing/project.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Microsoft.AspNet.Server.Testing/project.json b/src/Microsoft.AspNet.Server.Testing/project.json index 77079ef4f8..e6af8b13d7 100644 --- a/src/Microsoft.AspNet.Server.Testing/project.json +++ b/src/Microsoft.AspNet.Server.Testing/project.json @@ -26,7 +26,7 @@ }, "dnxcore50": { "dependencies": { - "System.Diagnostics.Process": "4.0.0-*", + "System.Diagnostics.Process": "4.1.0-*", "System.IO.FileSystem": "4.0.1-*", "System.Net.Http": "4.0.1-*", "System.Net.Primitives": "4.0.11-*", From a83c556bb7694d6d47a04094784b10fae9a76cb2 Mon Sep 17 00:00:00 2001 From: Pranav K Date: Wed, 9 Dec 2015 16:20:27 -0800 Subject: [PATCH 463/987] Remove compilation error support from Startup error page Fixes #510 --- .../Internal/HostingEngine.cs | 7 +- .../Startup/StartupExceptionPage.cs | 168 ++---------------- .../resources/Compilation_Exception.html | 6 - .../compiler/resources/GenericError.html | 5 - src/Microsoft.AspNet.Hosting/project.json | 1 - 5 files changed, 17 insertions(+), 170 deletions(-) delete mode 100644 src/Microsoft.AspNet.Hosting/compiler/resources/Compilation_Exception.html diff --git a/src/Microsoft.AspNet.Hosting/Internal/HostingEngine.cs b/src/Microsoft.AspNet.Hosting/Internal/HostingEngine.cs index 2d232995ee..6236fa2e8c 100644 --- a/src/Microsoft.AspNet.Hosting/Internal/HostingEngine.cs +++ b/src/Microsoft.AspNet.Hosting/Internal/HostingEngine.cs @@ -168,13 +168,8 @@ namespace Microsoft.AspNet.Hosting.Internal return builder.Build(); } - catch (Exception ex) + catch (Exception ex) when (_captureStartupErrors) { - if (!_captureStartupErrors) - { - throw; - } - // EnsureApplicationServices may have failed due to a missing or throwing Startup class. if (_applicationServices == null) { diff --git a/src/Microsoft.AspNet.Hosting/Startup/StartupExceptionPage.cs b/src/Microsoft.AspNet.Hosting/Startup/StartupExceptionPage.cs index 1419c5d427..a5f9dc1dbc 100644 --- a/src/Microsoft.AspNet.Hosting/Startup/StartupExceptionPage.cs +++ b/src/Microsoft.AspNet.Hosting/Startup/StartupExceptionPage.cs @@ -12,72 +12,38 @@ using System.Runtime.CompilerServices; using System.Runtime.ExceptionServices; using System.Text; using System.Text.Encodings.Web; -using Microsoft.Extensions.CompilationAbstractions; using Microsoft.Extensions.PlatformAbstractions; namespace Microsoft.AspNet.Hosting.Startup { internal static class StartupExceptionPage { - private const int MaxCompilationErrorsToShow = 20; - private static readonly string _errorPageFormatString = GetResourceString("GenericError.html", escapeBraces: true); private static readonly string _errorMessageFormatString = GetResourceString("GenericError_Message.html"); private static readonly string _errorExceptionFormatString = GetResourceString("GenericError_Exception.html"); private static readonly string _errorFooterFormatString = GetResourceString("GenericError_Footer.html"); - private static readonly string _compilationExceptionFormatString = GetResourceString("Compilation_Exception.html"); - public static byte[] GenerateErrorHtml(bool showDetails, IRuntimeEnvironment runtimeEnvironment, params object[] errorDetails) + public static byte[] GenerateErrorHtml(bool showDetails, IRuntimeEnvironment runtimeEnvironment, Exception exception) { - if (!showDetails) - { - errorDetails = new[] { "An error occurred while starting the application." }; - } - // Build the message for each error - var wasSourceCodeWrittenOntoPage = false; var builder = new StringBuilder(); var rawExceptionDetails = new StringBuilder(); - foreach (object error in errorDetails ?? new object[0]) + if (!showDetails) { - var ex = error as Exception; - if (ex == null && error is ExceptionDispatchInfo) + WriteMessage("An error occurred while starting the application.", builder); + } + else + { + Debug.Assert(exception != null); + var wasSourceCodeWrittenOntoPage = false; + var flattenedExceptions = FlattenAndReverseExceptionTree(exception); + foreach (var innerEx in flattenedExceptions) { - ex = ((ExceptionDispatchInfo)error).SourceException; + WriteException(innerEx, builder, ref wasSourceCodeWrittenOntoPage); } - if (ex != null) - { - var flattenedExceptions = FlattenAndReverseExceptionTree(ex); - - var compilationException = flattenedExceptions.OfType() - .FirstOrDefault(); - if (compilationException != null) - { - WriteException(compilationException, builder, ref wasSourceCodeWrittenOntoPage); - - var compilationErrorMessages = compilationException.CompilationFailures - .SelectMany(f => f.Messages.Select(m => m.FormattedMessage)) - .Take(MaxCompilationErrorsToShow); - - WriteRawExceptionDetails("Show raw compilation error details", compilationErrorMessages, rawExceptionDetails); - } - else - { - foreach (var innerEx in flattenedExceptions) - { - WriteException(innerEx, builder, ref wasSourceCodeWrittenOntoPage); - } - - WriteRawExceptionDetails("Show raw exception details", new[] { ex.ToString() }, rawExceptionDetails); - } - } - else - { - var message = Convert.ToString(error, CultureInfo.InvariantCulture); - WriteMessage(message, builder); - } + WriteRawExceptionDetails("Show raw exception details", exception.ToString(), rawExceptionDetails); } // Generate the footer @@ -171,84 +137,13 @@ namespace Microsoft.AspNet.Hosting.Startup private static string BuildMethodParametersUnescaped(MethodBase method) { - return "(" + string.Join(", ", method.GetParameters().Select(p => { + return "(" + string.Join(", ", method.GetParameters().Select(p => + { Type parameterType = p.ParameterType; return ((parameterType != null) ? PrettyPrintTypeName(parameterType) : "?") + " " + p.Name; })) + ")"; } - private static void BuildCodeSnippetDiv(CompilationFailure failure, - StringBuilder builder, - ref int totalErrorsShown) - { - const int NumContextLines = 3; - var fileName = failure.SourceFilePath; - if (totalErrorsShown < MaxCompilationErrorsToShow && - !string.IsNullOrEmpty(fileName)) - { - builder.Append(@"
") - .AppendFormat(@"
{0}
", HtmlEncodeAndReplaceLineBreaks(fileName)) - .AppendLine(); - - IEnumerable fileContent; - if (string.IsNullOrEmpty(failure.SourceFileContent)) - { - fileContent = File.ReadLines(fileName); - } - else - { - fileContent = failure.SourceFileContent.Split(new[] { Environment.NewLine }, StringSplitOptions.None); - } - foreach (var message in failure.Messages) - { - if (totalErrorsShown++ > MaxCompilationErrorsToShow) - { - break; - } - - if (totalErrorsShown > 1) - { - builder.AppendLine("
"); - } - - builder.Append(@"
") - .Append(HtmlEncodeAndReplaceLineBreaks(message.Message)) - .Append("
"); - - // StartLine and EndLine are 1-based - var startLine = message.StartLine - 1; - var endLine = message.EndLine - 1; - var preContextIndex = Math.Max(startLine - NumContextLines, 0); - var index = preContextIndex + 1; - foreach (var line in fileContent.Skip(preContextIndex).Take(startLine - preContextIndex)) - { - builder.Append(@"
") - .AppendFormat(@"{0}", index++) - .Append(HtmlEncodeAndReplaceLineBreaks(line)) - .AppendLine("
"); - } - - var numErrorLines = 1 + Math.Max(0, endLine - startLine); - foreach (var line in fileContent.Skip(startLine).Take(numErrorLines)) - { - builder.Append(@"
") - .AppendFormat(@"{0}", index++) - .Append(HtmlEncodeAndReplaceLineBreaks(line)) - .AppendLine("
"); - } - foreach (var line in fileContent.Skip(message.EndLine).Take(NumContextLines)) - { - builder.Append(@"
") - .AppendFormat(@"{0}", index++) - .Append(HtmlEncodeAndReplaceLineBreaks(line)) - .AppendLine("
"); - } - } - - builder.AppendLine("
"); // Close codeSnippet div - } - } - private static string GetResourceString(string name, bool escapeBraces = false) { // '{' and '}' are special in CSS, so we use "[[[0]]]" instead for {0} (and so on). @@ -451,7 +346,7 @@ namespace Microsoft.AspNet.Hosting.Startup stackTraceBuilder); } - private static void WriteRawExceptionDetails(string linkText, IEnumerable lines, StringBuilder rawExceptionDetails) + private static void WriteRawExceptionDetails(string linkText, string line, StringBuilder rawExceptionDetails) { rawExceptionDetails .AppendLine("
") @@ -460,10 +355,7 @@ namespace Microsoft.AspNet.Hosting.Startup .AppendLine("
") .Append("
");
 
-            foreach (var line in lines)
-            {
-                rawExceptionDetails.AppendLine(line);
-            }
+            rawExceptionDetails.AppendLine(line);
 
             rawExceptionDetails
                 .AppendLine("
") @@ -471,34 +363,6 @@ namespace Microsoft.AspNet.Hosting.Startup .AppendLine("
"); } - private static void WriteException(ICompilationException compilationException, - StringBuilder builder, - ref bool wasSourceCodeWrittenOntoPage) - { - var totalErrorsShown = 0; - var inlineSourceDiv = new StringBuilder(); - var firstStackFrame = true; - foreach (var failure in compilationException.CompilationFailures) - { - if (firstStackFrame) - { - firstStackFrame = false; - } - else - { - inlineSourceDiv.AppendLine("
"); - } - - BuildCodeSnippetDiv(failure, inlineSourceDiv, ref totalErrorsShown); - } - - wasSourceCodeWrittenOntoPage = totalErrorsShown > 0; - - builder.AppendFormat(CultureInfo.InvariantCulture, - _compilationExceptionFormatString, - inlineSourceDiv); - } - private static void WriteMessage(string message, StringBuilder builder) { // Build the
diff --git a/src/Microsoft.AspNet.Hosting/compiler/resources/Compilation_Exception.html b/src/Microsoft.AspNet.Hosting/compiler/resources/Compilation_Exception.html deleted file mode 100644 index 76f56157ba..0000000000 --- a/src/Microsoft.AspNet.Hosting/compiler/resources/Compilation_Exception.html +++ /dev/null @@ -1,6 +0,0 @@ -
- One or more compilation errors occurred:
-
- {0} -
-
diff --git a/src/Microsoft.AspNet.Hosting/compiler/resources/GenericError.html b/src/Microsoft.AspNet.Hosting/compiler/resources/GenericError.html index e7b4dc1bbd..c6b24c57e8 100644 --- a/src/Microsoft.AspNet.Hosting/compiler/resources/GenericError.html +++ b/src/Microsoft.AspNet.Hosting/compiler/resources/GenericError.html @@ -75,11 +75,6 @@ background-color: #f6f6f6; } - .codeSnippet .error-message { - color: red; - font-weight: normal; - } - .codeSnippet div.filename { font-weight: bold; background-color: white; diff --git a/src/Microsoft.AspNet.Hosting/project.json b/src/Microsoft.AspNet.Hosting/project.json index c34f9fd752..4054e9c8a8 100644 --- a/src/Microsoft.AspNet.Hosting/project.json +++ b/src/Microsoft.AspNet.Hosting/project.json @@ -21,7 +21,6 @@ "Microsoft.Extensions.Configuration.Json": "1.0.0-*", "Microsoft.Extensions.DependencyInjection": "1.0.0-*", "Microsoft.Extensions.Logging": "1.0.0-*", - "Microsoft.Extensions.CompilationAbstractions": "1.0.0-*", "Microsoft.Extensions.PlatformAbstractions": "1.0.0-*", "System.Diagnostics.DiagnosticSource": "4.0.0-*" }, From 8aa3fd6e9c0b4c307497b64be48241194d48cb19 Mon Sep 17 00:00:00 2001 From: Pranav K Date: Wed, 9 Dec 2015 16:31:25 -0800 Subject: [PATCH 464/987] Use TypeNameHelper for pretty printing names --- .../Startup/StartupExceptionPage.cs | 47 ++----------------- src/Microsoft.AspNet.Hosting/project.json | 4 ++ 2 files changed, 7 insertions(+), 44 deletions(-) diff --git a/src/Microsoft.AspNet.Hosting/Startup/StartupExceptionPage.cs b/src/Microsoft.AspNet.Hosting/Startup/StartupExceptionPage.cs index a5f9dc1dbc..bed39a6241 100644 --- a/src/Microsoft.AspNet.Hosting/Startup/StartupExceptionPage.cs +++ b/src/Microsoft.AspNet.Hosting/Startup/StartupExceptionPage.cs @@ -12,6 +12,7 @@ using System.Runtime.CompilerServices; using System.Runtime.ExceptionServices; using System.Text; using System.Text.Encodings.Web; +using Microsoft.Extensions.Internal; using Microsoft.Extensions.PlatformAbstractions; namespace Microsoft.AspNet.Hosting.Startup @@ -139,7 +140,7 @@ namespace Microsoft.AspNet.Hosting.Startup { return "(" + string.Join(", ", method.GetParameters().Select(p => { - Type parameterType = p.ParameterType; + var parameterType = p.ParameterType; return ((parameterType != null) ? PrettyPrintTypeName(parameterType) : "?") + " " + p.Name; })) + ")"; } @@ -215,50 +216,8 @@ namespace Microsoft.AspNet.Hosting.Startup return (didReadFailingLine) ? errorSubContents : null; } - private static string PrettyPrintTypeName(Type t) - { - try - { - RuntimeHelpers.EnsureSufficientExecutionStack(); + private static string PrettyPrintTypeName(Type type) => TypeNameHelper.GetTypeDisplayName(type, fullName: false); - var name = t.Name; - - // Degenerate case - if (string.IsNullOrEmpty(name)) - { - name = "?"; - } - - // Handle generic types - if (t.GetTypeInfo().IsGenericType) - { - // strip off the CLR generic type marker if it exists - var indexOfGenericTypeMarker = name.LastIndexOf('`'); - if (indexOfGenericTypeMarker >= 0) - { - name = name.Substring(0, indexOfGenericTypeMarker); - name += "<" + string.Join(", ", t.GetGenericArguments().Select(PrettyPrintTypeName)) + ">"; - } - } - - // Handle nested types - if (!t.IsGenericParameter) - { - var containerType = t.DeclaringType; - if (containerType != null) - { - name = PrettyPrintTypeName(containerType) + "." + name; - } - } - - return name; - } - catch - { - // If anything at all goes wrong, fall back to the full type name so that we don't crash the server. - return t.FullName; - } - } private static void SplitTypeIntoPrefixAndFriendlyName(Type type, out string prefix, out string friendlyName) { diff --git a/src/Microsoft.AspNet.Hosting/project.json b/src/Microsoft.AspNet.Hosting/project.json index 4054e9c8a8..81c7525f8e 100644 --- a/src/Microsoft.AspNet.Hosting/project.json +++ b/src/Microsoft.AspNet.Hosting/project.json @@ -22,6 +22,10 @@ "Microsoft.Extensions.DependencyInjection": "1.0.0-*", "Microsoft.Extensions.Logging": "1.0.0-*", "Microsoft.Extensions.PlatformAbstractions": "1.0.0-*", + "Microsoft.Extensions.TypeNameHelper.Sources": { + "version": "1.0.0-*", + "type": "build" + }, "System.Diagnostics.DiagnosticSource": "4.0.0-*" }, "frameworks": { From a4fec4943cbbaf88b675ad6319a19e7fb21263cd Mon Sep 17 00:00:00 2001 From: Pranav K Date: Fri, 11 Dec 2015 12:23:06 -0800 Subject: [PATCH 465/987] Updating to release NuGet.config. --- NuGet.config | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/NuGet.config b/NuGet.config index 03704957e8..9db87a421e 100644 --- a/NuGet.config +++ b/NuGet.config @@ -1,7 +1,7 @@ - + - + \ No newline at end of file From 3325bfc653583c1e1bb76929dad9cdd003fd4ff2 Mon Sep 17 00:00:00 2001 From: Kiran Challa Date: Sat, 12 Dec 2015 22:12:01 -0800 Subject: [PATCH 466/987] Fix how we chose target runtime in deployers --- .../Deployers/ApplicationDeployer.cs | 23 ++-- .../Deployers/ApplicationDeployerFactory.cs | 5 - .../Deployers/MonoDeployer.cs | 128 ------------------ 3 files changed, 11 insertions(+), 145 deletions(-) delete mode 100644 src/Microsoft.AspNet.Server.Testing/Deployers/MonoDeployer.cs diff --git a/src/Microsoft.AspNet.Server.Testing/Deployers/ApplicationDeployer.cs b/src/Microsoft.AspNet.Server.Testing/Deployers/ApplicationDeployer.cs index df1d0bcbe3..643c2d8310 100644 --- a/src/Microsoft.AspNet.Server.Testing/Deployers/ApplicationDeployer.cs +++ b/src/Microsoft.AspNet.Server.Testing/Deployers/ApplicationDeployer.cs @@ -103,27 +103,26 @@ namespace Microsoft.AspNet.Server.Testing string currentRuntimeBinPath = PlatformServices.Default.Runtime.RuntimePath; Logger.LogInformation($"Current runtime path is : {currentRuntimeBinPath}"); - var targetRuntimeName = new StringBuilder() + string targetRuntimeName; + if (DeploymentParameters.RuntimeFlavor == RuntimeFlavor.Mono) + { + targetRuntimeName = "dnx-mono"; + } + else + { + targetRuntimeName = new StringBuilder() .Append("dnx") .Append((DeploymentParameters.RuntimeFlavor == RuntimeFlavor.CoreClr) ? "-coreclr" : "-clr") .Append($"-{OSPrefix}") .Append((DeploymentParameters.RuntimeArchitecture == RuntimeArchitecture.x86) ? "-x86" : "-x64") .ToString(); - - string targetRuntimeBinPath; - // Ex: When current runtime is Mono and the tests are being run for CoreClr - if (currentRuntimeBinPath.Contains("dnx-mono")) - { - targetRuntimeBinPath = currentRuntimeBinPath.Replace("dnx-mono", targetRuntimeName); } - else - { - targetRuntimeBinPath = Regex.Replace( + + var targetRuntimeBinPath = Regex.Replace( currentRuntimeBinPath, - "dnx-(clr|coreclr)-(win|linux|darwin)-(x86|x64)", + "dnx-(mono|((clr|coreclr)-(win|linux|darwin)-(x86|x64)))", targetRuntimeName, RegexOptions.IgnoreCase); - } var targetRuntimeBinDir = new DirectoryInfo(targetRuntimeBinPath); if (targetRuntimeBinDir == null || !targetRuntimeBinDir.Exists) diff --git a/src/Microsoft.AspNet.Server.Testing/Deployers/ApplicationDeployerFactory.cs b/src/Microsoft.AspNet.Server.Testing/Deployers/ApplicationDeployerFactory.cs index 2ceaa03eed..4e4ae9d1e0 100644 --- a/src/Microsoft.AspNet.Server.Testing/Deployers/ApplicationDeployerFactory.cs +++ b/src/Microsoft.AspNet.Server.Testing/Deployers/ApplicationDeployerFactory.cs @@ -29,11 +29,6 @@ namespace Microsoft.AspNet.Server.Testing throw new ArgumentNullException(nameof(logger)); } - if (deploymentParameters.RuntimeFlavor == RuntimeFlavor.Mono) - { - return new MonoDeployer(deploymentParameters, logger); - } - switch (deploymentParameters.ServerType) { case ServerType.IISExpress: diff --git a/src/Microsoft.AspNet.Server.Testing/Deployers/MonoDeployer.cs b/src/Microsoft.AspNet.Server.Testing/Deployers/MonoDeployer.cs deleted file mode 100644 index 00e1d9b999..0000000000 --- a/src/Microsoft.AspNet.Server.Testing/Deployers/MonoDeployer.cs +++ /dev/null @@ -1,128 +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; -using System.Collections.Generic; -using System.Diagnostics; -using System.IO; -using System.Linq; -using System.Threading; -using Microsoft.Extensions.Logging; - -namespace Microsoft.AspNet.Server.Testing -{ - /// - /// Deployer for Kestrel on Mono. - /// - public class MonoDeployer : ApplicationDeployer - { - private Process _hostProcess; - - public MonoDeployer(DeploymentParameters deploymentParameters, ILogger logger) - : base(deploymentParameters, logger) - { - } - - public override DeploymentResult Deploy() - { - // Start timer - StartTimer(); - - var path = Environment.GetEnvironmentVariable("PATH"); - var runtimeBin = path.Split(new char[] { ':' }, StringSplitOptions.RemoveEmptyEntries). - Where(c => c.Contains("dnx-mono")).FirstOrDefault(); - - if (string.IsNullOrWhiteSpace(runtimeBin)) - { - throw new Exception("Runtime not detected on the machine."); - } - - var runtimeBinDir = new DirectoryInfo(runtimeBin); - ChosenRuntimePath = runtimeBinDir.FullName; - ChosenRuntimeName = runtimeBinDir.Parent.Name; - DeploymentParameters.DnxRuntime = ChosenRuntimeName; - - if (DeploymentParameters.PublishApplicationBeforeDeployment) - { - // We use full path to runtime to pack. - DnuPublish(); - } - - DeploymentParameters.EnvironmentVariables - .Add(new KeyValuePair("DNX_APPBASE", DeploymentParameters.ApplicationPath)); - - // Launch the host process. - var hostExitToken = StartMonoHost(); - - return new DeploymentResult - { - WebRootLocation = DeploymentParameters.ApplicationPath, - DeploymentParameters = DeploymentParameters, - ApplicationBaseUri = DeploymentParameters.ApplicationBaseUriHint, - HostShutdownToken = hostExitToken - }; - } - - private CancellationToken StartMonoHost() - { - if (DeploymentParameters.ServerType != ServerType.Kestrel) - { - throw new InvalidOperationException("kestrel is the only valid ServerType for Mono"); - } - - var dnxPath = Path.Combine(ChosenRuntimePath, DnxCommandName); - var dnxArgs = $"-p \"{DeploymentParameters.ApplicationPath}\" kestrel --server.urls {DeploymentParameters.ApplicationBaseUriHint}"; - Logger.LogInformation($"Executing command {dnxPath} {dnxArgs}"); - - var startInfo = new ProcessStartInfo - { - FileName = dnxPath, - Arguments = dnxArgs, - UseShellExecute = false, - CreateNoWindow = true, - RedirectStandardError = true, - RedirectStandardOutput = true, - // Trying a work around for https://github.com/aspnet/Hosting/issues/140. - RedirectStandardInput = true - }; - - AddEnvironmentVariablesToProcess(startInfo); - - _hostProcess = new Process() { StartInfo = startInfo }; - _hostProcess.ErrorDataReceived += (sender, dataArgs) => { Logger.LogError(dataArgs.Data ?? string.Empty); }; - _hostProcess.OutputDataReceived += (sender, dataArgs) => { Logger.LogInformation(dataArgs.Data ?? string.Empty); }; - _hostProcess.EnableRaisingEvents = true; - var hostExitTokenSource = new CancellationTokenSource(); - _hostProcess.Exited += (sender, e) => - { - TriggerHostShutdown(hostExitTokenSource); - }; - _hostProcess.Start(); - _hostProcess.BeginErrorReadLine(); - _hostProcess.BeginOutputReadLine(); - - if (_hostProcess.HasExited) - { - Logger.LogError("Host process {processName} exited with code {exitCode} or failed to start.", startInfo.FileName, _hostProcess.ExitCode); - throw new Exception("Failed to start host"); - } - - Logger.LogInformation("Started {fileName}. Process Id : {processId}", startInfo.FileName, _hostProcess.Id); - return hostExitTokenSource.Token; - } - - public override void Dispose() - { - ShutDownIfAnyHostProcess(_hostProcess); - - if (DeploymentParameters.PublishApplicationBeforeDeployment) - { - CleanPublishedOutput(); - } - - InvokeUserApplicationCleanup(); - - StopTimer(); - } - } -} \ No newline at end of file From 455d86594828b471028db08976c03db2357ba3f2 Mon Sep 17 00:00:00 2001 From: John Luo Date: Mon, 14 Dec 2015 10:02:27 -0800 Subject: [PATCH 467/987] Fixing deadlock hang in test when running in single threaded environment --- src/Microsoft.AspNet.TestHost/ClientHandler.cs | 2 +- test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Microsoft.AspNet.TestHost/ClientHandler.cs b/src/Microsoft.AspNet.TestHost/ClientHandler.cs index 30a48d38aa..0dac9f0546 100644 --- a/src/Microsoft.AspNet.TestHost/ClientHandler.cs +++ b/src/Microsoft.AspNet.TestHost/ClientHandler.cs @@ -94,7 +94,7 @@ namespace Microsoft.AspNet.TestHost } }); - return await state.ResponseTask; + return await state.ResponseTask.ConfigureAwait(false); } private class RequestState diff --git a/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs b/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs index 80e0e44f0f..b923a10826 100644 --- a/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs +++ b/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs @@ -353,7 +353,7 @@ namespace Microsoft.AspNet.TestHost [ConditionalFact] [FrameworkSkipCondition(RuntimeFrameworks.Mono, SkipReason = "Hangs randomly (issue #507)")] - public void CancelAborts() + public async Task CancelAborts() { TestServer server = TestServer.Create(app => { @@ -365,7 +365,7 @@ namespace Microsoft.AspNet.TestHost }); }); - Assert.Throws(() => { string result = server.CreateClient().GetStringAsync("/path").Result; }); + await Assert.ThrowsAsync(async () => { string result = await server.CreateClient().GetStringAsync("/path"); }); } [ConditionalFact] From 5e837b4eef82a26e74b9ad1d0edddacea560a9ab Mon Sep 17 00:00:00 2001 From: Martin Johns Date: Mon, 7 Dec 2015 09:57:49 +0100 Subject: [PATCH 468/987] Reduce overuse of null-conditional operator --- src/Microsoft.AspNet.Hosting/WebHostBuilder.cs | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/Microsoft.AspNet.Hosting/WebHostBuilder.cs b/src/Microsoft.AspNet.Hosting/WebHostBuilder.cs index 5c96962fb2..4157a831d5 100644 --- a/src/Microsoft.AspNet.Hosting/WebHostBuilder.cs +++ b/src/Microsoft.AspNet.Hosting/WebHostBuilder.cs @@ -88,14 +88,18 @@ namespace Microsoft.AspNet.Hosting _configureServices(services); } - if (PlatformServices.Default?.Application != null) + var defaultPlatformServices = PlatformServices.Default; + if (defaultPlatformServices != null) { - services.TryAdd(ServiceDescriptor.Instance(PlatformServices.Default.Application)); - } + if (defaultPlatformServices.Application != null) + { + services.TryAdd(ServiceDescriptor.Instance(defaultPlatformServices.Application)); + } - if (PlatformServices.Default?.Runtime != null) - { - services.TryAdd(ServiceDescriptor.Instance(PlatformServices.Default.Runtime)); + if (defaultPlatformServices.Runtime != null) + { + services.TryAdd(ServiceDescriptor.Instance(defaultPlatformServices.Runtime)); + } } return services; From 35f9de5ae146b00bad4cce3f53093a0cb1bff6de Mon Sep 17 00:00:00 2001 From: Pranav K Date: Thu, 17 Dec 2015 11:45:48 -0800 Subject: [PATCH 469/987] Reacting to DI and PlatformAbstraction changes --- src/Microsoft.AspNet.Hosting/WebHostBuilder.cs | 4 ++-- .../Fakes/RuntimeEnvironment.cs | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Microsoft.AspNet.Hosting/WebHostBuilder.cs b/src/Microsoft.AspNet.Hosting/WebHostBuilder.cs index 4157a831d5..5f4d3a1dd1 100644 --- a/src/Microsoft.AspNet.Hosting/WebHostBuilder.cs +++ b/src/Microsoft.AspNet.Hosting/WebHostBuilder.cs @@ -93,12 +93,12 @@ namespace Microsoft.AspNet.Hosting { if (defaultPlatformServices.Application != null) { - services.TryAdd(ServiceDescriptor.Instance(defaultPlatformServices.Application)); + services.TryAddSingleton(defaultPlatformServices.Application); } if (defaultPlatformServices.Runtime != null) { - services.TryAdd(ServiceDescriptor.Instance(defaultPlatformServices.Runtime)); + services.TryAddSingleton(defaultPlatformServices.Runtime); } } diff --git a/test/Microsoft.AspNet.Hosting.Tests/Fakes/RuntimeEnvironment.cs b/test/Microsoft.AspNet.Hosting.Tests/Fakes/RuntimeEnvironment.cs index ee180c4f01..c7cdd3f997 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/Fakes/RuntimeEnvironment.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/Fakes/RuntimeEnvironment.cs @@ -18,5 +18,7 @@ namespace Microsoft.AspNet.Hosting.Fakes public string RuntimeVersion { get; } = "TestRuntimeVersion"; public string RuntimePath { get; } = "TestRuntimePath"; + + public Platform OperatingSystemPlatform => Platform.Unknown; } } From 1c70ff4d139f7992457368467e9986b7af3a0200 Mon Sep 17 00:00:00 2001 From: David Fowler Date: Fri, 11 Dec 2015 13:03:43 -0800 Subject: [PATCH 470/987] API changes to Hosting and TestServer #525 --- Hosting.sln | 19 +- samples/SampleStartups/SampleStartups.xproj | 25 ++ .../SampleStartups/StartupBlockingOnStart.cs | 44 +++ .../StartupConfigureAddresses.cs | 44 +++ .../StartupExternallyControlled.cs | 56 +++ samples/SampleStartups/StartupFullControl.cs | 68 ++++ samples/SampleStartups/StartupHelloWorld.cs | 40 +++ samples/SampleStartups/project.json | 10 + .../IWebApplication.cs | 30 ++ .../Internal/Application.cs | 37 -- .../{ => Internal}/ApplicationLifetime.cs | 2 +- .../{ => Internal}/HostingEnvironment.cs | 2 +- .../HostingEnvironmentExtensions.cs | 4 +- .../Internal/IApplication.cs | 15 - .../Internal/IHostingEngine.cs | 15 - .../{HostingEngine.cs => WebApplication.cs} | 60 ++-- .../Internal/WebApplicationOptions.cs | 50 +++ src/Microsoft.AspNet.Hosting/Program.cs | 13 - .../WebApplication.cs | 93 ----- ...ostBuilder.cs => WebApplicationBuilder.cs} | 333 +++++++++--------- .../WebApplicationConfiguration.cs | 40 +++ .../WebApplicationExtensions.cs | 60 ++++ .../WebHostOptions.cs | 47 --- src/Microsoft.AspNet.TestHost/TestServer.cs | 75 +--- .../HostingEnvironmentExtensionsTests.cs | 13 +- .../StartupManagerTests.cs | 1 + ...Tests.cs => WebApplicationBuilderTests.cs} | 77 ++-- ...s => WebApplicationConfigurationsTests.cs} | 25 +- ...gEngineTests.cs => WebApplicationTests.cs} | 172 ++++----- .../RequestBuilderTests.cs | 7 +- .../TestClientTests.cs | 33 +- .../TestServerTests.cs | 147 +++++--- 32 files changed, 948 insertions(+), 709 deletions(-) create mode 100644 samples/SampleStartups/SampleStartups.xproj create mode 100644 samples/SampleStartups/StartupBlockingOnStart.cs create mode 100644 samples/SampleStartups/StartupConfigureAddresses.cs create mode 100644 samples/SampleStartups/StartupExternallyControlled.cs create mode 100644 samples/SampleStartups/StartupFullControl.cs create mode 100644 samples/SampleStartups/StartupHelloWorld.cs create mode 100644 samples/SampleStartups/project.json create mode 100644 src/Microsoft.AspNet.Hosting/IWebApplication.cs delete mode 100644 src/Microsoft.AspNet.Hosting/Internal/Application.cs rename src/Microsoft.AspNet.Hosting/{ => Internal}/ApplicationLifetime.cs (98%) rename src/Microsoft.AspNet.Hosting/{ => Internal}/HostingEnvironment.cs (93%) rename src/Microsoft.AspNet.Hosting/{ => Internal}/HostingEnvironmentExtensions.cs (92%) delete mode 100644 src/Microsoft.AspNet.Hosting/Internal/IApplication.cs delete mode 100644 src/Microsoft.AspNet.Hosting/Internal/IHostingEngine.cs rename src/Microsoft.AspNet.Hosting/Internal/{HostingEngine.cs => WebApplication.cs} (87%) create mode 100644 src/Microsoft.AspNet.Hosting/Internal/WebApplicationOptions.cs delete mode 100644 src/Microsoft.AspNet.Hosting/Program.cs delete mode 100644 src/Microsoft.AspNet.Hosting/WebApplication.cs rename src/Microsoft.AspNet.Hosting/{WebHostBuilder.cs => WebApplicationBuilder.cs} (65%) create mode 100644 src/Microsoft.AspNet.Hosting/WebApplicationConfiguration.cs create mode 100644 src/Microsoft.AspNet.Hosting/WebApplicationExtensions.cs delete mode 100644 src/Microsoft.AspNet.Hosting/WebHostOptions.cs rename test/Microsoft.AspNet.Hosting.Tests/{WebHostBuilderTests.cs => WebApplicationBuilderTests.cs} (66%) rename test/Microsoft.AspNet.Hosting.Tests/{WebHostConfigurationsTests.cs => WebApplicationConfigurationsTests.cs} (66%) rename test/Microsoft.AspNet.Hosting.Tests/{HostingEngineTests.cs => WebApplicationTests.cs} (77%) diff --git a/Hosting.sln b/Hosting.sln index 0c93390a49..a04fd5e533 100644 --- a/Hosting.sln +++ b/Hosting.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 14 -VisualStudioVersion = 14.0.22803.0 +VisualStudioVersion = 14.0.23107.0 MinimumVisualStudioVersion = 10.0.40219.1 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{E0497F39-AFFB-4819-A116-E39E361915AB}" EndProject @@ -26,6 +26,10 @@ Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNet.Hosting.Se EndProject Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNet.Server.Testing", "src\Microsoft.AspNet.Server.Testing\Microsoft.AspNet.Server.Testing.xproj", "{3DA89347-6731-4366-80C4-548F24E8607B}" EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "samples", "samples", "{9C7520A0-F2EB-411C-8BB2-80B39C937217}" +EndProject +Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "SampleStartups", "samples\SampleStartups\SampleStartups.xproj", "{485B6745-7648-400A-A969-F68FCF194E46}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -112,6 +116,18 @@ Global {3DA89347-6731-4366-80C4-548F24E8607B}.Release|Mixed Platforms.Build.0 = Release|Any CPU {3DA89347-6731-4366-80C4-548F24E8607B}.Release|x86.ActiveCfg = Release|Any CPU {3DA89347-6731-4366-80C4-548F24E8607B}.Release|x86.Build.0 = Release|Any CPU + {485B6745-7648-400A-A969-F68FCF194E46}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {485B6745-7648-400A-A969-F68FCF194E46}.Debug|Any CPU.Build.0 = Debug|Any CPU + {485B6745-7648-400A-A969-F68FCF194E46}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU + {485B6745-7648-400A-A969-F68FCF194E46}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU + {485B6745-7648-400A-A969-F68FCF194E46}.Debug|x86.ActiveCfg = Debug|Any CPU + {485B6745-7648-400A-A969-F68FCF194E46}.Debug|x86.Build.0 = Debug|Any CPU + {485B6745-7648-400A-A969-F68FCF194E46}.Release|Any CPU.ActiveCfg = Release|Any CPU + {485B6745-7648-400A-A969-F68FCF194E46}.Release|Any CPU.Build.0 = Release|Any CPU + {485B6745-7648-400A-A969-F68FCF194E46}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU + {485B6745-7648-400A-A969-F68FCF194E46}.Release|Mixed Platforms.Build.0 = Release|Any CPU + {485B6745-7648-400A-A969-F68FCF194E46}.Release|x86.ActiveCfg = Release|Any CPU + {485B6745-7648-400A-A969-F68FCF194E46}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -124,5 +140,6 @@ Global {BB780FBB-7842-4759-8DE7-96FA2E5571C1} = {E0497F39-AFFB-4819-A116-E39E361915AB} {FDBBA081-5248-4FC0-9E08-B46BEF3FA438} = {E0497F39-AFFB-4819-A116-E39E361915AB} {3DA89347-6731-4366-80C4-548F24E8607B} = {E0497F39-AFFB-4819-A116-E39E361915AB} + {485B6745-7648-400A-A969-F68FCF194E46} = {9C7520A0-F2EB-411C-8BB2-80B39C937217} EndGlobalSection EndGlobal diff --git a/samples/SampleStartups/SampleStartups.xproj b/samples/SampleStartups/SampleStartups.xproj new file mode 100644 index 0000000000..c22f75c6a2 --- /dev/null +++ b/samples/SampleStartups/SampleStartups.xproj @@ -0,0 +1,25 @@ + + + + 14.0 + $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) + + + + + 485b6745-7648-400a-a969-f68fcf194e46 + SampleStartups + ..\..\artifacts\obj\$(MSBuildProjectName) + ..\..\artifacts\bin\$(MSBuildProjectName)\ + + + + 2.0 + + + + + + + + diff --git a/samples/SampleStartups/StartupBlockingOnStart.cs b/samples/SampleStartups/StartupBlockingOnStart.cs new file mode 100644 index 0000000000..39db2830c4 --- /dev/null +++ b/samples/SampleStartups/StartupBlockingOnStart.cs @@ -0,0 +1,44 @@ +using System; +using Microsoft.AspNet.Builder; +using Microsoft.AspNet.Hosting; +using Microsoft.AspNet.Http; +using Microsoft.Extensions.DependencyInjection; + +// Note that this sample will not run. It is only here to illustrate usage patterns. + +namespace SampleStartups +{ + public class StartupBlockingOnStart + { + // This method gets called by the runtime. Use this method to add services to the container. + // For more information on how to configure your application, visit http://go.microsoft.com/fwlink/?LinkID=398940 + public void ConfigureServices(IServiceCollection services) + { + } + + // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. + public void Configure(IApplicationBuilder app) + { + app.Run(async (context) => + { + await context.Response.WriteAsync("Hello World!"); + }); + } + + // Entry point for the application. + public static void Main(string[] args) + { + var config = WebApplicationConfiguration.GetDefault(args); + + var application = new WebApplicationBuilder() + .UseConfiguration(config) + .UseStartup() + .Build(); + + using (application.Start()) + { + Console.ReadLine(); + } + } + } +} diff --git a/samples/SampleStartups/StartupConfigureAddresses.cs b/samples/SampleStartups/StartupConfigureAddresses.cs new file mode 100644 index 0000000000..0fff30e2f8 --- /dev/null +++ b/samples/SampleStartups/StartupConfigureAddresses.cs @@ -0,0 +1,44 @@ +using Microsoft.AspNet.Builder; +using Microsoft.AspNet.Hosting; +using Microsoft.AspNet.Http; +using Microsoft.Extensions.DependencyInjection; + +// Note that this sample will not run. It is only here to illustrate usage patterns. + +namespace SampleStartups +{ + public class StartupConfigureAddresses + { + // This method gets called by the runtime. Use this method to add services to the container. + // For more information on how to configure your application, visit http://go.microsoft.com/fwlink/?LinkID=398940 + public void ConfigureServices(IServiceCollection services) + { + } + + // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. + public void Configure(IApplicationBuilder app) + { + app.Run(async (context) => + { + await context.Response.WriteAsync("Hello World!"); + }); + } + + // Entry point for the application. + public static void Main(string[] args) + { + var config = WebApplicationConfiguration.GetDefault(args); + + var application = new WebApplicationBuilder() + .UseConfiguration(config) + .UseStartup() + .Build(); + + var addresses = application.GetAddresses(); + addresses.Add("http://localhost:5000"); + addresses.Add("http://localhost:5001"); + + application.Run(); + } + } +} diff --git a/samples/SampleStartups/StartupExternallyControlled.cs b/samples/SampleStartups/StartupExternallyControlled.cs new file mode 100644 index 0000000000..dc7ce9d8b4 --- /dev/null +++ b/samples/SampleStartups/StartupExternallyControlled.cs @@ -0,0 +1,56 @@ +using System; +using Microsoft.AspNet.Builder; +using Microsoft.AspNet.Hosting; +using Microsoft.AspNet.Http; +using Microsoft.Extensions.DependencyInjection; + +// Note that this sample will not run. It is only here to illustrate usage patterns. + +namespace SampleStartups +{ + public class StartupExternallyControlled + { + private readonly IWebApplication _host; + private IDisposable _application; + + // This method gets called by the runtime. Use this method to add services to the container. + // For more information on how to configure your application, visit http://go.microsoft.com/fwlink/?LinkID=398940 + public void ConfigureServices(IServiceCollection services) + { + } + + // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. + public void Configure(IApplicationBuilder app) + { + app.Run(async (context) => + { + await context.Response.WriteAsync("Hello World!"); + }); + } + + public StartupExternallyControlled() + { + _host = new WebApplicationBuilder().UseStartup().Build(); + + // Clear all configured addresses + _host.GetAddresses().Clear(); + } + + public void Start() + { + _application = _host.Start(); + } + + public void Stop() + { + _application.Dispose(); + } + + public void AddUrl(string url) + { + var addresses = _host.GetAddresses(); + + addresses.Add(url); + } + } +} diff --git a/samples/SampleStartups/StartupFullControl.cs b/samples/SampleStartups/StartupFullControl.cs new file mode 100644 index 0000000000..34a00a5a46 --- /dev/null +++ b/samples/SampleStartups/StartupFullControl.cs @@ -0,0 +1,68 @@ +using System; +using Microsoft.AspNet.Builder; +using Microsoft.AspNet.Hosting; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; + +// Note that this sample will not run. It is only here to illustrate usage patterns. + +namespace SampleStartups +{ + public class StartupFullControl + { + public static void Main(string[] args) + { + var application = new WebApplicationBuilder() + .UseServerFactory("Microsoft.AspNet.Server.Kestrel") // Set the server manually + .UseEnvironment("Development") + .UseWebRoot("public") + .ConfigureLogging(loggerFactory => + { + loggerFactory.AddProvider(new MyHostLoggerProvider()); + }) + .ConfigureServices(services => + { + // Configure services that the application can see + services.AddSingleton(); + }) + .Configure(app => + { + // Write the application inline, this won't call any startup class in the assembly + + app.Use(next => context => + { + return next(context); + }); + }) + .Build(); + + application.Run(); + } + } + + public class MyHostLoggerProvider : ILoggerProvider + { + public ILogger CreateLogger(string categoryName) + { + throw new NotImplementedException(); + } + + public void Dispose() + { + throw new NotImplementedException(); + } + } + + public interface IMyCustomService + { + void Go(); + } + + public class MyCustomService : IMyCustomService + { + public void Go() + { + throw new NotImplementedException(); + } + } +} diff --git a/samples/SampleStartups/StartupHelloWorld.cs b/samples/SampleStartups/StartupHelloWorld.cs new file mode 100644 index 0000000000..4ee08e2f16 --- /dev/null +++ b/samples/SampleStartups/StartupHelloWorld.cs @@ -0,0 +1,40 @@ +using Microsoft.AspNet.Builder; +using Microsoft.AspNet.Hosting; +using Microsoft.AspNet.Http; +using Microsoft.Extensions.DependencyInjection; + +// Note that this sample will not run. It is only here to illustrate usage patterns. + +namespace SampleStartups +{ + public class StartupHelloWorld + { + // This method gets called by the runtime. Use this method to add services to the container. + // For more information on how to configure your application, visit http://go.microsoft.com/fwlink/?LinkID=398940 + public void ConfigureServices(IServiceCollection services) + { + } + + // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. + public void Configure(IApplicationBuilder app) + { + app.Run(async (context) => + { + await context.Response.WriteAsync("Hello World!"); + }); + } + + // Entry point for the application. + public static void Main(string[] args) + { + var config = WebApplicationConfiguration.GetDefault(args); + + var application = new WebApplicationBuilder() + .UseConfiguration(config) + .UseStartup() + .Build(); + + application.Run(); + } + } +} diff --git a/samples/SampleStartups/project.json b/samples/SampleStartups/project.json new file mode 100644 index 0000000000..4fb88a1477 --- /dev/null +++ b/samples/SampleStartups/project.json @@ -0,0 +1,10 @@ +{ + "version": "1.0.0-*", + "dependencies": { + "Microsoft.AspNet.Hosting": "1.0.0-*" + }, + "frameworks": { + "dnx451": { }, + "dnxcore50": { } + } +} diff --git a/src/Microsoft.AspNet.Hosting/IWebApplication.cs b/src/Microsoft.AspNet.Hosting/IWebApplication.cs new file mode 100644 index 0000000000..0db082a45f --- /dev/null +++ b/src/Microsoft.AspNet.Hosting/IWebApplication.cs @@ -0,0 +1,30 @@ +// 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; +using Microsoft.AspNet.Http.Features; + +namespace Microsoft.AspNet.Hosting +{ + /// + /// Represents a configured web application + /// + public interface IWebApplication + { + /// + /// The exposed by the configured server. + /// + IFeatureCollection ServerFeatures { get; } + + /// + /// The for the application. + /// + IServiceProvider Services { get; } + + /// + /// Starts listening on the configured addresses. + /// + /// + IDisposable Start(); + } +} diff --git a/src/Microsoft.AspNet.Hosting/Internal/Application.cs b/src/Microsoft.AspNet.Hosting/Internal/Application.cs deleted file mode 100644 index ecbb916a6e..0000000000 --- a/src/Microsoft.AspNet.Hosting/Internal/Application.cs +++ /dev/null @@ -1,37 +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; -using Microsoft.AspNet.Http.Features; - -namespace Microsoft.AspNet.Hosting.Internal -{ - public class Application : IApplication - { - private readonly IDisposable _stop; - private readonly IServiceProvider _services; - private readonly IFeatureCollection _server; - - public Application(IServiceProvider services, IFeatureCollection server, IDisposable stop) - { - _services = services; - _server = server; - _stop = stop; - } - - public IFeatureCollection ServerFeatures - { - get { return _server; } - } - - public IServiceProvider Services - { - get { return _services; } - } - - public void Dispose() - { - _stop.Dispose(); - } - } -} diff --git a/src/Microsoft.AspNet.Hosting/ApplicationLifetime.cs b/src/Microsoft.AspNet.Hosting/Internal/ApplicationLifetime.cs similarity index 98% rename from src/Microsoft.AspNet.Hosting/ApplicationLifetime.cs rename to src/Microsoft.AspNet.Hosting/Internal/ApplicationLifetime.cs index 230b4fd4e3..8955cf8d1e 100644 --- a/src/Microsoft.AspNet.Hosting/ApplicationLifetime.cs +++ b/src/Microsoft.AspNet.Hosting/Internal/ApplicationLifetime.cs @@ -4,7 +4,7 @@ using System; using System.Threading; -namespace Microsoft.AspNet.Hosting +namespace Microsoft.AspNet.Hosting.Internal { /// /// Allows consumers to perform cleanup during a graceful shutdown. diff --git a/src/Microsoft.AspNet.Hosting/HostingEnvironment.cs b/src/Microsoft.AspNet.Hosting/Internal/HostingEnvironment.cs similarity index 93% rename from src/Microsoft.AspNet.Hosting/HostingEnvironment.cs rename to src/Microsoft.AspNet.Hosting/Internal/HostingEnvironment.cs index e7254247a2..0428ce490b 100644 --- a/src/Microsoft.AspNet.Hosting/HostingEnvironment.cs +++ b/src/Microsoft.AspNet.Hosting/Internal/HostingEnvironment.cs @@ -4,7 +4,7 @@ using Microsoft.AspNet.FileProviders; using Microsoft.Extensions.Configuration; -namespace Microsoft.AspNet.Hosting +namespace Microsoft.AspNet.Hosting.Internal { public class HostingEnvironment : IHostingEnvironment { diff --git a/src/Microsoft.AspNet.Hosting/HostingEnvironmentExtensions.cs b/src/Microsoft.AspNet.Hosting/Internal/HostingEnvironmentExtensions.cs similarity index 92% rename from src/Microsoft.AspNet.Hosting/HostingEnvironmentExtensions.cs rename to src/Microsoft.AspNet.Hosting/Internal/HostingEnvironmentExtensions.cs index 6b46ba7214..cf4e1303bc 100644 --- a/src/Microsoft.AspNet.Hosting/HostingEnvironmentExtensions.cs +++ b/src/Microsoft.AspNet.Hosting/Internal/HostingEnvironmentExtensions.cs @@ -7,11 +7,11 @@ using Microsoft.AspNet.FileProviders; using Microsoft.AspNet.Hosting.Internal; using Microsoft.Extensions.Configuration; -namespace Microsoft.AspNet.Hosting +namespace Microsoft.AspNet.Hosting.Internal { public static class HostingEnvironmentExtensions { - public static void Initialize(this IHostingEnvironment hostingEnvironment, string applicationBasePath, WebHostOptions options, IConfiguration configuration) + public static void Initialize(this IHostingEnvironment hostingEnvironment, string applicationBasePath, WebApplicationOptions options, IConfiguration configuration) { if (options == null) { diff --git a/src/Microsoft.AspNet.Hosting/Internal/IApplication.cs b/src/Microsoft.AspNet.Hosting/Internal/IApplication.cs deleted file mode 100644 index 99f807e10c..0000000000 --- a/src/Microsoft.AspNet.Hosting/Internal/IApplication.cs +++ /dev/null @@ -1,15 +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; -using Microsoft.AspNet.Http.Features; - -namespace Microsoft.AspNet.Hosting.Internal -{ - public interface IApplication : IDisposable - { - IFeatureCollection ServerFeatures { get; } - - IServiceProvider Services { get; } - } -} diff --git a/src/Microsoft.AspNet.Hosting/Internal/IHostingEngine.cs b/src/Microsoft.AspNet.Hosting/Internal/IHostingEngine.cs deleted file mode 100644 index 4b8789a9ca..0000000000 --- a/src/Microsoft.AspNet.Hosting/Internal/IHostingEngine.cs +++ /dev/null @@ -1,15 +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; - -namespace Microsoft.AspNet.Hosting.Internal -{ - public interface IHostingEngine - { - IApplication Start(); - - // Accessing this will block Use methods - IServiceProvider ApplicationServices { get; } - } -} \ No newline at end of file diff --git a/src/Microsoft.AspNet.Hosting/Internal/HostingEngine.cs b/src/Microsoft.AspNet.Hosting/Internal/WebApplication.cs similarity index 87% rename from src/Microsoft.AspNet.Hosting/Internal/HostingEngine.cs rename to src/Microsoft.AspNet.Hosting/Internal/WebApplication.cs index 6236fa2e8c..0014537a7b 100644 --- a/src/Microsoft.AspNet.Hosting/Internal/HostingEngine.cs +++ b/src/Microsoft.AspNet.Hosting/Internal/WebApplication.cs @@ -19,7 +19,7 @@ using Microsoft.Extensions.PlatformAbstractions; namespace Microsoft.AspNet.Hosting.Internal { - public class HostingEngine : IHostingEngine + public class WebApplication : IWebApplication { // This is defined by IIS's HttpPlatformHandler. private static readonly string ServerPort = "HTTP_PLATFORM_PORT"; @@ -27,11 +27,11 @@ namespace Microsoft.AspNet.Hosting.Internal private readonly IServiceCollection _applicationServiceCollection; private readonly IStartupLoader _startupLoader; private readonly ApplicationLifetime _applicationLifetime; - private readonly WebHostOptions _options; + private readonly WebApplicationOptions _options; private readonly IConfiguration _config; - private readonly bool _captureStartupErrors; private IServiceProvider _applicationServices; + private RequestDelegate _application; // Only one of these should be set internal string StartupAssemblyName { get; set; } @@ -43,12 +43,11 @@ namespace Microsoft.AspNet.Hosting.Internal internal string ServerFactoryLocation { get; set; } internal IServer Server { get; set; } - public HostingEngine( + public WebApplication( IServiceCollection appServices, IStartupLoader startupLoader, - WebHostOptions options, - IConfiguration config, - bool captureStartupErrors) + WebApplicationOptions options, + IConfiguration config) { if (appServices == null) { @@ -69,12 +68,11 @@ namespace Microsoft.AspNet.Hosting.Internal _options = options; _applicationServiceCollection = appServices; _startupLoader = startupLoader; - _captureStartupErrors = captureStartupErrors; _applicationLifetime = new ApplicationLifetime(); _applicationServiceCollection.AddSingleton(_applicationLifetime); } - public IServiceProvider ApplicationServices + public IServiceProvider Services { get { @@ -83,29 +81,45 @@ namespace Microsoft.AspNet.Hosting.Internal } } - public virtual IApplication Start() + public IFeatureCollection ServerFeatures { - var application = BuildApplication(); + get + { + return Server?.Features; + } + } - var logger = _applicationServices.GetRequiredService>(); + public void Initialize() + { + if (_application == null) + { + _application = BuildApplication(); + } + } + + public virtual IDisposable Start() + { + Initialize(); + + var logger = _applicationServices.GetRequiredService>(); var diagnosticSource = _applicationServices.GetRequiredService(); var httpContextFactory = _applicationServices.GetRequiredService(); logger.Starting(); - Server.Start(new HostingApplication(application, logger, diagnosticSource, httpContextFactory)); + Server.Start(new HostingApplication(_application, logger, diagnosticSource, httpContextFactory)); _applicationLifetime.NotifyStarted(); logger.Started(); - return new Application(ApplicationServices, Server.Features, new Disposable(() => - { - logger.Shutdown(); - _applicationLifetime.StopApplication(); - Server.Dispose(); - _applicationLifetime.NotifyStopped(); - (_applicationServices as IDisposable)?.Dispose(); - })); + return new Disposable(() => + { + logger.Shutdown(); + _applicationLifetime.StopApplication(); + Server.Dispose(); + _applicationLifetime.NotifyStopped(); + (_applicationServices as IDisposable)?.Dispose(); + }); } private void EnsureApplicationServices() @@ -168,7 +182,7 @@ namespace Microsoft.AspNet.Hosting.Internal return builder.Build(); } - catch (Exception ex) when (_captureStartupErrors) + catch (Exception ex) when (_options.CaptureStartupErrors) { // EnsureApplicationServices may have failed due to a missing or throwing Startup class. if (_applicationServices == null) @@ -180,7 +194,7 @@ namespace Microsoft.AspNet.Hosting.Internal // Write errors to standard out so they can be retrieved when not in development mode. Console.Out.WriteLine("Application startup exception: " + ex.ToString()); - var logger = _applicationServices.GetRequiredService>(); + var logger = _applicationServices.GetRequiredService>(); logger.ApplicationError(ex); // Generate an HTML error page. diff --git a/src/Microsoft.AspNet.Hosting/Internal/WebApplicationOptions.cs b/src/Microsoft.AspNet.Hosting/Internal/WebApplicationOptions.cs new file mode 100644 index 0000000000..ef76bcdb8f --- /dev/null +++ b/src/Microsoft.AspNet.Hosting/Internal/WebApplicationOptions.cs @@ -0,0 +1,50 @@ +// 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; +using Microsoft.Extensions.Configuration; + +namespace Microsoft.AspNet.Hosting.Internal +{ + public class WebApplicationOptions + { + private const string OldEnvironmentKey = "ENV"; + + public WebApplicationOptions() + { + } + + public WebApplicationOptions(IConfiguration configuration) + { + if (configuration == null) + { + throw new ArgumentNullException(nameof(configuration)); + } + + Application = configuration[WebApplicationConfiguration.ApplicationKey]; + DetailedErrors = ParseBool(configuration, WebApplicationConfiguration.DetailedErrorsKey); + CaptureStartupErrors = ParseBool(configuration, WebApplicationConfiguration.CaptureStartupErrorsKey); + Environment = configuration[WebApplicationConfiguration.EnvironmentKey] ?? configuration[OldEnvironmentKey]; + ServerFactoryLocation = configuration[WebApplicationConfiguration.ServerKey]; + WebRoot = configuration[WebApplicationConfiguration.WebRootKey]; + } + + public string Application { get; set; } + + public bool DetailedErrors { get; set; } + + public bool CaptureStartupErrors { get; set; } + + public string Environment { get; set; } + + public string ServerFactoryLocation { get; set; } + + public string WebRoot { get; set; } + + private static bool ParseBool(IConfiguration configuration, string key) + { + return string.Equals("true", configuration[key], StringComparison.OrdinalIgnoreCase) + || string.Equals("1", configuration[key], StringComparison.OrdinalIgnoreCase); + } + } +} \ No newline at end of file diff --git a/src/Microsoft.AspNet.Hosting/Program.cs b/src/Microsoft.AspNet.Hosting/Program.cs deleted file mode 100644 index 80fa43f73f..0000000000 --- a/src/Microsoft.AspNet.Hosting/Program.cs +++ /dev/null @@ -1,13 +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. - -namespace Microsoft.AspNet.Hosting -{ - public class Program - { - public static void Main(string[] args) - { - WebApplication.Run(args); - } - } -} diff --git a/src/Microsoft.AspNet.Hosting/WebApplication.cs b/src/Microsoft.AspNet.Hosting/WebApplication.cs deleted file mode 100644 index f819fcec7a..0000000000 --- a/src/Microsoft.AspNet.Hosting/WebApplication.cs +++ /dev/null @@ -1,93 +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; -using Microsoft.AspNet.Http.Features; -using Microsoft.AspNet.Server.Features; -using Microsoft.Extensions.Configuration; -using Microsoft.Extensions.DependencyInjection; - -namespace Microsoft.AspNet.Hosting -{ - public class WebApplication - { - private const string HostingJsonFile = "hosting.json"; - private const string EnvironmentVariablesPrefix = "ASPNET_"; - private const string ConfigFileKey = "config"; - - public static void Run(string[] args) - { - Run(startupType: null, args: args); - } - - public static void Run() - { - Run(typeof(TStartup), null); - } - - public static void Run(string[] args) - { - Run(typeof(TStartup), args); - } - - public static void Run(Type startupType) - { - Run(startupType, null); - } - - public static void Run(Type startupType, string[] args) - { - // Allow the location of the json file to be specified via a --config command line arg - var tempBuilder = new ConfigurationBuilder().AddCommandLine(args); - var tempConfig = tempBuilder.Build(); - var configFilePath = tempConfig[ConfigFileKey] ?? HostingJsonFile; - var config = LoadHostingConfiguration(configFilePath, args); - - var hostBuilder = new WebHostBuilder(config, captureStartupErrors: true); - if (startupType != null) - { - hostBuilder.UseStartup(startupType); - } - var host = hostBuilder.Build(); - using (var app = host.Start()) - { - var hostingEnv = app.Services.GetRequiredService(); - Console.WriteLine("Hosting environment: " + hostingEnv.EnvironmentName); - - var serverAddresses = app.ServerFeatures.Get(); - if (serverAddresses != null) - { - foreach (var address in serverAddresses.Addresses) - { - Console.WriteLine("Now listening on: " + address); - } - } - - Console.WriteLine("Application started. Press Ctrl+C to shut down."); - - var appLifetime = app.Services.GetRequiredService(); - - Console.CancelKeyPress += (sender, eventArgs) => - { - appLifetime.StopApplication(); - // Don't terminate the process immediately, wait for the Main thread to exit gracefully. - eventArgs.Cancel = true; - }; - - appLifetime.ApplicationStopping.WaitHandle.WaitOne(); - } - } - - internal static IConfiguration LoadHostingConfiguration(string configJsonPath, string[] args) - { - // We are adding all environment variables first and then adding the ASPNET_ ones - // with the prefix removed to unify with the command line and config file formats - return new ConfigurationBuilder() - .AddJsonFile(configJsonPath, optional: true) - .AddEnvironmentVariables() - .AddEnvironmentVariables(prefix: EnvironmentVariablesPrefix) - .AddCommandLine(args) - .Build(); - } - } -} diff --git a/src/Microsoft.AspNet.Hosting/WebHostBuilder.cs b/src/Microsoft.AspNet.Hosting/WebApplicationBuilder.cs similarity index 65% rename from src/Microsoft.AspNet.Hosting/WebHostBuilder.cs rename to src/Microsoft.AspNet.Hosting/WebApplicationBuilder.cs index 5f4d3a1dd1..4350a2b35b 100644 --- a/src/Microsoft.AspNet.Hosting/WebHostBuilder.cs +++ b/src/Microsoft.AspNet.Hosting/WebApplicationBuilder.cs @@ -18,49 +18,180 @@ using Microsoft.Extensions.PlatformAbstractions; namespace Microsoft.AspNet.Hosting { - public class WebHostBuilder + public class WebApplicationBuilder { private readonly IHostingEnvironment _hostingEnvironment; private readonly ILoggerFactory _loggerFactory; - private readonly IConfiguration _config; - private readonly WebHostOptions _options; + + private IConfiguration _config; + private WebApplicationOptions _options; private Action _configureServices; private string _environmentName; + private string _webRoot; // Only one of these should be set private StartupMethods _startup; private Type _startupType; private string _startupAssemblyName; - private readonly bool _captureStartupErrors; // Only one of these should be set private string _serverFactoryLocation; private IServerFactory _serverFactory; private IServer _server; - public WebHostBuilder() - : this(config: new ConfigurationBuilder().Build()) + public WebApplicationBuilder() { - } - - public WebHostBuilder(IConfiguration config) - : this(config: config, captureStartupErrors: false) - { - } - - public WebHostBuilder(IConfiguration config, bool captureStartupErrors) - { - if (config == null) - { - throw new ArgumentNullException(nameof(config)); - } - _hostingEnvironment = new HostingEnvironment(); _loggerFactory = new LoggerFactory(); - _config = config; - _options = new WebHostOptions(config); - _captureStartupErrors = captureStartupErrors; + } + + public WebApplicationBuilder UseConfiguration(IConfiguration configuration) + { + _config = configuration; + return this; + } + + public WebApplicationBuilder UseEnvironment(string environment) + { + if (environment == null) + { + throw new ArgumentNullException(nameof(environment)); + } + + _environmentName = environment; + return this; + } + + public WebApplicationBuilder UseWebRoot(string webRoot) + { + if (webRoot == null) + { + throw new ArgumentNullException(nameof(webRoot)); + } + _webRoot = webRoot; + return this; + } + + public WebApplicationBuilder UseServer(IServer server) + { + if (server == null) + { + throw new ArgumentNullException(nameof(server)); + } + + _server = server; + return this; + } + + public WebApplicationBuilder UseServerFactory(string assemblyName) + { + if (assemblyName == null) + { + throw new ArgumentNullException(nameof(assemblyName)); + } + + _serverFactoryLocation = assemblyName; + return this; + } + + public WebApplicationBuilder UseServerFactory(IServerFactory factory) + { + if (factory == null) + { + throw new ArgumentNullException(nameof(factory)); + } + + _serverFactory = factory; + return this; + } + + public WebApplicationBuilder UseStartup(string startupAssemblyName) + { + if (startupAssemblyName == null) + { + throw new ArgumentNullException(nameof(startupAssemblyName)); + } + + _startupAssemblyName = startupAssemblyName; + return this; + } + + public WebApplicationBuilder UseStartup(Type startupType) + { + if (startupType == null) + { + throw new ArgumentNullException(nameof(startupType)); + } + + _startupType = startupType; + return this; + } + + public WebApplicationBuilder UseStartup() where TStartup : class + { + return UseStartup(typeof(TStartup)); + } + + public WebApplicationBuilder ConfigureServices(Action configureServices) + { + _configureServices = configureServices; + return this; + } + + public WebApplicationBuilder Configure(Action configureApp) + { + if (configureApp == null) + { + throw new ArgumentNullException(nameof(configureApp)); + } + + _startup = new StartupMethods(configureApp); + return this; + } + + public WebApplicationBuilder ConfigureLogging(Action configureLogging) + { + configureLogging(_loggerFactory); + return this; + } + + public IWebApplication Build() + { + var hostingServices = BuildHostingServices(); + + var hostingContainer = hostingServices.BuildServiceProvider(); + + var appEnvironment = hostingContainer.GetRequiredService(); + var startupLoader = hostingContainer.GetRequiredService(); + + _config = _config ?? WebApplicationConfiguration.GetDefault(); + _options = new WebApplicationOptions(_config); + + // Initialize the hosting environment + _options.WebRoot = _webRoot ?? _options.WebRoot; + _hostingEnvironment.Initialize(appEnvironment.ApplicationBasePath, _options, _config); + + if (!string.IsNullOrEmpty(_environmentName)) + { + _hostingEnvironment.EnvironmentName = _environmentName; + } + + var application = new WebApplication(hostingServices, startupLoader, _options, _config); + + // Only one of these should be set, but they are used in priority + application.Server = _server; + application.ServerFactory = _serverFactory; + application.ServerFactoryLocation = _options.ServerFactoryLocation ?? _serverFactoryLocation; + + // Only one of these should be set, but they are used in priority + application.Startup = _startup; + application.StartupType = _startupType; + application.StartupAssemblyName = _startupAssemblyName ?? _options.Application; + + application.Initialize(); + + return application; } private IServiceCollection BuildHostingServices() @@ -83,11 +214,6 @@ namespace Microsoft.AspNet.Hosting // Conjure up a RequestServices services.AddTransient(); - if (_configureServices != null) - { - _configureServices(services); - } - var defaultPlatformServices = PlatformServices.Default; if (defaultPlatformServices != null) { @@ -102,153 +228,12 @@ namespace Microsoft.AspNet.Hosting } } + if (_configureServices != null) + { + _configureServices(services); + } + return services; } - - public IHostingEngine Build() - { - var hostingServices = BuildHostingServices(); - - var hostingContainer = hostingServices.BuildServiceProvider(); - - var appEnvironment = hostingContainer.GetRequiredService(); - var startupLoader = hostingContainer.GetRequiredService(); - - _hostingEnvironment.Initialize(appEnvironment.ApplicationBasePath, _options, _config); - if (!string.IsNullOrEmpty(_environmentName)) - { - _hostingEnvironment.EnvironmentName = _environmentName; - } - var engine = new HostingEngine(hostingServices, startupLoader, _options, _config, _captureStartupErrors); - - // Only one of these should be set, but they are used in priority - engine.Server = _server; - engine.ServerFactory = _serverFactory; - engine.ServerFactoryLocation = _options.Server ?? _serverFactoryLocation; - - // Only one of these should be set, but they are used in priority - engine.Startup = _startup; - engine.StartupType = _startupType; - engine.StartupAssemblyName = _startupAssemblyName ?? _options.Application ?? appEnvironment.ApplicationName; - - return engine; - } - - public WebHostBuilder UseServices(Action configureServices) - { - _configureServices = configureServices; - return this; - } - - public WebHostBuilder UseEnvironment(string environment) - { - if (environment == null) - { - throw new ArgumentNullException(nameof(environment)); - } - - _environmentName = environment; - return this; - } - - public WebHostBuilder UseServer(IServer server) - { - if (server == null) - { - throw new ArgumentNullException(nameof(server)); - } - - _server = server; - return this; - } - - public WebHostBuilder UseServerFactory(string assemblyName) - { - if (assemblyName == null) - { - throw new ArgumentNullException(nameof(assemblyName)); - } - - _serverFactoryLocation = assemblyName; - return this; - } - - public WebHostBuilder UseServerFactory(IServerFactory factory) - { - if (factory == null) - { - throw new ArgumentNullException(nameof(factory)); - } - - _serverFactory = factory; - return this; - } - - public WebHostBuilder UseStartup(string startupAssemblyName) - { - if (startupAssemblyName == null) - { - throw new ArgumentNullException(nameof(startupAssemblyName)); - } - - _startupAssemblyName = startupAssemblyName; - return this; - } - - public WebHostBuilder UseStartup(Type startupType) - { - if (startupType == null) - { - throw new ArgumentNullException(nameof(startupType)); - } - - _startupType = startupType; - return this; - } - - public WebHostBuilder UseStartup() where TStartup : class - { - return UseStartup(typeof(TStartup)); - } - - public WebHostBuilder UseStartup(Action configureApp) - { - if (configureApp == null) - { - throw new ArgumentNullException(nameof(configureApp)); - } - - return UseStartup(configureApp, configureServices: null); - } - - public WebHostBuilder UseStartup(Action configureApp, Func configureServices) - { - if (configureApp == null) - { - throw new ArgumentNullException(nameof(configureApp)); - } - - _startup = new StartupMethods(configureApp, configureServices); - return this; - } - - public WebHostBuilder UseStartup(Action configureApp, Action configureServices) - { - if (configureApp == null) - { - throw new ArgumentNullException(nameof(configureApp)); - } - - _startup = new StartupMethods(configureApp, - services => - { - if (configureServices != null) - { - configureServices(services); - } - return services.BuildServiceProvider(); - }); - return this; - } } } diff --git a/src/Microsoft.AspNet.Hosting/WebApplicationConfiguration.cs b/src/Microsoft.AspNet.Hosting/WebApplicationConfiguration.cs new file mode 100644 index 0000000000..0d71dafc2d --- /dev/null +++ b/src/Microsoft.AspNet.Hosting/WebApplicationConfiguration.cs @@ -0,0 +1,40 @@ +using Microsoft.Extensions.Configuration; + +namespace Microsoft.AspNet.Hosting +{ + public class WebApplicationConfiguration + { + public static readonly string ApplicationKey = "app"; + public static readonly string DetailedErrorsKey = "detailedErrors"; + public static readonly string EnvironmentKey = "environment"; + public static readonly string ServerKey = "server"; + public static readonly string WebRootKey = "webroot"; + public static readonly string CaptureStartupErrorsKey = "captureStartupErrors"; + + public static readonly string HostingJsonFile = "hosting.json"; + public static readonly string EnvironmentVariablesPrefix = "ASPNET_"; + + public static IConfiguration GetDefault() + { + return GetDefault(args: null); + } + + public static IConfiguration GetDefault(string[] args) + { + // We are adding all environment variables first and then adding the ASPNET_ ones + // with the prefix removed to unify with the command line and config file formats + var configBuilder = new ConfigurationBuilder() + .AddJsonFile(HostingJsonFile, optional: true) + .AddEnvironmentVariables() + .AddEnvironmentVariables(prefix: EnvironmentVariablesPrefix); + + if (args != null) + { + configBuilder.AddCommandLine(args); + } + + return configBuilder.Build(); + } + } + +} diff --git a/src/Microsoft.AspNet.Hosting/WebApplicationExtensions.cs b/src/Microsoft.AspNet.Hosting/WebApplicationExtensions.cs new file mode 100644 index 0000000000..a0b0f0b3f6 --- /dev/null +++ b/src/Microsoft.AspNet.Hosting/WebApplicationExtensions.cs @@ -0,0 +1,60 @@ +// 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; +using System.Collections.Generic; +using Microsoft.AspNet.Http.Features; +using Microsoft.AspNet.Server.Features; +using Microsoft.Extensions.DependencyInjection; + +namespace Microsoft.AspNet.Hosting +{ + public static class WebApplicationExtensions + { + /// + /// Retruns the server addresses the web application is going to listen on. + /// + /// + /// An which the addresses the server will listen to + public static ICollection GetAddresses(this IWebApplication application) + { + return application.ServerFeatures.Get()?.Addresses; + } + + /// + /// Runs a web application and block the calling thread until host shutdown. + /// + /// + public static void Run(this IWebApplication application) + { + using (application.Start()) + { + var hostingEnvironment = application.Services.GetService(); + var applicationLifetime = application.Services.GetService(); + + Console.WriteLine("Hosting environment: " + hostingEnvironment.EnvironmentName); + + var serverAddresses = application.GetAddresses(); + if (serverAddresses != null) + { + foreach (var address in serverAddresses) + { + Console.WriteLine("Now listening on: " + address); + } + } + + Console.WriteLine("Application started. Press Ctrl+C to shut down."); + + Console.CancelKeyPress += (sender, eventArgs) => + { + applicationLifetime.StopApplication(); + + // Don't terminate the process immediately, wait for the Main thread to exit gracefully. + eventArgs.Cancel = true; + }; + + applicationLifetime.ApplicationStopping.WaitHandle.WaitOne(); + } + } + } +} \ No newline at end of file diff --git a/src/Microsoft.AspNet.Hosting/WebHostOptions.cs b/src/Microsoft.AspNet.Hosting/WebHostOptions.cs deleted file mode 100644 index 89a0aad6bc..0000000000 --- a/src/Microsoft.AspNet.Hosting/WebHostOptions.cs +++ /dev/null @@ -1,47 +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; -using Microsoft.Extensions.Configuration; - -namespace Microsoft.AspNet.Hosting -{ - public class WebHostOptions - { - private const string ApplicationKey = "app"; - private const string DetailedErrorsKey = "detailedErrors"; - private const string EnvironmentKey = "environment"; - private const string ServerKey = "server"; - private const string WebRootKey = "webroot"; - private const string OldEnvironmentKey = "ENV"; - - public WebHostOptions() - { - } - - public WebHostOptions(IConfiguration configuration) - { - if (configuration == null) - { - throw new ArgumentNullException(nameof(configuration)); - } - - Application = configuration[ApplicationKey]; - DetailedErrors = string.Equals("true", configuration[DetailedErrorsKey], StringComparison.OrdinalIgnoreCase) - || string.Equals("1", configuration[DetailedErrorsKey], StringComparison.OrdinalIgnoreCase); - Environment = configuration[EnvironmentKey] ?? configuration[OldEnvironmentKey]; - Server = configuration[ServerKey]; - WebRoot = configuration[WebRootKey]; - } - - public string Application { get; set; } - - public bool DetailedErrors { get; set; } - - public string Environment { get; set; } - - public string Server { get; set; } - - public string WebRoot { get; set; } - } -} \ No newline at end of file diff --git a/src/Microsoft.AspNet.TestHost/TestServer.cs b/src/Microsoft.AspNet.TestHost/TestServer.cs index efeefac128..51980617cf 100644 --- a/src/Microsoft.AspNet.TestHost/TestServer.cs +++ b/src/Microsoft.AspNet.TestHost/TestServer.cs @@ -4,13 +4,10 @@ using System; using System.Net.Http; using System.Threading.Tasks; -using Microsoft.AspNet.Builder; using Microsoft.AspNet.Hosting; using Microsoft.AspNet.Hosting.Server; using Microsoft.AspNet.Http; using Microsoft.AspNet.Http.Features; -using Microsoft.Extensions.Configuration; -using Microsoft.Extensions.DependencyInjection; using Context = Microsoft.AspNet.Hosting.Internal.HostingApplication.Context; namespace Microsoft.AspNet.TestHost @@ -23,78 +20,16 @@ namespace Microsoft.AspNet.TestHost private bool _disposed = false; private IHttpApplication _application; - public TestServer(WebHostBuilder builder) + public TestServer(WebApplicationBuilder builder) { - var hostingEngine = builder.UseServer(this).Build(); - _appInstance = hostingEngine.Start(); + var application = builder.UseServer(this).Build(); + _appInstance = application.Start(); } public Uri BaseAddress { get; set; } = new Uri("http://localhost/"); IFeatureCollection IServer.Features { get; } - public static TestServer Create() - { - return Create(config: null, configureApp: null, configureServices: null); - } - - public static TestServer Create(Action configureApp) - { - return Create(config: null, configureApp: configureApp, configureServices: null); - } - - public static TestServer Create(Action configureApp, Action configureServices) - { - return Create(config: null, configureApp: configureApp, configureServices: configureServices); - } - - public static TestServer Create(Action configureApp, Func configureServices) - { - return new TestServer(CreateBuilder(config: null, configureApp: configureApp, configureServices: configureServices, configureHostServices: null)); - } - public static TestServer Create(Action configureApp, Func configureServices, Action configureHostServices) - { - return new TestServer(CreateBuilder(config: null, configureApp: configureApp, configureServices: configureServices, configureHostServices: configureHostServices)); - } - - public static TestServer Create(IConfiguration config, Action configureApp, Action configureServices) - { - return new TestServer(CreateBuilder(config, configureApp, configureServices)); - } - - public static WebHostBuilder CreateBuilder(IConfiguration config, Action configureApp, Action configureServices) - { - return CreateBuilder(config, configureApp, - s => - { - if (configureServices != null) - { - configureServices(s); - } - return s.BuildServiceProvider(); - }, null); - } - public static WebHostBuilder CreateBuilder(IConfiguration config, Action configureApp, Func configureServices) - { - return CreateBuilder(config, configureApp, configureServices, null); - } - - public static WebHostBuilder CreateBuilder(IConfiguration config, Action configureApp, Func configureServices, Action configureHostServices) - { - return CreateBuilder(config).UseStartup(configureApp, configureServices).UseServices(configureHostServices); - } - - public static WebHostBuilder CreateBuilder(IConfiguration config) - { - return new WebHostBuilder( - config ?? new ConfigurationBuilder().Build()); - } - - public static WebHostBuilder CreateBuilder() - { - return CreateBuilder(config: null); - } - public HttpMessageHandler CreateHandler() { var pathBase = BaseAddress == null ? PathString.Empty : PathString.FromUriComponent(BaseAddress); @@ -141,8 +76,8 @@ namespace Microsoft.AspNet.TestHost private class ApplicationWrapper : IHttpApplication { - IHttpApplication _application; - Action _preProcessRequestAsync; + private readonly IHttpApplication _application; + private readonly Action _preProcessRequestAsync; public ApplicationWrapper(IHttpApplication application, Action preProcessRequestAsync) { diff --git a/test/Microsoft.AspNet.Hosting.Tests/HostingEnvironmentExtensionsTests.cs b/test/Microsoft.AspNet.Hosting.Tests/HostingEnvironmentExtensionsTests.cs index 727130ded8..be2072bf9a 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/HostingEnvironmentExtensionsTests.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/HostingEnvironmentExtensionsTests.cs @@ -4,7 +4,6 @@ using System; using System.IO; using Microsoft.AspNet.FileProviders; -using Microsoft.AspNet.Hosting; using Microsoft.AspNet.Hosting.Internal; using Microsoft.Extensions.Configuration; using Xunit; @@ -18,7 +17,7 @@ namespace Microsoft.AspNet.Hosting.Tests { var env = new HostingEnvironment(); - env.Initialize(".", new WebHostOptions() {WebRoot = "testroot"}, null); + env.Initialize(".", new WebApplicationOptions() {WebRoot = "testroot"}, null); Assert.Equal(Path.GetFullPath("testroot"), env.WebRootPath); Assert.IsAssignableFrom(env.WebRootFileProvider); @@ -29,7 +28,7 @@ namespace Microsoft.AspNet.Hosting.Tests { var env = new HostingEnvironment(); - env.Initialize("testroot", new WebHostOptions(), null); + env.Initialize("testroot", new WebApplicationOptions(), null); Assert.Equal(Path.GetFullPath(Path.Combine("testroot","wwwroot")), env.WebRootPath); Assert.IsAssignableFrom(env.WebRootFileProvider); @@ -40,7 +39,7 @@ namespace Microsoft.AspNet.Hosting.Tests { var env = new HostingEnvironment(); - env.Initialize(Path.Combine("testroot", "wwwroot"), new WebHostOptions(), null); + env.Initialize(Path.Combine("testroot", "wwwroot"), new WebApplicationOptions(), null); Assert.Null(env.WebRootPath); Assert.IsAssignableFrom(env.WebRootFileProvider); @@ -52,7 +51,7 @@ namespace Microsoft.AspNet.Hosting.Tests var config = new ConfigurationBuilder().Build(); var env = new HostingEnvironment(); - env.Initialize(".", new WebHostOptions(), config); + env.Initialize(".", new WebApplicationOptions(), config); Assert.Same(config, env.Configuration); } @@ -63,7 +62,7 @@ namespace Microsoft.AspNet.Hosting.Tests var env = new HostingEnvironment(); env.EnvironmentName = "SomeName"; - env.Initialize(".", new WebHostOptions() { Environment = "NewName" }, null); + env.Initialize(".", new WebApplicationOptions() { Environment = "NewName" }, null); Assert.Equal("NewName", env.EnvironmentName); } @@ -73,7 +72,7 @@ namespace Microsoft.AspNet.Hosting.Tests { var env = new HostingEnvironment(); - env.Initialize(".", new WebHostOptions(), null); + env.Initialize(".", new WebApplicationOptions(), null); Assert.Throws(() => env.MapPath("file.txt")); } diff --git a/test/Microsoft.AspNet.Hosting.Tests/StartupManagerTests.cs b/test/Microsoft.AspNet.Hosting.Tests/StartupManagerTests.cs index 0272e66a81..8b0c67652d 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/StartupManagerTests.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/StartupManagerTests.cs @@ -7,6 +7,7 @@ using System.Reflection; using Microsoft.AspNet.Builder; using Microsoft.AspNet.Builder.Internal; using Microsoft.AspNet.Hosting.Fakes; +using Microsoft.AspNet.Hosting.Internal; using Microsoft.AspNet.Hosting.Startup; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.OptionsModel; diff --git a/test/Microsoft.AspNet.Hosting.Tests/WebHostBuilderTests.cs b/test/Microsoft.AspNet.Hosting.Tests/WebApplicationBuilderTests.cs similarity index 66% rename from test/Microsoft.AspNet.Hosting.Tests/WebHostBuilderTests.cs rename to test/Microsoft.AspNet.Hosting.Tests/WebApplicationBuilderTests.cs index cd7c1ee3b4..edeaffb499 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/WebHostBuilderTests.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/WebApplicationBuilderTests.cs @@ -17,35 +17,25 @@ using Xunit; namespace Microsoft.AspNet.Hosting { - public class WebHostBuilderTests + public class WebApplicationBuilderTests { - [Fact] - public void Build_uses_application_for_startup_assembly_by_default() - { - var builder = CreateWebHostBuilder(); - - var engine = (HostingEngine)builder.Build(); - - Assert.Equal("Microsoft.AspNet.Hosting.Tests", engine.StartupAssemblyName); - } - [Fact] public void Build_honors_UseStartup_with_string() { - var builder = CreateWebHostBuilder(); + var builder = CreateWebApplicationBuilder().UseServer(new TestServer()); - var engine = (HostingEngine)builder.UseStartup("MyStartupAssembly").Build(); + var application = (WebApplication)builder.UseStartup("MyStartupAssembly").Build(); - Assert.Equal("MyStartupAssembly", engine.StartupAssemblyName); + Assert.Equal("MyStartupAssembly", application.StartupAssemblyName); } [Fact] public async Task StartupMissing_Fallback() { - var builder = CreateWebHostBuilder(); + var builder = CreateWebApplicationBuilder(); var server = new TestServer(); - var engine = builder.UseServer(server).UseStartup("MissingStartupAssembly").Build(); - using (engine.Start()) + var application = builder.UseServer(server).UseStartup("MissingStartupAssembly").Build(); + using (application.Start()) { await AssertResponseContains(server.RequestDelegate, "MissingStartupAssembly"); } @@ -54,10 +44,10 @@ namespace Microsoft.AspNet.Hosting [Fact] public async Task StartupStaticCtorThrows_Fallback() { - var builder = CreateWebHostBuilder(); + var builder = CreateWebApplicationBuilder(); var server = new TestServer(); - var engine = builder.UseServer(server).UseStartup().Build(); - using (engine.Start()) + var application = builder.UseServer(server).UseStartup().Build(); + using (application.Start()) { await AssertResponseContains(server.RequestDelegate, "Exception from static constructor"); } @@ -66,10 +56,10 @@ namespace Microsoft.AspNet.Hosting [Fact] public async Task StartupCtorThrows_Fallback() { - var builder = CreateWebHostBuilder(); + var builder = CreateWebApplicationBuilder(); var server = new TestServer(); - var engine = builder.UseServer(server).UseStartup().Build(); - using (engine.Start()) + var application = builder.UseServer(server).UseStartup().Build(); + using (application.Start()) { await AssertResponseContains(server.RequestDelegate, "Exception from constructor"); } @@ -78,10 +68,10 @@ namespace Microsoft.AspNet.Hosting [Fact] public async Task StartupCtorThrows_TypeLoadException() { - var builder = CreateWebHostBuilder(); + var builder = CreateWebApplicationBuilder(); var server = new TestServer(); - var engine = builder.UseServer(server).UseStartup().Build(); - using (engine.Start()) + var application = builder.UseServer(server).UseStartup().Build(); + using (application.Start()) { await AssertResponseContains(server.RequestDelegate, "Message from the LoaderException"); } @@ -90,12 +80,12 @@ namespace Microsoft.AspNet.Hosting [Fact] public async Task IApplicationLifetimeRegisteredEvenWhenStartupCtorThrows_Fallback() { - var builder = CreateWebHostBuilder(); + var builder = CreateWebApplicationBuilder(); var server = new TestServer(); - var engine = builder.UseServer(server).UseStartup().Build(); - using (engine.Start()) + var application = builder.UseServer(server).UseStartup().Build(); + using (application.Start()) { - var service = engine.ApplicationServices.GetServices(); + var service = application.Services.GetServices(); Assert.NotNull(service); await AssertResponseContains(server.RequestDelegate, "Exception from constructor"); } @@ -104,10 +94,10 @@ namespace Microsoft.AspNet.Hosting [Fact] public async Task StartupConfigureServicesThrows_Fallback() { - var builder = CreateWebHostBuilder(); + var builder = CreateWebApplicationBuilder(); var server = new TestServer(); - var engine = builder.UseServer(server).UseStartup().Build(); - using (engine.Start()) + var application = builder.UseServer(server).UseStartup().Build(); + using (application.Start()) { await AssertResponseContains(server.RequestDelegate, "Exception from ConfigureServices"); } @@ -116,10 +106,10 @@ namespace Microsoft.AspNet.Hosting [Fact] public async Task StartupConfigureThrows_Fallback() { - var builder = CreateWebHostBuilder(); + var builder = CreateWebApplicationBuilder(); var server = new TestServer(); - var engine = builder.UseServer(server).UseStartup().Build(); - using (engine.Start()) + var application = builder.UseServer(server).UseStartup().Build(); + using (application.Start()) { await AssertResponseContains(server.RequestDelegate, "Exception from Configure"); } @@ -137,22 +127,27 @@ namespace Microsoft.AspNet.Hosting var config = builder.Build(); var expected = "MY_TEST_ENVIRONMENT"; - var webHost = new WebHostBuilder(config, captureStartupErrors: true).UseEnvironment(expected).Build(); + var application = new WebApplicationBuilder() + .UseConfiguration(config) + .UseEnvironment(expected) + .UseServer(new TestServer()) + .UseStartup("Microsoft.AspNet.Hosting.Tests") + .Build(); - Assert.Equal(expected, webHost.ApplicationServices.GetService().EnvironmentName); + Assert.Equal(expected, application.Services.GetService().EnvironmentName); } - private WebHostBuilder CreateWebHostBuilder() + private WebApplicationBuilder CreateWebApplicationBuilder() { var vals = new Dictionary { - { "server", "Microsoft.AspNet.Hosting.Tests" }, { "DetailedErrors", "true" }, + { "captureStartupErrors", "true" } }; var builder = new ConfigurationBuilder() .AddInMemoryCollection(vals); var config = builder.Build(); - return new WebHostBuilder(config, captureStartupErrors: true); + return new WebApplicationBuilder().UseConfiguration(config); } private async Task AssertResponseContains(RequestDelegate app, string expectedText) diff --git a/test/Microsoft.AspNet.Hosting.Tests/WebHostConfigurationsTests.cs b/test/Microsoft.AspNet.Hosting.Tests/WebApplicationConfigurationsTests.cs similarity index 66% rename from test/Microsoft.AspNet.Hosting.Tests/WebHostConfigurationsTests.cs rename to test/Microsoft.AspNet.Hosting.Tests/WebApplicationConfigurationsTests.cs index ea3b314bbd..3e935c68cd 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/WebHostConfigurationsTests.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/WebApplicationConfigurationsTests.cs @@ -1,23 +1,14 @@ // 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; -using System.Collections; using System.Collections.Generic; -using System.IO; -using System.Reflection; -using Microsoft.AspNet.Builder; -using Microsoft.AspNet.Builder.Internal; -using Microsoft.AspNet.Hosting.Fakes; -using Microsoft.AspNet.Hosting.Startup; +using Microsoft.AspNet.Hosting.Internal; using Microsoft.Extensions.Configuration; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.OptionsModel; using Xunit; namespace Microsoft.AspNet.Hosting.Tests { - public class WebHostConfigurationTests + public class WebApplicationConfigurationTests { [Fact] public void ReadsParametersCorrectly() @@ -29,22 +20,24 @@ namespace Microsoft.AspNet.Hosting.Tests {"app", "MyProjectReference"}, {"environment", "Development"}, {"detailederrors", "true"}, + { "captureStartupErrors", "true" } }; - var config = new WebHostOptions(new ConfigurationBuilder().AddInMemoryCollection(parameters).Build()); + var config = new WebApplicationOptions(new ConfigurationBuilder().AddInMemoryCollection(parameters).Build()); Assert.Equal("wwwroot", config.WebRoot); - Assert.Equal("Microsoft.AspNet.Server.Kestrel", config.Server); + Assert.Equal("Microsoft.AspNet.Server.Kestrel", config.ServerFactoryLocation); Assert.Equal("MyProjectReference", config.Application); Assert.Equal("Development", config.Environment); - Assert.Equal(true, config.DetailedErrors); + Assert.True(config.CaptureStartupErrors); + Assert.True(config.DetailedErrors); } [Fact] public void ReadsOldEnvKey() { var parameters = new Dictionary() { { "ENV", "Development" } }; - var config = new WebHostOptions(new ConfigurationBuilder().AddInMemoryCollection(parameters).Build()); + var config = new WebApplicationOptions(new ConfigurationBuilder().AddInMemoryCollection(parameters).Build()); Assert.Equal("Development", config.Environment); } @@ -55,7 +48,7 @@ namespace Microsoft.AspNet.Hosting.Tests public void AllowsNumberForDetailedErrors(string value, bool expected) { var parameters = new Dictionary() { { "detailedErrors", value } }; - var config = new WebHostOptions(new ConfigurationBuilder().AddInMemoryCollection(parameters).Build()); + var config = new WebApplicationOptions(new ConfigurationBuilder().AddInMemoryCollection(parameters).Build()); Assert.Equal(expected, config.DetailedErrors); } diff --git a/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs b/test/Microsoft.AspNet.Hosting.Tests/WebApplicationTests.cs similarity index 77% rename from test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs rename to test/Microsoft.AspNet.Hosting.Tests/WebApplicationTests.cs index da2dd15336..d66419639f 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/WebApplicationTests.cs @@ -9,7 +9,6 @@ using System.Linq; using System.Threading.Tasks; using Microsoft.AspNet.Builder; using Microsoft.AspNet.Hosting.Fakes; -using Microsoft.AspNet.Hosting.Internal; using Microsoft.AspNet.Hosting.Server; using Microsoft.AspNet.Hosting.Startup; using Microsoft.AspNet.Http; @@ -25,7 +24,7 @@ using Xunit; namespace Microsoft.AspNet.Hosting { - public class HostingEngineTests : IServerFactory, IServer + public class WebApplicationTests : IServerFactory, IServer { private readonly IList _startInstances = new List(); private IFeatureCollection _featuresSupportedByThisHost = NewFeatureCollection(); @@ -63,7 +62,7 @@ namespace Microsoft.AspNet.Hosting } [Fact] - public void HostingEngineThrowsWithNoServer() + public void WebApplicationThrowsWithNoServer() { var ex = Assert.Throws(() => CreateBuilder().Build().Start()); Assert.True(ex.Message.Contains("UseServer()")); @@ -86,9 +85,9 @@ namespace Microsoft.AspNet.Hosting var builder = new ConfigurationBuilder() .AddInMemoryCollection(vals); var config = builder.Build(); - var host = CreateBuilder(config).Build(); - host.Start(); - Assert.NotNull(host.ApplicationServices.GetRequiredService()); + var application = CreateBuilder(config).Build(); + application.Start(); + Assert.NotNull(application.Services.GetService()); } [Fact] @@ -102,9 +101,9 @@ namespace Microsoft.AspNet.Hosting var builder = new ConfigurationBuilder() .AddInMemoryCollection(vals); var config = builder.Build(); - var host = CreateBuilder(config).Build(); - host.Start(); - Assert.NotNull(host.ApplicationServices.GetRequiredService()); + var application = CreateBuilder(config).Build(); + application.Start(); + Assert.NotNull(application.Services.GetService()); } [Fact] @@ -119,10 +118,10 @@ namespace Microsoft.AspNet.Hosting var builder = new ConfigurationBuilder() .AddInMemoryCollection(vals); var config = builder.Build(); - var host = CreateBuilder(config).Build(); - var app = host.Start(); - Assert.NotNull(host.ApplicationServices.GetRequiredService()); - Assert.Equal("http://localhost:abc123", app.ServerFeatures.Get().Addresses.First()); + var application = CreateBuilder(config).Build(); + var app = application.Start(); + Assert.NotNull(application.Services.GetService()); + Assert.Equal("http://localhost:abc123", application.ServerFeatures.Get().Addresses.First()); } [Fact] @@ -136,10 +135,10 @@ namespace Microsoft.AspNet.Hosting var builder = new ConfigurationBuilder() .AddInMemoryCollection(vals); var config = builder.Build(); - var host = CreateBuilder(config).Build(); - var app = host.Start(); - Assert.NotNull(host.ApplicationServices.GetRequiredService()); - Assert.Equal("http://localhost:5000", app.ServerFeatures.Get().Addresses.First()); + var application = CreateBuilder(config).Build(); + var app = application.Start(); + Assert.NotNull(application.Services.GetService()); + Assert.Equal("http://localhost:5000", application.GetAddresses().First()); } [Fact] @@ -153,84 +152,85 @@ namespace Microsoft.AspNet.Hosting var builder = new ConfigurationBuilder() .AddInMemoryCollection(vals); var config = builder.Build(); - var host = CreateBuilder(config).Build(); - var app = host.Start(); - var hostingEnvironment = host.ApplicationServices.GetRequiredService(); + var application = CreateBuilder(config).Build(); + var app = application.Start(); + var hostingEnvironment = application.Services.GetService(); Assert.NotNull(hostingEnvironment.Configuration); Assert.Equal("Microsoft.AspNet.Hosting.Tests", hostingEnvironment.Configuration["Server"]); } [Fact] - public void HostingEngineCanBeStarted() + public void WebApplicationCanBeStarted() { - var engine = CreateBuilder() + var app = CreateBuilder() .UseServer(this) .UseStartup("Microsoft.AspNet.Hosting.Tests") .Build() .Start(); - Assert.NotNull(engine); + Assert.NotNull(app); Assert.Equal(1, _startInstances.Count); Assert.Equal(0, _startInstances[0].DisposeCalls); - engine.Dispose(); + app.Dispose(); Assert.Equal(1, _startInstances[0].DisposeCalls); } [Fact] - public void HostingEngineDisposesServiceProvider() + public void WebApplicationDisposesServiceProvider() { - var engine = CreateBuilder() + var application = CreateBuilder() .UseServer(this) - .UseServices(s => + .ConfigureServices(s => { s.AddTransient(); s.AddSingleton(); }) .UseStartup("Microsoft.AspNet.Hosting.Tests") - .Build() - .Start(); + .Build(); - var singleton = (FakeService)engine.Services.GetService(); - var transient = (FakeService)engine.Services.GetService(); + var app = application.Start(); + + var singleton = (FakeService)application.Services.GetService(); + var transient = (FakeService)application.Services.GetService(); Assert.False(singleton.Disposed); Assert.False(transient.Disposed); - engine.Dispose(); + app.Dispose(); Assert.True(singleton.Disposed); Assert.True(transient.Disposed); } [Fact] - public void HostingEngineNotifiesApplicationStarted() + public void WebApplicationNotifiesApplicationStarted() { - var host = CreateBuilder() + var application = CreateBuilder() .UseServer(this) .Build(); - var applicationLifetime = host.ApplicationServices.GetRequiredService(); + var applicationLifetime = application.Services.GetService(); Assert.False(applicationLifetime.ApplicationStarted.IsCancellationRequested); - using (host.Start()) + using (application.Start()) { Assert.True(applicationLifetime.ApplicationStarted.IsCancellationRequested); } } [Fact] - public void HostingEngineInjectsHostingEnvironment() + public void WebApplicationInjectsHostingEnvironment() { - var engine = CreateBuilder() + var application = CreateBuilder() .UseServer(this) .UseStartup("Microsoft.AspNet.Hosting.Tests") .UseEnvironment("WithHostingEnvironment") .Build(); - using (var server = engine.Start()) + using (application.Start()) { - var env = engine.ApplicationServices.GetRequiredService(); + var env = application.Services.GetService(); Assert.Equal("Changed", env.EnvironmentName); } } @@ -238,26 +238,29 @@ namespace Microsoft.AspNet.Hosting [Fact] public void CanReplaceStartupLoader() { - var engine = CreateBuilder().UseServices(services => services.AddTransient()) + var builder = CreateBuilder() + .ConfigureServices(services => + { + services.AddTransient(); + }) .UseServer(this) - .UseStartup("Microsoft.AspNet.Hosting.Tests") - .Build(); + .UseStartup("Microsoft.AspNet.Hosting.Tests"); - Assert.Throws(() => engine.Start()); + Assert.Throws(() => builder.Build()); } [Fact] public void CanCreateApplicationServicesWithAddedServices() { - var host = CreateBuilder().UseServices(services => services.AddOptions()).Build(); - Assert.NotNull(host.ApplicationServices.GetRequiredService>()); + var application = CreateBuilder().UseServer(this).ConfigureServices(services => services.AddOptions()).Build(); + Assert.NotNull(application.Services.GetRequiredService>()); } [Fact] public void EnvDefaultsToProductionIfNoConfig() { - var engine = CreateBuilder().Build(); - var env = engine.ApplicationServices.GetRequiredService(); + var application = CreateBuilder().UseServer(this).Build(); + var env = application.Services.GetService(); Assert.Equal(EnvironmentName.Production, env.EnvironmentName); } @@ -266,7 +269,7 @@ namespace Microsoft.AspNet.Hosting { var vals = new Dictionary { - // Old key is actualy ASPNET_ENV but WebHostConfiguration expects environment + // Old key is actualy ASPNET_ENV but WebApplicationConfiguration expects environment // variable names stripped from ASPNET_ prefix so using just ENV here { "ENV", "Staging" } }; @@ -275,8 +278,8 @@ namespace Microsoft.AspNet.Hosting .AddInMemoryCollection(vals); var config = builder.Build(); - var engine = CreateBuilder(config).Build(); - var env = engine.ApplicationServices.GetRequiredService(); + var application = CreateBuilder(config).UseServer(this).Build(); + var env = application.Services.GetService(); Assert.Equal("Staging", env.EnvironmentName); } @@ -292,8 +295,8 @@ namespace Microsoft.AspNet.Hosting .AddInMemoryCollection(vals); var config = builder.Build(); - var engine = CreateBuilder(config).Build(); - var env = engine.ApplicationServices.GetRequiredService(); + var application = CreateBuilder(config).UseServer(this).Build(); + var env = application.Services.GetService(); Assert.Equal("Staging", env.EnvironmentName); } @@ -309,8 +312,8 @@ namespace Microsoft.AspNet.Hosting .AddInMemoryCollection(vals); var config = builder.Build(); - var engine = CreateBuilder(config).UseServer(this).Build(); - var env = engine.ApplicationServices.GetRequiredService(); + var application = CreateBuilder(config).UseServer(this).Build(); + var env = application.Services.GetService(); Assert.Equal(Path.GetFullPath("testroot"), env.WebRootPath); Assert.True(env.WebRootFileProvider.GetFileInfo("TextFile.txt").Exists); } @@ -318,10 +321,10 @@ namespace Microsoft.AspNet.Hosting [Fact] public void IsEnvironment_Extension_Is_Case_Insensitive() { - var engine = CreateBuilder().UseServer(this).Build(); - using (engine.Start()) + var application = CreateBuilder().UseServer(this).Build(); + using (application.Start()) { - var env = engine.ApplicationServices.GetRequiredService(); + var env = application.Services.GetRequiredService(); Assert.True(env.IsEnvironment(EnvironmentName.Production)); Assert.True(env.IsEnvironment("producTion")); } @@ -349,7 +352,7 @@ namespace Microsoft.AspNet.Hosting } [Fact] - public void HostingEngine_CreatesDefaultRequestIdentifierFeature_IfNotPresent() + public void WebApplication_CreatesDefaultRequestIdentifierFeature_IfNotPresent() { // Arrange HttpContext httpContext = null; @@ -358,10 +361,10 @@ namespace Microsoft.AspNet.Hosting httpContext = innerHttpContext; return Task.FromResult(0); }); - var hostingEngine = CreateHostingEngine(requestDelegate); + var application = CreateApplication(requestDelegate); // Act - var disposable = hostingEngine.Start(); + var disposable = application.Start(); // Assert Assert.NotNull(httpContext); @@ -371,7 +374,7 @@ namespace Microsoft.AspNet.Hosting } [Fact] - public void HostingEngine_DoesNot_CreateDefaultRequestIdentifierFeature_IfPresent() + public void WebApplication_DoesNot_CreateDefaultRequestIdentifierFeature_IfPresent() { // Arrange HttpContext httpContext = null; @@ -382,10 +385,10 @@ namespace Microsoft.AspNet.Hosting }); var requestIdentifierFeature = new StubHttpRequestIdentifierFeature(); _featuresSupportedByThisHost[typeof(IHttpRequestIdentifierFeature)] = requestIdentifierFeature; - var hostingEngine = CreateHostingEngine(requestDelegate); + var application = CreateApplication(requestDelegate); // Act - var disposable = hostingEngine.Start(); + var disposable = application.Start(); // Assert Assert.NotNull(httpContext); @@ -393,16 +396,16 @@ namespace Microsoft.AspNet.Hosting } [Fact] - public void HostingEngine_InvokesConfigureMethodsOnlyOnce() + public void WebApplication_InvokesConfigureMethodsOnlyOnce() { - var engine = CreateBuilder() + var application = CreateBuilder() .UseServer(this) .UseStartup() .Build(); - using (engine.Start()) + using (application.Start()) { - var services = engine.ApplicationServices; - var services2 = engine.ApplicationServices; + var services = application.Services; + var services2 = application.Services; Assert.Equal(1, CountStartup.ConfigureCount); Assert.Equal(1, CountStartup.ConfigureServicesCount); } @@ -425,13 +428,13 @@ namespace Microsoft.AspNet.Hosting } [Fact] - public void HostingEngine_ThrowsForBadConfigureServiceSignature() + public void WebApplication_ThrowsForBadConfigureServiceSignature() { - var engine = CreateBuilder() + var builder = CreateBuilder() .UseServer(this) - .UseStartup() - .Build(); - var ex = Assert.Throws(() => engine.Start()); + .UseStartup(); + + var ex = Assert.Throws(() => builder.Build()); Assert.True(ex.Message.Contains("ConfigureServices")); } @@ -441,27 +444,26 @@ namespace Microsoft.AspNet.Hosting public void Configure(IApplicationBuilder app) { } } - private IHostingEngine CreateHostingEngine(RequestDelegate requestDelegate) + private IWebApplication CreateApplication(RequestDelegate requestDelegate) { - var host = CreateBuilder() + var builder = CreateBuilder() .UseServer(this) - .UseStartup( + .Configure( appBuilder => { appBuilder.ApplicationServices.GetRequiredService().AddProvider(new AllMessagesAreNeeded()); appBuilder.Run(requestDelegate); - }, - configureServices => configureServices.BuildServiceProvider()); - return host.Build(); + }); + return builder.Build(); } private void RunMapPath(string virtualPath, string expectedSuffix) { - var engine = CreateBuilder().UseServer(this).Build(); + var application = CreateBuilder().UseServer(this).Build(); - using (engine.Start()) + using (application.Start()) { - var env = engine.ApplicationServices.GetRequiredService(); + var env = application.Services.GetRequiredService(); // MapPath requires webroot to be set, we don't care // about file provider so just set it here env.WebRootPath = "."; @@ -471,9 +473,9 @@ namespace Microsoft.AspNet.Hosting } } - private WebHostBuilder CreateBuilder(IConfiguration config = null) + private WebApplicationBuilder CreateBuilder(IConfiguration config = null) { - return new WebHostBuilder(config ?? new ConfigurationBuilder().Build()); + return new WebApplicationBuilder().UseConfiguration(config ?? new ConfigurationBuilder().Build()).UseStartup("Microsoft.AspNet.Hosting.Tests"); } public void Start(IHttpApplication application) diff --git a/test/Microsoft.AspNet.TestHost.Tests/RequestBuilderTests.cs b/test/Microsoft.AspNet.TestHost.Tests/RequestBuilderTests.cs index bcc4c79707..a47cf1f00c 100644 --- a/test/Microsoft.AspNet.TestHost.Tests/RequestBuilderTests.cs +++ b/test/Microsoft.AspNet.TestHost.Tests/RequestBuilderTests.cs @@ -1,6 +1,7 @@ // 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.Hosting; using Microsoft.AspNet.Testing.xunit; using Xunit; @@ -13,7 +14,8 @@ namespace Microsoft.AspNet.TestHost [FrameworkSkipCondition(RuntimeFrameworks.Mono)] public void AddRequestHeader() { - var server = TestServer.Create(app => { }); + var builder = new WebApplicationBuilder().Configure(app => { }); + var server = new TestServer(builder); server.CreateRequest("/") .AddHeader("Host", "MyHost:90") .And(request => @@ -25,7 +27,8 @@ namespace Microsoft.AspNet.TestHost [Fact] public void AddContentHeaders() { - var server = TestServer.Create(app => { }); + var builder = new WebApplicationBuilder().Configure(app => { }); + var server = new TestServer(builder); server.CreateRequest("/") .AddHeader("Content-Type", "Test/Value") .And(request => diff --git a/test/Microsoft.AspNet.TestHost.Tests/TestClientTests.cs b/test/Microsoft.AspNet.TestHost.Tests/TestClientTests.cs index 61e0f2b9d7..a453aaa564 100644 --- a/test/Microsoft.AspNet.TestHost.Tests/TestClientTests.cs +++ b/test/Microsoft.AspNet.TestHost.Tests/TestClientTests.cs @@ -10,6 +10,7 @@ using System.Text; using System.Threading; using System.Threading.Tasks; using Microsoft.AspNet.Builder; +using Microsoft.AspNet.Hosting; using Microsoft.AspNet.Http; using Microsoft.AspNet.Testing.xunit; using Xunit; @@ -22,7 +23,7 @@ namespace Microsoft.AspNet.TestHost public TestClientTests() { - _server = TestServer.Create(app => app.Run(ctx => Task.FromResult(0))); + _server = new TestServer(new WebApplicationBuilder().Configure(app => app.Run(ctx => Task.FromResult(0)))); } [ConditionalFact] @@ -33,7 +34,8 @@ namespace Microsoft.AspNet.TestHost var expected = "GET Response"; RequestDelegate appDelegate = ctx => ctx.Response.WriteAsync(expected); - var server = TestServer.Create(app => app.Run(appDelegate)); + var builder = new WebApplicationBuilder().Configure(app => app.Run(appDelegate)); + var server = new TestServer(builder); var client = server.CreateClient(); // Act @@ -55,7 +57,8 @@ namespace Microsoft.AspNet.TestHost Assert.Equal("/", ctx.Request.Path.Value); return ctx.Response.WriteAsync(expected); }; - var server = TestServer.Create(app => app.Run(appDelegate)); + var builder = new WebApplicationBuilder().Configure(app => app.Run(appDelegate)); + var server = new TestServer(builder); var client = server.CreateClient(); // Act @@ -77,7 +80,8 @@ namespace Microsoft.AspNet.TestHost Assert.Equal("/", ctx.Request.Path.Value); return ctx.Response.WriteAsync(expected); }; - var server = TestServer.Create(app => app.Run(appDelegate)); + var builder = new WebApplicationBuilder().Configure(app => app.Run(appDelegate)); + var server = new TestServer(builder); var client = server.CreateClient(); // Act @@ -94,7 +98,8 @@ namespace Microsoft.AspNet.TestHost // Arrange RequestDelegate appDelegate = ctx => ctx.Response.WriteAsync(new StreamReader(ctx.Request.Body).ReadToEnd() + " PUT Response"); - var server = TestServer.Create(app => app.Run(appDelegate)); + var builder = new WebApplicationBuilder().Configure(app => app.Run(appDelegate)); + var server = new TestServer(builder); var client = server.CreateClient(); // Act @@ -112,7 +117,8 @@ namespace Microsoft.AspNet.TestHost // Arrange RequestDelegate appDelegate = async ctx => await ctx.Response.WriteAsync(new StreamReader(ctx.Request.Body).ReadToEnd() + " POST Response"); - var server = TestServer.Create(app => app.Run(appDelegate)); + var builder = new WebApplicationBuilder().Configure(app => app.Run(appDelegate)); + var server = new TestServer(builder); var client = server.CreateClient(); // Act @@ -150,10 +156,11 @@ namespace Microsoft.AspNet.TestHost } } }; - var server = TestServer.Create(app => + var builder = new WebApplicationBuilder().Configure(app => { app.Run(appDelegate); }); + var server = new TestServer(builder); // Act var client = server.CreateWebSocketClient(); @@ -198,10 +205,11 @@ namespace Microsoft.AspNet.TestHost websocket.Dispose(); } }; - var server = TestServer.Create(app => + var builder = new WebApplicationBuilder().Configure(app => { app.Run(appDelegate); }); + var server = new TestServer(builder); // Act var client = server.CreateWebSocketClient(); @@ -231,10 +239,11 @@ namespace Microsoft.AspNet.TestHost } } }; - var server = TestServer.Create(app => + var builder = new WebApplicationBuilder().Configure(app => { app.Run(appDelegate); }); + var server = new TestServer(builder); // Act var client = server.CreateWebSocketClient(); @@ -279,7 +288,8 @@ namespace Microsoft.AspNet.TestHost }; // Act - var server = TestServer.Create(app => app.Run(appDelegate)); + var builder = new WebApplicationBuilder().Configure(app => app.Run(appDelegate)); + var server = new TestServer(builder); var client = server.CreateClient(); var request = new HttpRequestMessage(HttpMethod.Get, "http://localhost:12345"); var response = await client.SendAsync(request, HttpCompletionOption.ResponseHeadersRead); @@ -310,7 +320,8 @@ namespace Microsoft.AspNet.TestHost }; // Act - var server = TestServer.Create(app => app.Run(appDelegate)); + var builder = new WebApplicationBuilder().Configure(app => app.Run(appDelegate)); + var server = new TestServer(builder); var client = server.CreateClient(); var cts = new CancellationTokenSource(); cts.CancelAfter(500); diff --git a/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs b/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs index b923a10826..92fdc85fb8 100644 --- a/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs +++ b/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs @@ -28,20 +28,21 @@ namespace Microsoft.AspNet.TestHost { // Arrange // Act & Assert (Does not throw) - TestServer.Create(app => { }); + new TestServer(new WebApplicationBuilder().Configure(app => { })); } [ConditionalFact] [FrameworkSkipCondition(RuntimeFrameworks.Mono, SkipReason = "Hangs randomly (issue #507)")] public async Task RequestServicesAutoCreated() { - var server = TestServer.Create(app => + var builder = new WebApplicationBuilder().Configure(app => { app.Run(context => { return context.Response.WriteAsync("RequestServices:" + (context.RequestServices != null)); }); }); + var server = new TestServer(builder); string result = await server.CreateClient().GetStringAsync("/path"); Assert.Equal("RequestServices:True", result); @@ -71,7 +72,8 @@ namespace Microsoft.AspNet.TestHost [FrameworkSkipCondition(RuntimeFrameworks.Mono, SkipReason = "Hangs randomly (issue #507)")] public async Task CustomServiceProviderSetsApplicationServices() { - var server = new TestServer(TestServer.CreateBuilder().UseStartup()); + var builder = new WebApplicationBuilder().UseStartup(); + var server = new TestServer(builder); string result = await server.CreateClient().GetStringAsync("/path"); Assert.Equal("ApplicationServicesEqual:True", result); } @@ -113,15 +115,20 @@ namespace Microsoft.AspNet.TestHost [FrameworkSkipCondition(RuntimeFrameworks.Mono, SkipReason = "Hangs randomly (issue #507)")] public async Task ExistingRequestServicesWillNotBeReplaced() { - var server = TestServer.Create(app => + var builder = new WebApplicationBuilder().Configure(app => { app.Run(context => { var service = context.RequestServices.GetService(); return context.Response.WriteAsync("Found:" + (service != null)); }); - }, - services => services.AddTransient()); + }) + .ConfigureServices(services => + { + services.AddTransient(); + }); + var server = new TestServer(builder); + string result = await server.CreateClient().GetStringAsync("/path"); Assert.Equal("Found:True", result); } @@ -130,19 +137,21 @@ namespace Microsoft.AspNet.TestHost [FrameworkSkipCondition(RuntimeFrameworks.Mono, SkipReason = "Hangs randomly (issue #507)")] public async Task CanSetCustomServiceProvider() { - var server = TestServer.Create(app => + var builder = new WebApplicationBuilder().Configure(app => { app.Run(context => { context.RequestServices = new ServiceCollection() .AddTransient() .BuildServiceProvider(); - + var s = context.RequestServices.GetRequiredService(); return context.Response.WriteAsync("Success"); }); }); + var server = new TestServer(builder); + string result = await server.CreateClient().GetStringAsync("/path"); Assert.Equal("Success", result); } @@ -178,15 +187,20 @@ namespace Microsoft.AspNet.TestHost public async Task ExistingServiceProviderFeatureWillNotBeReplaced() { var appServices = new ServiceCollection().BuildServiceProvider(); - var server = TestServer.Create(app => + var builder = new WebApplicationBuilder().Configure(app => { app.Run(context => { Assert.Equal(appServices, context.RequestServices); return context.Response.WriteAsync("Success"); }); - }, - services => services.AddSingleton(new ReplaceServiceProvidersFeatureFilter(appServices, appServices))); + }) + .ConfigureServices(services => + { + services.AddSingleton(new ReplaceServiceProvidersFeatureFilter(appServices, appServices)); + }); + var server = new TestServer(builder); + var result = await server.CreateClient().GetStringAsync("/path"); Assert.Equal("Success", result); } @@ -215,15 +229,20 @@ namespace Microsoft.AspNet.TestHost [FrameworkSkipCondition(RuntimeFrameworks.Mono, SkipReason = "Hangs randomly (issue #507)")] public async Task WillReplaceServiceProviderFeatureWithNullRequestServices() { - var server = TestServer.Create(app => + var builder = new WebApplicationBuilder().Configure(app => { app.Run(context => { Assert.NotNull(context.RequestServices); return context.Response.WriteAsync("Success"); }); - }, - services => services.AddTransient()); + }) + .ConfigureServices(services => + { + services.AddTransient(); + }); + var server = new TestServer(builder); + var result = await server.CreateClient().GetStringAsync("/path"); Assert.Equal("Success", result); } @@ -232,7 +251,7 @@ namespace Microsoft.AspNet.TestHost [FrameworkSkipCondition(RuntimeFrameworks.Mono, SkipReason = "Hangs randomly (issue #507)")] public async Task CanAccessLogger() { - var server = TestServer.Create(app => + var builder = new WebApplicationBuilder().Configure(app => { app.Run(context => { @@ -240,6 +259,7 @@ namespace Microsoft.AspNet.TestHost return context.Response.WriteAsync("FoundLogger:" + (logger != null)); }); }); + var server = new TestServer(builder); string result = await server.CreateClient().GetStringAsync("/path"); Assert.Equal("FoundLogger:True", result); @@ -249,18 +269,19 @@ namespace Microsoft.AspNet.TestHost [FrameworkSkipCondition(RuntimeFrameworks.Mono, SkipReason = "Hangs randomly (issue #507)")] public async Task CanAccessHttpContext() { - Action configureServices = services => - { - services.AddSingleton(); - }; - TestServer server = TestServer.Create(app => + var builder = new WebApplicationBuilder().Configure(app => { app.Run(context => { var accessor = app.ApplicationServices.GetRequiredService(); - return context.Response.WriteAsync("HasContext:"+(accessor.HttpContext != null)); + return context.Response.WriteAsync("HasContext:" + (accessor.HttpContext != null)); }); - }, configureServices); + }) + .ConfigureServices(services => + { + services.AddSingleton(); + }); + var server = new TestServer(builder); string result = await server.CreateClient().GetStringAsync("/path"); Assert.Equal("HasContext:True", result); @@ -280,19 +301,20 @@ namespace Microsoft.AspNet.TestHost [FrameworkSkipCondition(RuntimeFrameworks.Mono, SkipReason = "Hangs randomly (issue #507)")] public async Task CanAddNewHostServices() { - Action configureServices = services => - { - services.AddSingleton(); - services.AddSingleton(); - }; - TestServer server = TestServer.Create(app => + var builder = new WebApplicationBuilder().Configure(app => { app.Run(context => { var accessor = app.ApplicationServices.GetRequiredService(); return context.Response.WriteAsync("HasContext:" + (accessor.Accessor.HttpContext != null)); }); - }, configureServices); + }) + .ConfigureServices(services => + { + services.AddSingleton(); + services.AddSingleton(); + }); + var server = new TestServer(builder); string result = await server.CreateClient().GetStringAsync("/path"); Assert.Equal("HasContext:True", result); @@ -302,13 +324,14 @@ namespace Microsoft.AspNet.TestHost [FrameworkSkipCondition(RuntimeFrameworks.Mono, SkipReason = "Hangs randomly (issue #507)")] public async Task CreateInvokesApp() { - TestServer server = TestServer.Create(app => + var builder = new WebApplicationBuilder().Configure(app => { app.Run(context => { return context.Response.WriteAsync("CreateInvokesApp"); }); }); + var server = new TestServer(builder); string result = await server.CreateClient().GetStringAsync("/path"); Assert.Equal("CreateInvokesApp", result); @@ -318,7 +341,7 @@ namespace Microsoft.AspNet.TestHost [FrameworkSkipCondition(RuntimeFrameworks.Mono, SkipReason = "Hangs randomly (issue #507)")] public async Task DisposeStreamIgnored() { - TestServer server = TestServer.Create(app => + var builder = new WebApplicationBuilder().Configure(app => { app.Run(async context => { @@ -326,6 +349,7 @@ namespace Microsoft.AspNet.TestHost context.Response.Body.Dispose(); }); }); + var server = new TestServer(builder); HttpResponseMessage result = await server.CreateClient().GetAsync("/"); Assert.Equal(HttpStatusCode.OK, result.StatusCode); @@ -336,7 +360,7 @@ namespace Microsoft.AspNet.TestHost [FrameworkSkipCondition(RuntimeFrameworks.Mono, SkipReason = "Hangs randomly (issue #507)")] public async Task DisposedServerThrows() { - TestServer server = TestServer.Create(app => + var builder = new WebApplicationBuilder().Configure(app => { app.Run(async context => { @@ -344,6 +368,7 @@ namespace Microsoft.AspNet.TestHost context.Response.Body.Dispose(); }); }); + var server = new TestServer(builder); HttpResponseMessage result = await server.CreateClient().GetAsync("/"); Assert.Equal(HttpStatusCode.OK, result.StatusCode); @@ -355,15 +380,17 @@ namespace Microsoft.AspNet.TestHost [FrameworkSkipCondition(RuntimeFrameworks.Mono, SkipReason = "Hangs randomly (issue #507)")] public async Task CancelAborts() { - TestServer server = TestServer.Create(app => - { - app.Run(context => - { - TaskCompletionSource tcs = new TaskCompletionSource(); - tcs.SetCanceled(); - return tcs.Task; - }); - }); + var builder = new WebApplicationBuilder() + .Configure(app => + { + app.Run(context => + { + TaskCompletionSource tcs = new TaskCompletionSource(); + tcs.SetCanceled(); + return tcs.Task; + }); + }); + var server = new TestServer(builder); await Assert.ThrowsAsync(async () => { string result = await server.CreateClient().GetStringAsync("/path"); }); } @@ -372,7 +399,9 @@ namespace Microsoft.AspNet.TestHost [FrameworkSkipCondition(RuntimeFrameworks.Mono, SkipReason = "Hangs randomly (issue #507)")] public async Task CanCreateViaStartupType() { - TestServer server = new TestServer(TestServer.CreateBuilder().UseStartup()); + var builder = new WebApplicationBuilder() + .UseStartup(); + var server = new TestServer(builder); HttpResponseMessage result = await server.CreateClient().GetAsync("/"); Assert.Equal(HttpStatusCode.OK, result.StatusCode); Assert.Equal("FoundService:True", await result.Content.ReadAsStringAsync()); @@ -382,9 +411,11 @@ namespace Microsoft.AspNet.TestHost [FrameworkSkipCondition(RuntimeFrameworks.Mono, SkipReason = "Hangs randomly (issue #507)")] public async Task CanCreateViaStartupTypeAndSpecifyEnv() { - TestServer server = new TestServer(TestServer.CreateBuilder() - .UseStartup() - .UseEnvironment("Foo")); + var builder = new WebApplicationBuilder() + .UseStartup() + .UseEnvironment("Foo"); + var server = new TestServer(builder); + HttpResponseMessage result = await server.CreateClient().GetAsync("/"); Assert.Equal(HttpStatusCode.OK, result.StatusCode); Assert.Equal("FoundFoo:False", await result.Content.ReadAsStringAsync()); @@ -395,14 +426,18 @@ namespace Microsoft.AspNet.TestHost public async Task BeginEndDiagnosticAvailable() { DiagnosticListener diagnosticListener = null; - var server = TestServer.Create(app => - { - diagnosticListener = app.ApplicationServices.GetRequiredService(); - app.Run(context => - { - return context.Response.WriteAsync("Hello World"); - }); - }); + + var builder = new WebApplicationBuilder() + .Configure(app => + { + diagnosticListener = app.ApplicationServices.GetRequiredService(); + app.Run(context => + { + return context.Response.WriteAsync("Hello World"); + }); + }); + var server = new TestServer(builder); + var listener = new TestDiagnosticListener(); diagnosticListener.SubscribeWithAdapter(listener); var result = await server.CreateClient().GetStringAsync("/path"); @@ -421,7 +456,7 @@ namespace Microsoft.AspNet.TestHost public async Task ExceptionDiagnosticAvailable() { DiagnosticListener diagnosticListener = null; - var server = TestServer.Create(app => + var builder = new WebApplicationBuilder().Configure(app => { diagnosticListener = app.ApplicationServices.GetRequiredService(); app.Run(context => @@ -429,10 +464,12 @@ namespace Microsoft.AspNet.TestHost throw new Exception("Test exception"); }); }); + var server = new TestServer(builder); + var listener = new TestDiagnosticListener(); diagnosticListener.SubscribeWithAdapter(listener); await Assert.ThrowsAsync(() => server.CreateClient().GetAsync("/path")); - + // This ensures that all diagnostics are completely written to the diagnostic listener Thread.Sleep(1000); From 94bf7bf2d5646f85b9bf6748e8c814106d3781e4 Mon Sep 17 00:00:00 2001 From: Chris R Date: Mon, 21 Dec 2015 10:17:50 -0800 Subject: [PATCH 471/987] Dont select an architecture specific version of IIS Express. --- .../Deployers/IISExpressDeployer.cs | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Testing/Deployers/IISExpressDeployer.cs b/src/Microsoft.AspNet.Server.Testing/Deployers/IISExpressDeployer.cs index 96f69b2b7f..c60bf11b37 100644 --- a/src/Microsoft.AspNet.Server.Testing/Deployers/IISExpressDeployer.cs +++ b/src/Microsoft.AspNet.Server.Testing/Deployers/IISExpressDeployer.cs @@ -126,20 +126,11 @@ namespace Microsoft.AspNet.Server.Testing private string GetIISExpressPath() { // Get path to program files - var iisExpressPath = Path.Combine(Environment.GetEnvironmentVariable("ProgramFiles(x86)"), "IIS Express", "iisexpress.exe"); - - // Get path to 64 bit of IIS Express - if (DeploymentParameters.RuntimeArchitecture == RuntimeArchitecture.x64) - { - iisExpressPath = Path.Combine(Environment.GetEnvironmentVariable("ProgramFiles"), "IIS Express", "iisexpress.exe"); - - // If process is 32 bit, the path points to x86. Replace path to point to x64 - iisExpressPath = IntPtr.Size == 8 ? iisExpressPath : iisExpressPath.Replace(" (x86)", ""); - } + var iisExpressPath = Path.Combine(Environment.GetEnvironmentVariable("SystemDrive") + "\\", "Program Files", "IIS Express", "iisexpress.exe"); if (!File.Exists(iisExpressPath)) { - throw new Exception("Unable to find IISExpress on the machine"); + throw new Exception("Unable to find IISExpress on the machine: " + iisExpressPath); } return iisExpressPath; From 7b43502817950107cd7e23d10530288e39e9a320 Mon Sep 17 00:00:00 2001 From: John Luo Date: Mon, 21 Dec 2015 14:37:04 -0800 Subject: [PATCH 472/987] Update selfhost to specify server via command line --- .../Deployers/SelfHostDeployer.cs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Testing/Deployers/SelfHostDeployer.cs b/src/Microsoft.AspNet.Server.Testing/Deployers/SelfHostDeployer.cs index 1d2c2b1ed7..e1fdc509b0 100644 --- a/src/Microsoft.AspNet.Server.Testing/Deployers/SelfHostDeployer.cs +++ b/src/Microsoft.AspNet.Server.Testing/Deployers/SelfHostDeployer.cs @@ -2,6 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Threading; @@ -51,10 +52,14 @@ namespace Microsoft.AspNet.Server.Testing var commandName = DeploymentParameters.Command; if (string.IsNullOrEmpty(commandName)) { - commandName = DeploymentParameters.ServerType == ServerType.WebListener ? "weblistener" : "kestrel"; + commandName = "run"; } + var dnxPath = Path.Combine(ChosenRuntimePath, DnxCommandName); - var dnxArgs = $"-p \"{DeploymentParameters.ApplicationPath}\" {commandName} --server.urls {DeploymentParameters.ApplicationBaseUriHint}"; + var dnxArgs = $"-p \"{DeploymentParameters.ApplicationPath}\" {commandName} " + + $"--server.urls {DeploymentParameters.ApplicationBaseUriHint} " + + $"--server {(DeploymentParameters.ServerType == ServerType.WebListener ? "Microsoft.AspNet.Server.WebListener" : "Microsoft.AspNet.Server.Kestrel")}"; + Logger.LogInformation($"Executing {dnxPath} {dnxArgs}"); var startInfo = new ProcessStartInfo From 0e2fa1711df2fc7ec68c401f03a27560ab51cef7 Mon Sep 17 00:00:00 2001 From: Hao Kung Date: Mon, 21 Dec 2015 14:53:01 -0800 Subject: [PATCH 473/987] React to OptionsModel => Options --- test/Microsoft.AspNet.Hosting.Tests/StartupManagerTests.cs | 2 +- test/Microsoft.AspNet.Hosting.Tests/WebApplicationTests.cs | 2 +- test/Microsoft.AspNet.Hosting.Tests/project.json | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/test/Microsoft.AspNet.Hosting.Tests/StartupManagerTests.cs b/test/Microsoft.AspNet.Hosting.Tests/StartupManagerTests.cs index 8b0c67652d..6c7f3dd5fc 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/StartupManagerTests.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/StartupManagerTests.cs @@ -10,7 +10,7 @@ using Microsoft.AspNet.Hosting.Fakes; using Microsoft.AspNet.Hosting.Internal; using Microsoft.AspNet.Hosting.Startup; using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.OptionsModel; +using Microsoft.Extensions.Options; using Xunit; namespace Microsoft.AspNet.Hosting.Tests diff --git a/test/Microsoft.AspNet.Hosting.Tests/WebApplicationTests.cs b/test/Microsoft.AspNet.Hosting.Tests/WebApplicationTests.cs index d66419639f..74621076fe 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/WebApplicationTests.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/WebApplicationTests.cs @@ -18,7 +18,7 @@ using Microsoft.AspNet.Testing.xunit; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; -using Microsoft.Extensions.OptionsModel; +using Microsoft.Extensions.Options; using Microsoft.Extensions.Primitives; using Xunit; diff --git a/test/Microsoft.AspNet.Hosting.Tests/project.json b/test/Microsoft.AspNet.Hosting.Tests/project.json index 07b3452630..1a974b1eea 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/project.json +++ b/test/Microsoft.AspNet.Hosting.Tests/project.json @@ -7,7 +7,7 @@ "Microsoft.AspNet.Hosting": "1.0.0-*", "Microsoft.AspNet.Owin": "1.0.0-*", "Microsoft.AspNet.Testing": "1.0.0-*", - "Microsoft.Extensions.OptionsModel": "1.0.0-*", + "Microsoft.Extensions.Options": "1.0.0-*", "Microsoft.Extensions.PlatformAbstractions": "1.0.0-*", "xunit.runner.aspnet": "2.0.0-aspnet-*" }, From 45a1981e3b7f727412a8094ef02e329673b2b564 Mon Sep 17 00:00:00 2001 From: Henk Mollema Date: Tue, 22 Dec 2015 08:50:31 +0100 Subject: [PATCH 474/987] Remove dnx451 and dnxcore50 TFM's --- src/Microsoft.AspNet.Hosting/project.json | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/src/Microsoft.AspNet.Hosting/project.json b/src/Microsoft.AspNet.Hosting/project.json index 81c7525f8e..a44b68f284 100644 --- a/src/Microsoft.AspNet.Hosting/project.json +++ b/src/Microsoft.AspNet.Hosting/project.json @@ -29,23 +29,11 @@ "System.Diagnostics.DiagnosticSource": "4.0.0-*" }, "frameworks": { - "dnx451": { - "frameworkAssemblies": { - "System.Runtime": "" - } - }, "net451": { "frameworkAssemblies": { "System.Runtime": { "type": "build" } } }, - "dnxcore50": { - "dependencies": { - "System.Console": "4.0.0-*", - "System.Diagnostics.StackTrace": "4.0.1-*", - "System.Reflection.Extensions": "4.0.1-*" - } - }, "dotnet5.4": { "dependencies": { "System.Console": "4.0.0-*", From 216fe7843c3f295b6dc5799fcb0dc4e69f73f75c Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Tue, 22 Dec 2015 13:44:57 +0000 Subject: [PATCH 475/987] Remove unnecessary state machine --- src/Microsoft.AspNet.Hosting/Internal/HostingApplication.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Microsoft.AspNet.Hosting/Internal/HostingApplication.cs b/src/Microsoft.AspNet.Hosting/Internal/HostingApplication.cs index c5b74dca72..5ed245354a 100644 --- a/src/Microsoft.AspNet.Hosting/Internal/HostingApplication.cs +++ b/src/Microsoft.AspNet.Hosting/Internal/HostingApplication.cs @@ -76,9 +76,9 @@ namespace Microsoft.AspNet.Hosting.Internal _httpContextFactory.Dispose(httpContext); } - public async Task ProcessRequestAsync(Context context) + public Task ProcessRequestAsync(Context context) { - await _application(context.HttpContext); + return _application(context.HttpContext); } public struct Context From f5a866ff3cb84b44499c90c1ca9ed2a57860de07 Mon Sep 17 00:00:00 2001 From: John Luo Date: Tue, 22 Dec 2015 15:12:28 -0800 Subject: [PATCH 476/987] Using new PlatformServices API --- .../Deployers/ApplicationDeployer.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Testing/Deployers/ApplicationDeployer.cs b/src/Microsoft.AspNet.Server.Testing/Deployers/ApplicationDeployer.cs index 643c2d8310..f2a07b24fd 100644 --- a/src/Microsoft.AspNet.Server.Testing/Deployers/ApplicationDeployer.cs +++ b/src/Microsoft.AspNet.Server.Testing/Deployers/ApplicationDeployer.cs @@ -39,15 +39,15 @@ namespace Microsoft.AspNet.Server.Testing { get { - if (TestPlatformHelper.IsLinux) + if (PlatformServices.Default.Runtime.OperatingSystemPlatform == Platform.Linux) { return "linux"; } - else if (TestPlatformHelper.IsMac) + else if (PlatformServices.Default.Runtime.OperatingSystemPlatform == Platform.Darwin) { return "darwin"; } - else if (TestPlatformHelper.IsWindows) + else if (PlatformServices.Default.Runtime.OperatingSystemPlatform == Platform.Windows) { return "win"; } From 83c8816eb79ca42158fe8fc7684f5013c9d529c8 Mon Sep 17 00:00:00 2001 From: Erez Testiler Date: Tue, 22 Dec 2015 09:39:50 -0500 Subject: [PATCH 477/987] Add support for hosting within a Windows service. --- Hosting.sln | 17 +++- ...osoft.AspNet.Hosting.WindowsServices.xproj | 19 +++++ .../WebApplicationExtensions.cs | 39 +++++++++ .../WebApplicationService.cs | 80 +++++++++++++++++++ .../project.json | 22 +++++ 5 files changed, 176 insertions(+), 1 deletion(-) create mode 100644 src/Microsoft.AspNet.Hosting.WindowsServices/Microsoft.AspNet.Hosting.WindowsServices.xproj create mode 100644 src/Microsoft.AspNet.Hosting.WindowsServices/WebApplicationExtensions.cs create mode 100644 src/Microsoft.AspNet.Hosting.WindowsServices/WebApplicationService.cs create mode 100644 src/Microsoft.AspNet.Hosting.WindowsServices/project.json diff --git a/Hosting.sln b/Hosting.sln index a04fd5e533..ea81db18f9 100644 --- a/Hosting.sln +++ b/Hosting.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 14 -VisualStudioVersion = 14.0.23107.0 +VisualStudioVersion = 14.0.24720.0 MinimumVisualStudioVersion = 10.0.40219.1 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{E0497F39-AFFB-4819-A116-E39E361915AB}" EndProject @@ -30,6 +30,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "samples", "samples", "{9C75 EndProject Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "SampleStartups", "samples\SampleStartups\SampleStartups.xproj", "{485B6745-7648-400A-A969-F68FCF194E46}" EndProject +Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNet.Hosting.WindowsServices", "src\Microsoft.AspNet.Hosting.WindowsServices\Microsoft.AspNet.Hosting.WindowsServices.xproj", "{03148731-EA95-40A2-BAE8-A12315EA1748}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -128,6 +130,18 @@ Global {485B6745-7648-400A-A969-F68FCF194E46}.Release|Mixed Platforms.Build.0 = Release|Any CPU {485B6745-7648-400A-A969-F68FCF194E46}.Release|x86.ActiveCfg = Release|Any CPU {485B6745-7648-400A-A969-F68FCF194E46}.Release|x86.Build.0 = Release|Any CPU + {03148731-EA95-40A2-BAE8-A12315EA1748}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {03148731-EA95-40A2-BAE8-A12315EA1748}.Debug|Any CPU.Build.0 = Debug|Any CPU + {03148731-EA95-40A2-BAE8-A12315EA1748}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU + {03148731-EA95-40A2-BAE8-A12315EA1748}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU + {03148731-EA95-40A2-BAE8-A12315EA1748}.Debug|x86.ActiveCfg = Debug|Any CPU + {03148731-EA95-40A2-BAE8-A12315EA1748}.Debug|x86.Build.0 = Debug|Any CPU + {03148731-EA95-40A2-BAE8-A12315EA1748}.Release|Any CPU.ActiveCfg = Release|Any CPU + {03148731-EA95-40A2-BAE8-A12315EA1748}.Release|Any CPU.Build.0 = Release|Any CPU + {03148731-EA95-40A2-BAE8-A12315EA1748}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU + {03148731-EA95-40A2-BAE8-A12315EA1748}.Release|Mixed Platforms.Build.0 = Release|Any CPU + {03148731-EA95-40A2-BAE8-A12315EA1748}.Release|x86.ActiveCfg = Release|Any CPU + {03148731-EA95-40A2-BAE8-A12315EA1748}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -141,5 +155,6 @@ Global {FDBBA081-5248-4FC0-9E08-B46BEF3FA438} = {E0497F39-AFFB-4819-A116-E39E361915AB} {3DA89347-6731-4366-80C4-548F24E8607B} = {E0497F39-AFFB-4819-A116-E39E361915AB} {485B6745-7648-400A-A969-F68FCF194E46} = {9C7520A0-F2EB-411C-8BB2-80B39C937217} + {03148731-EA95-40A2-BAE8-A12315EA1748} = {E0497F39-AFFB-4819-A116-E39E361915AB} EndGlobalSection EndGlobal diff --git a/src/Microsoft.AspNet.Hosting.WindowsServices/Microsoft.AspNet.Hosting.WindowsServices.xproj b/src/Microsoft.AspNet.Hosting.WindowsServices/Microsoft.AspNet.Hosting.WindowsServices.xproj new file mode 100644 index 0000000000..39ccb16031 --- /dev/null +++ b/src/Microsoft.AspNet.Hosting.WindowsServices/Microsoft.AspNet.Hosting.WindowsServices.xproj @@ -0,0 +1,19 @@ + + + + 14.0 + $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) + + + + 03148731-ea95-40a2-bae8-a12315ea1748 + Microsoft.AspNet.Hosting.WindowsServices + ..\..\artifacts\obj\$(MSBuildProjectName) + ..\..\artifacts\bin\$(MSBuildProjectName)\ + + + 2.0 + + + + \ No newline at end of file diff --git a/src/Microsoft.AspNet.Hosting.WindowsServices/WebApplicationExtensions.cs b/src/Microsoft.AspNet.Hosting.WindowsServices/WebApplicationExtensions.cs new file mode 100644 index 0000000000..4eb008faa9 --- /dev/null +++ b/src/Microsoft.AspNet.Hosting.WindowsServices/WebApplicationExtensions.cs @@ -0,0 +1,39 @@ +using System.ServiceProcess; + +namespace Microsoft.AspNet.Hosting.WindowsServices +{ + /// + /// Extensions to + /// + public static class WebApplicationExtensions + { + /// + /// Runs the specified web application inside a Windows service and blocks until the service is stopped. + /// + /// An instance of the to host in the Windows service. + /// + /// This example shows how to use . + /// + /// public class Program + /// { + /// public static void Main(string[] args) + /// { + /// var config = WebApplicationConfiguration.GetDefault(args); + /// + /// var application = new WebApplicationBuilder() + /// .UseConfiguration(config) + /// .Build(); + /// + /// // This call will block until the service is stopped. + /// application.RunAsService(); + /// } + /// } + /// + /// + public static void RunAsService(this IWebApplication application) + { + var webApplicationService = new WebApplicationService(application); + ServiceBase.Run(webApplicationService); + } + } +} diff --git a/src/Microsoft.AspNet.Hosting.WindowsServices/WebApplicationService.cs b/src/Microsoft.AspNet.Hosting.WindowsServices/WebApplicationService.cs new file mode 100644 index 0000000000..11819d3411 --- /dev/null +++ b/src/Microsoft.AspNet.Hosting.WindowsServices/WebApplicationService.cs @@ -0,0 +1,80 @@ +using Microsoft.AspNet.Hosting.Internal; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; +using System; +using System.ServiceProcess; + +namespace Microsoft.AspNet.Hosting.WindowsServices +{ + /// + /// Provides an implementation of a Windows service that hosts ASP.NET. + /// + public class WebApplicationService : ServiceBase + { + private const string HostingJsonFile = "hosting.json"; + private const string EnvironmentVariablesPrefix = "ASPNET_"; + private const string ConfigFileKey = "config"; + private IWebApplication _application; + private IDisposable _applicationShutdown; + private bool _stopRequestedByWindows; + + /// + /// Creates an instance of WebApplicationService which hosts the specified web application. + /// + /// The web application to host in the Windows service. + public WebApplicationService(IWebApplication application) + { + _application = application; + } + + protected sealed override void OnStart(string[] args) + { + OnStarting(args); + + _application + .Services + .GetRequiredService() + .ApplicationStopped + .Register(() => + { + if (!_stopRequestedByWindows) + { + Stop(); + } + }); + + _applicationShutdown = _application.Start(); + + OnStarted(); + } + + protected sealed override void OnStop() + { + _stopRequestedByWindows = true; + OnStopping(); + _applicationShutdown?.Dispose(); + OnStopped(); + } + + /// + /// Executes before ASP.NET starts. + /// + /// The command line arguments passed to the service. + protected virtual void OnStarting(string[] args) { } + + /// + /// Executes after ASP.NET starts. + /// + protected virtual void OnStarted() { } + + /// + /// Executes before ASP.NET shuts down. + /// + protected virtual void OnStopping() { } + + /// + /// Executes after ASP.NET shuts down. + /// + protected virtual void OnStopped() { } + } +} diff --git a/src/Microsoft.AspNet.Hosting.WindowsServices/project.json b/src/Microsoft.AspNet.Hosting.WindowsServices/project.json new file mode 100644 index 0000000000..3da4890272 --- /dev/null +++ b/src/Microsoft.AspNet.Hosting.WindowsServices/project.json @@ -0,0 +1,22 @@ +{ + "version": "1.0.0-*", + "description": "ASP.NET 5 core hosting infrastructure and startup logic for web applications running within a Windows service.", + "repository": { + "type": "git", + "url": "git://github.com/aspnet/hosting" + }, + "compilationOptions": { + "warningsAsErrors": true, + "keyFile": "../../tools/Key.snk" + }, + "dependencies": { + "Microsoft.AspNet.Hosting": "1.0.0-*" + }, + "frameworks": { + "net451": { + "frameworkAssemblies": { + "System.ServiceProcess": "" + } + } + } +} From 4ec36de602cd9775088fa4d6125ea8ef04e22e4c Mon Sep 17 00:00:00 2001 From: John Luo Date: Tue, 22 Dec 2015 16:56:32 -0800 Subject: [PATCH 478/987] Minor cleanup of WindowsServices --- .../WebApplicationExtensions.cs | 5 ++++- .../WebApplicationService.cs | 10 ++++------ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/Microsoft.AspNet.Hosting.WindowsServices/WebApplicationExtensions.cs b/src/Microsoft.AspNet.Hosting.WindowsServices/WebApplicationExtensions.cs index 4eb008faa9..41f3e0548f 100644 --- a/src/Microsoft.AspNet.Hosting.WindowsServices/WebApplicationExtensions.cs +++ b/src/Microsoft.AspNet.Hosting.WindowsServices/WebApplicationExtensions.cs @@ -1,4 +1,7 @@ -using System.ServiceProcess; +// 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.ServiceProcess; namespace Microsoft.AspNet.Hosting.WindowsServices { diff --git a/src/Microsoft.AspNet.Hosting.WindowsServices/WebApplicationService.cs b/src/Microsoft.AspNet.Hosting.WindowsServices/WebApplicationService.cs index 11819d3411..a50d0d76a7 100644 --- a/src/Microsoft.AspNet.Hosting.WindowsServices/WebApplicationService.cs +++ b/src/Microsoft.AspNet.Hosting.WindowsServices/WebApplicationService.cs @@ -1,8 +1,9 @@ -using Microsoft.AspNet.Hosting.Internal; -using Microsoft.Extensions.Configuration; -using Microsoft.Extensions.DependencyInjection; +// 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; using System.ServiceProcess; +using Microsoft.Extensions.DependencyInjection; namespace Microsoft.AspNet.Hosting.WindowsServices { @@ -11,9 +12,6 @@ namespace Microsoft.AspNet.Hosting.WindowsServices /// public class WebApplicationService : ServiceBase { - private const string HostingJsonFile = "hosting.json"; - private const string EnvironmentVariablesPrefix = "ASPNET_"; - private const string ConfigFileKey = "config"; private IWebApplication _application; private IDisposable _applicationShutdown; private bool _stopRequestedByWindows; From d07a07228771ebdc1a06835d0ee67d50d61ec126 Mon Sep 17 00:00:00 2001 From: John Luo Date: Tue, 22 Dec 2015 19:58:51 -0800 Subject: [PATCH 479/987] Adding AssemblyInfo for WindowsServices --- .../Properties/AssemblyInfo.cs | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 src/Microsoft.AspNet.Hosting.WindowsServices/Properties/AssemblyInfo.cs diff --git a/src/Microsoft.AspNet.Hosting.WindowsServices/Properties/AssemblyInfo.cs b/src/Microsoft.AspNet.Hosting.WindowsServices/Properties/AssemblyInfo.cs new file mode 100644 index 0000000000..b16f6dfb0a --- /dev/null +++ b/src/Microsoft.AspNet.Hosting.WindowsServices/Properties/AssemblyInfo.cs @@ -0,0 +1,8 @@ +// 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.Reflection; +using System.Resources; + +[assembly: AssemblyMetadata("Serviceable", "True")] +[assembly: NeutralResourcesLanguage("en-us")] From e4e40033b113e27f6f95a3886019275abe7c0c1e Mon Sep 17 00:00:00 2001 From: David Fowler Date: Thu, 31 Dec 2015 13:39:39 -0800 Subject: [PATCH 480/987] React to HttpAbstractions changes --- .../WebApplicationTests.cs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/test/Microsoft.AspNet.Hosting.Tests/WebApplicationTests.cs b/test/Microsoft.AspNet.Hosting.Tests/WebApplicationTests.cs index 74621076fe..9278d7ad17 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/WebApplicationTests.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/WebApplicationTests.cs @@ -558,11 +558,21 @@ namespace Microsoft.AspNet.Hosting { } + public TFeature Get() + { + return default(TFeature); + } + public IEnumerator> GetEnumerator() { yield break; } + public void Set(TFeature instance) + { + throw new NotSupportedException(); + } + IEnumerator IEnumerable.GetEnumerator() { yield break; From d8a20521f1bf799df362d32fd35c6a0bb280aad0 Mon Sep 17 00:00:00 2001 From: David Fowler Date: Mon, 4 Jan 2016 16:38:23 -0800 Subject: [PATCH 481/987] Add Options to the default set of services #547 --- src/Microsoft.AspNet.Hosting/WebApplicationBuilder.cs | 1 + src/Microsoft.AspNet.Hosting/project.json | 1 + 2 files changed, 2 insertions(+) diff --git a/src/Microsoft.AspNet.Hosting/WebApplicationBuilder.cs b/src/Microsoft.AspNet.Hosting/WebApplicationBuilder.cs index 4350a2b35b..12e595c50d 100644 --- a/src/Microsoft.AspNet.Hosting/WebApplicationBuilder.cs +++ b/src/Microsoft.AspNet.Hosting/WebApplicationBuilder.cs @@ -206,6 +206,7 @@ namespace Microsoft.AspNet.Hosting services.AddTransient(); services.AddTransient(); services.AddLogging(); + services.AddOptions(); var diagnosticSource = new DiagnosticListener("Microsoft.AspNet"); services.AddSingleton(diagnosticSource); diff --git a/src/Microsoft.AspNet.Hosting/project.json b/src/Microsoft.AspNet.Hosting/project.json index a44b68f284..302aa0ba37 100644 --- a/src/Microsoft.AspNet.Hosting/project.json +++ b/src/Microsoft.AspNet.Hosting/project.json @@ -15,6 +15,7 @@ "Microsoft.AspNet.Hosting.Server.Abstractions": "1.0.0-*", "Microsoft.AspNet.Http": "1.0.0-*", "Microsoft.AspNet.Http.Extensions": "1.0.0-*", + "Microsoft.Extensions.Options": "1.0.0-*", "Microsoft.Extensions.Configuration": "1.0.0-*", "Microsoft.Extensions.Configuration.CommandLine": "1.0.0-*", "Microsoft.Extensions.Configuration.EnvironmentVariables": "1.0.0-*", From 46e3e25ec7c5212029b64a25efbe1f11cba2afc5 Mon Sep 17 00:00:00 2001 From: David Fowler Date: Mon, 4 Jan 2016 17:43:23 -0800 Subject: [PATCH 482/987] Add the ability to set the IApplicationEnvironment.ApplicationBasePath - Added UseApplicationBasePath which sets the base path (used for views and static files) --- samples/SampleStartups/StartupFullControl.cs | 2 ++ .../WebApplicationBuilder.cs | 36 ++++++++++++++++++- .../WebApplicationBuilderTests.cs | 22 ++++++++++++ 3 files changed, 59 insertions(+), 1 deletion(-) diff --git a/samples/SampleStartups/StartupFullControl.cs b/samples/SampleStartups/StartupFullControl.cs index 34a00a5a46..82c32791d6 100644 --- a/samples/SampleStartups/StartupFullControl.cs +++ b/samples/SampleStartups/StartupFullControl.cs @@ -1,4 +1,5 @@ using System; +using System.IO; using Microsoft.AspNet.Builder; using Microsoft.AspNet.Hosting; using Microsoft.Extensions.DependencyInjection; @@ -14,6 +15,7 @@ namespace SampleStartups { var application = new WebApplicationBuilder() .UseServerFactory("Microsoft.AspNet.Server.Kestrel") // Set the server manually + .UseApplicationBasePath(Directory.GetCurrentDirectory()) // Override the application base with the current directory .UseEnvironment("Development") .UseWebRoot("public") .ConfigureLogging(loggerFactory => diff --git a/src/Microsoft.AspNet.Hosting/WebApplicationBuilder.cs b/src/Microsoft.AspNet.Hosting/WebApplicationBuilder.cs index 12e595c50d..bec3ee4381 100644 --- a/src/Microsoft.AspNet.Hosting/WebApplicationBuilder.cs +++ b/src/Microsoft.AspNet.Hosting/WebApplicationBuilder.cs @@ -3,6 +3,7 @@ using System; using System.Diagnostics; +using System.Runtime.Versioning; using Microsoft.AspNet.Builder; using Microsoft.AspNet.Hosting.Builder; using Microsoft.AspNet.Hosting.Internal; @@ -29,6 +30,7 @@ namespace Microsoft.AspNet.Hosting private Action _configureServices; private string _environmentName; private string _webRoot; + private string _applicationBasePath; // Only one of these should be set private StartupMethods _startup; @@ -52,6 +54,12 @@ namespace Microsoft.AspNet.Hosting return this; } + public WebApplicationBuilder UseApplicationBasePath(string applicationBasePath) + { + _applicationBasePath = applicationBasePath; + return this; + } + public WebApplicationBuilder UseEnvironment(string environment) { if (environment == null) @@ -216,11 +224,18 @@ namespace Microsoft.AspNet.Hosting services.AddTransient(); var defaultPlatformServices = PlatformServices.Default; + if (defaultPlatformServices != null) { if (defaultPlatformServices.Application != null) { - services.TryAddSingleton(defaultPlatformServices.Application); + var appEnv = defaultPlatformServices.Application; + if (!string.IsNullOrEmpty(_applicationBasePath)) + { + appEnv = new WrappedApplicationEnvironment(_applicationBasePath, appEnv); + } + + services.TryAddSingleton(appEnv); } if (defaultPlatformServices.Runtime != null) @@ -236,5 +251,24 @@ namespace Microsoft.AspNet.Hosting return services; } + + private class WrappedApplicationEnvironment : IApplicationEnvironment + { + public WrappedApplicationEnvironment(string applicationBasePath, IApplicationEnvironment env) + { + ApplicationBasePath = applicationBasePath; + ApplicationName = env.ApplicationName; + ApplicationVersion = env.ApplicationVersion; + RuntimeFramework = env.RuntimeFramework; + } + + public string ApplicationBasePath { get; } + + public string ApplicationName { get; } + + public string ApplicationVersion { get; } + + public FrameworkName RuntimeFramework { get; } + } } } diff --git a/test/Microsoft.AspNet.Hosting.Tests/WebApplicationBuilderTests.cs b/test/Microsoft.AspNet.Hosting.Tests/WebApplicationBuilderTests.cs index edeaffb499..06f912ac17 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/WebApplicationBuilderTests.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/WebApplicationBuilderTests.cs @@ -13,6 +13,7 @@ using Microsoft.AspNet.Http.Features; using Microsoft.AspNet.Http.Internal; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.PlatformAbstractions; using Xunit; namespace Microsoft.AspNet.Hosting @@ -137,6 +138,27 @@ namespace Microsoft.AspNet.Hosting Assert.Equal(expected, application.Services.GetService().EnvironmentName); } + [Fact] + public void UseBasePathConfiguresBasePath() + { + var vals = new Dictionary + { + { "ENV", "Dev" }, + }; + var builder = new ConfigurationBuilder() + .AddInMemoryCollection(vals); + var config = builder.Build(); + + var application = new WebApplicationBuilder() + .UseConfiguration(config) + .UseApplicationBasePath("/foo/bar") + .UseServer(new TestServer()) + .UseStartup("Microsoft.AspNet.Hosting.Tests") + .Build(); + + Assert.Equal("/foo/bar", application.Services.GetService().ApplicationBasePath); + } + private WebApplicationBuilder CreateWebApplicationBuilder() { var vals = new Dictionary From e72924796e7bc84f2e71c93b178f0f8846576ea4 Mon Sep 17 00:00:00 2001 From: David Fowler Date: Wed, 6 Jan 2016 18:08:57 -0800 Subject: [PATCH 483/987] More hosting API changes - Added IWebApplicationBuilder and moved it to Hosting.Abstractions as a target for others to extend the web application builder. - Made methods extension methods where possible - Added UseUrls --- .../SampleStartups/StartupBlockingOnStart.cs | 3 +- .../StartupConfigureAddresses.cs | 5 +- .../StartupExternallyControlled.cs | 17 +- samples/SampleStartups/StartupFullControl.cs | 7 +- .../IWebApplication.cs | 4 +- .../IWebApplicationBuilder.cs | 28 ++++ .../project.json | 4 +- .../WebApplicationService.cs | 5 +- .../Internal/IncludedConfigurationProvider.cs | 39 +++++ .../Internal/WebApplication.cs | 31 ++-- .../Internal/WebApplicationOptions.cs | 3 + .../WebApplicationBuilder.cs | 124 ++++----------- .../WebApplicationBuilderExtensions.cs | 148 ++++++++++++++++++ .../WebApplicationConfiguration.cs | 4 +- .../WebApplicationExtensions.cs | 60 ------- src/Microsoft.AspNet.TestHost/TestServer.cs | 14 +- .../WebApplicationBuilderTests.cs | 45 +++++- .../WebApplicationConfigurationsTests.cs | 10 +- .../WebApplicationTests.cs | 64 ++++---- 19 files changed, 373 insertions(+), 242 deletions(-) rename src/{Microsoft.AspNet.Hosting => Microsoft.AspNet.Hosting.Abstractions}/IWebApplication.cs (91%) create mode 100644 src/Microsoft.AspNet.Hosting.Abstractions/IWebApplicationBuilder.cs create mode 100644 src/Microsoft.AspNet.Hosting/Internal/IncludedConfigurationProvider.cs create mode 100644 src/Microsoft.AspNet.Hosting/WebApplicationBuilderExtensions.cs delete mode 100644 src/Microsoft.AspNet.Hosting/WebApplicationExtensions.cs diff --git a/samples/SampleStartups/StartupBlockingOnStart.cs b/samples/SampleStartups/StartupBlockingOnStart.cs index 39db2830c4..fdbc094d1b 100644 --- a/samples/SampleStartups/StartupBlockingOnStart.cs +++ b/samples/SampleStartups/StartupBlockingOnStart.cs @@ -35,8 +35,9 @@ namespace SampleStartups .UseStartup() .Build(); - using (application.Start()) + using (application) { + application.Start(); Console.ReadLine(); } } diff --git a/samples/SampleStartups/StartupConfigureAddresses.cs b/samples/SampleStartups/StartupConfigureAddresses.cs index 0fff30e2f8..00df99135b 100644 --- a/samples/SampleStartups/StartupConfigureAddresses.cs +++ b/samples/SampleStartups/StartupConfigureAddresses.cs @@ -32,12 +32,9 @@ namespace SampleStartups var application = new WebApplicationBuilder() .UseConfiguration(config) .UseStartup() + .UseUrls("http://localhost:5000", "http://localhost:5001") .Build(); - var addresses = application.GetAddresses(); - addresses.Add("http://localhost:5000"); - addresses.Add("http://localhost:5001"); - application.Run(); } } diff --git a/samples/SampleStartups/StartupExternallyControlled.cs b/samples/SampleStartups/StartupExternallyControlled.cs index dc7ce9d8b4..538e97decd 100644 --- a/samples/SampleStartups/StartupExternallyControlled.cs +++ b/samples/SampleStartups/StartupExternallyControlled.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using Microsoft.AspNet.Builder; using Microsoft.AspNet.Hosting; using Microsoft.AspNet.Http; @@ -10,8 +11,8 @@ namespace SampleStartups { public class StartupExternallyControlled { - private readonly IWebApplication _host; - private IDisposable _application; + private IWebApplication _application; + private readonly List _urls = new List(); // This method gets called by the runtime. Use this method to add services to the container. // For more information on how to configure your application, visit http://go.microsoft.com/fwlink/?LinkID=398940 @@ -30,15 +31,13 @@ namespace SampleStartups public StartupExternallyControlled() { - _host = new WebApplicationBuilder().UseStartup().Build(); - - // Clear all configured addresses - _host.GetAddresses().Clear(); } public void Start() { - _application = _host.Start(); + _application = new WebApplicationBuilder() + .UseStartup() + .Start(_urls.ToArray()); } public void Stop() @@ -48,9 +47,7 @@ namespace SampleStartups public void AddUrl(string url) { - var addresses = _host.GetAddresses(); - - addresses.Add(url); + _urls.Add(url); } } } diff --git a/samples/SampleStartups/StartupFullControl.cs b/samples/SampleStartups/StartupFullControl.cs index 82c32791d6..1279bfb1a0 100644 --- a/samples/SampleStartups/StartupFullControl.cs +++ b/samples/SampleStartups/StartupFullControl.cs @@ -14,14 +14,11 @@ namespace SampleStartups public static void Main(string[] args) { var application = new WebApplicationBuilder() - .UseServerFactory("Microsoft.AspNet.Server.Kestrel") // Set the server manually + .UseServer("Microsoft.AspNet.Server.Kestrel") // Set the server manually .UseApplicationBasePath(Directory.GetCurrentDirectory()) // Override the application base with the current directory + .UseUrls("http://*:1000", "https://*:902") .UseEnvironment("Development") .UseWebRoot("public") - .ConfigureLogging(loggerFactory => - { - loggerFactory.AddProvider(new MyHostLoggerProvider()); - }) .ConfigureServices(services => { // Configure services that the application can see diff --git a/src/Microsoft.AspNet.Hosting/IWebApplication.cs b/src/Microsoft.AspNet.Hosting.Abstractions/IWebApplication.cs similarity index 91% rename from src/Microsoft.AspNet.Hosting/IWebApplication.cs rename to src/Microsoft.AspNet.Hosting.Abstractions/IWebApplication.cs index 0db082a45f..cfafc97ee5 100644 --- a/src/Microsoft.AspNet.Hosting/IWebApplication.cs +++ b/src/Microsoft.AspNet.Hosting.Abstractions/IWebApplication.cs @@ -9,7 +9,7 @@ namespace Microsoft.AspNet.Hosting /// /// Represents a configured web application /// - public interface IWebApplication + public interface IWebApplication : IDisposable { /// /// The exposed by the configured server. @@ -25,6 +25,6 @@ namespace Microsoft.AspNet.Hosting /// Starts listening on the configured addresses. /// /// - IDisposable Start(); + void Start(); } } diff --git a/src/Microsoft.AspNet.Hosting.Abstractions/IWebApplicationBuilder.cs b/src/Microsoft.AspNet.Hosting.Abstractions/IWebApplicationBuilder.cs new file mode 100644 index 0000000000..e92288a572 --- /dev/null +++ b/src/Microsoft.AspNet.Hosting.Abstractions/IWebApplicationBuilder.cs @@ -0,0 +1,28 @@ +// 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; +using Microsoft.AspNet.Builder; +using Microsoft.AspNet.Hosting.Server; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; + +namespace Microsoft.AspNet.Hosting +{ + public interface IWebApplicationBuilder + { + IWebApplication Build(); + + IWebApplicationBuilder UseConfiguration(IConfiguration configuration); + + IWebApplicationBuilder UseServer(IServerFactory factory); + + IWebApplicationBuilder UseStartup(Type startupType); + + IWebApplicationBuilder ConfigureServices(Action configureServices); + + IWebApplicationBuilder Configure(Action configureApplication); + + IWebApplicationBuilder UseSetting(string key, string value); + } +} \ No newline at end of file diff --git a/src/Microsoft.AspNet.Hosting.Abstractions/project.json b/src/Microsoft.AspNet.Hosting.Abstractions/project.json index 087bc75058..f6a665e878 100644 --- a/src/Microsoft.AspNet.Hosting.Abstractions/project.json +++ b/src/Microsoft.AspNet.Hosting.Abstractions/project.json @@ -12,7 +12,9 @@ "dependencies": { "Microsoft.AspNet.Http.Abstractions": "1.0.0-*", "Microsoft.AspNet.FileProviders.Abstractions": "1.0.0-*", - "Microsoft.Extensions.Configuration.Abstractions": "1.0.0-*" + "Microsoft.AspNet.Hosting.Server.Abstractions": "1.0.0-*", + "Microsoft.Extensions.Configuration.Abstractions": "1.0.0-*", + "Microsoft.Extensions.DependencyInjection.Abstractions": "1.0.0-*" }, "frameworks": { "net451": {}, diff --git a/src/Microsoft.AspNet.Hosting.WindowsServices/WebApplicationService.cs b/src/Microsoft.AspNet.Hosting.WindowsServices/WebApplicationService.cs index a50d0d76a7..4cecc5705a 100644 --- a/src/Microsoft.AspNet.Hosting.WindowsServices/WebApplicationService.cs +++ b/src/Microsoft.AspNet.Hosting.WindowsServices/WebApplicationService.cs @@ -13,7 +13,6 @@ namespace Microsoft.AspNet.Hosting.WindowsServices public class WebApplicationService : ServiceBase { private IWebApplication _application; - private IDisposable _applicationShutdown; private bool _stopRequestedByWindows; /// @@ -41,7 +40,7 @@ namespace Microsoft.AspNet.Hosting.WindowsServices } }); - _applicationShutdown = _application.Start(); + _application.Start(); OnStarted(); } @@ -50,7 +49,7 @@ namespace Microsoft.AspNet.Hosting.WindowsServices { _stopRequestedByWindows = true; OnStopping(); - _applicationShutdown?.Dispose(); + _application?.Dispose(); OnStopped(); } diff --git a/src/Microsoft.AspNet.Hosting/Internal/IncludedConfigurationProvider.cs b/src/Microsoft.AspNet.Hosting/Internal/IncludedConfigurationProvider.cs new file mode 100644 index 0000000000..5feb23e761 --- /dev/null +++ b/src/Microsoft.AspNet.Hosting/Internal/IncludedConfigurationProvider.cs @@ -0,0 +1,39 @@ +// 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; +using Microsoft.Extensions.Configuration; + +namespace Microsoft.AspNet.Hosting.Internal +{ + // TODO: Remove this once https://github.com/aspnet/Configuration/pull/349 gets merged + internal class IncludedConfigurationProvider : ConfigurationProvider + { + public IncludedConfigurationProvider(IConfiguration source) + { + if (source == null) + { + throw new ArgumentNullException(nameof(source)); + } + int pathStart = 0; + var section = source as IConfigurationSection; + if (section != null) + { + pathStart = section.Path.Length + 1; + } + foreach (var child in source.GetChildren()) + { + AddSection(child, pathStart); + } + } + + private void AddSection(IConfigurationSection section, int pathStart) + { + Data.Add(section.Path.Substring(pathStart), section.Value); + foreach (var child in section.GetChildren()) + { + AddSection(child, pathStart); + } + } + } +} diff --git a/src/Microsoft.AspNet.Hosting/Internal/WebApplication.cs b/src/Microsoft.AspNet.Hosting/Internal/WebApplication.cs index 0014537a7b..170a7f26cd 100644 --- a/src/Microsoft.AspNet.Hosting/Internal/WebApplication.cs +++ b/src/Microsoft.AspNet.Hosting/Internal/WebApplication.cs @@ -32,6 +32,7 @@ namespace Microsoft.AspNet.Hosting.Internal private IServiceProvider _applicationServices; private RequestDelegate _application; + private ILogger _logger; // Only one of these should be set internal string StartupAssemblyName { get; set; } @@ -41,7 +42,7 @@ namespace Microsoft.AspNet.Hosting.Internal // Only one of these should be set internal IServerFactory ServerFactory { get; set; } internal string ServerFactoryLocation { get; set; } - internal IServer Server { get; set; } + private IServer Server { get; set; } public WebApplication( IServiceCollection appServices, @@ -97,29 +98,20 @@ namespace Microsoft.AspNet.Hosting.Internal } } - public virtual IDisposable Start() + public virtual void Start() { Initialize(); - var logger = _applicationServices.GetRequiredService>(); + _logger = _applicationServices.GetRequiredService>(); var diagnosticSource = _applicationServices.GetRequiredService(); var httpContextFactory = _applicationServices.GetRequiredService(); - logger.Starting(); + _logger.Starting(); - Server.Start(new HostingApplication(_application, logger, diagnosticSource, httpContextFactory)); + Server.Start(new HostingApplication(_application, _logger, diagnosticSource, httpContextFactory)); _applicationLifetime.NotifyStarted(); - logger.Started(); - - return new Disposable(() => - { - logger.Shutdown(); - _applicationLifetime.StopApplication(); - Server.Dispose(); - _applicationLifetime.NotifyStopped(); - (_applicationServices as IDisposable)?.Dispose(); - }); + _logger.Started(); } private void EnsureApplicationServices() @@ -248,6 +240,15 @@ namespace Microsoft.AspNet.Hosting.Internal } } + public void Dispose() + { + _logger?.Shutdown(); + _applicationLifetime.StopApplication(); + Server?.Dispose(); + _applicationLifetime.NotifyStopped(); + (_applicationServices as IDisposable)?.Dispose(); + } + private class Disposable : IDisposable { private Action _dispose; diff --git a/src/Microsoft.AspNet.Hosting/Internal/WebApplicationOptions.cs b/src/Microsoft.AspNet.Hosting/Internal/WebApplicationOptions.cs index ef76bcdb8f..1019c866ec 100644 --- a/src/Microsoft.AspNet.Hosting/Internal/WebApplicationOptions.cs +++ b/src/Microsoft.AspNet.Hosting/Internal/WebApplicationOptions.cs @@ -27,6 +27,7 @@ namespace Microsoft.AspNet.Hosting.Internal Environment = configuration[WebApplicationConfiguration.EnvironmentKey] ?? configuration[OldEnvironmentKey]; ServerFactoryLocation = configuration[WebApplicationConfiguration.ServerKey]; WebRoot = configuration[WebApplicationConfiguration.WebRootKey]; + ApplicationBasePath = configuration[WebApplicationConfiguration.ApplicationBaseKey]; } public string Application { get; set; } @@ -41,6 +42,8 @@ namespace Microsoft.AspNet.Hosting.Internal public string WebRoot { get; set; } + public string ApplicationBasePath { get; set; } + private static bool ParseBool(IConfiguration configuration, string key) { return string.Equals("true", configuration[key], StringComparison.OrdinalIgnoreCase) diff --git a/src/Microsoft.AspNet.Hosting/WebApplicationBuilder.cs b/src/Microsoft.AspNet.Hosting/WebApplicationBuilder.cs index bec3ee4381..236b5c8392 100644 --- a/src/Microsoft.AspNet.Hosting/WebApplicationBuilder.cs +++ b/src/Microsoft.AspNet.Hosting/WebApplicationBuilder.cs @@ -2,6 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.Collections.Generic; using System.Diagnostics; using System.Runtime.Versioning; using Microsoft.AspNet.Builder; @@ -16,10 +17,11 @@ using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection.Extensions; using Microsoft.Extensions.Logging; using Microsoft.Extensions.PlatformAbstractions; +using Microsoft.Extensions.Primitives; namespace Microsoft.AspNet.Hosting { - public class WebApplicationBuilder + public class WebApplicationBuilder : IWebApplicationBuilder { private readonly IHostingEnvironment _hostingEnvironment; private readonly ILoggerFactory _loggerFactory; @@ -28,19 +30,15 @@ namespace Microsoft.AspNet.Hosting private WebApplicationOptions _options; private Action _configureServices; - private string _environmentName; - private string _webRoot; - private string _applicationBasePath; // Only one of these should be set private StartupMethods _startup; private Type _startupType; - private string _startupAssemblyName; // Only one of these should be set - private string _serverFactoryLocation; private IServerFactory _serverFactory; - private IServer _server; + + private Dictionary _settings = new Dictionary(StringComparer.OrdinalIgnoreCase); public WebApplicationBuilder() { @@ -48,62 +46,19 @@ namespace Microsoft.AspNet.Hosting _loggerFactory = new LoggerFactory(); } - public WebApplicationBuilder UseConfiguration(IConfiguration configuration) + public IWebApplicationBuilder UseSetting(string key, string value) + { + _settings[key] = value; + return this; + } + + public IWebApplicationBuilder UseConfiguration(IConfiguration configuration) { _config = configuration; return this; } - public WebApplicationBuilder UseApplicationBasePath(string applicationBasePath) - { - _applicationBasePath = applicationBasePath; - return this; - } - - public WebApplicationBuilder UseEnvironment(string environment) - { - if (environment == null) - { - throw new ArgumentNullException(nameof(environment)); - } - - _environmentName = environment; - return this; - } - - public WebApplicationBuilder UseWebRoot(string webRoot) - { - if (webRoot == null) - { - throw new ArgumentNullException(nameof(webRoot)); - } - _webRoot = webRoot; - return this; - } - - public WebApplicationBuilder UseServer(IServer server) - { - if (server == null) - { - throw new ArgumentNullException(nameof(server)); - } - - _server = server; - return this; - } - - public WebApplicationBuilder UseServerFactory(string assemblyName) - { - if (assemblyName == null) - { - throw new ArgumentNullException(nameof(assemblyName)); - } - - _serverFactoryLocation = assemblyName; - return this; - } - - public WebApplicationBuilder UseServerFactory(IServerFactory factory) + public IWebApplicationBuilder UseServer(IServerFactory factory) { if (factory == null) { @@ -114,18 +69,7 @@ namespace Microsoft.AspNet.Hosting return this; } - public WebApplicationBuilder UseStartup(string startupAssemblyName) - { - if (startupAssemblyName == null) - { - throw new ArgumentNullException(nameof(startupAssemblyName)); - } - - _startupAssemblyName = startupAssemblyName; - return this; - } - - public WebApplicationBuilder UseStartup(Type startupType) + public IWebApplicationBuilder UseStartup(Type startupType) { if (startupType == null) { @@ -136,18 +80,13 @@ namespace Microsoft.AspNet.Hosting return this; } - public WebApplicationBuilder UseStartup() where TStartup : class - { - return UseStartup(typeof(TStartup)); - } - - public WebApplicationBuilder ConfigureServices(Action configureServices) + public IWebApplicationBuilder ConfigureServices(Action configureServices) { _configureServices = configureServices; return this; } - public WebApplicationBuilder Configure(Action configureApp) + public IWebApplicationBuilder Configure(Action configureApp) { if (configureApp == null) { @@ -158,7 +97,7 @@ namespace Microsoft.AspNet.Hosting return this; } - public WebApplicationBuilder ConfigureLogging(Action configureLogging) + public IWebApplicationBuilder ConfigureLogging(Action configureLogging) { configureLogging(_loggerFactory); return this; @@ -173,29 +112,19 @@ namespace Microsoft.AspNet.Hosting var appEnvironment = hostingContainer.GetRequiredService(); var startupLoader = hostingContainer.GetRequiredService(); - _config = _config ?? WebApplicationConfiguration.GetDefault(); - _options = new WebApplicationOptions(_config); - // Initialize the hosting environment - _options.WebRoot = _webRoot ?? _options.WebRoot; _hostingEnvironment.Initialize(appEnvironment.ApplicationBasePath, _options, _config); - if (!string.IsNullOrEmpty(_environmentName)) - { - _hostingEnvironment.EnvironmentName = _environmentName; - } - var application = new WebApplication(hostingServices, startupLoader, _options, _config); // Only one of these should be set, but they are used in priority - application.Server = _server; application.ServerFactory = _serverFactory; - application.ServerFactoryLocation = _options.ServerFactoryLocation ?? _serverFactoryLocation; + application.ServerFactoryLocation = _options.ServerFactoryLocation; // Only one of these should be set, but they are used in priority application.Startup = _startup; application.StartupType = _startupType; - application.StartupAssemblyName = _startupAssemblyName ?? _options.Application; + application.StartupAssemblyName = _options.Application; application.Initialize(); @@ -204,6 +133,17 @@ namespace Microsoft.AspNet.Hosting private IServiceCollection BuildHostingServices() { + // Apply the configuration settings + var configuration = _config ?? WebApplicationConfiguration.GetDefault(); + + var mergedConfiguration = new ConfigurationBuilder() + .Add(new IncludedConfigurationProvider(configuration)) + .AddInMemoryCollection(_settings) + .Build(); + + _config = mergedConfiguration; + _options = new WebApplicationOptions(_config); + var services = new ServiceCollection(); services.AddSingleton(_hostingEnvironment); services.AddSingleton(_loggerFactory); @@ -230,9 +170,9 @@ namespace Microsoft.AspNet.Hosting if (defaultPlatformServices.Application != null) { var appEnv = defaultPlatformServices.Application; - if (!string.IsNullOrEmpty(_applicationBasePath)) + if (!string.IsNullOrEmpty(_options.ApplicationBasePath)) { - appEnv = new WrappedApplicationEnvironment(_applicationBasePath, appEnv); + appEnv = new WrappedApplicationEnvironment(_options.ApplicationBasePath, appEnv); } services.TryAddSingleton(appEnv); diff --git a/src/Microsoft.AspNet.Hosting/WebApplicationBuilderExtensions.cs b/src/Microsoft.AspNet.Hosting/WebApplicationBuilderExtensions.cs new file mode 100644 index 0000000000..e49ba7f4ed --- /dev/null +++ b/src/Microsoft.AspNet.Hosting/WebApplicationBuilderExtensions.cs @@ -0,0 +1,148 @@ +// 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; +using Microsoft.AspNet.Hosting.Server; +using Microsoft.AspNet.Server.Features; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; + +namespace Microsoft.AspNet.Hosting +{ + public static class WebApplicationBuilderExtensions + { + private static readonly string ServerUrlsSeparator = ";"; + + public static IWebApplicationBuilder UseStartup(this IWebApplicationBuilder applicationBuilder) where TStartup : class + { + return applicationBuilder.UseStartup(typeof(TStartup)); + } + + public static IWebApplicationBuilder UseServer(this IWebApplicationBuilder applicationBuilder, string assemblyName) + { + if (assemblyName == null) + { + throw new ArgumentNullException(nameof(assemblyName)); + } + + return applicationBuilder.UseSetting(WebApplicationConfiguration.ServerKey, assemblyName); + } + + public static IWebApplicationBuilder UseServer(this IWebApplicationBuilder applicationBuilder, IServer server) + { + if (server == null) + { + throw new ArgumentNullException(nameof(server)); + } + + return applicationBuilder.UseServer(new ServerFactory(server)); + } + + public static IWebApplicationBuilder UseApplicationBasePath(this IWebApplicationBuilder applicationBuilder, string applicationBasePath) + { + if (applicationBasePath == null) + { + throw new ArgumentNullException(nameof(applicationBasePath)); + } + + return applicationBuilder.UseSetting(WebApplicationConfiguration.ApplicationBaseKey, applicationBasePath); + } + + public static IWebApplicationBuilder UseEnvironment(this IWebApplicationBuilder applicationBuilder, string environment) + { + if (environment == null) + { + throw new ArgumentNullException(nameof(environment)); + } + + return applicationBuilder.UseSetting(WebApplicationConfiguration.EnvironmentKey, environment); + } + + public static IWebApplicationBuilder UseWebRoot(this IWebApplicationBuilder applicationBuilder, string webRoot) + { + if (webRoot == null) + { + throw new ArgumentNullException(nameof(webRoot)); + } + + return applicationBuilder.UseSetting(WebApplicationConfiguration.WebRootKey, webRoot); + } + + public static IWebApplicationBuilder UseUrls(this IWebApplicationBuilder applicationBuilder, params string[] urls) + { + if (urls == null) + { + throw new ArgumentNullException(nameof(urls)); + } + + return applicationBuilder.UseSetting(WebApplicationConfiguration.ServerUrlsKey, string.Join(ServerUrlsSeparator, urls)); + } + + public static IWebApplicationBuilder UseStartup(this IWebApplicationBuilder applicationBuilder, string startupAssemblyName) + { + if (startupAssemblyName == null) + { + throw new ArgumentNullException(nameof(startupAssemblyName)); + } + + return applicationBuilder.UseSetting(WebApplicationConfiguration.ApplicationKey, startupAssemblyName); + } + + public static IWebApplication Start(this IWebApplicationBuilder applicationBuilder, params string[] urls) + { + var application = applicationBuilder.UseUrls(urls).Build(); + application.Start(); + return application; + } + + /// + /// Runs a web application and block the calling thread until host shutdown. + /// + /// + public static void Run(this IWebApplication application) + { + using (application) + { + application.Start(); + + var hostingEnvironment = application.Services.GetService(); + var applicationLifetime = application.Services.GetService(); + + Console.WriteLine("Hosting environment: " + hostingEnvironment.EnvironmentName); + + var serverAddresses = application.ServerFeatures.Get()?.Addresses; + if (serverAddresses != null) + { + foreach (var address in serverAddresses) + { + Console.WriteLine("Now listening on: " + address); + } + } + + Console.WriteLine("Application started. Press Ctrl+C to shut down."); + + Console.CancelKeyPress += (sender, eventArgs) => + { + applicationLifetime.StopApplication(); + + // Don't terminate the process immediately, wait for the Main thread to exit gracefully. + eventArgs.Cancel = true; + }; + + applicationLifetime.ApplicationStopping.WaitHandle.WaitOne(); + } + } + + private class ServerFactory : IServerFactory + { + private readonly IServer _server; + + public ServerFactory(IServer server) + { + _server = server; + } + + public IServer CreateServer(IConfiguration configuration) => _server; + } + } +} \ No newline at end of file diff --git a/src/Microsoft.AspNet.Hosting/WebApplicationConfiguration.cs b/src/Microsoft.AspNet.Hosting/WebApplicationConfiguration.cs index 0d71dafc2d..49eff15003 100644 --- a/src/Microsoft.AspNet.Hosting/WebApplicationConfiguration.cs +++ b/src/Microsoft.AspNet.Hosting/WebApplicationConfiguration.cs @@ -4,12 +4,14 @@ namespace Microsoft.AspNet.Hosting { public class WebApplicationConfiguration { - public static readonly string ApplicationKey = "app"; + public static readonly string ApplicationKey = "application"; public static readonly string DetailedErrorsKey = "detailedErrors"; public static readonly string EnvironmentKey = "environment"; public static readonly string ServerKey = "server"; public static readonly string WebRootKey = "webroot"; public static readonly string CaptureStartupErrorsKey = "captureStartupErrors"; + public static readonly string ServerUrlsKey = "server.urls"; + public static readonly string ApplicationBaseKey = "applicationBase"; public static readonly string HostingJsonFile = "hosting.json"; public static readonly string EnvironmentVariablesPrefix = "ASPNET_"; diff --git a/src/Microsoft.AspNet.Hosting/WebApplicationExtensions.cs b/src/Microsoft.AspNet.Hosting/WebApplicationExtensions.cs deleted file mode 100644 index a0b0f0b3f6..0000000000 --- a/src/Microsoft.AspNet.Hosting/WebApplicationExtensions.cs +++ /dev/null @@ -1,60 +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; -using System.Collections.Generic; -using Microsoft.AspNet.Http.Features; -using Microsoft.AspNet.Server.Features; -using Microsoft.Extensions.DependencyInjection; - -namespace Microsoft.AspNet.Hosting -{ - public static class WebApplicationExtensions - { - /// - /// Retruns the server addresses the web application is going to listen on. - /// - /// - /// An which the addresses the server will listen to - public static ICollection GetAddresses(this IWebApplication application) - { - return application.ServerFeatures.Get()?.Addresses; - } - - /// - /// Runs a web application and block the calling thread until host shutdown. - /// - /// - public static void Run(this IWebApplication application) - { - using (application.Start()) - { - var hostingEnvironment = application.Services.GetService(); - var applicationLifetime = application.Services.GetService(); - - Console.WriteLine("Hosting environment: " + hostingEnvironment.EnvironmentName); - - var serverAddresses = application.GetAddresses(); - if (serverAddresses != null) - { - foreach (var address in serverAddresses) - { - Console.WriteLine("Now listening on: " + address); - } - } - - Console.WriteLine("Application started. Press Ctrl+C to shut down."); - - Console.CancelKeyPress += (sender, eventArgs) => - { - applicationLifetime.StopApplication(); - - // Don't terminate the process immediately, wait for the Main thread to exit gracefully. - eventArgs.Cancel = true; - }; - - applicationLifetime.ApplicationStopping.WaitHandle.WaitOne(); - } - } - } -} \ No newline at end of file diff --git a/src/Microsoft.AspNet.TestHost/TestServer.cs b/src/Microsoft.AspNet.TestHost/TestServer.cs index 51980617cf..38da4fd213 100644 --- a/src/Microsoft.AspNet.TestHost/TestServer.cs +++ b/src/Microsoft.AspNet.TestHost/TestServer.cs @@ -16,14 +16,15 @@ namespace Microsoft.AspNet.TestHost { private const string DefaultEnvironmentName = "Development"; private const string ServerName = nameof(TestServer); - private IDisposable _appInstance; + private IWebApplication _appInstance; private bool _disposed = false; private IHttpApplication _application; - public TestServer(WebApplicationBuilder builder) + public TestServer(IWebApplicationBuilder builder) { var application = builder.UseServer(this).Build(); - _appInstance = application.Start(); + application.Start(); + _appInstance = application; } public Uri BaseAddress { get; set; } = new Uri("http://localhost/"); @@ -59,8 +60,11 @@ namespace Microsoft.AspNet.TestHost public void Dispose() { - _disposed = true; - _appInstance.Dispose(); + if (!_disposed) + { + _disposed = true; + _appInstance.Dispose(); + } } void IServer.Start(IHttpApplication application) diff --git a/test/Microsoft.AspNet.Hosting.Tests/WebApplicationBuilderTests.cs b/test/Microsoft.AspNet.Hosting.Tests/WebApplicationBuilderTests.cs index 06f912ac17..a71b92bbae 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/WebApplicationBuilderTests.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/WebApplicationBuilderTests.cs @@ -36,8 +36,9 @@ namespace Microsoft.AspNet.Hosting var builder = CreateWebApplicationBuilder(); var server = new TestServer(); var application = builder.UseServer(server).UseStartup("MissingStartupAssembly").Build(); - using (application.Start()) + using (application) { + application.Start(); await AssertResponseContains(server.RequestDelegate, "MissingStartupAssembly"); } } @@ -48,8 +49,9 @@ namespace Microsoft.AspNet.Hosting var builder = CreateWebApplicationBuilder(); var server = new TestServer(); var application = builder.UseServer(server).UseStartup().Build(); - using (application.Start()) + using (application) { + application.Start(); await AssertResponseContains(server.RequestDelegate, "Exception from static constructor"); } } @@ -60,8 +62,9 @@ namespace Microsoft.AspNet.Hosting var builder = CreateWebApplicationBuilder(); var server = new TestServer(); var application = builder.UseServer(server).UseStartup().Build(); - using (application.Start()) + using (application) { + application.Start(); await AssertResponseContains(server.RequestDelegate, "Exception from constructor"); } } @@ -72,8 +75,9 @@ namespace Microsoft.AspNet.Hosting var builder = CreateWebApplicationBuilder(); var server = new TestServer(); var application = builder.UseServer(server).UseStartup().Build(); - using (application.Start()) + using (application) { + application.Start(); await AssertResponseContains(server.RequestDelegate, "Message from the LoaderException"); } } @@ -84,8 +88,9 @@ namespace Microsoft.AspNet.Hosting var builder = CreateWebApplicationBuilder(); var server = new TestServer(); var application = builder.UseServer(server).UseStartup().Build(); - using (application.Start()) + using (application) { + application.Start(); var service = application.Services.GetServices(); Assert.NotNull(service); await AssertResponseContains(server.RequestDelegate, "Exception from constructor"); @@ -98,8 +103,9 @@ namespace Microsoft.AspNet.Hosting var builder = CreateWebApplicationBuilder(); var server = new TestServer(); var application = builder.UseServer(server).UseStartup().Build(); - using (application.Start()) + using (application) { + application.Start(); await AssertResponseContains(server.RequestDelegate, "Exception from ConfigureServices"); } } @@ -110,8 +116,9 @@ namespace Microsoft.AspNet.Hosting var builder = CreateWebApplicationBuilder(); var server = new TestServer(); var application = builder.UseServer(server).UseStartup().Build(); - using (application.Start()) + using (application) { + application.Start(); await AssertResponseContains(server.RequestDelegate, "Exception from Configure"); } } @@ -138,6 +145,28 @@ namespace Microsoft.AspNet.Hosting Assert.Equal(expected, application.Services.GetService().EnvironmentName); } + [Fact] + public void BuildAndDispose() + { + var vals = new Dictionary + { + { "ENV", "Dev" }, + }; + var builder = new ConfigurationBuilder() + .AddInMemoryCollection(vals); + var config = builder.Build(); + + var expected = "MY_TEST_ENVIRONMENT"; + var application = new WebApplicationBuilder() + .UseConfiguration(config) + .UseEnvironment(expected) + .UseServer(new TestServer()) + .UseStartup("Microsoft.AspNet.Hosting.Tests") + .Build(); + + application.Dispose(); + } + [Fact] public void UseBasePathConfiguresBasePath() { @@ -159,7 +188,7 @@ namespace Microsoft.AspNet.Hosting Assert.Equal("/foo/bar", application.Services.GetService().ApplicationBasePath); } - private WebApplicationBuilder CreateWebApplicationBuilder() + private IWebApplicationBuilder CreateWebApplicationBuilder() { var vals = new Dictionary { diff --git a/test/Microsoft.AspNet.Hosting.Tests/WebApplicationConfigurationsTests.cs b/test/Microsoft.AspNet.Hosting.Tests/WebApplicationConfigurationsTests.cs index 3e935c68cd..cd7dbdd569 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/WebApplicationConfigurationsTests.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/WebApplicationConfigurationsTests.cs @@ -15,11 +15,11 @@ namespace Microsoft.AspNet.Hosting.Tests { var parameters = new Dictionary() { - {"webroot", "wwwroot"}, - {"server", "Microsoft.AspNet.Server.Kestrel"}, - {"app", "MyProjectReference"}, - {"environment", "Development"}, - {"detailederrors", "true"}, + { "webroot", "wwwroot"}, + { "server", "Microsoft.AspNet.Server.Kestrel"}, + { "application", "MyProjectReference"}, + { "environment", "Development"}, + { "detailederrors", "true"}, { "captureStartupErrors", "true" } }; diff --git a/test/Microsoft.AspNet.Hosting.Tests/WebApplicationTests.cs b/test/Microsoft.AspNet.Hosting.Tests/WebApplicationTests.cs index 9278d7ad17..d20f85b16e 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/WebApplicationTests.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/WebApplicationTests.cs @@ -119,7 +119,7 @@ namespace Microsoft.AspNet.Hosting .AddInMemoryCollection(vals); var config = builder.Build(); var application = CreateBuilder(config).Build(); - var app = application.Start(); + application.Start(); Assert.NotNull(application.Services.GetService()); Assert.Equal("http://localhost:abc123", application.ServerFeatures.Get().Addresses.First()); } @@ -136,9 +136,9 @@ namespace Microsoft.AspNet.Hosting .AddInMemoryCollection(vals); var config = builder.Build(); var application = CreateBuilder(config).Build(); - var app = application.Start(); + application.Start(); Assert.NotNull(application.Services.GetService()); - Assert.Equal("http://localhost:5000", application.GetAddresses().First()); + Assert.Equal("http://localhost:5000", application.ServerFeatures.Get().Addresses.First()); } [Fact] @@ -153,7 +153,7 @@ namespace Microsoft.AspNet.Hosting .AddInMemoryCollection(vals); var config = builder.Build(); var application = CreateBuilder(config).Build(); - var app = application.Start(); + application.Start(); var hostingEnvironment = application.Services.GetService(); Assert.NotNull(hostingEnvironment.Configuration); Assert.Equal("Microsoft.AspNet.Hosting.Tests", hostingEnvironment.Configuration["Server"]); @@ -163,9 +163,8 @@ namespace Microsoft.AspNet.Hosting public void WebApplicationCanBeStarted() { var app = CreateBuilder() - .UseServer(this) + .UseServer((IServerFactory)this) .UseStartup("Microsoft.AspNet.Hosting.Tests") - .Build() .Start(); Assert.NotNull(app); @@ -181,7 +180,7 @@ namespace Microsoft.AspNet.Hosting public void WebApplicationDisposesServiceProvider() { var application = CreateBuilder() - .UseServer(this) + .UseServer((IServerFactory)this) .ConfigureServices(s => { s.AddTransient(); @@ -190,7 +189,7 @@ namespace Microsoft.AspNet.Hosting .UseStartup("Microsoft.AspNet.Hosting.Tests") .Build(); - var app = application.Start(); + application.Start(); var singleton = (FakeService)application.Services.GetService(); var transient = (FakeService)application.Services.GetService(); @@ -198,7 +197,7 @@ namespace Microsoft.AspNet.Hosting Assert.False(singleton.Disposed); Assert.False(transient.Disposed); - app.Dispose(); + application.Dispose(); Assert.True(singleton.Disposed); Assert.True(transient.Disposed); @@ -208,13 +207,14 @@ namespace Microsoft.AspNet.Hosting public void WebApplicationNotifiesApplicationStarted() { var application = CreateBuilder() - .UseServer(this) + .UseServer((IServerFactory)this) .Build(); var applicationLifetime = application.Services.GetService(); Assert.False(applicationLifetime.ApplicationStarted.IsCancellationRequested); - using (application.Start()) + using (application) { + application.Start(); Assert.True(applicationLifetime.ApplicationStarted.IsCancellationRequested); } } @@ -223,13 +223,14 @@ namespace Microsoft.AspNet.Hosting public void WebApplicationInjectsHostingEnvironment() { var application = CreateBuilder() - .UseServer(this) + .UseServer((IServerFactory)this) .UseStartup("Microsoft.AspNet.Hosting.Tests") .UseEnvironment("WithHostingEnvironment") .Build(); - using (application.Start()) + using (application) { + application.Start(); var env = application.Services.GetService(); Assert.Equal("Changed", env.EnvironmentName); } @@ -243,7 +244,7 @@ namespace Microsoft.AspNet.Hosting { services.AddTransient(); }) - .UseServer(this) + .UseServer((IServerFactory)this) .UseStartup("Microsoft.AspNet.Hosting.Tests"); Assert.Throws(() => builder.Build()); @@ -252,14 +253,14 @@ namespace Microsoft.AspNet.Hosting [Fact] public void CanCreateApplicationServicesWithAddedServices() { - var application = CreateBuilder().UseServer(this).ConfigureServices(services => services.AddOptions()).Build(); + var application = CreateBuilder().UseServer((IServerFactory)this).ConfigureServices(services => services.AddOptions()).Build(); Assert.NotNull(application.Services.GetRequiredService>()); } [Fact] public void EnvDefaultsToProductionIfNoConfig() { - var application = CreateBuilder().UseServer(this).Build(); + var application = CreateBuilder().UseServer((IServerFactory)this).Build(); var env = application.Services.GetService(); Assert.Equal(EnvironmentName.Production, env.EnvironmentName); } @@ -278,7 +279,7 @@ namespace Microsoft.AspNet.Hosting .AddInMemoryCollection(vals); var config = builder.Build(); - var application = CreateBuilder(config).UseServer(this).Build(); + var application = CreateBuilder(config).UseServer((IServerFactory)this).Build(); var env = application.Services.GetService(); Assert.Equal("Staging", env.EnvironmentName); } @@ -295,7 +296,7 @@ namespace Microsoft.AspNet.Hosting .AddInMemoryCollection(vals); var config = builder.Build(); - var application = CreateBuilder(config).UseServer(this).Build(); + var application = CreateBuilder(config).UseServer((IServerFactory)this).Build(); var env = application.Services.GetService(); Assert.Equal("Staging", env.EnvironmentName); } @@ -312,7 +313,7 @@ namespace Microsoft.AspNet.Hosting .AddInMemoryCollection(vals); var config = builder.Build(); - var application = CreateBuilder(config).UseServer(this).Build(); + var application = CreateBuilder(config).UseServer((IServerFactory)this).Build(); var env = application.Services.GetService(); Assert.Equal(Path.GetFullPath("testroot"), env.WebRootPath); Assert.True(env.WebRootFileProvider.GetFileInfo("TextFile.txt").Exists); @@ -321,9 +322,10 @@ namespace Microsoft.AspNet.Hosting [Fact] public void IsEnvironment_Extension_Is_Case_Insensitive() { - var application = CreateBuilder().UseServer(this).Build(); - using (application.Start()) + var application = CreateBuilder().UseServer((IServerFactory)this).Build(); + using (application) { + application.Start(); var env = application.Services.GetRequiredService(); Assert.True(env.IsEnvironment(EnvironmentName.Production)); Assert.True(env.IsEnvironment("producTion")); @@ -364,7 +366,7 @@ namespace Microsoft.AspNet.Hosting var application = CreateApplication(requestDelegate); // Act - var disposable = application.Start(); + application.Start(); // Assert Assert.NotNull(httpContext); @@ -388,7 +390,7 @@ namespace Microsoft.AspNet.Hosting var application = CreateApplication(requestDelegate); // Act - var disposable = application.Start(); + application.Start(); // Assert Assert.NotNull(httpContext); @@ -399,11 +401,12 @@ namespace Microsoft.AspNet.Hosting public void WebApplication_InvokesConfigureMethodsOnlyOnce() { var application = CreateBuilder() - .UseServer(this) + .UseServer((IServerFactory)this) .UseStartup() .Build(); - using (application.Start()) + using (application) { + application.Start(); var services = application.Services; var services2 = application.Services; Assert.Equal(1, CountStartup.ConfigureCount); @@ -431,7 +434,7 @@ namespace Microsoft.AspNet.Hosting public void WebApplication_ThrowsForBadConfigureServiceSignature() { var builder = CreateBuilder() - .UseServer(this) + .UseServer((IServerFactory)this) .UseStartup(); var ex = Assert.Throws(() => builder.Build()); @@ -447,7 +450,7 @@ namespace Microsoft.AspNet.Hosting private IWebApplication CreateApplication(RequestDelegate requestDelegate) { var builder = CreateBuilder() - .UseServer(this) + .UseServer((IServerFactory)this) .Configure( appBuilder => { @@ -459,10 +462,11 @@ namespace Microsoft.AspNet.Hosting private void RunMapPath(string virtualPath, string expectedSuffix) { - var application = CreateBuilder().UseServer(this).Build(); + var application = CreateBuilder().UseServer((IServerFactory)this).Build(); - using (application.Start()) + using (application) { + application.Start(); var env = application.Services.GetRequiredService(); // MapPath requires webroot to be set, we don't care // about file provider so just set it here @@ -473,7 +477,7 @@ namespace Microsoft.AspNet.Hosting } } - private WebApplicationBuilder CreateBuilder(IConfiguration config = null) + private IWebApplicationBuilder CreateBuilder(IConfiguration config = null) { return new WebApplicationBuilder().UseConfiguration(config ?? new ConfigurationBuilder().Build()).UseStartup("Microsoft.AspNet.Hosting.Tests"); } From 294e16732f3ffdb8dd15041c6beb3cdafaf37ee6 Mon Sep 17 00:00:00 2001 From: David Fowler Date: Thu, 7 Jan 2016 07:49:29 -0800 Subject: [PATCH 484/987] Move default config to Hosting.Abstractions --- .../WebApplicationDefaults.cs | 20 +++++++++++++++++++ .../Internal/WebApplicationOptions.cs | 14 ++++++------- .../WebApplicationBuilderExtensions.cs | 12 +++++------ .../WebApplicationConfiguration.cs | 16 ++------------- 4 files changed, 35 insertions(+), 27 deletions(-) create mode 100644 src/Microsoft.AspNet.Hosting.Abstractions/WebApplicationDefaults.cs diff --git a/src/Microsoft.AspNet.Hosting.Abstractions/WebApplicationDefaults.cs b/src/Microsoft.AspNet.Hosting.Abstractions/WebApplicationDefaults.cs new file mode 100644 index 0000000000..3efa2561ad --- /dev/null +++ b/src/Microsoft.AspNet.Hosting.Abstractions/WebApplicationDefaults.cs @@ -0,0 +1,20 @@ +// 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. + +namespace Microsoft.AspNet.Hosting +{ + public static class WebApplicationDefaults + { + public static readonly string ApplicationKey = "application"; + public static readonly string DetailedErrorsKey = "detailedErrors"; + public static readonly string EnvironmentKey = "environment"; + public static readonly string ServerKey = "server"; + public static readonly string WebRootKey = "webroot"; + public static readonly string CaptureStartupErrorsKey = "captureStartupErrors"; + public static readonly string ServerUrlsKey = "server.urls"; + public static readonly string ApplicationBaseKey = "applicationBase"; + + public static readonly string HostingJsonFile = "hosting.json"; + public static readonly string EnvironmentVariablesPrefix = "ASPNET_"; + } +} diff --git a/src/Microsoft.AspNet.Hosting/Internal/WebApplicationOptions.cs b/src/Microsoft.AspNet.Hosting/Internal/WebApplicationOptions.cs index 1019c866ec..dd4ef59750 100644 --- a/src/Microsoft.AspNet.Hosting/Internal/WebApplicationOptions.cs +++ b/src/Microsoft.AspNet.Hosting/Internal/WebApplicationOptions.cs @@ -21,13 +21,13 @@ namespace Microsoft.AspNet.Hosting.Internal throw new ArgumentNullException(nameof(configuration)); } - Application = configuration[WebApplicationConfiguration.ApplicationKey]; - DetailedErrors = ParseBool(configuration, WebApplicationConfiguration.DetailedErrorsKey); - CaptureStartupErrors = ParseBool(configuration, WebApplicationConfiguration.CaptureStartupErrorsKey); - Environment = configuration[WebApplicationConfiguration.EnvironmentKey] ?? configuration[OldEnvironmentKey]; - ServerFactoryLocation = configuration[WebApplicationConfiguration.ServerKey]; - WebRoot = configuration[WebApplicationConfiguration.WebRootKey]; - ApplicationBasePath = configuration[WebApplicationConfiguration.ApplicationBaseKey]; + Application = configuration[WebApplicationDefaults.ApplicationKey]; + DetailedErrors = ParseBool(configuration, WebApplicationDefaults.DetailedErrorsKey); + CaptureStartupErrors = ParseBool(configuration, WebApplicationDefaults.CaptureStartupErrorsKey); + Environment = configuration[WebApplicationDefaults.EnvironmentKey] ?? configuration[OldEnvironmentKey]; + ServerFactoryLocation = configuration[WebApplicationDefaults.ServerKey]; + WebRoot = configuration[WebApplicationDefaults.WebRootKey]; + ApplicationBasePath = configuration[WebApplicationDefaults.ApplicationBaseKey]; } public string Application { get; set; } diff --git a/src/Microsoft.AspNet.Hosting/WebApplicationBuilderExtensions.cs b/src/Microsoft.AspNet.Hosting/WebApplicationBuilderExtensions.cs index e49ba7f4ed..555c087bd3 100644 --- a/src/Microsoft.AspNet.Hosting/WebApplicationBuilderExtensions.cs +++ b/src/Microsoft.AspNet.Hosting/WebApplicationBuilderExtensions.cs @@ -25,7 +25,7 @@ namespace Microsoft.AspNet.Hosting throw new ArgumentNullException(nameof(assemblyName)); } - return applicationBuilder.UseSetting(WebApplicationConfiguration.ServerKey, assemblyName); + return applicationBuilder.UseSetting(WebApplicationDefaults.ServerKey, assemblyName); } public static IWebApplicationBuilder UseServer(this IWebApplicationBuilder applicationBuilder, IServer server) @@ -45,7 +45,7 @@ namespace Microsoft.AspNet.Hosting throw new ArgumentNullException(nameof(applicationBasePath)); } - return applicationBuilder.UseSetting(WebApplicationConfiguration.ApplicationBaseKey, applicationBasePath); + return applicationBuilder.UseSetting(WebApplicationDefaults.ApplicationBaseKey, applicationBasePath); } public static IWebApplicationBuilder UseEnvironment(this IWebApplicationBuilder applicationBuilder, string environment) @@ -55,7 +55,7 @@ namespace Microsoft.AspNet.Hosting throw new ArgumentNullException(nameof(environment)); } - return applicationBuilder.UseSetting(WebApplicationConfiguration.EnvironmentKey, environment); + return applicationBuilder.UseSetting(WebApplicationDefaults.EnvironmentKey, environment); } public static IWebApplicationBuilder UseWebRoot(this IWebApplicationBuilder applicationBuilder, string webRoot) @@ -65,7 +65,7 @@ namespace Microsoft.AspNet.Hosting throw new ArgumentNullException(nameof(webRoot)); } - return applicationBuilder.UseSetting(WebApplicationConfiguration.WebRootKey, webRoot); + return applicationBuilder.UseSetting(WebApplicationDefaults.WebRootKey, webRoot); } public static IWebApplicationBuilder UseUrls(this IWebApplicationBuilder applicationBuilder, params string[] urls) @@ -75,7 +75,7 @@ namespace Microsoft.AspNet.Hosting throw new ArgumentNullException(nameof(urls)); } - return applicationBuilder.UseSetting(WebApplicationConfiguration.ServerUrlsKey, string.Join(ServerUrlsSeparator, urls)); + return applicationBuilder.UseSetting(WebApplicationDefaults.ServerUrlsKey, string.Join(ServerUrlsSeparator, urls)); } public static IWebApplicationBuilder UseStartup(this IWebApplicationBuilder applicationBuilder, string startupAssemblyName) @@ -85,7 +85,7 @@ namespace Microsoft.AspNet.Hosting throw new ArgumentNullException(nameof(startupAssemblyName)); } - return applicationBuilder.UseSetting(WebApplicationConfiguration.ApplicationKey, startupAssemblyName); + return applicationBuilder.UseSetting(WebApplicationDefaults.ApplicationKey, startupAssemblyName); } public static IWebApplication Start(this IWebApplicationBuilder applicationBuilder, params string[] urls) diff --git a/src/Microsoft.AspNet.Hosting/WebApplicationConfiguration.cs b/src/Microsoft.AspNet.Hosting/WebApplicationConfiguration.cs index 49eff15003..3bc3013858 100644 --- a/src/Microsoft.AspNet.Hosting/WebApplicationConfiguration.cs +++ b/src/Microsoft.AspNet.Hosting/WebApplicationConfiguration.cs @@ -4,18 +4,6 @@ namespace Microsoft.AspNet.Hosting { public class WebApplicationConfiguration { - public static readonly string ApplicationKey = "application"; - public static readonly string DetailedErrorsKey = "detailedErrors"; - public static readonly string EnvironmentKey = "environment"; - public static readonly string ServerKey = "server"; - public static readonly string WebRootKey = "webroot"; - public static readonly string CaptureStartupErrorsKey = "captureStartupErrors"; - public static readonly string ServerUrlsKey = "server.urls"; - public static readonly string ApplicationBaseKey = "applicationBase"; - - public static readonly string HostingJsonFile = "hosting.json"; - public static readonly string EnvironmentVariablesPrefix = "ASPNET_"; - public static IConfiguration GetDefault() { return GetDefault(args: null); @@ -26,9 +14,9 @@ namespace Microsoft.AspNet.Hosting // We are adding all environment variables first and then adding the ASPNET_ ones // with the prefix removed to unify with the command line and config file formats var configBuilder = new ConfigurationBuilder() - .AddJsonFile(HostingJsonFile, optional: true) + .AddJsonFile(WebApplicationDefaults.HostingJsonFile, optional: true) .AddEnvironmentVariables() - .AddEnvironmentVariables(prefix: EnvironmentVariablesPrefix); + .AddEnvironmentVariables(prefix: WebApplicationDefaults.EnvironmentVariablesPrefix); if (args != null) { From 2c7f0ff35d4ff1be7d4839410aefa7fac658b096 Mon Sep 17 00:00:00 2001 From: John Luo Date: Thu, 7 Jan 2016 15:19:41 -0800 Subject: [PATCH 485/987] Remove IncludedConfigurationProvider since it's been added to Configuration repo --- .../Internal/IncludedConfigurationProvider.cs | 39 ------------------- 1 file changed, 39 deletions(-) delete mode 100644 src/Microsoft.AspNet.Hosting/Internal/IncludedConfigurationProvider.cs diff --git a/src/Microsoft.AspNet.Hosting/Internal/IncludedConfigurationProvider.cs b/src/Microsoft.AspNet.Hosting/Internal/IncludedConfigurationProvider.cs deleted file mode 100644 index 5feb23e761..0000000000 --- a/src/Microsoft.AspNet.Hosting/Internal/IncludedConfigurationProvider.cs +++ /dev/null @@ -1,39 +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; -using Microsoft.Extensions.Configuration; - -namespace Microsoft.AspNet.Hosting.Internal -{ - // TODO: Remove this once https://github.com/aspnet/Configuration/pull/349 gets merged - internal class IncludedConfigurationProvider : ConfigurationProvider - { - public IncludedConfigurationProvider(IConfiguration source) - { - if (source == null) - { - throw new ArgumentNullException(nameof(source)); - } - int pathStart = 0; - var section = source as IConfigurationSection; - if (section != null) - { - pathStart = section.Path.Length + 1; - } - foreach (var child in source.GetChildren()) - { - AddSection(child, pathStart); - } - } - - private void AddSection(IConfigurationSection section, int pathStart) - { - Data.Add(section.Path.Substring(pathStart), section.Value); - foreach (var child in section.GetChildren()) - { - AddSection(child, pathStart); - } - } - } -} From 6ff83dddfee9d9b44d01b6645df5cf6b70a1caa6 Mon Sep 17 00:00:00 2001 From: Victor Hurdugaci Date: Thu, 7 Jan 2016 14:37:04 -0800 Subject: [PATCH 486/987] Build with dotnet --- .gitignore | 2 + .travis.yml | 8 ++- appveyor.yml | 2 +- build.cmd | 68 +++++++++---------- build.sh | 47 +++++++------ .../HostingEnvironmentExtensionsTests.cs | 2 +- .../WebApplicationTests.cs | 2 +- .../project.json | 44 +++++++----- .../project.json | 37 ++++++---- 9 files changed, 121 insertions(+), 91 deletions(-) diff --git a/.gitignore b/.gitignore index 58ebbb8fa3..718941ca08 100644 --- a/.gitignore +++ b/.gitignore @@ -26,3 +26,5 @@ nuget.exe *.sln.ide project.lock.json /.vs/ +.build/ +.testPublish/ \ No newline at end of file diff --git a/.travis.yml b/.travis.yml index 2fc624899f..bf811dc26a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -10,9 +10,11 @@ addons: - libssl-dev - libunwind8 - zlib1g -env: - - KOREBUILD_DNU_RESTORE_CORECLR=true mono: - 4.0.5 +os: + - linux + - osx +osx_image: xcode7.1 script: - - ./build.sh --quiet verify + - ./build.sh verify \ No newline at end of file diff --git a/appveyor.yml b/appveyor.yml index 636a7618d3..3fab83e134 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,7 +1,7 @@ init: - git config --global core.autocrlf true build_script: - - build.cmd --quiet verify + - build.cmd verify clone_depth: 1 test: off deploy: off \ No newline at end of file diff --git a/build.cmd b/build.cmd index 553e3929a0..ebb619e737 100644 --- a/build.cmd +++ b/build.cmd @@ -1,40 +1,40 @@ -@echo off -cd %~dp0 - +@ECHO off SETLOCAL + +SET REPO_FOLDER=%~dp0 +CD %REPO_FOLDER% + +SET BUILD_FOLDER=.build +SET KOREBUILD_FOLDER=%BUILD_FOLDER%\KoreBuild-dotnet +SET KOREBUILD_VERSION= + +SET NUGET_PATH=%BUILD_FOLDER%\NuGet.exe SET NUGET_VERSION=latest SET CACHED_NUGET=%LocalAppData%\NuGet\nuget.%NUGET_VERSION%.exe -SET BUILDCMD_KOREBUILD_VERSION= -SET BUILDCMD_DNX_VERSION= -IF EXIST %CACHED_NUGET% goto copynuget -echo Downloading latest version of NuGet.exe... -IF NOT EXIST %LocalAppData%\NuGet md %LocalAppData%\NuGet -@powershell -NoProfile -ExecutionPolicy unrestricted -Command "$ProgressPreference = 'SilentlyContinue'; Invoke-WebRequest 'https://dist.nuget.org/win-x86-commandline/%NUGET_VERSION%/nuget.exe' -OutFile '%CACHED_NUGET%'" - -:copynuget -IF EXIST .nuget\nuget.exe goto restore -md .nuget -copy %CACHED_NUGET% .nuget\nuget.exe > nul - -:restore -IF EXIST packages\Sake goto getdnx -IF "%BUILDCMD_KOREBUILD_VERSION%"=="" ( - .nuget\nuget.exe install KoreBuild -ExcludeVersion -o packages -nocache -pre -) ELSE ( - .nuget\nuget.exe install KoreBuild -version %BUILDCMD_KOREBUILD_VERSION% -ExcludeVersion -o packages -nocache -pre -) -.nuget\NuGet.exe install Sake -ExcludeVersion -Source https://www.nuget.org/api/v2/ -Out packages - -:getdnx -IF "%BUILDCMD_DNX_VERSION%"=="" ( - SET BUILDCMD_DNX_VERSION=latest -) -IF "%SKIP_DNX_INSTALL%"=="" ( - CALL packages\KoreBuild\build\dnvm install %BUILDCMD_DNX_VERSION% -runtime CoreCLR -arch x86 -alias default - CALL packages\KoreBuild\build\dnvm install default -runtime CLR -arch x86 -alias default -) ELSE ( - CALL packages\KoreBuild\build\dnvm use default -runtime CLR -arch x86 +IF NOT EXIST %BUILD_FOLDER% ( + md %BUILD_FOLDER% ) -packages\Sake\tools\Sake.exe -I packages\KoreBuild\build -f makefile.shade %* +IF NOT EXIST %NUGET_PATH% ( + IF NOT EXIST %CACHED_NUGET% ( + echo Downloading latest version of NuGet.exe... + IF NOT EXIST %LocalAppData%\NuGet ( + md %LocalAppData%\NuGet + ) + @powershell -NoProfile -ExecutionPolicy unrestricted -Command "$ProgressPreference = 'SilentlyContinue'; Invoke-WebRequest 'https://dist.nuget.org/win-x86-commandline/%NUGET_VERSION%/nuget.exe' -OutFile '%CACHED_NUGET%'" + ) + + copy %CACHED_NUGET% %NUGET_PATH% > nul +) + +IF NOT EXIST %KOREBUILD_FOLDER% ( + SET KOREBUILD_DOWNLOAD_ARGS= + IF NOT "%KOREBUILD_VERSION%"=="" ( + SET KOREBUILD_DOWNLOAD_ARGS=-version %KOREBUILD_VERSION% + ) + + %BUILD_FOLDER%\nuget.exe install KoreBuild-dotnet -ExcludeVersion -o %BUILD_FOLDER% -nocache -pre %KOREBUILD_DOWNLOAD_ARGS% +) + +"%KOREBUILD_FOLDER%\build\KoreBuild.cmd" %* diff --git a/build.sh b/build.sh index da4e3fcd1c..7b5e25e3a8 100755 --- a/build.sh +++ b/build.sh @@ -1,5 +1,18 @@ #!/usr/bin/env bash +SOURCE="${BASH_SOURCE[0]}" +while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink + DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )" + SOURCE="$(readlink "$SOURCE")" + [[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE" # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located +done +repoFolder="$( cd -P "$( dirname "$SOURCE" )" && pwd )" + +buildFolder=.build +koreBuildFolder=$buildFolder/KoreBuild-dotnet + +nugetPath=$buildFolder/nuget.exe + if test `uname` = Darwin; then cachedir=~/Library/Caches/KBuild else @@ -11,33 +24,25 @@ else fi mkdir -p $cachedir nugetVersion=latest -cachePath=$cachedir/nuget.$nugetVersion.exe +cacheNuget=$cachedir/nuget.$nugetVersion.exe -url=https://dist.nuget.org/win-x86-commandline/$nugetVersion/nuget.exe +nugetUrl=https://dist.nuget.org/win-x86-commandline/$nugetVersion/nuget.exe -if test ! -f $cachePath; then - wget -O $cachePath $url 2>/dev/null || curl -o $cachePath --location $url /dev/null +if test ! -d $buildFolder; then + mkdir $buildFolder fi -if test ! -e .nuget; then - mkdir .nuget - cp $cachePath .nuget/nuget.exe +if test ! -f $nugetPath; then + if test ! -f $cacheNuget; then + wget -O $cacheNuget $nugetUrl 2>/dev/null || curl -o $cacheNuget --location $nugetUrl /dev/null + fi + + cp $cacheNuget $nugetPath fi -if test ! -d packages/Sake; then - mono .nuget/nuget.exe install KoreBuild -ExcludeVersion -o packages -nocache -pre - mono .nuget/nuget.exe install Sake -ExcludeVersion -Source https://www.nuget.org/api/v2/ -Out packages +if test ! -d $koreBuildFolder; then + mono $nugetPath install KoreBuild-dotnet -ExcludeVersion -o $buildFolder -nocache -pre fi -if ! type dnvm > /dev/null 2>&1; then - source packages/KoreBuild/build/dnvm.sh -fi +source $koreBuildFolder/build/KoreBuild.sh -if ! type dnx > /dev/null 2>&1 || [ -z "$SKIP_DNX_INSTALL" ]; then - dnvm install latest -runtime coreclr -alias default - dnvm install default -runtime mono -alias default -else - dnvm use default -runtime mono -fi - -mono packages/Sake/tools/Sake.exe -I packages/KoreBuild/build -f makefile.shade "$@" diff --git a/test/Microsoft.AspNet.Hosting.Tests/HostingEnvironmentExtensionsTests.cs b/test/Microsoft.AspNet.Hosting.Tests/HostingEnvironmentExtensionsTests.cs index be2072bf9a..dd60adc4b5 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/HostingEnvironmentExtensionsTests.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/HostingEnvironmentExtensionsTests.cs @@ -23,7 +23,7 @@ namespace Microsoft.AspNet.Hosting.Tests Assert.IsAssignableFrom(env.WebRootFileProvider); } - [Fact] + [Fact(Skip = "Missing content publish property")] public void DefaultsToWwwrootSubdir() { var env = new HostingEnvironment(); diff --git a/test/Microsoft.AspNet.Hosting.Tests/WebApplicationTests.cs b/test/Microsoft.AspNet.Hosting.Tests/WebApplicationTests.cs index d20f85b16e..fcbb01736a 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/WebApplicationTests.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/WebApplicationTests.cs @@ -301,7 +301,7 @@ namespace Microsoft.AspNet.Hosting Assert.Equal("Staging", env.EnvironmentName); } - [Fact] + [Fact(Skip = "Missing content publish property")] public void WebRootCanBeResolvedFromTheConfig() { var vals = new Dictionary diff --git a/test/Microsoft.AspNet.Hosting.Tests/project.json b/test/Microsoft.AspNet.Hosting.Tests/project.json index 1a974b1eea..99ea348770 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/project.json +++ b/test/Microsoft.AspNet.Hosting.Tests/project.json @@ -1,21 +1,33 @@ { - "compilationOptions": { - "warningsAsErrors": true, - "keyFile": "../../tools/Key.snk" + "compilationOptions": { + "warningsAsErrors": true, + "keyFile": "../../tools/Key.snk" + }, + "content": [ + "testroot/**/*" + ], + "dependencies": { + "Microsoft.AspNet.Hosting": "1.0.0-*", + "Microsoft.AspNet.Owin": "1.0.0-*", + "Microsoft.AspNet.Testing": "1.0.0-*", + "Microsoft.Extensions.Options": "1.0.0-*", + "Microsoft.Extensions.PlatformAbstractions": "1.0.0-*", + "xunit": "2.1.0" + }, + "frameworks": { + "dnx451": { + "dependencies": { + "xunit.runner.console": "2.1.0" + } }, - "dependencies": { - "Microsoft.AspNet.Hosting": "1.0.0-*", - "Microsoft.AspNet.Owin": "1.0.0-*", - "Microsoft.AspNet.Testing": "1.0.0-*", - "Microsoft.Extensions.Options": "1.0.0-*", - "Microsoft.Extensions.PlatformAbstractions": "1.0.0-*", + "dnxcore50": { + "dependencies": { "xunit.runner.aspnet": "2.0.0-aspnet-*" - }, - "frameworks": { - "dnx451": { }, - "dnxcore50": { } - }, - "commands": { - "test": "xunit.runner.aspnet" + } } + }, + "testRunner": "xunit", + "commands": { + "test": "xunit.runner.aspnet" + } } diff --git a/test/Microsoft.AspNet.TestHost.Tests/project.json b/test/Microsoft.AspNet.TestHost.Tests/project.json index 661f7c8602..58a862cb86 100644 --- a/test/Microsoft.AspNet.TestHost.Tests/project.json +++ b/test/Microsoft.AspNet.TestHost.Tests/project.json @@ -1,19 +1,28 @@ { - "compilationOptions": { - "warningsAsErrors": true, - "keyFile": "../../tools/Key.snk" + "compilationOptions": { + "warningsAsErrors": true, + "keyFile": "../../tools/Key.snk" + }, + "dependencies": { + "Microsoft.AspNet.Testing": "1.0.0-*", + "Microsoft.AspNet.TestHost": "1.0.0-*", + "Microsoft.Extensions.DiagnosticAdapter": "1.0.0-*", + "xunit": "2.1.0" + }, + "frameworks": { + "dnx451": { + "dependencies": { + "xunit.runner.console": "2.1.0" + } }, - "dependencies": { - "Microsoft.AspNet.Testing": "1.0.0-*", - "Microsoft.AspNet.TestHost": "1.0.0-*", - "Microsoft.Extensions.DiagnosticAdapter": "1.0.0-*", + "dnxcore50": { + "dependencies": { "xunit.runner.aspnet": "2.0.0-aspnet-*" - }, - "commands": { - "test": "xunit.runner.aspnet" - }, - "frameworks": { - "dnx451": { }, - "dnxcore50": { } + } } + }, + "testRunner": "xunit", + "commands": { + "test": "xunit.runner.aspnet" + } } From 48451bdabcf0fcabd24cc4863b5d5b0c89637273 Mon Sep 17 00:00:00 2001 From: John Luo Date: Mon, 11 Jan 2016 13:28:48 -0800 Subject: [PATCH 487/987] Making application available from TestServer #519 --- src/Microsoft.AspNet.TestHost/TestServer.cs | 8 ++++++++ .../TestServerTests.cs | 15 +++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/src/Microsoft.AspNet.TestHost/TestServer.cs b/src/Microsoft.AspNet.TestHost/TestServer.cs index 38da4fd213..6d6d4ef4c9 100644 --- a/src/Microsoft.AspNet.TestHost/TestServer.cs +++ b/src/Microsoft.AspNet.TestHost/TestServer.cs @@ -29,6 +29,14 @@ namespace Microsoft.AspNet.TestHost public Uri BaseAddress { get; set; } = new Uri("http://localhost/"); + public IWebApplication Application + { + get + { + return _appInstance; + } + } + IFeatureCollection IServer.Features { get; } public HttpMessageHandler CreateHandler() diff --git a/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs b/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs index 92fdc85fb8..02a56de542 100644 --- a/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs +++ b/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs @@ -31,6 +31,21 @@ namespace Microsoft.AspNet.TestHost new TestServer(new WebApplicationBuilder().Configure(app => { })); } + [Fact] + public void ApplicationServicesAvailableFromTestServer() + { + var testService = new TestService(); + var builder = new WebApplicationBuilder() + .Configure(app => { }) + .ConfigureServices(services => + { + services.AddSingleton(testService); + }); + var server = new TestServer(builder); + + Assert.Equal(testService, server.Application.Services.GetRequiredService()); + } + [ConditionalFact] [FrameworkSkipCondition(RuntimeFrameworks.Mono, SkipReason = "Hangs randomly (issue #507)")] public async Task RequestServicesAutoCreated() From ccde3309789a49bd2fb2b09c38ab90630a1f70c3 Mon Sep 17 00:00:00 2001 From: Troy Dai Date: Mon, 11 Jan 2016 00:58:40 -0800 Subject: [PATCH 488/987] Update IISDeployer and its base class --- .../Common/DeploymentParameters.cs | 8 +- .../Deployers/ApplicationDeployer.cs | 183 +++++++----------- .../Deployers/ApplicationDeployerFactory.cs | 4 +- .../Deployers/IISDeployer.cs | 132 ++++++------- .../Deployers/IISExpressDeployer.cs | 2 +- .../Deployers/SelfHostDeployer.cs | 6 +- 6 files changed, 135 insertions(+), 200 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Testing/Common/DeploymentParameters.cs b/src/Microsoft.AspNet.Server.Testing/Common/DeploymentParameters.cs index f4b64df53f..83dfa962e0 100644 --- a/src/Microsoft.AspNet.Server.Testing/Common/DeploymentParameters.cs +++ b/src/Microsoft.AspNet.Server.Testing/Common/DeploymentParameters.cs @@ -42,11 +42,11 @@ namespace Microsoft.AspNet.Server.Testing EnvironmentVariables.Add(new KeyValuePair("ASPNET_DETAILEDERRORS", "true")); } - public ServerType ServerType { get; private set; } + public ServerType ServerType { get; } - public RuntimeFlavor RuntimeFlavor { get; private set; } + public RuntimeFlavor RuntimeFlavor { get; } - public RuntimeArchitecture RuntimeArchitecture { get; private set; } + public RuntimeArchitecture RuntimeArchitecture { get; } /// /// Suggested base url for the deployed application. The final deployed url could be @@ -77,8 +77,6 @@ namespace Microsoft.AspNet.Server.Testing /// public bool PublishWithNoSource { get; set; } - public string DnxRuntime { get; set; } - /// /// Environment variables to be set before starting the host. /// Not applicable for IIS Scenarios. diff --git a/src/Microsoft.AspNet.Server.Testing/Deployers/ApplicationDeployer.cs b/src/Microsoft.AspNet.Server.Testing/Deployers/ApplicationDeployer.cs index f2a07b24fd..8901e08f0d 100644 --- a/src/Microsoft.AspNet.Server.Testing/Deployers/ApplicationDeployer.cs +++ b/src/Microsoft.AspNet.Server.Testing/Deployers/ApplicationDeployer.cs @@ -5,8 +5,6 @@ using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; -using System.Text; -using System.Text.RegularExpressions; using System.Threading; using Microsoft.AspNet.Testing; using Microsoft.Extensions.Logging; @@ -19,128 +17,78 @@ namespace Microsoft.AspNet.Server.Testing /// public abstract class ApplicationDeployer : IApplicationDeployer { - /// - /// Example: runtimes/dnx-coreclr-win-x64.1.0.0-rc1-15844/bin - /// - protected string ChosenRuntimePath { get; set; } + private readonly Stopwatch _stopwatch = new Stopwatch(); - /// - /// Examples: dnx-coreclr-win-x64.1.0.0-rc1-15844, dnx-mono.1.0.0-rc1-15844 - /// - protected string ChosenRuntimeName { get; set; } - - protected DeploymentParameters DeploymentParameters { get; private set; } - - protected ILogger Logger { get; private set; } - - protected Stopwatch StopWatch { get; private set; } = new Stopwatch(); - - protected string OSPrefix - { - get - { - if (PlatformServices.Default.Runtime.OperatingSystemPlatform == Platform.Linux) - { - return "linux"; - } - else if (PlatformServices.Default.Runtime.OperatingSystemPlatform == Platform.Darwin) - { - return "darwin"; - } - else if (PlatformServices.Default.Runtime.OperatingSystemPlatform == Platform.Windows) - { - return "win"; - } - else - { - throw new InvalidOperationException("Unrecognized operating system"); - } - } - } - - protected string DnuCommandName - { - get - { - if (TestPlatformHelper.IsWindows) - { - return "dnu.cmd"; - } - else - { - return "dnu"; - } - } - } - - protected string DnxCommandName - { - get - { - if (TestPlatformHelper.IsWindows) - { - return "dnx.exe"; - } - else - { - return "dnx"; - } - } - } - - public abstract DeploymentResult Deploy(); - - public ApplicationDeployer( - DeploymentParameters deploymentParameters, - ILogger logger) + public ApplicationDeployer(DeploymentParameters deploymentParameters, ILogger logger) { DeploymentParameters = deploymentParameters; Logger = logger; + DnuCommandName = TestPlatformHelper.IsWindows ? "dnu.cmd" : "dnu"; + DnxCommandName = TestPlatformHelper.IsWindows ? "dnx.exe" : "dnx"; } - protected string PopulateChosenRuntimeInformation() + protected DeploymentParameters DeploymentParameters { get; } + + protected ILogger Logger { get; } + + protected string DnuCommandName { get; } + + protected string DnxCommandName { get; } + + protected string TargetRuntimeName { get; private set; } + + protected string TargetRuntimeBinPath { get; private set; } + + protected string ToolingRuntimeBinPath { get; private set; } + + public abstract DeploymentResult Deploy(); + + protected void PickRuntime() { - string currentRuntimeBinPath = PlatformServices.Default.Runtime.RuntimePath; + var currentRuntimeBinPath = PlatformServices.Default.Runtime.RuntimePath; Logger.LogInformation($"Current runtime path is : {currentRuntimeBinPath}"); - string targetRuntimeName; + var currentRuntimeFullName = new DirectoryInfo(currentRuntimeBinPath).Parent.Name; + var currentRuntimeVersionParts = currentRuntimeFullName.Split(new char[] { '.' }, 2); + if (currentRuntimeVersionParts.Length < 2) + { + throw new ArgumentNullException($"The current runtime bin path points to a runtime name doesn't indicate a version: {currentRuntimeBinPath}."); + } + var currentRuntimeVersion = currentRuntimeVersionParts[1]; + + var runtimeHome = new DirectoryInfo(currentRuntimeBinPath).Parent.Parent.FullName; + Logger.LogInformation($"Runtime home folder: {runtimeHome}"); + if (DeploymentParameters.RuntimeFlavor == RuntimeFlavor.Mono) { - targetRuntimeName = "dnx-mono"; + // TODO: review on mono + TargetRuntimeName = $"dnx-mono.{currentRuntimeVersion}"; + TargetRuntimeBinPath = Path.Combine(runtimeHome, TargetRuntimeName, "bin"); + ToolingRuntimeBinPath = TargetRuntimeBinPath; } else { - targetRuntimeName = new StringBuilder() - .Append("dnx") - .Append((DeploymentParameters.RuntimeFlavor == RuntimeFlavor.CoreClr) ? "-coreclr" : "-clr") - .Append($"-{OSPrefix}") - .Append((DeploymentParameters.RuntimeArchitecture == RuntimeArchitecture.x86) ? "-x86" : "-x64") - .ToString(); + var flavor = DeploymentParameters.RuntimeFlavor == RuntimeFlavor.CoreClr ? "coreclr" : "clr"; + var architecture = DeploymentParameters.RuntimeArchitecture == RuntimeArchitecture.x86 ? "x86" : "x64"; + + // tooling runtime will stick to coreclr so as to prevent long path issue during publishing + ToolingRuntimeBinPath = Path.Combine(runtimeHome, $"dnx-coreclr-{GetOSPrefix()}-{architecture}.{currentRuntimeVersion}", "bin"); + + TargetRuntimeName = $"dnx-{flavor}-{GetOSPrefix()}-{architecture}.{currentRuntimeVersion}"; + TargetRuntimeBinPath = Path.Combine(runtimeHome, TargetRuntimeName, "bin"); } - var targetRuntimeBinPath = Regex.Replace( - currentRuntimeBinPath, - "dnx-(mono|((clr|coreclr)-(win|linux|darwin)-(x86|x64)))", - targetRuntimeName, - RegexOptions.IgnoreCase); - - var targetRuntimeBinDir = new DirectoryInfo(targetRuntimeBinPath); - if (targetRuntimeBinDir == null || !targetRuntimeBinDir.Exists) + if (!Directory.Exists(ToolingRuntimeBinPath) || !Directory.Exists(TargetRuntimeBinPath)) { - throw new Exception($"Requested runtime at location '{targetRuntimeBinPath}' does not exist.Please make sure it is installed before running test."); + throw new Exception($"Requested runtime '{ToolingRuntimeBinPath}' or '{TargetRuntimeBinPath}; does not exist. Please make sure it is installed before running test."); } - ChosenRuntimePath = targetRuntimeBinDir.FullName; - ChosenRuntimeName = targetRuntimeBinDir.Parent.Name; - DeploymentParameters.DnxRuntime = ChosenRuntimeName; - - Logger.LogInformation($"Chosen runtime path is {ChosenRuntimePath}"); + Logger.LogInformation($"Pick target runtime {TargetRuntimeBinPath}"); + Logger.LogInformation($"Pick tooling runtime {ToolingRuntimeBinPath}"); // Work around win7 search path issues. - var newPath = ChosenRuntimePath + Path.PathSeparator + Environment.GetEnvironmentVariable("PATH"); + var newPath = TargetRuntimeBinPath + Path.PathSeparator + Environment.GetEnvironmentVariable("PATH"); DeploymentParameters.EnvironmentVariables.Add(new KeyValuePair("PATH", newPath)); - - return ChosenRuntimeName; } protected void DnuPublish(string publishRoot = null) @@ -150,9 +98,9 @@ namespace Microsoft.AspNet.Server.Testing var noSource = DeploymentParameters.PublishWithNoSource ? "--no-source" : string.Empty; var command = DeploymentParameters.Command ?? "web"; var parameters = $"publish {DeploymentParameters.ApplicationPath} -o {DeploymentParameters.PublishedApplicationRootPath}" - + $" --runtime {DeploymentParameters.DnxRuntime} {noSource} --iis-command {command}"; + + $" --runtime {TargetRuntimeName} {noSource} --iis-command {command}"; - var dnuPath = Path.Combine(ChosenRuntimePath, DnuCommandName); + var dnuPath = Path.Combine(ToolingRuntimeBinPath, DnuCommandName); Logger.LogInformation($"Executing command {dnuPath} {parameters}"); var startInfo = new ProcessStartInfo @@ -166,8 +114,8 @@ namespace Microsoft.AspNet.Server.Testing }; var hostProcess = new Process() { StartInfo = startInfo }; - hostProcess.ErrorDataReceived += (sender, dataArgs) => { Logger.LogError(dataArgs.Data ?? string.Empty); }; - hostProcess.OutputDataReceived += (sender, dataArgs) => { Logger.LogInformation(dataArgs.Data ?? string.Empty); }; + hostProcess.ErrorDataReceived += (sender, dataArgs) => { Logger.LogWarning(dataArgs.Data ?? string.Empty); }; + hostProcess.OutputDataReceived += (sender, dataArgs) => { Logger.LogTrace(dataArgs.Data ?? string.Empty); }; hostProcess.Start(); hostProcess.BeginErrorReadLine(); hostProcess.BeginOutputReadLine(); @@ -180,10 +128,9 @@ namespace Microsoft.AspNet.Server.Testing DeploymentParameters.ApplicationPath = (DeploymentParameters.ServerType == ServerType.IISExpress || - DeploymentParameters.ServerType == ServerType.IIS) ? + DeploymentParameters.ServerType == ServerType.IIS) ? Path.Combine(DeploymentParameters.PublishedApplicationRootPath, "wwwroot") : - Path.Combine(DeploymentParameters.PublishedApplicationRootPath, "approot", "src", - new DirectoryInfo(DeploymentParameters.ApplicationPath).Name); + Path.Combine(DeploymentParameters.PublishedApplicationRootPath, "approot", "src", new DirectoryInfo(DeploymentParameters.ApplicationPath).Name); Logger.LogInformation($"dnu publish finished with exit code : {hostProcess.ExitCode}"); } @@ -299,15 +246,27 @@ namespace Microsoft.AspNet.Server.Testing protected void StartTimer() { Logger.LogInformation($"Deploying {DeploymentParameters.ToString()}"); - StopWatch.Start(); + _stopwatch.Start(); } protected void StopTimer() { - StopWatch.Stop(); - Logger.LogInformation("[Time]: Total time taken for this test variation '{t}' seconds", StopWatch.Elapsed.TotalSeconds); + _stopwatch.Stop(); + Logger.LogInformation("[Time]: Total time taken for this test variation '{t}' seconds", _stopwatch.Elapsed.TotalSeconds); } public abstract void Dispose(); + + protected static string GetOSPrefix() + { + switch (PlatformServices.Default.Runtime.OperatingSystemPlatform) + { + case Platform.Linux: return "linux"; + case Platform.Darwin: return "darwin"; + case Platform.Windows: return "win"; + default: + throw new InvalidOperationException("Unrecognized operating system"); + } + } } } \ No newline at end of file diff --git a/src/Microsoft.AspNet.Server.Testing/Deployers/ApplicationDeployerFactory.cs b/src/Microsoft.AspNet.Server.Testing/Deployers/ApplicationDeployerFactory.cs index 4e4ae9d1e0..0b5776b8b4 100644 --- a/src/Microsoft.AspNet.Server.Testing/Deployers/ApplicationDeployerFactory.cs +++ b/src/Microsoft.AspNet.Server.Testing/Deployers/ApplicationDeployerFactory.cs @@ -33,7 +33,7 @@ namespace Microsoft.AspNet.Server.Testing { case ServerType.IISExpress: return new IISExpressDeployer(deploymentParameters, logger); -#if NET451 +#if DNX451 case ServerType.IIS: return new IISDeployer(deploymentParameters, logger); #endif @@ -48,4 +48,4 @@ namespace Microsoft.AspNet.Server.Testing } } } -} \ No newline at end of file +} diff --git a/src/Microsoft.AspNet.Server.Testing/Deployers/IISDeployer.cs b/src/Microsoft.AspNet.Server.Testing/Deployers/IISDeployer.cs index 5403dbc1df..3ba827af7c 100644 --- a/src/Microsoft.AspNet.Server.Testing/Deployers/IISDeployer.cs +++ b/src/Microsoft.AspNet.Server.Testing/Deployers/IISDeployer.cs @@ -1,12 +1,13 @@ // 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. -#if NET451 +#if DNX451 + using System; -using System.IO; using System.Linq; +using System.Net; +using System.Net.Sockets; using System.Threading; -using System.Xml; using Microsoft.Extensions.Logging; using Microsoft.Web.Administration; @@ -36,10 +37,10 @@ namespace Microsoft.AspNet.Server.Testing _application = new IISApplication(DeploymentParameters, Logger); - DeploymentParameters.DnxRuntime = PopulateChosenRuntimeInformation(); + PickRuntime(); // Publish to IIS root\application folder. - DnuPublish(publishRoot: _application.WebSiteRootFolder); + DnuPublish(); // Drop a json file instead of setting environment variable. SetAspEnvironmentWithJson(); @@ -59,19 +60,11 @@ namespace Microsoft.AspNet.Server.Testing WebRootLocation = DeploymentParameters.ApplicationPath, DeploymentParameters = DeploymentParameters, // Accomodate the vdir name. - ApplicationBaseUri = new UriBuilder(Uri.UriSchemeHttp, "localhost", IISApplication.Port, _application.VirtualDirectoryName).Uri.AbsoluteUri + "/", + ApplicationBaseUri = new UriBuilder(Uri.UriSchemeHttp, "localhost", _application.Port).Uri.AbsoluteUri + "/", HostShutdownToken = _hostShutdownToken.Token }; } - private void SetAspEnvironmentWithJson() - { - // Drop a hosting.json with Hosting:Environment information. - Logger.LogInformation("Creating hosting.json file with Hosting:Environment."); - var jsonFile = Path.Combine(DeploymentParameters.ApplicationPath, "hosting.json"); - File.WriteAllText(jsonFile, string.Format("{ \"Hosting:Environment\":\"{0}\" }", DeploymentParameters.EnvironmentName)); - } - public override void Dispose() { if (_application != null) @@ -83,6 +76,8 @@ namespace Microsoft.AspNet.Server.Testing } TriggerHostShutdown(_hostShutdownToken); + + Thread.Sleep(TimeSpan.FromSeconds(3)); } CleanPublishedOutput(); @@ -91,94 +86,79 @@ namespace Microsoft.AspNet.Server.Testing StopTimer(); } + private void SetAspEnvironmentWithJson() + { + ////S Drop a hosting.json with Hosting:Environment information. + // Logger.LogInformation("Creating hosting.json file with Hosting:Environment."); + // var jsonFile = Path.Combine(DeploymentParameters.ApplicationPath, "hosting.json"); + // File.WriteAllText(jsonFile, string.Format("{ \"Hosting:Environment\":\"{0}\" }", DeploymentParameters.EnvironmentName)); + } + private class IISApplication { - private const string WebSiteName = "ASPNETTESTRUNS"; - private readonly ServerManager _serverManager = new ServerManager(); private readonly DeploymentParameters _deploymentParameters; private readonly ILogger _logger; - private ApplicationPool _applicationPool; - private Application _application; - private Site _website; - - public string VirtualDirectoryName { get; set; } - - // Always create website with the same port. - public const int Port = 5100; - - public string WebSiteRootFolder - { - get - { - return Path.Combine( - Environment.GetEnvironmentVariable("SystemDrive") + @"\", - "inetpub", - WebSiteName); - } - } public IISApplication(DeploymentParameters deploymentParameters, ILogger logger) { _deploymentParameters = deploymentParameters; _logger = logger; + + WebSiteName = CreateTestSiteName(); + Port = FindFreePort(); } + public int Port { get; } + + public string WebSiteName { get; } + + public string WebSiteRootFolder => $"{Environment.GetEnvironmentVariable("SystemDrive")}\\inetpub\\{WebSiteName}"; + public void Deploy() { - VirtualDirectoryName = new DirectoryInfo(_deploymentParameters.ApplicationPath).Parent.Name; - _applicationPool = CreateAppPool(VirtualDirectoryName); - _application = Website.Applications.Add("/" + VirtualDirectoryName, _deploymentParameters.ApplicationPath); - _application.ApplicationPoolName = _applicationPool.Name; + _serverManager.Sites.Add(WebSiteName, _deploymentParameters.ApplicationPath, Port); _serverManager.CommitChanges(); } - private Site Website - { - get - { - _website = _serverManager.Sites.Where(s => s.Name == WebSiteName).FirstOrDefault(); - if (_website == null) - { - _website = _serverManager.Sites.Add(WebSiteName, WebSiteRootFolder, Port); - } - - return _website; - } - } - - private ApplicationPool CreateAppPool(string appPoolName) - { - var applicationPool = _serverManager.ApplicationPools.Add(appPoolName); - applicationPool.ManagedRuntimeVersion = string.Empty; - - applicationPool.Enable32BitAppOnWin64 = (_deploymentParameters.RuntimeArchitecture == RuntimeArchitecture.x86); - _logger.LogInformation("Created {bit} application pool '{name}' with runtime version {runtime}.", - _deploymentParameters.RuntimeArchitecture, applicationPool.Name, - string.IsNullOrEmpty(applicationPool.ManagedRuntimeVersion) ? "that is default" : applicationPool.ManagedRuntimeVersion); - return applicationPool; - } - public void StopAndDeleteAppPool() { - _logger.LogInformation("Stopping application pool '{name}' and deleting application.", _applicationPool.Name); - - if (_applicationPool != null) + if (string.IsNullOrEmpty(WebSiteName)) { - _applicationPool.Stop(); + return; } - // Remove the application from website. - if (_application != null) + var siteToRemove = _serverManager.Sites.FirstOrDefault(site => site.Name == WebSiteName); + if (siteToRemove != null) { - _application = Website.Applications.Where(a => a.Path == _application.Path).FirstOrDefault(); - Website.Applications.Remove(_application); - _serverManager.ApplicationPools.Remove(_serverManager.ApplicationPools[_applicationPool.Name]); + siteToRemove.Stop(); + _serverManager.Sites.Remove(siteToRemove); _serverManager.CommitChanges(); - _logger.LogInformation("Successfully stopped application pool '{name}' and deleted application from IIS.", _applicationPool.Name); + } + } + + private static int FindFreePort() + { + using (var socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)) + { + socket.Bind(new IPEndPoint(IPAddress.Loopback, 0)); + return ((IPEndPoint)socket.LocalEndPoint).Port; + } + } + + private string CreateTestSiteName() + { + if (!string.IsNullOrEmpty(_deploymentParameters.SiteName)) + { + return $"{_deploymentParameters.SiteName}{DateTime.Now.ToString("yyyyMMddHHmmss")}"; + } + else + { + return $"testsite{DateTime.Now.ToString("yyyyMMddHHmmss")}"; } } } } } -#endif \ No newline at end of file + +#endif diff --git a/src/Microsoft.AspNet.Server.Testing/Deployers/IISExpressDeployer.cs b/src/Microsoft.AspNet.Server.Testing/Deployers/IISExpressDeployer.cs index c60bf11b37..d3911ac925 100644 --- a/src/Microsoft.AspNet.Server.Testing/Deployers/IISExpressDeployer.cs +++ b/src/Microsoft.AspNet.Server.Testing/Deployers/IISExpressDeployer.cs @@ -26,7 +26,7 @@ namespace Microsoft.AspNet.Server.Testing // Start timer StartTimer(); - DeploymentParameters.DnxRuntime = PopulateChosenRuntimeInformation(); + PickRuntime(); // For now we always auto-publish. Otherwise we'll have to write our own local web.config for the HttpPlatformHandler DeploymentParameters.PublishApplicationBeforeDeployment = true; diff --git a/src/Microsoft.AspNet.Server.Testing/Deployers/SelfHostDeployer.cs b/src/Microsoft.AspNet.Server.Testing/Deployers/SelfHostDeployer.cs index e1fdc509b0..c018f0dac7 100644 --- a/src/Microsoft.AspNet.Server.Testing/Deployers/SelfHostDeployer.cs +++ b/src/Microsoft.AspNet.Server.Testing/Deployers/SelfHostDeployer.cs @@ -2,11 +2,9 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Threading; -using Microsoft.AspNet.Testing; using Microsoft.Extensions.Logging; namespace Microsoft.AspNet.Server.Testing @@ -28,7 +26,7 @@ namespace Microsoft.AspNet.Server.Testing // Start timer StartTimer(); - DeploymentParameters.DnxRuntime = PopulateChosenRuntimeInformation(); + PickRuntime(); if (DeploymentParameters.PublishApplicationBeforeDeployment) { @@ -55,7 +53,7 @@ namespace Microsoft.AspNet.Server.Testing commandName = "run"; } - var dnxPath = Path.Combine(ChosenRuntimePath, DnxCommandName); + var dnxPath = Path.Combine(TargetRuntimeBinPath, DnxCommandName); var dnxArgs = $"-p \"{DeploymentParameters.ApplicationPath}\" {commandName} " + $"--server.urls {DeploymentParameters.ApplicationBaseUriHint} " + $"--server {(DeploymentParameters.ServerType == ServerType.WebListener ? "Microsoft.AspNet.Server.WebListener" : "Microsoft.AspNet.Server.Kestrel")}"; From 1b05fb442ecb6ea0ba48beff035e78bd151fe9e2 Mon Sep 17 00:00:00 2001 From: John Luo Date: Mon, 11 Jan 2016 20:50:34 -0800 Subject: [PATCH 489/987] Add extension to configure capture startup errors setting which defaults to true #552 --- .../WebApplicationBuilderExtensions.cs | 5 ++++ .../WebApplicationConfiguration.cs | 12 +++++++++- .../WebApplicationBuilderTests.cs | 23 +++++++++++++++++++ .../WebApplicationConfigurationsTests.cs | 8 +++++++ 4 files changed, 47 insertions(+), 1 deletion(-) diff --git a/src/Microsoft.AspNet.Hosting/WebApplicationBuilderExtensions.cs b/src/Microsoft.AspNet.Hosting/WebApplicationBuilderExtensions.cs index 555c087bd3..e4fd487507 100644 --- a/src/Microsoft.AspNet.Hosting/WebApplicationBuilderExtensions.cs +++ b/src/Microsoft.AspNet.Hosting/WebApplicationBuilderExtensions.cs @@ -13,6 +13,11 @@ namespace Microsoft.AspNet.Hosting { private static readonly string ServerUrlsSeparator = ";"; + public static IWebApplicationBuilder UseCaptureStartupErrors(this IWebApplicationBuilder applicationBuilder, bool captureStartupError) + { + return applicationBuilder.UseSetting(WebApplicationDefaults.CaptureStartupErrorsKey, captureStartupError ? "true" : "false"); + } + public static IWebApplicationBuilder UseStartup(this IWebApplicationBuilder applicationBuilder) where TStartup : class { return applicationBuilder.UseStartup(typeof(TStartup)); diff --git a/src/Microsoft.AspNet.Hosting/WebApplicationConfiguration.cs b/src/Microsoft.AspNet.Hosting/WebApplicationConfiguration.cs index 3bc3013858..e08549b8c8 100644 --- a/src/Microsoft.AspNet.Hosting/WebApplicationConfiguration.cs +++ b/src/Microsoft.AspNet.Hosting/WebApplicationConfiguration.cs @@ -1,4 +1,8 @@ -using Microsoft.Extensions.Configuration; +// 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.Collections.Generic; +using Microsoft.Extensions.Configuration; namespace Microsoft.AspNet.Hosting { @@ -11,9 +15,15 @@ namespace Microsoft.AspNet.Hosting public static IConfiguration GetDefault(string[] args) { + var defaultSettings = new Dictionary + { + { WebApplicationDefaults.CaptureStartupErrorsKey, "true" } + }; + // We are adding all environment variables first and then adding the ASPNET_ ones // with the prefix removed to unify with the command line and config file formats var configBuilder = new ConfigurationBuilder() + .AddInMemoryCollection(defaultSettings) .AddJsonFile(WebApplicationDefaults.HostingJsonFile, optional: true) .AddEnvironmentVariables() .AddEnvironmentVariables(prefix: WebApplicationDefaults.EnvironmentVariablesPrefix); diff --git a/test/Microsoft.AspNet.Hosting.Tests/WebApplicationBuilderTests.cs b/test/Microsoft.AspNet.Hosting.Tests/WebApplicationBuilderTests.cs index a71b92bbae..d316a3b460 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/WebApplicationBuilderTests.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/WebApplicationBuilderTests.cs @@ -123,6 +123,29 @@ namespace Microsoft.AspNet.Hosting } } + [Fact] + public void CaptureStartupErrorsByDefault() + { + var applicationBuilder = new WebApplicationBuilder() + .UseServer(new TestServer()) + .UseStartup(); + + // This should not throw + applicationBuilder.Build(); + } + + [Fact] + public void UseCaptureStartupErrorsHonored() + { + var applicationBuilder = new WebApplicationBuilder() + .UseCaptureStartupErrors(false) + .UseServer(new TestServer()) + .UseStartup(); + + var exception = Assert.Throws(() => applicationBuilder.Build()); + Assert.Equal("A public method named 'ConfigureProduction' or 'Configure' could not be found in the 'Microsoft.AspNet.Hosting.Fakes.StartupBoom' type.", exception.Message); + } + [Fact] public void UseEnvironmentIsNotOverriden() { diff --git a/test/Microsoft.AspNet.Hosting.Tests/WebApplicationConfigurationsTests.cs b/test/Microsoft.AspNet.Hosting.Tests/WebApplicationConfigurationsTests.cs index cd7dbdd569..8c27409f1c 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/WebApplicationConfigurationsTests.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/WebApplicationConfigurationsTests.cs @@ -10,6 +10,14 @@ namespace Microsoft.AspNet.Hosting.Tests { public class WebApplicationConfigurationTests { + [Fact] + public void DefaultCapturesStartupErrors() + { + var config = new WebApplicationOptions(WebApplicationConfiguration.GetDefault()); + + Assert.True(config.CaptureStartupErrors); + } + [Fact] public void ReadsParametersCorrectly() { From eb617eb9a9c75cfa80b01292107fc57700237474 Mon Sep 17 00:00:00 2001 From: Troy Dai Date: Tue, 12 Jan 2016 11:34:14 -0800 Subject: [PATCH 490/987] Publish to inetpub --- src/Microsoft.AspNet.Server.Testing/Deployers/IISDeployer.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Microsoft.AspNet.Server.Testing/Deployers/IISDeployer.cs b/src/Microsoft.AspNet.Server.Testing/Deployers/IISDeployer.cs index 3ba827af7c..7edbea1491 100644 --- a/src/Microsoft.AspNet.Server.Testing/Deployers/IISDeployer.cs +++ b/src/Microsoft.AspNet.Server.Testing/Deployers/IISDeployer.cs @@ -40,7 +40,7 @@ namespace Microsoft.AspNet.Server.Testing PickRuntime(); // Publish to IIS root\application folder. - DnuPublish(); + DnuPublish(publishRoot: _application.WebSiteRootFolder); // Drop a json file instead of setting environment variable. SetAspEnvironmentWithJson(); From 317c9d0e80994a9aeaa1decafc62fa1e4f91b60e Mon Sep 17 00:00:00 2001 From: Chris R Date: Tue, 12 Jan 2016 11:42:36 -0800 Subject: [PATCH 491/987] Remove HttpPlatformHandler port detection. --- .../Internal/WebApplication.cs | 16 ++-------------- .../WebApplicationTests.cs | 18 ------------------ 2 files changed, 2 insertions(+), 32 deletions(-) diff --git a/src/Microsoft.AspNet.Hosting/Internal/WebApplication.cs b/src/Microsoft.AspNet.Hosting/Internal/WebApplication.cs index 170a7f26cd..74e95c4bc5 100644 --- a/src/Microsoft.AspNet.Hosting/Internal/WebApplication.cs +++ b/src/Microsoft.AspNet.Hosting/Internal/WebApplication.cs @@ -21,9 +21,6 @@ namespace Microsoft.AspNet.Hosting.Internal { public class WebApplication : IWebApplication { - // This is defined by IIS's HttpPlatformHandler. - private static readonly string ServerPort = "HTTP_PLATFORM_PORT"; - private readonly IServiceCollection _applicationServiceCollection; private readonly IStartupLoader _startupLoader; private readonly ApplicationLifetime _applicationLifetime; @@ -223,19 +220,10 @@ namespace Microsoft.AspNet.Hosting.Internal Server = ServerFactory.CreateServer(_config); var addresses = Server.Features?.Get()?.Addresses; - if (addresses != null && !addresses.IsReadOnly) + if (addresses != null && !addresses.IsReadOnly && addresses.Count == 0) { - var port = _config[ServerPort]; - if (!string.IsNullOrEmpty(port)) - { - addresses.Add("http://localhost:" + port); - } - // Provide a default address if there aren't any configured. - if (addresses.Count == 0) - { - addresses.Add("http://localhost:5000"); - } + addresses.Add("http://localhost:5000"); } } } diff --git a/test/Microsoft.AspNet.Hosting.Tests/WebApplicationTests.cs b/test/Microsoft.AspNet.Hosting.Tests/WebApplicationTests.cs index fcbb01736a..a83818a9cf 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/WebApplicationTests.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/WebApplicationTests.cs @@ -106,24 +106,6 @@ namespace Microsoft.AspNet.Hosting Assert.NotNull(application.Services.GetService()); } - [Fact] - public void CanSpecifyPortConfig() - { - var vals = new Dictionary - { - { "Server", "Microsoft.AspNet.Hosting.Tests" }, - { "HTTP_PLATFORM_PORT", "abc123" } - }; - - var builder = new ConfigurationBuilder() - .AddInMemoryCollection(vals); - var config = builder.Build(); - var application = CreateBuilder(config).Build(); - application.Start(); - Assert.NotNull(application.Services.GetService()); - Assert.Equal("http://localhost:abc123", application.ServerFeatures.Get().Addresses.First()); - } - [Fact] public void CanDefaultAddresseIfNotConfigured() { From d422201e016f2836b8e226683e541c1d8270351c Mon Sep 17 00:00:00 2001 From: John Luo Date: Tue, 12 Jan 2016 00:47:18 -0800 Subject: [PATCH 492/987] Elaborating error message when no startup is specified --- src/Microsoft.AspNet.Hosting/Startup/StartupLoader.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Microsoft.AspNet.Hosting/Startup/StartupLoader.cs b/src/Microsoft.AspNet.Hosting/Startup/StartupLoader.cs index 1898dd818a..c77cbced34 100644 --- a/src/Microsoft.AspNet.Hosting/Startup/StartupLoader.cs +++ b/src/Microsoft.AspNet.Hosting/Startup/StartupLoader.cs @@ -43,7 +43,10 @@ namespace Microsoft.AspNet.Hosting.Startup var environmentName = _hostingEnv.EnvironmentName; if (string.IsNullOrEmpty(startupAssemblyName)) { - throw new ArgumentException("Value cannot be null or empty.", nameof(startupAssemblyName)); + throw new ArgumentException( + string.Format("A startup method, startup type or startup assembly is required. If specifying an assembly, '{0}' cannot be null or empty.", + nameof(startupAssemblyName)), + nameof(startupAssemblyName)); } var assembly = Assembly.Load(new AssemblyName(startupAssemblyName)); From fa72fdeaedd9629a64a74124a82632fcc425f22a Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Fri, 1 Jan 2016 20:14:01 +0000 Subject: [PATCH 493/987] Higher accuracy in timings --- .../Internal/HostingApplication.cs | 31 ++++++++++++------- .../Internal/HostingLoggerExtensions.cs | 14 ++++----- 2 files changed, 27 insertions(+), 18 deletions(-) diff --git a/src/Microsoft.AspNet.Hosting/Internal/HostingApplication.cs b/src/Microsoft.AspNet.Hosting/Internal/HostingApplication.cs index 5ed245354a..7b77757e7f 100644 --- a/src/Microsoft.AspNet.Hosting/Internal/HostingApplication.cs +++ b/src/Microsoft.AspNet.Hosting/Internal/HostingApplication.cs @@ -33,41 +33,50 @@ namespace Microsoft.AspNet.Hosting.Internal public Context CreateContext(IFeatureCollection contextFeatures) { var httpContext = _httpContextFactory.Create(contextFeatures); - var startTick = Environment.TickCount; + var diagnoticsEnabled = _diagnosticSource.IsEnabled("Microsoft.AspNet.Hosting.BeginRequest"); + var startTimestamp = (diagnoticsEnabled || _logger.IsEnabled(LogLevel.Information)) ? Stopwatch.GetTimestamp() : 0; var scope = _logger.RequestScope(httpContext); _logger.RequestStarting(httpContext); - if (_diagnosticSource.IsEnabled("Microsoft.AspNet.Hosting.BeginRequest")) + if (diagnoticsEnabled) { - _diagnosticSource.Write("Microsoft.AspNet.Hosting.BeginRequest", new { httpContext = httpContext, tickCount = startTick }); + _diagnosticSource.Write("Microsoft.AspNet.Hosting.BeginRequest", new { httpContext = httpContext, timestamp = startTimestamp }); } return new Context { HttpContext = httpContext, Scope = scope, - StartTick = startTick, + StartTimestamp = startTimestamp, }; } public void DisposeContext(Context context, Exception exception) { var httpContext = context.HttpContext; - var currentTick = Environment.TickCount; - _logger.RequestFinished(httpContext, context.StartTick, currentTick); if (exception == null) { - if (_diagnosticSource.IsEnabled("Microsoft.AspNet.Hosting.EndRequest")) + var diagnoticsEnabled = _diagnosticSource.IsEnabled("Microsoft.AspNet.Hosting.EndRequest"); + var currentTimestamp = (diagnoticsEnabled || context.StartTimestamp != 0) ? Stopwatch.GetTimestamp() : 0; + + _logger.RequestFinished(httpContext, context.StartTimestamp, currentTimestamp); + + if (diagnoticsEnabled) { - _diagnosticSource.Write("Microsoft.AspNet.Hosting.EndRequest", new { httpContext = httpContext, tickCount = currentTick }); + _diagnosticSource.Write("Microsoft.AspNet.Hosting.EndRequest", new { httpContext = httpContext, timestamp = currentTimestamp }); } } else { - if (_diagnosticSource.IsEnabled("Microsoft.AspNet.Hosting.UnhandledException")) + var diagnoticsEnabled = _diagnosticSource.IsEnabled("Microsoft.AspNet.Hosting.UnhandledException"); + var currentTimestamp = (diagnoticsEnabled || context.StartTimestamp != 0) ? Stopwatch.GetTimestamp() : 0; + + _logger.RequestFinished(httpContext, context.StartTimestamp, currentTimestamp); + + if (diagnoticsEnabled) { - _diagnosticSource.Write("Microsoft.AspNet.Hosting.UnhandledException", new { httpContext = httpContext, tickCount = currentTick, exception = exception }); + _diagnosticSource.Write("Microsoft.AspNet.Hosting.UnhandledException", new { httpContext = httpContext, timestamp = currentTimestamp, exception = exception }); } } @@ -85,7 +94,7 @@ namespace Microsoft.AspNet.Hosting.Internal { public HttpContext HttpContext { get; set; } public IDisposable Scope { get; set; } - public int StartTick { get; set; } + public long StartTimestamp { get; set; } } } } diff --git a/src/Microsoft.AspNet.Hosting/Internal/HostingLoggerExtensions.cs b/src/Microsoft.AspNet.Hosting/Internal/HostingLoggerExtensions.cs index 4f149d5b44..0fdf122848 100644 --- a/src/Microsoft.AspNet.Hosting/Internal/HostingLoggerExtensions.cs +++ b/src/Microsoft.AspNet.Hosting/Internal/HostingLoggerExtensions.cs @@ -2,6 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.Diagnostics; using System.Collections.Generic; using Microsoft.AspNet.Http; using Microsoft.Extensions.Logging; @@ -10,8 +11,8 @@ namespace Microsoft.AspNet.Hosting.Internal { internal static class HostingLoggerExtensions { - private const long TicksPerMillisecond = 10000; - + private static readonly double TimestampToTicks = TimeSpan.TicksPerSecond / (double)Stopwatch.Frequency; + public static IDisposable RequestScope(this ILogger logger, HttpContext httpContext) { return logger.BeginScopeImpl(new HostingLogScope(httpContext)); @@ -30,13 +31,12 @@ namespace Microsoft.AspNet.Hosting.Internal } } - public static void RequestFinished(this ILogger logger, HttpContext httpContext, int startTimeInTicks, int currentTick) + public static void RequestFinished(this ILogger logger, HttpContext httpContext, long startTimestamp, long currentTimestamp) { - if (logger.IsEnabled(LogLevel.Information)) + // Don't log if Information logging wasn't enabled at start or end of request as time will be wildly wrong. + if (startTimestamp != 0) { - var elapsed = new TimeSpan(TicksPerMillisecond * (currentTick < startTimeInTicks ? - (int.MaxValue - startTimeInTicks) + (currentTick - int.MinValue) : - currentTick - startTimeInTicks)); + var elapsed = new TimeSpan((long)(TimestampToTicks * (currentTimestamp - startTimestamp))); logger.Log( logLevel: LogLevel.Information, From f7be1fb80e485c96102cd134fd64d4f063814c16 Mon Sep 17 00:00:00 2001 From: John Luo Date: Mon, 11 Jan 2016 16:57:59 -0800 Subject: [PATCH 494/987] Fixing logger nullref when context created with no feature #532 --- .../ClientHandler.cs | 9 ++-- .../WebSocketClient.cs | 7 +-- .../ClientHandlerTests.cs | 48 +++++++++++++++++++ .../TestClientTests.cs | 44 ++++++++++++----- .../TestServerTests.cs | 1 - 5 files changed, 90 insertions(+), 19 deletions(-) diff --git a/src/Microsoft.AspNet.TestHost/ClientHandler.cs b/src/Microsoft.AspNet.TestHost/ClientHandler.cs index 0dac9f0546..9f3a9f0fbb 100644 --- a/src/Microsoft.AspNet.TestHost/ClientHandler.cs +++ b/src/Microsoft.AspNet.TestHost/ClientHandler.cs @@ -124,12 +124,13 @@ namespace Microsoft.AspNet.TestHost request.Headers.Host = request.RequestUri.GetComponents(UriComponents.HostAndPort, UriFormat.UriEscaped); } - Context = application.CreateContext(new FeatureCollection()); + var contextFeatures = new FeatureCollection(); + contextFeatures.Set(new RequestFeature()); + _responseFeature = new ResponseFeature(); + contextFeatures.Set(_responseFeature); + Context = application.CreateContext(contextFeatures); var httpContext = Context.HttpContext; - httpContext.Features.Set(new RequestFeature()); - _responseFeature = new ResponseFeature(); - httpContext.Features.Set(_responseFeature); var serverRequest = httpContext.Request; serverRequest.Protocol = "HTTP/" + request.Version.ToString(2); serverRequest.Scheme = request.RequestUri.Scheme; diff --git a/src/Microsoft.AspNet.TestHost/WebSocketClient.cs b/src/Microsoft.AspNet.TestHost/WebSocketClient.cs index 8c9da7e11b..b26a1a4223 100644 --- a/src/Microsoft.AspNet.TestHost/WebSocketClient.cs +++ b/src/Microsoft.AspNet.TestHost/WebSocketClient.cs @@ -98,11 +98,13 @@ namespace Microsoft.AspNet.TestHost _application = application; // HttpContext - Context = _application.CreateContext(new FeatureCollection()); + var contextFeatures = new FeatureCollection(); + contextFeatures.Set(new RequestFeature()); + contextFeatures.Set(new ResponseFeature()); + Context = _application.CreateContext(contextFeatures); var httpContext = Context.HttpContext; // Request - httpContext.Features.Set(new RequestFeature()); var request = httpContext.Request; request.Protocol = "HTTP/1.1"; var scheme = uri.Scheme; @@ -130,7 +132,6 @@ namespace Microsoft.AspNet.TestHost request.Body = Stream.Null; // Response - httpContext.Features.Set(new ResponseFeature()); var response = httpContext.Response; response.Body = Stream.Null; response.StatusCode = 200; diff --git a/test/Microsoft.AspNet.TestHost.Tests/ClientHandlerTests.cs b/test/Microsoft.AspNet.TestHost.Tests/ClientHandlerTests.cs index 820f98d1fb..b439df01bd 100644 --- a/test/Microsoft.AspNet.TestHost.Tests/ClientHandlerTests.cs +++ b/test/Microsoft.AspNet.TestHost.Tests/ClientHandlerTests.cs @@ -5,13 +5,19 @@ using System; using System.IO; using System.Linq; using System.Net.Http; +using System.Text; using System.Threading; using System.Threading.Tasks; +using Microsoft.AspNet.Builder; +using Microsoft.AspNet.Hosting; +using Microsoft.AspNet.Hosting.Internal; using Microsoft.AspNet.Hosting.Server; using Microsoft.AspNet.Http; using Microsoft.AspNet.Http.Internal; using Microsoft.AspNet.Http.Features; using Microsoft.AspNet.Testing.xunit; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; using Xunit; using Context = Microsoft.AspNet.Hosting.Internal.HostingApplication.Context; @@ -269,5 +275,47 @@ namespace Microsoft.AspNet.TestHost return _application(context.HttpContext); } } + + + [ConditionalFact] + [FrameworkSkipCondition(RuntimeFrameworks.Mono, SkipReason = "Hangs randomly (issue #507)")] + public async Task ClientHandlerCreateContextWithDefaultRequestParameters() + { + // This logger will attempt to access information from HttpRequest once the HttpContext is created + var logger = new VerifierLogger(); + var builder = new WebApplicationBuilder() + .ConfigureServices(services => + { + services.AddSingleton>(logger); + }) + .Configure(app => + { + app.Run(context => + { + return Task.FromResult(0); + }); + }); + var server = new TestServer(builder); + + // The HttpContext will be created and the logger will make sure that the HttpRequest exists and contains reasonable values + var result = await server.CreateClient().GetStringAsync("/"); + } + + private class VerifierLogger : ILogger + { + public IDisposable BeginScopeImpl(object state) => new NoopDispoasble(); + + public bool IsEnabled(LogLevel logLevel) => true; + + // This call verifies that fields of HttpRequest are accessed and valid + public void Log(LogLevel logLevel, int eventId, object state, Exception exception, Func formatter) => formatter(state, exception); + + class NoopDispoasble : IDisposable + { + public void Dispose() + { + } + } + } } } diff --git a/test/Microsoft.AspNet.TestHost.Tests/TestClientTests.cs b/test/Microsoft.AspNet.TestHost.Tests/TestClientTests.cs index a453aaa564..42a1a7752f 100644 --- a/test/Microsoft.AspNet.TestHost.Tests/TestClientTests.cs +++ b/test/Microsoft.AspNet.TestHost.Tests/TestClientTests.cs @@ -11,21 +11,17 @@ using System.Threading; using System.Threading.Tasks; using Microsoft.AspNet.Builder; using Microsoft.AspNet.Hosting; +using Microsoft.AspNet.Hosting.Internal; using Microsoft.AspNet.Http; using Microsoft.AspNet.Testing.xunit; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; using Xunit; namespace Microsoft.AspNet.TestHost { public class TestClientTests { - private readonly TestServer _server; - - public TestClientTests() - { - _server = new TestServer(new WebApplicationBuilder().Configure(app => app.Run(ctx => Task.FromResult(0)))); - } - [ConditionalFact] [FrameworkSkipCondition(RuntimeFrameworks.Mono, SkipReason = "Hangs randomly (issue #507)")] public async Task GetAsyncWorks() @@ -134,6 +130,8 @@ namespace Microsoft.AspNet.TestHost public async Task WebSocketWorks() { // Arrange + // This logger will attempt to access information from HttpRequest once the HttpContext is createds + var logger = new VerifierLogger(); RequestDelegate appDelegate = async ctx => { if (ctx.WebSockets.IsWebSocketRequest) @@ -156,14 +154,20 @@ namespace Microsoft.AspNet.TestHost } } }; - var builder = new WebApplicationBuilder().Configure(app => - { - app.Run(appDelegate); - }); + var builder = new WebApplicationBuilder() + .ConfigureServices(services => + { + services.AddSingleton>(logger); + }) + .Configure(app => + { + app.Run(appDelegate); + }); var server = new TestServer(builder); // Act var client = server.CreateWebSocketClient(); + // The HttpContext will be created and the logger will make sure that the HttpRequest exists and contains reasonable values var clientSocket = await client.ConnectAsync(new System.Uri("http://localhost"), CancellationToken.None); var hello = Encoding.UTF8.GetBytes("hello"); await clientSocket.SendAsync(new System.ArraySegment(hello), WebSocketMessageType.Text, true, CancellationToken.None); @@ -192,6 +196,24 @@ namespace Microsoft.AspNet.TestHost clientSocket.Dispose(); } + + private class VerifierLogger : ILogger + { + public IDisposable BeginScopeImpl(object state) => new NoopDispoasble(); + + public bool IsEnabled(LogLevel logLevel) => true; + + // This call verifies that fields of HttpRequest are accessed and valid + public void Log(LogLevel logLevel, int eventId, object state, Exception exception, Func formatter) => formatter(state, exception); + + class NoopDispoasble : IDisposable + { + public void Dispose() + { + } + } + } + [ConditionalFact] [FrameworkSkipCondition(RuntimeFrameworks.Mono, SkipReason = "Hangs randomly (issue #507)")] public async Task WebSocketDisposalThrowsOnPeer() diff --git a/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs b/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs index 02a56de542..8d55816777 100644 --- a/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs +++ b/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs @@ -10,7 +10,6 @@ using System.Threading.Tasks; using Microsoft.AspNet.Builder; using Microsoft.AspNet.Hosting; using Microsoft.AspNet.Http; -using Microsoft.AspNet.Http.Features; using Microsoft.AspNet.Http.Features.Internal; using Microsoft.AspNet.Http.Internal; using Microsoft.AspNet.Testing.xunit; From c747ce630d03388714137b918c490e16198a9323 Mon Sep 17 00:00:00 2001 From: John Luo Date: Wed, 13 Jan 2016 10:59:29 -0800 Subject: [PATCH 495/987] TestServer should not capture startup errors by default --- .../IWebApplicationBuilder.cs | 3 ++ .../WebApplicationBuilder.cs | 11 ++++++-- src/Microsoft.AspNet.TestHost/TestServer.cs | 5 ++++ .../TestServerTests.cs | 28 +++++++++++++++++++ 4 files changed, 45 insertions(+), 2 deletions(-) diff --git a/src/Microsoft.AspNet.Hosting.Abstractions/IWebApplicationBuilder.cs b/src/Microsoft.AspNet.Hosting.Abstractions/IWebApplicationBuilder.cs index e92288a572..d4953e3af4 100644 --- a/src/Microsoft.AspNet.Hosting.Abstractions/IWebApplicationBuilder.cs +++ b/src/Microsoft.AspNet.Hosting.Abstractions/IWebApplicationBuilder.cs @@ -2,6 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.Collections.Generic; using Microsoft.AspNet.Builder; using Microsoft.AspNet.Hosting.Server; using Microsoft.Extensions.Configuration; @@ -13,6 +14,8 @@ namespace Microsoft.AspNet.Hosting { IWebApplication Build(); + IDictionary Settings { get; } + IWebApplicationBuilder UseConfiguration(IConfiguration configuration); IWebApplicationBuilder UseServer(IServerFactory factory); diff --git a/src/Microsoft.AspNet.Hosting/WebApplicationBuilder.cs b/src/Microsoft.AspNet.Hosting/WebApplicationBuilder.cs index 236b5c8392..4ec45e9c61 100644 --- a/src/Microsoft.AspNet.Hosting/WebApplicationBuilder.cs +++ b/src/Microsoft.AspNet.Hosting/WebApplicationBuilder.cs @@ -17,7 +17,6 @@ using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection.Extensions; using Microsoft.Extensions.Logging; using Microsoft.Extensions.PlatformAbstractions; -using Microsoft.Extensions.Primitives; namespace Microsoft.AspNet.Hosting { @@ -38,7 +37,7 @@ namespace Microsoft.AspNet.Hosting // Only one of these should be set private IServerFactory _serverFactory; - private Dictionary _settings = new Dictionary(StringComparer.OrdinalIgnoreCase); + private IDictionary _settings = new Dictionary(StringComparer.OrdinalIgnoreCase); public WebApplicationBuilder() { @@ -46,6 +45,14 @@ namespace Microsoft.AspNet.Hosting _loggerFactory = new LoggerFactory(); } + public IDictionary Settings + { + get + { + return _settings; + } + } + public IWebApplicationBuilder UseSetting(string key, string value) { _settings[key] = value; diff --git a/src/Microsoft.AspNet.TestHost/TestServer.cs b/src/Microsoft.AspNet.TestHost/TestServer.cs index 6d6d4ef4c9..57a1cefd7c 100644 --- a/src/Microsoft.AspNet.TestHost/TestServer.cs +++ b/src/Microsoft.AspNet.TestHost/TestServer.cs @@ -22,6 +22,11 @@ namespace Microsoft.AspNet.TestHost public TestServer(IWebApplicationBuilder builder) { + if (!builder.Settings.ContainsKey(WebApplicationDefaults.CaptureStartupErrorsKey)) + { + builder.UseCaptureStartupErrors(false); + } + var application = builder.UseServer(this).Build(); application.Start(); _appInstance = application; diff --git a/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs b/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs index 8d55816777..2919f940ba 100644 --- a/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs +++ b/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs @@ -30,6 +30,34 @@ namespace Microsoft.AspNet.TestHost new TestServer(new WebApplicationBuilder().Configure(app => { })); } + + [Fact] + public void DoesNotCaptureStartupErrorsByDefault() + { + var builder = new WebApplicationBuilder() + .Configure(app => + { + throw new InvalidOperationException(); + }); + + Assert.Throws(() => new TestServer(builder)); + } + + + [Fact] + public void CaptureStartupErrorsSettingPreserved() + { + var builder = new WebApplicationBuilder() + .UseCaptureStartupErrors(true) + .Configure(app => + { + throw new InvalidOperationException(); + }); + + // Does not throw + new TestServer(builder); + } + [Fact] public void ApplicationServicesAvailableFromTestServer() { From 3c79b425f1eafea3c177797ae1ed1354c6ee904e Mon Sep 17 00:00:00 2001 From: Pavel Krymets Date: Wed, 13 Jan 2016 13:48:38 -0800 Subject: [PATCH 496/987] Use dynamic ports for all deployers --- .../Common/FreePortHelper.cs | 38 +++++++++++++++++++ .../Deployers/ApplicationDeployer.cs | 2 +- .../Deployers/IISDeployer.cs | 29 +++++--------- .../Deployers/IISExpressDeployer.cs | 12 +++--- .../Deployers/SelfHostDeployer.cs | 10 +++-- 5 files changed, 61 insertions(+), 30 deletions(-) create mode 100644 src/Microsoft.AspNet.Server.Testing/Common/FreePortHelper.cs diff --git a/src/Microsoft.AspNet.Server.Testing/Common/FreePortHelper.cs b/src/Microsoft.AspNet.Server.Testing/Common/FreePortHelper.cs new file mode 100644 index 0000000000..f21ae3d001 --- /dev/null +++ b/src/Microsoft.AspNet.Server.Testing/Common/FreePortHelper.cs @@ -0,0 +1,38 @@ +// 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; +using System.Net; +using System.Net.Sockets; + +namespace Microsoft.AspNet.Server.Testing.Common +{ + public static class FreePortHelper + { + public static Uri FindFreeUrl(string urlHint) + { + var uriHint = new Uri(urlHint); + var builder = new UriBuilder(uriHint) + { + Port = FindFreePort(uriHint.Port) + }; + return builder.Uri; + } + + public static int FindFreePort(int initialPort) + { + using (var socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)) + { + try + { + socket.Bind(new IPEndPoint(IPAddress.Loopback, initialPort)); + } + catch (SocketException) + { + socket.Bind(new IPEndPoint(IPAddress.Loopback, 0)); + } + return ((IPEndPoint)socket.LocalEndPoint).Port; + } + } + } +} diff --git a/src/Microsoft.AspNet.Server.Testing/Deployers/ApplicationDeployer.cs b/src/Microsoft.AspNet.Server.Testing/Deployers/ApplicationDeployer.cs index 8901e08f0d..868f3a6e60 100644 --- a/src/Microsoft.AspNet.Server.Testing/Deployers/ApplicationDeployer.cs +++ b/src/Microsoft.AspNet.Server.Testing/Deployers/ApplicationDeployer.cs @@ -93,7 +93,7 @@ namespace Microsoft.AspNet.Server.Testing protected void DnuPublish(string publishRoot = null) { - DeploymentParameters.PublishedApplicationRootPath = Path.Combine(publishRoot ?? Path.GetTempPath(), Guid.NewGuid().ToString()); + DeploymentParameters.PublishedApplicationRootPath = publishRoot ?? Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString()); var noSource = DeploymentParameters.PublishWithNoSource ? "--no-source" : string.Empty; var command = DeploymentParameters.Command ?? "web"; diff --git a/src/Microsoft.AspNet.Server.Testing/Deployers/IISDeployer.cs b/src/Microsoft.AspNet.Server.Testing/Deployers/IISDeployer.cs index 7edbea1491..f292252842 100644 --- a/src/Microsoft.AspNet.Server.Testing/Deployers/IISDeployer.cs +++ b/src/Microsoft.AspNet.Server.Testing/Deployers/IISDeployer.cs @@ -8,6 +8,7 @@ using System.Linq; using System.Net; using System.Net.Sockets; using System.Threading; +using Microsoft.AspNet.Server.Testing.Common; using Microsoft.Extensions.Logging; using Microsoft.Web.Administration; @@ -45,10 +46,12 @@ namespace Microsoft.AspNet.Server.Testing // Drop a json file instead of setting environment variable. SetAspEnvironmentWithJson(); + var uri = FreePortHelper.FindFreeUrl(DeploymentParameters.ApplicationBaseUriHint); + lock (_syncObject) { // To prevent modifying the IIS setup concurrently. - _application.Deploy(); + _application.Deploy(uri); } // Warm up time for IIS setup. @@ -60,7 +63,7 @@ namespace Microsoft.AspNet.Server.Testing WebRootLocation = DeploymentParameters.ApplicationPath, DeploymentParameters = DeploymentParameters, // Accomodate the vdir name. - ApplicationBaseUri = new UriBuilder(Uri.UriSchemeHttp, "localhost", _application.Port).Uri.AbsoluteUri + "/", + ApplicationBaseUri = uri.ToString(), HostShutdownToken = _hostShutdownToken.Token }; } @@ -104,20 +107,16 @@ namespace Microsoft.AspNet.Server.Testing { _deploymentParameters = deploymentParameters; _logger = logger; - WebSiteName = CreateTestSiteName(); - Port = FindFreePort(); } - public int Port { get; } - public string WebSiteName { get; } public string WebSiteRootFolder => $"{Environment.GetEnvironmentVariable("SystemDrive")}\\inetpub\\{WebSiteName}"; - public void Deploy() + public void Deploy(Uri uri) { - _serverManager.Sites.Add(WebSiteName, _deploymentParameters.ApplicationPath, Port); + _serverManager.Sites.Add(WebSiteName, _deploymentParameters.ApplicationPath, uri.Port); _serverManager.CommitChanges(); } @@ -136,25 +135,15 @@ namespace Microsoft.AspNet.Server.Testing _serverManager.CommitChanges(); } } - - private static int FindFreePort() - { - using (var socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)) - { - socket.Bind(new IPEndPoint(IPAddress.Loopback, 0)); - return ((IPEndPoint)socket.LocalEndPoint).Port; - } - } - private string CreateTestSiteName() { if (!string.IsNullOrEmpty(_deploymentParameters.SiteName)) { - return $"{_deploymentParameters.SiteName}{DateTime.Now.ToString("yyyyMMddHHmmss")}"; + return $"{_deploymentParameters.SiteName}{DateTime.Now.ToString("yyyyMMddHHmmss")}"; } else { - return $"testsite{DateTime.Now.ToString("yyyyMMddHHmmss")}"; + return $"testsite{DateTime.Now.ToString("yyyyMMddHHmmss")}"; } } } diff --git a/src/Microsoft.AspNet.Server.Testing/Deployers/IISExpressDeployer.cs b/src/Microsoft.AspNet.Server.Testing/Deployers/IISExpressDeployer.cs index d3911ac925..7146908c0c 100644 --- a/src/Microsoft.AspNet.Server.Testing/Deployers/IISExpressDeployer.cs +++ b/src/Microsoft.AspNet.Server.Testing/Deployers/IISExpressDeployer.cs @@ -6,6 +6,7 @@ using System.Diagnostics; using System.IO; using System.Threading; using Microsoft.Extensions.Logging; +using Microsoft.AspNet.Server.Testing.Common; namespace Microsoft.AspNet.Server.Testing { @@ -35,20 +36,21 @@ namespace Microsoft.AspNet.Server.Testing DnuPublish(); } + var uri = FreePortHelper.FindFreeUrl(DeploymentParameters.ApplicationBaseUriHint); // Launch the host process. - var hostExitToken = StartIISExpress(); + var hostExitToken = StartIISExpress(uri); return new DeploymentResult { WebRootLocation = DeploymentParameters.ApplicationPath, DeploymentParameters = DeploymentParameters, // Right now this works only for urls like http://localhost:5001/. Does not work for http://localhost:5001/subpath. - ApplicationBaseUri = DeploymentParameters.ApplicationBaseUriHint, + ApplicationBaseUri = uri.ToString(), HostShutdownToken = hostExitToken }; } - private CancellationToken StartIISExpress() + private CancellationToken StartIISExpress(Uri uri) { if (!string.IsNullOrWhiteSpace(DeploymentParameters.ApplicationHostConfigTemplateContent)) { @@ -58,7 +60,7 @@ namespace Microsoft.AspNet.Server.Testing DeploymentParameters.ApplicationHostConfigTemplateContent = DeploymentParameters.ApplicationHostConfigTemplateContent .Replace("[ApplicationPhysicalPath]", DeploymentParameters.ApplicationPath) - .Replace("[PORT]", new Uri(DeploymentParameters.ApplicationBaseUriHint).Port.ToString()); + .Replace("[PORT]", uri.Port.ToString()); DeploymentParameters.ApplicationHostConfigLocation = Path.GetTempFileName(); @@ -72,7 +74,7 @@ namespace Microsoft.AspNet.Server.Testing } var parameters = string.IsNullOrWhiteSpace(DeploymentParameters.ApplicationHostConfigLocation) ? - string.Format("/port:{0} /path:\"{1}\" /trace:error", new Uri(DeploymentParameters.ApplicationBaseUriHint).Port, webroot) : + string.Format("/port:{0} /path:\"{1}\" /trace:error", uri.Port, webroot) : string.Format("/site:{0} /config:{1} /trace:error", DeploymentParameters.SiteName, DeploymentParameters.ApplicationHostConfigLocation); var iisExpressPath = GetIISExpressPath(); diff --git a/src/Microsoft.AspNet.Server.Testing/Deployers/SelfHostDeployer.cs b/src/Microsoft.AspNet.Server.Testing/Deployers/SelfHostDeployer.cs index c018f0dac7..4c502189d7 100644 --- a/src/Microsoft.AspNet.Server.Testing/Deployers/SelfHostDeployer.cs +++ b/src/Microsoft.AspNet.Server.Testing/Deployers/SelfHostDeployer.cs @@ -6,6 +6,7 @@ using System.Diagnostics; using System.IO; using System.Threading; using Microsoft.Extensions.Logging; +using Microsoft.AspNet.Server.Testing.Common; namespace Microsoft.AspNet.Server.Testing { @@ -33,19 +34,20 @@ namespace Microsoft.AspNet.Server.Testing DnuPublish(); } + var uri = FreePortHelper.FindFreeUrl(DeploymentParameters.ApplicationBaseUriHint); // Launch the host process. - var hostExitToken = StartSelfHost(); + var hostExitToken = StartSelfHost(uri); return new DeploymentResult { WebRootLocation = DeploymentParameters.ApplicationPath, DeploymentParameters = DeploymentParameters, - ApplicationBaseUri = DeploymentParameters.ApplicationBaseUriHint, + ApplicationBaseUri = uri.ToString(), HostShutdownToken = hostExitToken }; } - private CancellationToken StartSelfHost() + private CancellationToken StartSelfHost(Uri uri) { var commandName = DeploymentParameters.Command; if (string.IsNullOrEmpty(commandName)) @@ -55,7 +57,7 @@ namespace Microsoft.AspNet.Server.Testing var dnxPath = Path.Combine(TargetRuntimeBinPath, DnxCommandName); var dnxArgs = $"-p \"{DeploymentParameters.ApplicationPath}\" {commandName} " + - $"--server.urls {DeploymentParameters.ApplicationBaseUriHint} " + + $"--server.urls {uri} " + $"--server {(DeploymentParameters.ServerType == ServerType.WebListener ? "Microsoft.AspNet.Server.WebListener" : "Microsoft.AspNet.Server.Kestrel")}"; Logger.LogInformation($"Executing {dnxPath} {dnxArgs}"); From 80bc8bbbe1de75ef4ca322504f7c433ab589148b Mon Sep 17 00:00:00 2001 From: Troy Dai Date: Thu, 14 Jan 2016 14:47:15 -0800 Subject: [PATCH 497/987] Fix test break caused by null ApplicationBaseUrlHint In addtion to the fix here are the changes to improve the helper: 1. Rename the helper to better represent its function; 2. Add overload to generate free port without hint; 3. Add overload to generate local test url; --- .../{FreePortHelper.cs => TestUriHelper.cs} | 28 ++++++++++++++----- .../Deployers/IISDeployer.cs | 4 +-- .../Deployers/IISExpressDeployer.cs | 2 +- .../Deployers/SelfHostDeployer.cs | 2 +- 4 files changed, 24 insertions(+), 12 deletions(-) rename src/Microsoft.AspNet.Server.Testing/Common/{FreePortHelper.cs => TestUriHelper.cs} (59%) diff --git a/src/Microsoft.AspNet.Server.Testing/Common/FreePortHelper.cs b/src/Microsoft.AspNet.Server.Testing/Common/TestUriHelper.cs similarity index 59% rename from src/Microsoft.AspNet.Server.Testing/Common/FreePortHelper.cs rename to src/Microsoft.AspNet.Server.Testing/Common/TestUriHelper.cs index f21ae3d001..d64101f713 100644 --- a/src/Microsoft.AspNet.Server.Testing/Common/FreePortHelper.cs +++ b/src/Microsoft.AspNet.Server.Testing/Common/TestUriHelper.cs @@ -7,16 +7,29 @@ using System.Net.Sockets; namespace Microsoft.AspNet.Server.Testing.Common { - public static class FreePortHelper + public static class TestUriHelper { - public static Uri FindFreeUrl(string urlHint) + public static Uri BuildTestUri() { - var uriHint = new Uri(urlHint); - var builder = new UriBuilder(uriHint) + return new UriBuilder("http", "localhost", FindFreePort()).Uri; + } + + public static Uri BuildTestUri(string hint) + { + if (string.IsNullOrEmpty(hint)) { - Port = FindFreePort(uriHint.Port) - }; - return builder.Uri; + return BuildTestUri(); + } + else + { + var uriHint = new Uri(hint); + return new UriBuilder(uriHint) { Port = FindFreePort(uriHint.Port) }.Uri; + } + } + + public static int FindFreePort() + { + return FindFreePort(0); } public static int FindFreePort(int initialPort) @@ -31,6 +44,7 @@ namespace Microsoft.AspNet.Server.Testing.Common { socket.Bind(new IPEndPoint(IPAddress.Loopback, 0)); } + return ((IPEndPoint)socket.LocalEndPoint).Port; } } diff --git a/src/Microsoft.AspNet.Server.Testing/Deployers/IISDeployer.cs b/src/Microsoft.AspNet.Server.Testing/Deployers/IISDeployer.cs index f292252842..0c167587a5 100644 --- a/src/Microsoft.AspNet.Server.Testing/Deployers/IISDeployer.cs +++ b/src/Microsoft.AspNet.Server.Testing/Deployers/IISDeployer.cs @@ -5,8 +5,6 @@ using System; using System.Linq; -using System.Net; -using System.Net.Sockets; using System.Threading; using Microsoft.AspNet.Server.Testing.Common; using Microsoft.Extensions.Logging; @@ -46,7 +44,7 @@ namespace Microsoft.AspNet.Server.Testing // Drop a json file instead of setting environment variable. SetAspEnvironmentWithJson(); - var uri = FreePortHelper.FindFreeUrl(DeploymentParameters.ApplicationBaseUriHint); + var uri = TestUriHelper.BuildTestUri(); lock (_syncObject) { diff --git a/src/Microsoft.AspNet.Server.Testing/Deployers/IISExpressDeployer.cs b/src/Microsoft.AspNet.Server.Testing/Deployers/IISExpressDeployer.cs index 7146908c0c..f7441bf9e0 100644 --- a/src/Microsoft.AspNet.Server.Testing/Deployers/IISExpressDeployer.cs +++ b/src/Microsoft.AspNet.Server.Testing/Deployers/IISExpressDeployer.cs @@ -36,7 +36,7 @@ namespace Microsoft.AspNet.Server.Testing DnuPublish(); } - var uri = FreePortHelper.FindFreeUrl(DeploymentParameters.ApplicationBaseUriHint); + var uri = TestUriHelper.BuildTestUri(DeploymentParameters.ApplicationBaseUriHint); // Launch the host process. var hostExitToken = StartIISExpress(uri); diff --git a/src/Microsoft.AspNet.Server.Testing/Deployers/SelfHostDeployer.cs b/src/Microsoft.AspNet.Server.Testing/Deployers/SelfHostDeployer.cs index 4c502189d7..144a9b3a8a 100644 --- a/src/Microsoft.AspNet.Server.Testing/Deployers/SelfHostDeployer.cs +++ b/src/Microsoft.AspNet.Server.Testing/Deployers/SelfHostDeployer.cs @@ -34,7 +34,7 @@ namespace Microsoft.AspNet.Server.Testing DnuPublish(); } - var uri = FreePortHelper.FindFreeUrl(DeploymentParameters.ApplicationBaseUriHint); + var uri = TestUriHelper.BuildTestUri(DeploymentParameters.ApplicationBaseUriHint); // Launch the host process. var hostExitToken = StartSelfHost(uri); From 7a44cf4da9aafda0399bd246334ba4363c28910a Mon Sep 17 00:00:00 2001 From: Nate McMaster Date: Thu, 14 Jan 2016 16:41:15 -0800 Subject: [PATCH 498/987] Updating build script --- build.sh | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/build.sh b/build.sh index 7b5e25e3a8..263fb667a8 100755 --- a/build.sh +++ b/build.sh @@ -1,13 +1,5 @@ #!/usr/bin/env bash -SOURCE="${BASH_SOURCE[0]}" -while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink - DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )" - SOURCE="$(readlink "$SOURCE")" - [[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE" # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located -done -repoFolder="$( cd -P "$( dirname "$SOURCE" )" && pwd )" - buildFolder=.build koreBuildFolder=$buildFolder/KoreBuild-dotnet @@ -42,7 +34,12 @@ fi if test ! -d $koreBuildFolder; then mono $nugetPath install KoreBuild-dotnet -ExcludeVersion -o $buildFolder -nocache -pre + chmod +x $koreBuildFolder/build/KoreBuild.sh fi -source $koreBuildFolder/build/KoreBuild.sh +makeFile=makefile.shade +if [ ! -e $makeFile ]; then + makeFile=$koreBuildFolder/build/makefile.shade +fi +./$koreBuildFolder/build/KoreBuild.sh -n $nugetPath -m $makeFile "$@" From 0673acedc4de48fc86192ffbbb59d2a6b86bc3c3 Mon Sep 17 00:00:00 2001 From: David Fowler Date: Fri, 15 Jan 2016 11:20:57 +0000 Subject: [PATCH 499/987] Added overload of Run that triggers shutdown on a cancellation token - Added test - Changed NotifyStopped() after all work has been done --- .../Internal/WebApplication.cs | 2 +- .../WebApplicationBuilderExtensions.cs | 42 +++++++++++++++---- .../WebApplicationTests.cs | 32 +++++++++++++- 3 files changed, 67 insertions(+), 9 deletions(-) diff --git a/src/Microsoft.AspNet.Hosting/Internal/WebApplication.cs b/src/Microsoft.AspNet.Hosting/Internal/WebApplication.cs index 74e95c4bc5..066ec19253 100644 --- a/src/Microsoft.AspNet.Hosting/Internal/WebApplication.cs +++ b/src/Microsoft.AspNet.Hosting/Internal/WebApplication.cs @@ -233,8 +233,8 @@ namespace Microsoft.AspNet.Hosting.Internal _logger?.Shutdown(); _applicationLifetime.StopApplication(); Server?.Dispose(); - _applicationLifetime.NotifyStopped(); (_applicationServices as IDisposable)?.Dispose(); + _applicationLifetime.NotifyStopped(); } private class Disposable : IDisposable diff --git a/src/Microsoft.AspNet.Hosting/WebApplicationBuilderExtensions.cs b/src/Microsoft.AspNet.Hosting/WebApplicationBuilderExtensions.cs index e4fd487507..abc9da77a3 100644 --- a/src/Microsoft.AspNet.Hosting/WebApplicationBuilderExtensions.cs +++ b/src/Microsoft.AspNet.Hosting/WebApplicationBuilderExtensions.cs @@ -2,6 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.Threading; using Microsoft.AspNet.Hosting.Server; using Microsoft.AspNet.Server.Features; using Microsoft.Extensions.Configuration; @@ -105,6 +106,32 @@ namespace Microsoft.AspNet.Hosting /// /// public static void Run(this IWebApplication application) + { + using (var cts = new CancellationTokenSource()) + { + Console.CancelKeyPress += (sender, eventArgs) => + { + cts.Cancel(); + + // Don't terminate the process immediately, wait for the Main thread to exit gracefully. + eventArgs.Cancel = true; + }; + + application.Run(cts.Token, "Application started. Press Ctrl+C to shut down."); + } + } + + /// + /// Runs a web application and block the calling thread until token is triggered or shutdown is triggered + /// + /// + /// The token to trigger shutdown + public static void Run(this IWebApplication application, CancellationToken token) + { + application.Run(token, shutdownMessage: null); + } + + private static void Run(this IWebApplication application, CancellationToken token, string shutdownMessage) { using (application) { @@ -124,15 +151,16 @@ namespace Microsoft.AspNet.Hosting } } - Console.WriteLine("Application started. Press Ctrl+C to shut down."); - - Console.CancelKeyPress += (sender, eventArgs) => + if (!string.IsNullOrEmpty(shutdownMessage)) { - applicationLifetime.StopApplication(); + Console.WriteLine(shutdownMessage); + } - // Don't terminate the process immediately, wait for the Main thread to exit gracefully. - eventArgs.Cancel = true; - }; + token.Register(state => + { + ((IApplicationLifetime)state).StopApplication(); + }, + applicationLifetime); applicationLifetime.ApplicationStopping.WaitHandle.WaitOne(); } diff --git a/test/Microsoft.AspNet.Hosting.Tests/WebApplicationTests.cs b/test/Microsoft.AspNet.Hosting.Tests/WebApplicationTests.cs index a83818a9cf..a759535009 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/WebApplicationTests.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/WebApplicationTests.cs @@ -6,6 +6,7 @@ using System.Collections; using System.Collections.Generic; using System.IO; using System.Linq; +using System.Threading; using System.Threading.Tasks; using Microsoft.AspNet.Builder; using Microsoft.AspNet.Hosting.Fakes; @@ -30,7 +31,8 @@ namespace Microsoft.AspNet.Hosting private IFeatureCollection _featuresSupportedByThisHost = NewFeatureCollection(); private IFeatureCollection _instanceFeaturesSupportedByThisHost; - public IFeatureCollection Features { + public IFeatureCollection Features + { get { var features = new FeatureCollection(); @@ -158,6 +160,34 @@ namespace Microsoft.AspNet.Hosting Assert.Equal(1, _startInstances[0].DisposeCalls); } + [Fact] + public void WebApplicationShutsDownWhenTokenTriggers() + { + var app = CreateBuilder() + .UseServer((IServerFactory)this) + .UseStartup("Microsoft.AspNet.Hosting.Tests") + .Build(); + + var lifetime = app.Services.GetRequiredService(); + + var cts = new CancellationTokenSource(); + + Task.Run(() => app.Run(cts.Token)); + + // Wait on the app to be started + lifetime.ApplicationStarted.WaitHandle.WaitOne(); + + Assert.Equal(1, _startInstances.Count); + Assert.Equal(0, _startInstances[0].DisposeCalls); + + cts.Cancel(); + + // Wait on the app to shutdown + lifetime.ApplicationStopped.WaitHandle.WaitOne(); + + Assert.Equal(1, _startInstances[0].DisposeCalls); + } + [Fact] public void WebApplicationDisposesServiceProvider() { From cad9ea1df7e78c52c99346de17b6fc3c2bc2c67e Mon Sep 17 00:00:00 2001 From: John Luo Date: Sat, 16 Jan 2016 23:11:41 -0800 Subject: [PATCH 500/987] Rename WebApplication to WebHost --- .../SampleStartups/StartupBlockingOnStart.cs | 10 +- .../StartupConfigureAddresses.cs | 8 +- .../StartupExternallyControlled.cs | 6 +- samples/SampleStartups/StartupFullControl.cs | 4 +- samples/SampleStartups/StartupHelloWorld.cs | 8 +- .../IHostingEnvironment.cs | 2 +- .../IWebApplicationBuilder.cs | 31 --- .../{IWebApplication.cs => IWebHost.cs} | 6 +- .../IWebHostBuilder.cs | 73 +++++++ ...licationDefaults.cs => WebHostDefaults.cs} | 2 +- ...pplicationService.cs => WebHostService.cs} | 19 +- ....cs => WebHostWindowsServiceExtensions.cs} | 20 +- .../Internal/HostingEnvironmentExtensions.cs | 2 +- .../{WebApplication.cs => WebHost.cs} | 14 +- ...pplicationOptions.cs => WebHostOptions.cs} | 20 +- .../WebApplicationBuilderExtensions.cs | 181 ------------------ ...pplicationBuilder.cs => WebHostBuilder.cs} | 89 +++++++-- .../WebHostBuilderExtensions.cs | 123 ++++++++++++ ...nfiguration.cs => WebHostConfiguration.cs} | 8 +- .../WebHostExtensions.cs | 78 ++++++++ src/Microsoft.AspNet.TestHost/TestServer.cs | 18 +- .../HostingEnvironmentExtensionsTests.cs | 12 +- ...BuilderTests.cs => WebHostBuilderTests.cs} | 90 ++++----- ...Tests.cs => WebHostConfigurationsTests.cs} | 10 +- ...WebApplicationTests.cs => WebHostTests.cs} | 152 +++++++-------- .../ClientHandlerTests.cs | 6 +- .../RequestBuilderTests.cs | 4 +- .../TestClientTests.cs | 24 +-- .../TestServerTests.cs | 44 ++--- 29 files changed, 583 insertions(+), 481 deletions(-) delete mode 100644 src/Microsoft.AspNet.Hosting.Abstractions/IWebApplicationBuilder.cs rename src/Microsoft.AspNet.Hosting.Abstractions/{IWebApplication.cs => IWebHost.cs} (81%) create mode 100644 src/Microsoft.AspNet.Hosting.Abstractions/IWebHostBuilder.cs rename src/Microsoft.AspNet.Hosting.Abstractions/{WebApplicationDefaults.cs => WebHostDefaults.cs} (95%) rename src/Microsoft.AspNet.Hosting.WindowsServices/{WebApplicationService.cs => WebHostService.cs} (77%) rename src/Microsoft.AspNet.Hosting.WindowsServices/{WebApplicationExtensions.cs => WebHostWindowsServiceExtensions.cs} (56%) rename src/Microsoft.AspNet.Hosting/Internal/{WebApplication.cs => WebHost.cs} (96%) rename src/Microsoft.AspNet.Hosting/Internal/{WebApplicationOptions.cs => WebHostOptions.cs} (59%) delete mode 100644 src/Microsoft.AspNet.Hosting/WebApplicationBuilderExtensions.cs rename src/Microsoft.AspNet.Hosting/{WebApplicationBuilder.cs => WebHostBuilder.cs} (61%) create mode 100644 src/Microsoft.AspNet.Hosting/WebHostBuilderExtensions.cs rename src/Microsoft.AspNet.Hosting/{WebApplicationConfiguration.cs => WebHostConfiguration.cs} (78%) create mode 100644 src/Microsoft.AspNet.Hosting/WebHostExtensions.cs rename test/Microsoft.AspNet.Hosting.Tests/{WebApplicationBuilderTests.cs => WebHostBuilderTests.cs} (71%) rename test/Microsoft.AspNet.Hosting.Tests/{WebApplicationConfigurationsTests.cs => WebHostConfigurationsTests.cs} (78%) rename test/Microsoft.AspNet.Hosting.Tests/{WebApplicationTests.cs => WebHostTests.cs} (79%) diff --git a/samples/SampleStartups/StartupBlockingOnStart.cs b/samples/SampleStartups/StartupBlockingOnStart.cs index fdbc094d1b..40d914f379 100644 --- a/samples/SampleStartups/StartupBlockingOnStart.cs +++ b/samples/SampleStartups/StartupBlockingOnStart.cs @@ -28,16 +28,14 @@ namespace SampleStartups // Entry point for the application. public static void Main(string[] args) { - var config = WebApplicationConfiguration.GetDefault(args); - - var application = new WebApplicationBuilder() - .UseConfiguration(config) + var host = new WebHostBuilder() + .UseDefaultConfiguration(args) .UseStartup() .Build(); - using (application) + using (host) { - application.Start(); + host.Start(); Console.ReadLine(); } } diff --git a/samples/SampleStartups/StartupConfigureAddresses.cs b/samples/SampleStartups/StartupConfigureAddresses.cs index 00df99135b..31a9a38a43 100644 --- a/samples/SampleStartups/StartupConfigureAddresses.cs +++ b/samples/SampleStartups/StartupConfigureAddresses.cs @@ -27,15 +27,13 @@ namespace SampleStartups // Entry point for the application. public static void Main(string[] args) { - var config = WebApplicationConfiguration.GetDefault(args); - - var application = new WebApplicationBuilder() - .UseConfiguration(config) + var host = new WebHostBuilder() + .UseDefaultConfiguration(args) .UseStartup() .UseUrls("http://localhost:5000", "http://localhost:5001") .Build(); - application.Run(); + host.Run(); } } } diff --git a/samples/SampleStartups/StartupExternallyControlled.cs b/samples/SampleStartups/StartupExternallyControlled.cs index 538e97decd..b024ede322 100644 --- a/samples/SampleStartups/StartupExternallyControlled.cs +++ b/samples/SampleStartups/StartupExternallyControlled.cs @@ -11,7 +11,7 @@ namespace SampleStartups { public class StartupExternallyControlled { - private IWebApplication _application; + private IWebHost _host; private readonly List _urls = new List(); // This method gets called by the runtime. Use this method to add services to the container. @@ -35,14 +35,14 @@ namespace SampleStartups public void Start() { - _application = new WebApplicationBuilder() + _host = new WebHostBuilder() .UseStartup() .Start(_urls.ToArray()); } public void Stop() { - _application.Dispose(); + _host.Dispose(); } public void AddUrl(string url) diff --git a/samples/SampleStartups/StartupFullControl.cs b/samples/SampleStartups/StartupFullControl.cs index 1279bfb1a0..6445a77bc4 100644 --- a/samples/SampleStartups/StartupFullControl.cs +++ b/samples/SampleStartups/StartupFullControl.cs @@ -13,7 +13,7 @@ namespace SampleStartups { public static void Main(string[] args) { - var application = new WebApplicationBuilder() + var host = new WebHostBuilder() .UseServer("Microsoft.AspNet.Server.Kestrel") // Set the server manually .UseApplicationBasePath(Directory.GetCurrentDirectory()) // Override the application base with the current directory .UseUrls("http://*:1000", "https://*:902") @@ -35,7 +35,7 @@ namespace SampleStartups }) .Build(); - application.Run(); + host.Run(); } } diff --git a/samples/SampleStartups/StartupHelloWorld.cs b/samples/SampleStartups/StartupHelloWorld.cs index 4ee08e2f16..7a76ca4563 100644 --- a/samples/SampleStartups/StartupHelloWorld.cs +++ b/samples/SampleStartups/StartupHelloWorld.cs @@ -27,14 +27,12 @@ namespace SampleStartups // Entry point for the application. public static void Main(string[] args) { - var config = WebApplicationConfiguration.GetDefault(args); - - var application = new WebApplicationBuilder() - .UseConfiguration(config) + var host = new WebHostBuilder() + .UseDefaultConfiguration(args) .UseStartup() .Build(); - application.Run(); + host.Run(); } } } diff --git a/src/Microsoft.AspNet.Hosting.Abstractions/IHostingEnvironment.cs b/src/Microsoft.AspNet.Hosting.Abstractions/IHostingEnvironment.cs index cfc96be02f..6c9ddf464b 100644 --- a/src/Microsoft.AspNet.Hosting.Abstractions/IHostingEnvironment.cs +++ b/src/Microsoft.AspNet.Hosting.Abstractions/IHostingEnvironment.cs @@ -16,7 +16,7 @@ namespace Microsoft.AspNet.Hosting /// of the "Hosting:Environment" (on Windows) or "Hosting__Environment" (on Linux & OS X) environment variable. /// // This must be settable! - string EnvironmentName { get; set; } + string EnvironmentName { get; set; } /// /// Gets or sets the absolute path to the directory that contains the web-servable application content files. diff --git a/src/Microsoft.AspNet.Hosting.Abstractions/IWebApplicationBuilder.cs b/src/Microsoft.AspNet.Hosting.Abstractions/IWebApplicationBuilder.cs deleted file mode 100644 index d4953e3af4..0000000000 --- a/src/Microsoft.AspNet.Hosting.Abstractions/IWebApplicationBuilder.cs +++ /dev/null @@ -1,31 +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; -using System.Collections.Generic; -using Microsoft.AspNet.Builder; -using Microsoft.AspNet.Hosting.Server; -using Microsoft.Extensions.Configuration; -using Microsoft.Extensions.DependencyInjection; - -namespace Microsoft.AspNet.Hosting -{ - public interface IWebApplicationBuilder - { - IWebApplication Build(); - - IDictionary Settings { get; } - - IWebApplicationBuilder UseConfiguration(IConfiguration configuration); - - IWebApplicationBuilder UseServer(IServerFactory factory); - - IWebApplicationBuilder UseStartup(Type startupType); - - IWebApplicationBuilder ConfigureServices(Action configureServices); - - IWebApplicationBuilder Configure(Action configureApplication); - - IWebApplicationBuilder UseSetting(string key, string value); - } -} \ No newline at end of file diff --git a/src/Microsoft.AspNet.Hosting.Abstractions/IWebApplication.cs b/src/Microsoft.AspNet.Hosting.Abstractions/IWebHost.cs similarity index 81% rename from src/Microsoft.AspNet.Hosting.Abstractions/IWebApplication.cs rename to src/Microsoft.AspNet.Hosting.Abstractions/IWebHost.cs index cfafc97ee5..45522b6b4c 100644 --- a/src/Microsoft.AspNet.Hosting.Abstractions/IWebApplication.cs +++ b/src/Microsoft.AspNet.Hosting.Abstractions/IWebHost.cs @@ -7,9 +7,9 @@ using Microsoft.AspNet.Http.Features; namespace Microsoft.AspNet.Hosting { /// - /// Represents a configured web application + /// Represents a configured web host /// - public interface IWebApplication : IDisposable + public interface IWebHost : IDisposable { /// /// The exposed by the configured server. @@ -17,7 +17,7 @@ namespace Microsoft.AspNet.Hosting IFeatureCollection ServerFeatures { get; } /// - /// The for the application. + /// The for the host. /// IServiceProvider Services { get; } diff --git a/src/Microsoft.AspNet.Hosting.Abstractions/IWebHostBuilder.cs b/src/Microsoft.AspNet.Hosting.Abstractions/IWebHostBuilder.cs new file mode 100644 index 0000000000..60017adb17 --- /dev/null +++ b/src/Microsoft.AspNet.Hosting.Abstractions/IWebHostBuilder.cs @@ -0,0 +1,73 @@ +// 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; +using System.Collections.Generic; +using Microsoft.AspNet.Builder; +using Microsoft.AspNet.Hosting.Server; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; + +namespace Microsoft.AspNet.Hosting +{ + /// + /// A builder for + /// + public interface IWebHostBuilder + { + /// + /// Builds an which hosts a web application. + /// + IWebHost Build(); + + /// + /// Gets the raw settings to be used by the web host. Values specified here will override + /// the configuration set by . + /// + IDictionary Settings { get; } + + /// + /// Specify the to be used by the web host. If no configuration is + /// provided to the builder, the default configuration will be used. + /// + /// The to be used. + /// The . + IWebHostBuilder UseConfiguration(IConfiguration configuration); + + /// + /// Specify the to be used by the web host. + /// + /// The to be used. + /// The . + IWebHostBuilder UseServer(IServerFactory factory); + + /// + /// Specify the startup type to be used by the web host. + /// + /// The to be used. + /// The . + IWebHostBuilder UseStartup(Type startupType); + + /// + /// Specify the delegate that is used to configure the services of the web application. + /// + /// The delegate that configures the . + /// The . + IWebHostBuilder ConfigureServices(Action configureServices); + + /// + /// Specify the startup method to be used to configure the web application. + /// + /// The delegate that configures the . + /// The . + IWebHostBuilder Configure(Action configureApplication); + + /// + /// Add or replace a setting in . + /// + /// The key of the setting to add or replace. + /// The value of the setting to add or replace. + /// The . + IWebHostBuilder UseSetting(string key, string value); + } +} \ No newline at end of file diff --git a/src/Microsoft.AspNet.Hosting.Abstractions/WebApplicationDefaults.cs b/src/Microsoft.AspNet.Hosting.Abstractions/WebHostDefaults.cs similarity index 95% rename from src/Microsoft.AspNet.Hosting.Abstractions/WebApplicationDefaults.cs rename to src/Microsoft.AspNet.Hosting.Abstractions/WebHostDefaults.cs index 3efa2561ad..c87cff6476 100644 --- a/src/Microsoft.AspNet.Hosting.Abstractions/WebApplicationDefaults.cs +++ b/src/Microsoft.AspNet.Hosting.Abstractions/WebHostDefaults.cs @@ -3,7 +3,7 @@ namespace Microsoft.AspNet.Hosting { - public static class WebApplicationDefaults + public static class WebHostDefaults { public static readonly string ApplicationKey = "application"; public static readonly string DetailedErrorsKey = "detailedErrors"; diff --git a/src/Microsoft.AspNet.Hosting.WindowsServices/WebApplicationService.cs b/src/Microsoft.AspNet.Hosting.WindowsServices/WebHostService.cs similarity index 77% rename from src/Microsoft.AspNet.Hosting.WindowsServices/WebApplicationService.cs rename to src/Microsoft.AspNet.Hosting.WindowsServices/WebHostService.cs index 4cecc5705a..590f54cc63 100644 --- a/src/Microsoft.AspNet.Hosting.WindowsServices/WebApplicationService.cs +++ b/src/Microsoft.AspNet.Hosting.WindowsServices/WebHostService.cs @@ -1,7 +1,6 @@ // 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; using System.ServiceProcess; using Microsoft.Extensions.DependencyInjection; @@ -10,25 +9,25 @@ namespace Microsoft.AspNet.Hosting.WindowsServices /// /// Provides an implementation of a Windows service that hosts ASP.NET. /// - public class WebApplicationService : ServiceBase + public class WebHostService : ServiceBase { - private IWebApplication _application; + private IWebHost _host; private bool _stopRequestedByWindows; /// - /// Creates an instance of WebApplicationService which hosts the specified web application. + /// Creates an instance of WebHostService which hosts the specified web application. /// - /// The web application to host in the Windows service. - public WebApplicationService(IWebApplication application) + /// The configured web host containing the web application to host in the Windows service. + public WebHostService(IWebHost host) { - _application = application; + _host = host; } protected sealed override void OnStart(string[] args) { OnStarting(args); - _application + _host .Services .GetRequiredService() .ApplicationStopped @@ -40,7 +39,7 @@ namespace Microsoft.AspNet.Hosting.WindowsServices } }); - _application.Start(); + _host.Start(); OnStarted(); } @@ -49,7 +48,7 @@ namespace Microsoft.AspNet.Hosting.WindowsServices { _stopRequestedByWindows = true; OnStopping(); - _application?.Dispose(); + _host?.Dispose(); OnStopped(); } diff --git a/src/Microsoft.AspNet.Hosting.WindowsServices/WebApplicationExtensions.cs b/src/Microsoft.AspNet.Hosting.WindowsServices/WebHostWindowsServiceExtensions.cs similarity index 56% rename from src/Microsoft.AspNet.Hosting.WindowsServices/WebApplicationExtensions.cs rename to src/Microsoft.AspNet.Hosting.WindowsServices/WebHostWindowsServiceExtensions.cs index 41f3e0548f..4034c5976f 100644 --- a/src/Microsoft.AspNet.Hosting.WindowsServices/WebApplicationExtensions.cs +++ b/src/Microsoft.AspNet.Hosting.WindowsServices/WebHostWindowsServiceExtensions.cs @@ -6,37 +6,37 @@ using System.ServiceProcess; namespace Microsoft.AspNet.Hosting.WindowsServices { /// - /// Extensions to + /// Extensions to /// - public static class WebApplicationExtensions + public static class WebHostWindowsServiceExtensions { /// /// Runs the specified web application inside a Windows service and blocks until the service is stopped. /// - /// An instance of the to host in the Windows service. + /// An instance of the to host in the Windows service. /// - /// This example shows how to use . + /// This example shows how to use . /// /// public class Program /// { /// public static void Main(string[] args) /// { - /// var config = WebApplicationConfiguration.GetDefault(args); + /// var config = WebHostConfiguration.GetDefault(args); /// - /// var application = new WebApplicationBuilder() + /// var host = new WebHostBuilder() /// .UseConfiguration(config) /// .Build(); /// /// // This call will block until the service is stopped. - /// application.RunAsService(); + /// host.RunAsService(); /// } /// } /// /// - public static void RunAsService(this IWebApplication application) + public static void RunAsService(this IWebHost host) { - var webApplicationService = new WebApplicationService(application); - ServiceBase.Run(webApplicationService); + var webHostService = new WebHostService(host); + ServiceBase.Run(webHostService); } } } diff --git a/src/Microsoft.AspNet.Hosting/Internal/HostingEnvironmentExtensions.cs b/src/Microsoft.AspNet.Hosting/Internal/HostingEnvironmentExtensions.cs index cf4e1303bc..36f8c9bb41 100644 --- a/src/Microsoft.AspNet.Hosting/Internal/HostingEnvironmentExtensions.cs +++ b/src/Microsoft.AspNet.Hosting/Internal/HostingEnvironmentExtensions.cs @@ -11,7 +11,7 @@ namespace Microsoft.AspNet.Hosting.Internal { public static class HostingEnvironmentExtensions { - public static void Initialize(this IHostingEnvironment hostingEnvironment, string applicationBasePath, WebApplicationOptions options, IConfiguration configuration) + public static void Initialize(this IHostingEnvironment hostingEnvironment, string applicationBasePath, WebHostOptions options, IConfiguration configuration) { if (options == null) { diff --git a/src/Microsoft.AspNet.Hosting/Internal/WebApplication.cs b/src/Microsoft.AspNet.Hosting/Internal/WebHost.cs similarity index 96% rename from src/Microsoft.AspNet.Hosting/Internal/WebApplication.cs rename to src/Microsoft.AspNet.Hosting/Internal/WebHost.cs index 066ec19253..d68d6604b7 100644 --- a/src/Microsoft.AspNet.Hosting/Internal/WebApplication.cs +++ b/src/Microsoft.AspNet.Hosting/Internal/WebHost.cs @@ -19,17 +19,17 @@ using Microsoft.Extensions.PlatformAbstractions; namespace Microsoft.AspNet.Hosting.Internal { - public class WebApplication : IWebApplication + public class WebHost : IWebHost { private readonly IServiceCollection _applicationServiceCollection; private readonly IStartupLoader _startupLoader; private readonly ApplicationLifetime _applicationLifetime; - private readonly WebApplicationOptions _options; + private readonly WebHostOptions _options; private readonly IConfiguration _config; private IServiceProvider _applicationServices; private RequestDelegate _application; - private ILogger _logger; + private ILogger _logger; // Only one of these should be set internal string StartupAssemblyName { get; set; } @@ -41,10 +41,10 @@ namespace Microsoft.AspNet.Hosting.Internal internal string ServerFactoryLocation { get; set; } private IServer Server { get; set; } - public WebApplication( + public WebHost( IServiceCollection appServices, IStartupLoader startupLoader, - WebApplicationOptions options, + WebHostOptions options, IConfiguration config) { if (appServices == null) @@ -99,7 +99,7 @@ namespace Microsoft.AspNet.Hosting.Internal { Initialize(); - _logger = _applicationServices.GetRequiredService>(); + _logger = _applicationServices.GetRequiredService>(); var diagnosticSource = _applicationServices.GetRequiredService(); var httpContextFactory = _applicationServices.GetRequiredService(); @@ -183,7 +183,7 @@ namespace Microsoft.AspNet.Hosting.Internal // Write errors to standard out so they can be retrieved when not in development mode. Console.Out.WriteLine("Application startup exception: " + ex.ToString()); - var logger = _applicationServices.GetRequiredService>(); + var logger = _applicationServices.GetRequiredService>(); logger.ApplicationError(ex); // Generate an HTML error page. diff --git a/src/Microsoft.AspNet.Hosting/Internal/WebApplicationOptions.cs b/src/Microsoft.AspNet.Hosting/Internal/WebHostOptions.cs similarity index 59% rename from src/Microsoft.AspNet.Hosting/Internal/WebApplicationOptions.cs rename to src/Microsoft.AspNet.Hosting/Internal/WebHostOptions.cs index dd4ef59750..a5e6ffeec3 100644 --- a/src/Microsoft.AspNet.Hosting/Internal/WebApplicationOptions.cs +++ b/src/Microsoft.AspNet.Hosting/Internal/WebHostOptions.cs @@ -6,28 +6,28 @@ using Microsoft.Extensions.Configuration; namespace Microsoft.AspNet.Hosting.Internal { - public class WebApplicationOptions + public class WebHostOptions { private const string OldEnvironmentKey = "ENV"; - public WebApplicationOptions() + public WebHostOptions() { } - public WebApplicationOptions(IConfiguration configuration) + public WebHostOptions(IConfiguration configuration) { if (configuration == null) { throw new ArgumentNullException(nameof(configuration)); } - Application = configuration[WebApplicationDefaults.ApplicationKey]; - DetailedErrors = ParseBool(configuration, WebApplicationDefaults.DetailedErrorsKey); - CaptureStartupErrors = ParseBool(configuration, WebApplicationDefaults.CaptureStartupErrorsKey); - Environment = configuration[WebApplicationDefaults.EnvironmentKey] ?? configuration[OldEnvironmentKey]; - ServerFactoryLocation = configuration[WebApplicationDefaults.ServerKey]; - WebRoot = configuration[WebApplicationDefaults.WebRootKey]; - ApplicationBasePath = configuration[WebApplicationDefaults.ApplicationBaseKey]; + Application = configuration[WebHostDefaults.ApplicationKey]; + DetailedErrors = ParseBool(configuration, WebHostDefaults.DetailedErrorsKey); + CaptureStartupErrors = ParseBool(configuration, WebHostDefaults.CaptureStartupErrorsKey); + Environment = configuration[WebHostDefaults.EnvironmentKey] ?? configuration[OldEnvironmentKey]; + ServerFactoryLocation = configuration[WebHostDefaults.ServerKey]; + WebRoot = configuration[WebHostDefaults.WebRootKey]; + ApplicationBasePath = configuration[WebHostDefaults.ApplicationBaseKey]; } public string Application { get; set; } diff --git a/src/Microsoft.AspNet.Hosting/WebApplicationBuilderExtensions.cs b/src/Microsoft.AspNet.Hosting/WebApplicationBuilderExtensions.cs deleted file mode 100644 index abc9da77a3..0000000000 --- a/src/Microsoft.AspNet.Hosting/WebApplicationBuilderExtensions.cs +++ /dev/null @@ -1,181 +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; -using System.Threading; -using Microsoft.AspNet.Hosting.Server; -using Microsoft.AspNet.Server.Features; -using Microsoft.Extensions.Configuration; -using Microsoft.Extensions.DependencyInjection; - -namespace Microsoft.AspNet.Hosting -{ - public static class WebApplicationBuilderExtensions - { - private static readonly string ServerUrlsSeparator = ";"; - - public static IWebApplicationBuilder UseCaptureStartupErrors(this IWebApplicationBuilder applicationBuilder, bool captureStartupError) - { - return applicationBuilder.UseSetting(WebApplicationDefaults.CaptureStartupErrorsKey, captureStartupError ? "true" : "false"); - } - - public static IWebApplicationBuilder UseStartup(this IWebApplicationBuilder applicationBuilder) where TStartup : class - { - return applicationBuilder.UseStartup(typeof(TStartup)); - } - - public static IWebApplicationBuilder UseServer(this IWebApplicationBuilder applicationBuilder, string assemblyName) - { - if (assemblyName == null) - { - throw new ArgumentNullException(nameof(assemblyName)); - } - - return applicationBuilder.UseSetting(WebApplicationDefaults.ServerKey, assemblyName); - } - - public static IWebApplicationBuilder UseServer(this IWebApplicationBuilder applicationBuilder, IServer server) - { - if (server == null) - { - throw new ArgumentNullException(nameof(server)); - } - - return applicationBuilder.UseServer(new ServerFactory(server)); - } - - public static IWebApplicationBuilder UseApplicationBasePath(this IWebApplicationBuilder applicationBuilder, string applicationBasePath) - { - if (applicationBasePath == null) - { - throw new ArgumentNullException(nameof(applicationBasePath)); - } - - return applicationBuilder.UseSetting(WebApplicationDefaults.ApplicationBaseKey, applicationBasePath); - } - - public static IWebApplicationBuilder UseEnvironment(this IWebApplicationBuilder applicationBuilder, string environment) - { - if (environment == null) - { - throw new ArgumentNullException(nameof(environment)); - } - - return applicationBuilder.UseSetting(WebApplicationDefaults.EnvironmentKey, environment); - } - - public static IWebApplicationBuilder UseWebRoot(this IWebApplicationBuilder applicationBuilder, string webRoot) - { - if (webRoot == null) - { - throw new ArgumentNullException(nameof(webRoot)); - } - - return applicationBuilder.UseSetting(WebApplicationDefaults.WebRootKey, webRoot); - } - - public static IWebApplicationBuilder UseUrls(this IWebApplicationBuilder applicationBuilder, params string[] urls) - { - if (urls == null) - { - throw new ArgumentNullException(nameof(urls)); - } - - return applicationBuilder.UseSetting(WebApplicationDefaults.ServerUrlsKey, string.Join(ServerUrlsSeparator, urls)); - } - - public static IWebApplicationBuilder UseStartup(this IWebApplicationBuilder applicationBuilder, string startupAssemblyName) - { - if (startupAssemblyName == null) - { - throw new ArgumentNullException(nameof(startupAssemblyName)); - } - - return applicationBuilder.UseSetting(WebApplicationDefaults.ApplicationKey, startupAssemblyName); - } - - public static IWebApplication Start(this IWebApplicationBuilder applicationBuilder, params string[] urls) - { - var application = applicationBuilder.UseUrls(urls).Build(); - application.Start(); - return application; - } - - /// - /// Runs a web application and block the calling thread until host shutdown. - /// - /// - public static void Run(this IWebApplication application) - { - using (var cts = new CancellationTokenSource()) - { - Console.CancelKeyPress += (sender, eventArgs) => - { - cts.Cancel(); - - // Don't terminate the process immediately, wait for the Main thread to exit gracefully. - eventArgs.Cancel = true; - }; - - application.Run(cts.Token, "Application started. Press Ctrl+C to shut down."); - } - } - - /// - /// Runs a web application and block the calling thread until token is triggered or shutdown is triggered - /// - /// - /// The token to trigger shutdown - public static void Run(this IWebApplication application, CancellationToken token) - { - application.Run(token, shutdownMessage: null); - } - - private static void Run(this IWebApplication application, CancellationToken token, string shutdownMessage) - { - using (application) - { - application.Start(); - - var hostingEnvironment = application.Services.GetService(); - var applicationLifetime = application.Services.GetService(); - - Console.WriteLine("Hosting environment: " + hostingEnvironment.EnvironmentName); - - var serverAddresses = application.ServerFeatures.Get()?.Addresses; - if (serverAddresses != null) - { - foreach (var address in serverAddresses) - { - Console.WriteLine("Now listening on: " + address); - } - } - - if (!string.IsNullOrEmpty(shutdownMessage)) - { - Console.WriteLine(shutdownMessage); - } - - token.Register(state => - { - ((IApplicationLifetime)state).StopApplication(); - }, - applicationLifetime); - - applicationLifetime.ApplicationStopping.WaitHandle.WaitOne(); - } - } - - private class ServerFactory : IServerFactory - { - private readonly IServer _server; - - public ServerFactory(IServer server) - { - _server = server; - } - - public IServer CreateServer(IConfiguration configuration) => _server; - } - } -} \ No newline at end of file diff --git a/src/Microsoft.AspNet.Hosting/WebApplicationBuilder.cs b/src/Microsoft.AspNet.Hosting/WebHostBuilder.cs similarity index 61% rename from src/Microsoft.AspNet.Hosting/WebApplicationBuilder.cs rename to src/Microsoft.AspNet.Hosting/WebHostBuilder.cs index 4ec45e9c61..0f385a8ac6 100644 --- a/src/Microsoft.AspNet.Hosting/WebApplicationBuilder.cs +++ b/src/Microsoft.AspNet.Hosting/WebHostBuilder.cs @@ -20,13 +20,16 @@ using Microsoft.Extensions.PlatformAbstractions; namespace Microsoft.AspNet.Hosting { - public class WebApplicationBuilder : IWebApplicationBuilder + /// + /// A builder for + /// + public class WebHostBuilder : IWebHostBuilder { private readonly IHostingEnvironment _hostingEnvironment; private readonly ILoggerFactory _loggerFactory; private IConfiguration _config; - private WebApplicationOptions _options; + private WebHostOptions _options; private Action _configureServices; @@ -39,12 +42,16 @@ namespace Microsoft.AspNet.Hosting private IDictionary _settings = new Dictionary(StringComparer.OrdinalIgnoreCase); - public WebApplicationBuilder() + public WebHostBuilder() { _hostingEnvironment = new HostingEnvironment(); _loggerFactory = new LoggerFactory(); } + /// + /// Gets the raw settings to be used by the web host. Values specified here will override + /// the configuration set by . + /// public IDictionary Settings { get @@ -53,19 +60,36 @@ namespace Microsoft.AspNet.Hosting } } - public IWebApplicationBuilder UseSetting(string key, string value) + /// + /// Add or replace a setting in . + /// + /// The key of the setting to add or replace. + /// The value of the setting to add or replace. + /// The . + public IWebHostBuilder UseSetting(string key, string value) { _settings[key] = value; return this; } - public IWebApplicationBuilder UseConfiguration(IConfiguration configuration) + /// + /// Specify the to be used by the web host. If no configuration is + /// provided to the builder, the default configuration will be used. + /// + /// The to be used. + /// The . + public IWebHostBuilder UseConfiguration(IConfiguration configuration) { _config = configuration; return this; } - public IWebApplicationBuilder UseServer(IServerFactory factory) + /// + /// Specify the to be used by the web host. + /// + /// The to be used. + /// The . + public IWebHostBuilder UseServer(IServerFactory factory) { if (factory == null) { @@ -76,7 +100,12 @@ namespace Microsoft.AspNet.Hosting return this; } - public IWebApplicationBuilder UseStartup(Type startupType) + /// + /// Specify the startup type to be used by the web host. + /// + /// The to be used. + /// The . + public IWebHostBuilder UseStartup(Type startupType) { if (startupType == null) { @@ -87,13 +116,23 @@ namespace Microsoft.AspNet.Hosting return this; } - public IWebApplicationBuilder ConfigureServices(Action configureServices) + /// + /// Specify the delegate that is used to configure the services of the web application. + /// + /// The delegate that configures the . + /// The . + public IWebHostBuilder ConfigureServices(Action configureServices) { _configureServices = configureServices; return this; } - public IWebApplicationBuilder Configure(Action configureApp) + /// + /// Specify the startup method to be used to configure the web application. + /// + /// The delegate that configures the . + /// The . + public IWebHostBuilder Configure(Action configureApp) { if (configureApp == null) { @@ -104,13 +143,21 @@ namespace Microsoft.AspNet.Hosting return this; } - public IWebApplicationBuilder ConfigureLogging(Action configureLogging) + /// + /// Configure the provided which will be available as a hosting service. + /// + /// The delegate that configures the . + /// The . + public IWebHostBuilder ConfigureLogging(Action configureLogging) { configureLogging(_loggerFactory); return this; } - public IWebApplication Build() + /// + /// Builds the required services and an which hosts a web application. + /// + public IWebHost Build() { var hostingServices = BuildHostingServices(); @@ -122,26 +169,26 @@ namespace Microsoft.AspNet.Hosting // Initialize the hosting environment _hostingEnvironment.Initialize(appEnvironment.ApplicationBasePath, _options, _config); - var application = new WebApplication(hostingServices, startupLoader, _options, _config); + var host = new WebHost(hostingServices, startupLoader, _options, _config); // Only one of these should be set, but they are used in priority - application.ServerFactory = _serverFactory; - application.ServerFactoryLocation = _options.ServerFactoryLocation; + host.ServerFactory = _serverFactory; + host.ServerFactoryLocation = _options.ServerFactoryLocation; // Only one of these should be set, but they are used in priority - application.Startup = _startup; - application.StartupType = _startupType; - application.StartupAssemblyName = _options.Application; + host.Startup = _startup; + host.StartupType = _startupType; + host.StartupAssemblyName = _options.Application; - application.Initialize(); + host.Initialize(); - return application; + return host; } private IServiceCollection BuildHostingServices() { // Apply the configuration settings - var configuration = _config ?? WebApplicationConfiguration.GetDefault(); + var configuration = _config ?? WebHostConfiguration.GetDefault(); var mergedConfiguration = new ConfigurationBuilder() .Add(new IncludedConfigurationProvider(configuration)) @@ -149,7 +196,7 @@ namespace Microsoft.AspNet.Hosting .Build(); _config = mergedConfiguration; - _options = new WebApplicationOptions(_config); + _options = new WebHostOptions(_config); var services = new ServiceCollection(); services.AddSingleton(_hostingEnvironment); diff --git a/src/Microsoft.AspNet.Hosting/WebHostBuilderExtensions.cs b/src/Microsoft.AspNet.Hosting/WebHostBuilderExtensions.cs new file mode 100644 index 0000000000..db10bdd6d1 --- /dev/null +++ b/src/Microsoft.AspNet.Hosting/WebHostBuilderExtensions.cs @@ -0,0 +1,123 @@ +// 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; +using Microsoft.AspNet.Hosting.Server; +using Microsoft.Extensions.Configuration; + +namespace Microsoft.AspNet.Hosting +{ + public static class WebHostBuilderExtensions + { + private static readonly string ServerUrlsSeparator = ";"; + + public static IWebHostBuilder UseDefaultConfiguration(this IWebHostBuilder builder) + { + return builder.UseDefaultConfiguration(args: null); + } + + public static IWebHostBuilder UseDefaultConfiguration(this IWebHostBuilder builder, string[] args) + { + return builder.UseConfiguration(WebHostConfiguration.GetDefault(args)); + } + + public static IWebHostBuilder UseCaptureStartupErrors(this IWebHostBuilder hostBuilder, bool captureStartupError) + { + return hostBuilder.UseSetting(WebHostDefaults.CaptureStartupErrorsKey, captureStartupError ? "true" : "false"); + } + + public static IWebHostBuilder UseStartup(this IWebHostBuilder hostBuilder) where TStartup : class + { + return hostBuilder.UseStartup(typeof(TStartup)); + } + + public static IWebHostBuilder UseServer(this IWebHostBuilder hostBuilder, string assemblyName) + { + if (assemblyName == null) + { + throw new ArgumentNullException(nameof(assemblyName)); + } + + return hostBuilder.UseSetting(WebHostDefaults.ServerKey, assemblyName); + } + + public static IWebHostBuilder UseServer(this IWebHostBuilder hostBuilder, IServer server) + { + if (server == null) + { + throw new ArgumentNullException(nameof(server)); + } + + return hostBuilder.UseServer(new ServerFactory(server)); + } + + public static IWebHostBuilder UseApplicationBasePath(this IWebHostBuilder hostBuilder, string applicationBasePath) + { + if (applicationBasePath == null) + { + throw new ArgumentNullException(nameof(applicationBasePath)); + } + + return hostBuilder.UseSetting(WebHostDefaults.ApplicationBaseKey, applicationBasePath); + } + + public static IWebHostBuilder UseEnvironment(this IWebHostBuilder hostBuilder, string environment) + { + if (environment == null) + { + throw new ArgumentNullException(nameof(environment)); + } + + return hostBuilder.UseSetting(WebHostDefaults.EnvironmentKey, environment); + } + + public static IWebHostBuilder UseWebRoot(this IWebHostBuilder hostBuilder, string webRoot) + { + if (webRoot == null) + { + throw new ArgumentNullException(nameof(webRoot)); + } + + return hostBuilder.UseSetting(WebHostDefaults.WebRootKey, webRoot); + } + + public static IWebHostBuilder UseUrls(this IWebHostBuilder hostBuilder, params string[] urls) + { + if (urls == null) + { + throw new ArgumentNullException(nameof(urls)); + } + + return hostBuilder.UseSetting(WebHostDefaults.ServerUrlsKey, string.Join(ServerUrlsSeparator, urls)); + } + + public static IWebHostBuilder UseStartup(this IWebHostBuilder hostBuilder, string startupAssemblyName) + { + if (startupAssemblyName == null) + { + throw new ArgumentNullException(nameof(startupAssemblyName)); + } + + return hostBuilder.UseSetting(WebHostDefaults.ApplicationKey, startupAssemblyName); + } + + public static IWebHost Start(this IWebHostBuilder hostBuilder, params string[] urls) + { + var host = hostBuilder.UseUrls(urls).Build(); + host.Start(); + return host; + } + + private class ServerFactory : IServerFactory + { + private readonly IServer _server; + + public ServerFactory(IServer server) + { + _server = server; + } + + public IServer CreateServer(IConfiguration configuration) => _server; + } + } +} \ No newline at end of file diff --git a/src/Microsoft.AspNet.Hosting/WebApplicationConfiguration.cs b/src/Microsoft.AspNet.Hosting/WebHostConfiguration.cs similarity index 78% rename from src/Microsoft.AspNet.Hosting/WebApplicationConfiguration.cs rename to src/Microsoft.AspNet.Hosting/WebHostConfiguration.cs index e08549b8c8..76d539117a 100644 --- a/src/Microsoft.AspNet.Hosting/WebApplicationConfiguration.cs +++ b/src/Microsoft.AspNet.Hosting/WebHostConfiguration.cs @@ -6,7 +6,7 @@ using Microsoft.Extensions.Configuration; namespace Microsoft.AspNet.Hosting { - public class WebApplicationConfiguration + public class WebHostConfiguration { public static IConfiguration GetDefault() { @@ -17,16 +17,16 @@ namespace Microsoft.AspNet.Hosting { var defaultSettings = new Dictionary { - { WebApplicationDefaults.CaptureStartupErrorsKey, "true" } + { WebHostDefaults.CaptureStartupErrorsKey, "true" } }; // We are adding all environment variables first and then adding the ASPNET_ ones // with the prefix removed to unify with the command line and config file formats var configBuilder = new ConfigurationBuilder() .AddInMemoryCollection(defaultSettings) - .AddJsonFile(WebApplicationDefaults.HostingJsonFile, optional: true) + .AddJsonFile(WebHostDefaults.HostingJsonFile, optional: true) .AddEnvironmentVariables() - .AddEnvironmentVariables(prefix: WebApplicationDefaults.EnvironmentVariablesPrefix); + .AddEnvironmentVariables(prefix: WebHostDefaults.EnvironmentVariablesPrefix); if (args != null) { diff --git a/src/Microsoft.AspNet.Hosting/WebHostExtensions.cs b/src/Microsoft.AspNet.Hosting/WebHostExtensions.cs new file mode 100644 index 0000000000..0e2f6480fe --- /dev/null +++ b/src/Microsoft.AspNet.Hosting/WebHostExtensions.cs @@ -0,0 +1,78 @@ +// 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; +using System.Threading; +using Microsoft.AspNet.Server.Features; +using Microsoft.Extensions.DependencyInjection; + +namespace Microsoft.AspNet.Hosting +{ + public static class WebHostExtensions + { + /// + /// Runs a web application and block the calling thread until host shutdown. + /// + /// + public static void Run(this IWebHost host) + { + using (var cts = new CancellationTokenSource()) + { + Console.CancelKeyPress += (sender, eventArgs) => + { + cts.Cancel(); + + // Don't terminate the process immediately, wait for the Main thread to exit gracefully. + eventArgs.Cancel = true; + }; + + host.Run(cts.Token, "Application started. Press Ctrl+C to shut down."); + } + } + + /// + /// Runs a web application and block the calling thread until token is triggered or shutdown is triggered + /// + /// + /// The token to trigger shutdown + public static void Run(this IWebHost host, CancellationToken token) + { + host.Run(token, shutdownMessage: null); + } + + private static void Run(this IWebHost host, CancellationToken token, string shutdownMessage) + { + using (host) + { + host.Start(); + + var hostingEnvironment = host.Services.GetService(); + var applicationLifetime = host.Services.GetService(); + + Console.WriteLine("Hosting environment: " + hostingEnvironment.EnvironmentName); + + var serverAddresses = host.ServerFeatures.Get()?.Addresses; + if (serverAddresses != null) + { + foreach (var address in serverAddresses) + { + Console.WriteLine("Now listening on: " + address); + } + } + + if (!string.IsNullOrEmpty(shutdownMessage)) + { + Console.WriteLine(shutdownMessage); + } + + token.Register(state => + { + ((IApplicationLifetime)state).StopApplication(); + }, + applicationLifetime); + + applicationLifetime.ApplicationStopping.WaitHandle.WaitOne(); + } + } + } +} \ No newline at end of file diff --git a/src/Microsoft.AspNet.TestHost/TestServer.cs b/src/Microsoft.AspNet.TestHost/TestServer.cs index 57a1cefd7c..1e85bf96cb 100644 --- a/src/Microsoft.AspNet.TestHost/TestServer.cs +++ b/src/Microsoft.AspNet.TestHost/TestServer.cs @@ -16,29 +16,29 @@ namespace Microsoft.AspNet.TestHost { private const string DefaultEnvironmentName = "Development"; private const string ServerName = nameof(TestServer); - private IWebApplication _appInstance; + private IWebHost _hostInstance; private bool _disposed = false; private IHttpApplication _application; - public TestServer(IWebApplicationBuilder builder) + public TestServer(IWebHostBuilder builder) { - if (!builder.Settings.ContainsKey(WebApplicationDefaults.CaptureStartupErrorsKey)) + if (!builder.Settings.ContainsKey(WebHostDefaults.CaptureStartupErrorsKey)) { builder.UseCaptureStartupErrors(false); } - var application = builder.UseServer(this).Build(); - application.Start(); - _appInstance = application; + var host = builder.UseServer(this).Build(); + host.Start(); + _hostInstance = host; } public Uri BaseAddress { get; set; } = new Uri("http://localhost/"); - public IWebApplication Application + public IWebHost Host { get { - return _appInstance; + return _hostInstance; } } @@ -76,7 +76,7 @@ namespace Microsoft.AspNet.TestHost if (!_disposed) { _disposed = true; - _appInstance.Dispose(); + _hostInstance.Dispose(); } } diff --git a/test/Microsoft.AspNet.Hosting.Tests/HostingEnvironmentExtensionsTests.cs b/test/Microsoft.AspNet.Hosting.Tests/HostingEnvironmentExtensionsTests.cs index dd60adc4b5..60a413acf5 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/HostingEnvironmentExtensionsTests.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/HostingEnvironmentExtensionsTests.cs @@ -17,7 +17,7 @@ namespace Microsoft.AspNet.Hosting.Tests { var env = new HostingEnvironment(); - env.Initialize(".", new WebApplicationOptions() {WebRoot = "testroot"}, null); + env.Initialize(".", new WebHostOptions() {WebRoot = "testroot"}, null); Assert.Equal(Path.GetFullPath("testroot"), env.WebRootPath); Assert.IsAssignableFrom(env.WebRootFileProvider); @@ -28,7 +28,7 @@ namespace Microsoft.AspNet.Hosting.Tests { var env = new HostingEnvironment(); - env.Initialize("testroot", new WebApplicationOptions(), null); + env.Initialize("testroot", new WebHostOptions(), null); Assert.Equal(Path.GetFullPath(Path.Combine("testroot","wwwroot")), env.WebRootPath); Assert.IsAssignableFrom(env.WebRootFileProvider); @@ -39,7 +39,7 @@ namespace Microsoft.AspNet.Hosting.Tests { var env = new HostingEnvironment(); - env.Initialize(Path.Combine("testroot", "wwwroot"), new WebApplicationOptions(), null); + env.Initialize(Path.Combine("testroot", "wwwroot"), new WebHostOptions(), null); Assert.Null(env.WebRootPath); Assert.IsAssignableFrom(env.WebRootFileProvider); @@ -51,7 +51,7 @@ namespace Microsoft.AspNet.Hosting.Tests var config = new ConfigurationBuilder().Build(); var env = new HostingEnvironment(); - env.Initialize(".", new WebApplicationOptions(), config); + env.Initialize(".", new WebHostOptions(), config); Assert.Same(config, env.Configuration); } @@ -62,7 +62,7 @@ namespace Microsoft.AspNet.Hosting.Tests var env = new HostingEnvironment(); env.EnvironmentName = "SomeName"; - env.Initialize(".", new WebApplicationOptions() { Environment = "NewName" }, null); + env.Initialize(".", new WebHostOptions() { Environment = "NewName" }, null); Assert.Equal("NewName", env.EnvironmentName); } @@ -72,7 +72,7 @@ namespace Microsoft.AspNet.Hosting.Tests { var env = new HostingEnvironment(); - env.Initialize(".", new WebApplicationOptions(), null); + env.Initialize(".", new WebHostOptions(), null); Assert.Throws(() => env.MapPath("file.txt")); } diff --git a/test/Microsoft.AspNet.Hosting.Tests/WebApplicationBuilderTests.cs b/test/Microsoft.AspNet.Hosting.Tests/WebHostBuilderTests.cs similarity index 71% rename from test/Microsoft.AspNet.Hosting.Tests/WebApplicationBuilderTests.cs rename to test/Microsoft.AspNet.Hosting.Tests/WebHostBuilderTests.cs index d316a3b460..01c5346c66 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/WebApplicationBuilderTests.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/WebHostBuilderTests.cs @@ -18,27 +18,27 @@ using Xunit; namespace Microsoft.AspNet.Hosting { - public class WebApplicationBuilderTests + public class WebHostBuilderTests { [Fact] public void Build_honors_UseStartup_with_string() { - var builder = CreateWebApplicationBuilder().UseServer(new TestServer()); + var builder = CreateWebHostBuilder().UseServer(new TestServer()); - var application = (WebApplication)builder.UseStartup("MyStartupAssembly").Build(); + var host = (WebHost)builder.UseStartup("MyStartupAssembly").Build(); - Assert.Equal("MyStartupAssembly", application.StartupAssemblyName); + Assert.Equal("MyStartupAssembly", host.StartupAssemblyName); } [Fact] public async Task StartupMissing_Fallback() { - var builder = CreateWebApplicationBuilder(); + var builder = CreateWebHostBuilder(); var server = new TestServer(); - var application = builder.UseServer(server).UseStartup("MissingStartupAssembly").Build(); - using (application) + var host = builder.UseServer(server).UseStartup("MissingStartupAssembly").Build(); + using (host) { - application.Start(); + host.Start(); await AssertResponseContains(server.RequestDelegate, "MissingStartupAssembly"); } } @@ -46,12 +46,12 @@ namespace Microsoft.AspNet.Hosting [Fact] public async Task StartupStaticCtorThrows_Fallback() { - var builder = CreateWebApplicationBuilder(); + var builder = CreateWebHostBuilder(); var server = new TestServer(); - var application = builder.UseServer(server).UseStartup().Build(); - using (application) + var host = builder.UseServer(server).UseStartup().Build(); + using (host) { - application.Start(); + host.Start(); await AssertResponseContains(server.RequestDelegate, "Exception from static constructor"); } } @@ -59,12 +59,12 @@ namespace Microsoft.AspNet.Hosting [Fact] public async Task StartupCtorThrows_Fallback() { - var builder = CreateWebApplicationBuilder(); + var builder = CreateWebHostBuilder(); var server = new TestServer(); - var application = builder.UseServer(server).UseStartup().Build(); - using (application) + var host = builder.UseServer(server).UseStartup().Build(); + using (host) { - application.Start(); + host.Start(); await AssertResponseContains(server.RequestDelegate, "Exception from constructor"); } } @@ -72,12 +72,12 @@ namespace Microsoft.AspNet.Hosting [Fact] public async Task StartupCtorThrows_TypeLoadException() { - var builder = CreateWebApplicationBuilder(); + var builder = CreateWebHostBuilder(); var server = new TestServer(); - var application = builder.UseServer(server).UseStartup().Build(); - using (application) + var host = builder.UseServer(server).UseStartup().Build(); + using (host) { - application.Start(); + host.Start(); await AssertResponseContains(server.RequestDelegate, "Message from the LoaderException"); } } @@ -85,13 +85,13 @@ namespace Microsoft.AspNet.Hosting [Fact] public async Task IApplicationLifetimeRegisteredEvenWhenStartupCtorThrows_Fallback() { - var builder = CreateWebApplicationBuilder(); + var builder = CreateWebHostBuilder(); var server = new TestServer(); - var application = builder.UseServer(server).UseStartup().Build(); - using (application) + var host = builder.UseServer(server).UseStartup().Build(); + using (host) { - application.Start(); - var service = application.Services.GetServices(); + host.Start(); + var service = host.Services.GetServices(); Assert.NotNull(service); await AssertResponseContains(server.RequestDelegate, "Exception from constructor"); } @@ -100,12 +100,12 @@ namespace Microsoft.AspNet.Hosting [Fact] public async Task StartupConfigureServicesThrows_Fallback() { - var builder = CreateWebApplicationBuilder(); + var builder = CreateWebHostBuilder(); var server = new TestServer(); - var application = builder.UseServer(server).UseStartup().Build(); - using (application) + var host = builder.UseServer(server).UseStartup().Build(); + using (host) { - application.Start(); + host.Start(); await AssertResponseContains(server.RequestDelegate, "Exception from ConfigureServices"); } } @@ -113,12 +113,12 @@ namespace Microsoft.AspNet.Hosting [Fact] public async Task StartupConfigureThrows_Fallback() { - var builder = CreateWebApplicationBuilder(); + var builder = CreateWebHostBuilder(); var server = new TestServer(); - var application = builder.UseServer(server).UseStartup().Build(); - using (application) + var host = builder.UseServer(server).UseStartup().Build(); + using (host) { - application.Start(); + host.Start(); await AssertResponseContains(server.RequestDelegate, "Exception from Configure"); } } @@ -126,23 +126,23 @@ namespace Microsoft.AspNet.Hosting [Fact] public void CaptureStartupErrorsByDefault() { - var applicationBuilder = new WebApplicationBuilder() + var hostBuilder = new WebHostBuilder() .UseServer(new TestServer()) .UseStartup(); // This should not throw - applicationBuilder.Build(); + hostBuilder.Build(); } [Fact] public void UseCaptureStartupErrorsHonored() { - var applicationBuilder = new WebApplicationBuilder() + var hostBuilder = new WebHostBuilder() .UseCaptureStartupErrors(false) .UseServer(new TestServer()) .UseStartup(); - var exception = Assert.Throws(() => applicationBuilder.Build()); + var exception = Assert.Throws(() => hostBuilder.Build()); Assert.Equal("A public method named 'ConfigureProduction' or 'Configure' could not be found in the 'Microsoft.AspNet.Hosting.Fakes.StartupBoom' type.", exception.Message); } @@ -158,14 +158,14 @@ namespace Microsoft.AspNet.Hosting var config = builder.Build(); var expected = "MY_TEST_ENVIRONMENT"; - var application = new WebApplicationBuilder() + var host = new WebHostBuilder() .UseConfiguration(config) .UseEnvironment(expected) .UseServer(new TestServer()) .UseStartup("Microsoft.AspNet.Hosting.Tests") .Build(); - Assert.Equal(expected, application.Services.GetService().EnvironmentName); + Assert.Equal(expected, host.Services.GetService().EnvironmentName); } [Fact] @@ -180,14 +180,14 @@ namespace Microsoft.AspNet.Hosting var config = builder.Build(); var expected = "MY_TEST_ENVIRONMENT"; - var application = new WebApplicationBuilder() + var host = new WebHostBuilder() .UseConfiguration(config) .UseEnvironment(expected) .UseServer(new TestServer()) .UseStartup("Microsoft.AspNet.Hosting.Tests") .Build(); - application.Dispose(); + host.Dispose(); } [Fact] @@ -201,17 +201,17 @@ namespace Microsoft.AspNet.Hosting .AddInMemoryCollection(vals); var config = builder.Build(); - var application = new WebApplicationBuilder() + var host = new WebHostBuilder() .UseConfiguration(config) .UseApplicationBasePath("/foo/bar") .UseServer(new TestServer()) .UseStartup("Microsoft.AspNet.Hosting.Tests") .Build(); - Assert.Equal("/foo/bar", application.Services.GetService().ApplicationBasePath); + Assert.Equal("/foo/bar", host.Services.GetService().ApplicationBasePath); } - private IWebApplicationBuilder CreateWebApplicationBuilder() + private IWebHostBuilder CreateWebHostBuilder() { var vals = new Dictionary { @@ -221,7 +221,7 @@ namespace Microsoft.AspNet.Hosting var builder = new ConfigurationBuilder() .AddInMemoryCollection(vals); var config = builder.Build(); - return new WebApplicationBuilder().UseConfiguration(config); + return new WebHostBuilder().UseConfiguration(config); } private async Task AssertResponseContains(RequestDelegate app, string expectedText) diff --git a/test/Microsoft.AspNet.Hosting.Tests/WebApplicationConfigurationsTests.cs b/test/Microsoft.AspNet.Hosting.Tests/WebHostConfigurationsTests.cs similarity index 78% rename from test/Microsoft.AspNet.Hosting.Tests/WebApplicationConfigurationsTests.cs rename to test/Microsoft.AspNet.Hosting.Tests/WebHostConfigurationsTests.cs index 8c27409f1c..b88eb51dc9 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/WebApplicationConfigurationsTests.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/WebHostConfigurationsTests.cs @@ -8,12 +8,12 @@ using Xunit; namespace Microsoft.AspNet.Hosting.Tests { - public class WebApplicationConfigurationTests + public class WebHostConfigurationTests { [Fact] public void DefaultCapturesStartupErrors() { - var config = new WebApplicationOptions(WebApplicationConfiguration.GetDefault()); + var config = new WebHostOptions(WebHostConfiguration.GetDefault()); Assert.True(config.CaptureStartupErrors); } @@ -31,7 +31,7 @@ namespace Microsoft.AspNet.Hosting.Tests { "captureStartupErrors", "true" } }; - var config = new WebApplicationOptions(new ConfigurationBuilder().AddInMemoryCollection(parameters).Build()); + var config = new WebHostOptions(new ConfigurationBuilder().AddInMemoryCollection(parameters).Build()); Assert.Equal("wwwroot", config.WebRoot); Assert.Equal("Microsoft.AspNet.Server.Kestrel", config.ServerFactoryLocation); @@ -45,7 +45,7 @@ namespace Microsoft.AspNet.Hosting.Tests public void ReadsOldEnvKey() { var parameters = new Dictionary() { { "ENV", "Development" } }; - var config = new WebApplicationOptions(new ConfigurationBuilder().AddInMemoryCollection(parameters).Build()); + var config = new WebHostOptions(new ConfigurationBuilder().AddInMemoryCollection(parameters).Build()); Assert.Equal("Development", config.Environment); } @@ -56,7 +56,7 @@ namespace Microsoft.AspNet.Hosting.Tests public void AllowsNumberForDetailedErrors(string value, bool expected) { var parameters = new Dictionary() { { "detailedErrors", value } }; - var config = new WebApplicationOptions(new ConfigurationBuilder().AddInMemoryCollection(parameters).Build()); + var config = new WebHostOptions(new ConfigurationBuilder().AddInMemoryCollection(parameters).Build()); Assert.Equal(expected, config.DetailedErrors); } diff --git a/test/Microsoft.AspNet.Hosting.Tests/WebApplicationTests.cs b/test/Microsoft.AspNet.Hosting.Tests/WebHostTests.cs similarity index 79% rename from test/Microsoft.AspNet.Hosting.Tests/WebApplicationTests.cs rename to test/Microsoft.AspNet.Hosting.Tests/WebHostTests.cs index a759535009..1526192d94 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/WebApplicationTests.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/WebHostTests.cs @@ -25,7 +25,7 @@ using Xunit; namespace Microsoft.AspNet.Hosting { - public class WebApplicationTests : IServerFactory, IServer + public class WebHostTests : IServerFactory, IServer { private readonly IList _startInstances = new List(); private IFeatureCollection _featuresSupportedByThisHost = NewFeatureCollection(); @@ -64,7 +64,7 @@ namespace Microsoft.AspNet.Hosting } [Fact] - public void WebApplicationThrowsWithNoServer() + public void WebHostThrowsWithNoServer() { var ex = Assert.Throws(() => CreateBuilder().Build().Start()); Assert.True(ex.Message.Contains("UseServer()")); @@ -87,9 +87,9 @@ namespace Microsoft.AspNet.Hosting var builder = new ConfigurationBuilder() .AddInMemoryCollection(vals); var config = builder.Build(); - var application = CreateBuilder(config).Build(); - application.Start(); - Assert.NotNull(application.Services.GetService()); + var host = CreateBuilder(config).Build(); + host.Start(); + Assert.NotNull(host.Services.GetService()); } [Fact] @@ -103,9 +103,9 @@ namespace Microsoft.AspNet.Hosting var builder = new ConfigurationBuilder() .AddInMemoryCollection(vals); var config = builder.Build(); - var application = CreateBuilder(config).Build(); - application.Start(); - Assert.NotNull(application.Services.GetService()); + var host = CreateBuilder(config).Build(); + host.Start(); + Assert.NotNull(host.Services.GetService()); } [Fact] @@ -119,10 +119,10 @@ namespace Microsoft.AspNet.Hosting var builder = new ConfigurationBuilder() .AddInMemoryCollection(vals); var config = builder.Build(); - var application = CreateBuilder(config).Build(); - application.Start(); - Assert.NotNull(application.Services.GetService()); - Assert.Equal("http://localhost:5000", application.ServerFeatures.Get().Addresses.First()); + var host = CreateBuilder(config).Build(); + host.Start(); + Assert.NotNull(host.Services.GetService()); + Assert.Equal("http://localhost:5000", host.ServerFeatures.Get().Addresses.First()); } [Fact] @@ -136,45 +136,45 @@ namespace Microsoft.AspNet.Hosting var builder = new ConfigurationBuilder() .AddInMemoryCollection(vals); var config = builder.Build(); - var application = CreateBuilder(config).Build(); - application.Start(); - var hostingEnvironment = application.Services.GetService(); + var host = CreateBuilder(config).Build(); + host.Start(); + var hostingEnvironment = host.Services.GetService(); Assert.NotNull(hostingEnvironment.Configuration); Assert.Equal("Microsoft.AspNet.Hosting.Tests", hostingEnvironment.Configuration["Server"]); } [Fact] - public void WebApplicationCanBeStarted() + public void WebHostCanBeStarted() { - var app = CreateBuilder() + var host = CreateBuilder() .UseServer((IServerFactory)this) .UseStartup("Microsoft.AspNet.Hosting.Tests") .Start(); - Assert.NotNull(app); + Assert.NotNull(host); Assert.Equal(1, _startInstances.Count); Assert.Equal(0, _startInstances[0].DisposeCalls); - app.Dispose(); + host.Dispose(); Assert.Equal(1, _startInstances[0].DisposeCalls); } [Fact] - public void WebApplicationShutsDownWhenTokenTriggers() + public void WebHostShutsDownWhenTokenTriggers() { - var app = CreateBuilder() + var host = CreateBuilder() .UseServer((IServerFactory)this) .UseStartup("Microsoft.AspNet.Hosting.Tests") .Build(); - var lifetime = app.Services.GetRequiredService(); + var lifetime = host.Services.GetRequiredService(); var cts = new CancellationTokenSource(); - Task.Run(() => app.Run(cts.Token)); + Task.Run(() => host.Run(cts.Token)); - // Wait on the app to be started + // Wait on the host to be started lifetime.ApplicationStarted.WaitHandle.WaitOne(); Assert.Equal(1, _startInstances.Count); @@ -182,16 +182,16 @@ namespace Microsoft.AspNet.Hosting cts.Cancel(); - // Wait on the app to shutdown + // Wait on the host to shutdown lifetime.ApplicationStopped.WaitHandle.WaitOne(); Assert.Equal(1, _startInstances[0].DisposeCalls); } [Fact] - public void WebApplicationDisposesServiceProvider() + public void WebHostDisposesServiceProvider() { - var application = CreateBuilder() + var host = CreateBuilder() .UseServer((IServerFactory)this) .ConfigureServices(s => { @@ -201,49 +201,49 @@ namespace Microsoft.AspNet.Hosting .UseStartup("Microsoft.AspNet.Hosting.Tests") .Build(); - application.Start(); + host.Start(); - var singleton = (FakeService)application.Services.GetService(); - var transient = (FakeService)application.Services.GetService(); + var singleton = (FakeService)host.Services.GetService(); + var transient = (FakeService)host.Services.GetService(); Assert.False(singleton.Disposed); Assert.False(transient.Disposed); - application.Dispose(); + host.Dispose(); Assert.True(singleton.Disposed); Assert.True(transient.Disposed); } [Fact] - public void WebApplicationNotifiesApplicationStarted() + public void WebHostNotifiesApplicationStarted() { - var application = CreateBuilder() + var host = CreateBuilder() .UseServer((IServerFactory)this) .Build(); - var applicationLifetime = application.Services.GetService(); + var applicationLifetime = host.Services.GetService(); Assert.False(applicationLifetime.ApplicationStarted.IsCancellationRequested); - using (application) + using (host) { - application.Start(); + host.Start(); Assert.True(applicationLifetime.ApplicationStarted.IsCancellationRequested); } } [Fact] - public void WebApplicationInjectsHostingEnvironment() + public void WebHostInjectsHostingEnvironment() { - var application = CreateBuilder() + var host = CreateBuilder() .UseServer((IServerFactory)this) .UseStartup("Microsoft.AspNet.Hosting.Tests") .UseEnvironment("WithHostingEnvironment") .Build(); - using (application) + using (host) { - application.Start(); - var env = application.Services.GetService(); + host.Start(); + var env = host.Services.GetService(); Assert.Equal("Changed", env.EnvironmentName); } } @@ -265,15 +265,15 @@ namespace Microsoft.AspNet.Hosting [Fact] public void CanCreateApplicationServicesWithAddedServices() { - var application = CreateBuilder().UseServer((IServerFactory)this).ConfigureServices(services => services.AddOptions()).Build(); - Assert.NotNull(application.Services.GetRequiredService>()); + var host = CreateBuilder().UseServer((IServerFactory)this).ConfigureServices(services => services.AddOptions()).Build(); + Assert.NotNull(host.Services.GetRequiredService>()); } [Fact] public void EnvDefaultsToProductionIfNoConfig() { - var application = CreateBuilder().UseServer((IServerFactory)this).Build(); - var env = application.Services.GetService(); + var host = CreateBuilder().UseServer((IServerFactory)this).Build(); + var env = host.Services.GetService(); Assert.Equal(EnvironmentName.Production, env.EnvironmentName); } @@ -282,7 +282,7 @@ namespace Microsoft.AspNet.Hosting { var vals = new Dictionary { - // Old key is actualy ASPNET_ENV but WebApplicationConfiguration expects environment + // Old key is actualy ASPNET_ENV but WebHostConfiguration expects environment // variable names stripped from ASPNET_ prefix so using just ENV here { "ENV", "Staging" } }; @@ -291,8 +291,8 @@ namespace Microsoft.AspNet.Hosting .AddInMemoryCollection(vals); var config = builder.Build(); - var application = CreateBuilder(config).UseServer((IServerFactory)this).Build(); - var env = application.Services.GetService(); + var host = CreateBuilder(config).UseServer((IServerFactory)this).Build(); + var env = host.Services.GetService(); Assert.Equal("Staging", env.EnvironmentName); } @@ -308,8 +308,8 @@ namespace Microsoft.AspNet.Hosting .AddInMemoryCollection(vals); var config = builder.Build(); - var application = CreateBuilder(config).UseServer((IServerFactory)this).Build(); - var env = application.Services.GetService(); + var host = CreateBuilder(config).UseServer((IServerFactory)this).Build(); + var env = host.Services.GetService(); Assert.Equal("Staging", env.EnvironmentName); } @@ -325,8 +325,8 @@ namespace Microsoft.AspNet.Hosting .AddInMemoryCollection(vals); var config = builder.Build(); - var application = CreateBuilder(config).UseServer((IServerFactory)this).Build(); - var env = application.Services.GetService(); + var host = CreateBuilder(config).UseServer((IServerFactory)this).Build(); + var env = host.Services.GetService(); Assert.Equal(Path.GetFullPath("testroot"), env.WebRootPath); Assert.True(env.WebRootFileProvider.GetFileInfo("TextFile.txt").Exists); } @@ -334,11 +334,11 @@ namespace Microsoft.AspNet.Hosting [Fact] public void IsEnvironment_Extension_Is_Case_Insensitive() { - var application = CreateBuilder().UseServer((IServerFactory)this).Build(); - using (application) + var host = CreateBuilder().UseServer((IServerFactory)this).Build(); + using (host) { - application.Start(); - var env = application.Services.GetRequiredService(); + host.Start(); + var env = host.Services.GetRequiredService(); Assert.True(env.IsEnvironment(EnvironmentName.Production)); Assert.True(env.IsEnvironment("producTion")); } @@ -366,7 +366,7 @@ namespace Microsoft.AspNet.Hosting } [Fact] - public void WebApplication_CreatesDefaultRequestIdentifierFeature_IfNotPresent() + public void WebHost_CreatesDefaultRequestIdentifierFeature_IfNotPresent() { // Arrange HttpContext httpContext = null; @@ -375,10 +375,10 @@ namespace Microsoft.AspNet.Hosting httpContext = innerHttpContext; return Task.FromResult(0); }); - var application = CreateApplication(requestDelegate); + var host = CreateHost(requestDelegate); // Act - application.Start(); + host.Start(); // Assert Assert.NotNull(httpContext); @@ -388,7 +388,7 @@ namespace Microsoft.AspNet.Hosting } [Fact] - public void WebApplication_DoesNot_CreateDefaultRequestIdentifierFeature_IfPresent() + public void WebHost_DoesNot_CreateDefaultRequestIdentifierFeature_IfPresent() { // Arrange HttpContext httpContext = null; @@ -399,10 +399,10 @@ namespace Microsoft.AspNet.Hosting }); var requestIdentifierFeature = new StubHttpRequestIdentifierFeature(); _featuresSupportedByThisHost[typeof(IHttpRequestIdentifierFeature)] = requestIdentifierFeature; - var application = CreateApplication(requestDelegate); + var host = CreateHost(requestDelegate); // Act - application.Start(); + host.Start(); // Assert Assert.NotNull(httpContext); @@ -410,17 +410,17 @@ namespace Microsoft.AspNet.Hosting } [Fact] - public void WebApplication_InvokesConfigureMethodsOnlyOnce() + public void WebHost_InvokesConfigureMethodsOnlyOnce() { - var application = CreateBuilder() + var host = CreateBuilder() .UseServer((IServerFactory)this) .UseStartup() .Build(); - using (application) + using (host) { - application.Start(); - var services = application.Services; - var services2 = application.Services; + host.Start(); + var services = host.Services; + var services2 = host.Services; Assert.Equal(1, CountStartup.ConfigureCount); Assert.Equal(1, CountStartup.ConfigureServicesCount); } @@ -443,7 +443,7 @@ namespace Microsoft.AspNet.Hosting } [Fact] - public void WebApplication_ThrowsForBadConfigureServiceSignature() + public void WebHost_ThrowsForBadConfigureServiceSignature() { var builder = CreateBuilder() .UseServer((IServerFactory)this) @@ -459,7 +459,7 @@ namespace Microsoft.AspNet.Hosting public void Configure(IApplicationBuilder app) { } } - private IWebApplication CreateApplication(RequestDelegate requestDelegate) + private IWebHost CreateHost(RequestDelegate requestDelegate) { var builder = CreateBuilder() .UseServer((IServerFactory)this) @@ -474,12 +474,12 @@ namespace Microsoft.AspNet.Hosting private void RunMapPath(string virtualPath, string expectedSuffix) { - var application = CreateBuilder().UseServer((IServerFactory)this).Build(); + var host = CreateBuilder().UseServer((IServerFactory)this).Build(); - using (application) + using (host) { - application.Start(); - var env = application.Services.GetRequiredService(); + host.Start(); + var env = host.Services.GetRequiredService(); // MapPath requires webroot to be set, we don't care // about file provider so just set it here env.WebRootPath = "."; @@ -489,9 +489,9 @@ namespace Microsoft.AspNet.Hosting } } - private IWebApplicationBuilder CreateBuilder(IConfiguration config = null) + private IWebHostBuilder CreateBuilder(IConfiguration config = null) { - return new WebApplicationBuilder().UseConfiguration(config ?? new ConfigurationBuilder().Build()).UseStartup("Microsoft.AspNet.Hosting.Tests"); + return new WebHostBuilder().UseConfiguration(config ?? new ConfigurationBuilder().Build()).UseStartup("Microsoft.AspNet.Hosting.Tests"); } public void Start(IHttpApplication application) diff --git a/test/Microsoft.AspNet.TestHost.Tests/ClientHandlerTests.cs b/test/Microsoft.AspNet.TestHost.Tests/ClientHandlerTests.cs index b439df01bd..06b570afb3 100644 --- a/test/Microsoft.AspNet.TestHost.Tests/ClientHandlerTests.cs +++ b/test/Microsoft.AspNet.TestHost.Tests/ClientHandlerTests.cs @@ -283,10 +283,10 @@ namespace Microsoft.AspNet.TestHost { // This logger will attempt to access information from HttpRequest once the HttpContext is created var logger = new VerifierLogger(); - var builder = new WebApplicationBuilder() + var builder = new WebHostBuilder() .ConfigureServices(services => { - services.AddSingleton>(logger); + services.AddSingleton>(logger); }) .Configure(app => { @@ -301,7 +301,7 @@ namespace Microsoft.AspNet.TestHost var result = await server.CreateClient().GetStringAsync("/"); } - private class VerifierLogger : ILogger + private class VerifierLogger : ILogger { public IDisposable BeginScopeImpl(object state) => new NoopDispoasble(); diff --git a/test/Microsoft.AspNet.TestHost.Tests/RequestBuilderTests.cs b/test/Microsoft.AspNet.TestHost.Tests/RequestBuilderTests.cs index a47cf1f00c..77b2e6e9b2 100644 --- a/test/Microsoft.AspNet.TestHost.Tests/RequestBuilderTests.cs +++ b/test/Microsoft.AspNet.TestHost.Tests/RequestBuilderTests.cs @@ -14,7 +14,7 @@ namespace Microsoft.AspNet.TestHost [FrameworkSkipCondition(RuntimeFrameworks.Mono)] public void AddRequestHeader() { - var builder = new WebApplicationBuilder().Configure(app => { }); + var builder = new WebHostBuilder().Configure(app => { }); var server = new TestServer(builder); server.CreateRequest("/") .AddHeader("Host", "MyHost:90") @@ -27,7 +27,7 @@ namespace Microsoft.AspNet.TestHost [Fact] public void AddContentHeaders() { - var builder = new WebApplicationBuilder().Configure(app => { }); + var builder = new WebHostBuilder().Configure(app => { }); var server = new TestServer(builder); server.CreateRequest("/") .AddHeader("Content-Type", "Test/Value") diff --git a/test/Microsoft.AspNet.TestHost.Tests/TestClientTests.cs b/test/Microsoft.AspNet.TestHost.Tests/TestClientTests.cs index 42a1a7752f..4312836514 100644 --- a/test/Microsoft.AspNet.TestHost.Tests/TestClientTests.cs +++ b/test/Microsoft.AspNet.TestHost.Tests/TestClientTests.cs @@ -30,7 +30,7 @@ namespace Microsoft.AspNet.TestHost var expected = "GET Response"; RequestDelegate appDelegate = ctx => ctx.Response.WriteAsync(expected); - var builder = new WebApplicationBuilder().Configure(app => app.Run(appDelegate)); + var builder = new WebHostBuilder().Configure(app => app.Run(appDelegate)); var server = new TestServer(builder); var client = server.CreateClient(); @@ -53,7 +53,7 @@ namespace Microsoft.AspNet.TestHost Assert.Equal("/", ctx.Request.Path.Value); return ctx.Response.WriteAsync(expected); }; - var builder = new WebApplicationBuilder().Configure(app => app.Run(appDelegate)); + var builder = new WebHostBuilder().Configure(app => app.Run(appDelegate)); var server = new TestServer(builder); var client = server.CreateClient(); @@ -76,7 +76,7 @@ namespace Microsoft.AspNet.TestHost Assert.Equal("/", ctx.Request.Path.Value); return ctx.Response.WriteAsync(expected); }; - var builder = new WebApplicationBuilder().Configure(app => app.Run(appDelegate)); + var builder = new WebHostBuilder().Configure(app => app.Run(appDelegate)); var server = new TestServer(builder); var client = server.CreateClient(); @@ -94,7 +94,7 @@ namespace Microsoft.AspNet.TestHost // Arrange RequestDelegate appDelegate = ctx => ctx.Response.WriteAsync(new StreamReader(ctx.Request.Body).ReadToEnd() + " PUT Response"); - var builder = new WebApplicationBuilder().Configure(app => app.Run(appDelegate)); + var builder = new WebHostBuilder().Configure(app => app.Run(appDelegate)); var server = new TestServer(builder); var client = server.CreateClient(); @@ -113,7 +113,7 @@ namespace Microsoft.AspNet.TestHost // Arrange RequestDelegate appDelegate = async ctx => await ctx.Response.WriteAsync(new StreamReader(ctx.Request.Body).ReadToEnd() + " POST Response"); - var builder = new WebApplicationBuilder().Configure(app => app.Run(appDelegate)); + var builder = new WebHostBuilder().Configure(app => app.Run(appDelegate)); var server = new TestServer(builder); var client = server.CreateClient(); @@ -154,10 +154,10 @@ namespace Microsoft.AspNet.TestHost } } }; - var builder = new WebApplicationBuilder() + var builder = new WebHostBuilder() .ConfigureServices(services => { - services.AddSingleton>(logger); + services.AddSingleton>(logger); }) .Configure(app => { @@ -197,7 +197,7 @@ namespace Microsoft.AspNet.TestHost } - private class VerifierLogger : ILogger + private class VerifierLogger : ILogger { public IDisposable BeginScopeImpl(object state) => new NoopDispoasble(); @@ -227,7 +227,7 @@ namespace Microsoft.AspNet.TestHost websocket.Dispose(); } }; - var builder = new WebApplicationBuilder().Configure(app => + var builder = new WebHostBuilder().Configure(app => { app.Run(appDelegate); }); @@ -261,7 +261,7 @@ namespace Microsoft.AspNet.TestHost } } }; - var builder = new WebApplicationBuilder().Configure(app => + var builder = new WebHostBuilder().Configure(app => { app.Run(appDelegate); }); @@ -310,7 +310,7 @@ namespace Microsoft.AspNet.TestHost }; // Act - var builder = new WebApplicationBuilder().Configure(app => app.Run(appDelegate)); + var builder = new WebHostBuilder().Configure(app => app.Run(appDelegate)); var server = new TestServer(builder); var client = server.CreateClient(); var request = new HttpRequestMessage(HttpMethod.Get, "http://localhost:12345"); @@ -342,7 +342,7 @@ namespace Microsoft.AspNet.TestHost }; // Act - var builder = new WebApplicationBuilder().Configure(app => app.Run(appDelegate)); + var builder = new WebHostBuilder().Configure(app => app.Run(appDelegate)); var server = new TestServer(builder); var client = server.CreateClient(); var cts = new CancellationTokenSource(); diff --git a/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs b/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs index 2919f940ba..d544e1bf14 100644 --- a/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs +++ b/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs @@ -27,14 +27,14 @@ namespace Microsoft.AspNet.TestHost { // Arrange // Act & Assert (Does not throw) - new TestServer(new WebApplicationBuilder().Configure(app => { })); + new TestServer(new WebHostBuilder().Configure(app => { })); } [Fact] public void DoesNotCaptureStartupErrorsByDefault() { - var builder = new WebApplicationBuilder() + var builder = new WebHostBuilder() .Configure(app => { throw new InvalidOperationException(); @@ -47,7 +47,7 @@ namespace Microsoft.AspNet.TestHost [Fact] public void CaptureStartupErrorsSettingPreserved() { - var builder = new WebApplicationBuilder() + var builder = new WebHostBuilder() .UseCaptureStartupErrors(true) .Configure(app => { @@ -62,7 +62,7 @@ namespace Microsoft.AspNet.TestHost public void ApplicationServicesAvailableFromTestServer() { var testService = new TestService(); - var builder = new WebApplicationBuilder() + var builder = new WebHostBuilder() .Configure(app => { }) .ConfigureServices(services => { @@ -70,14 +70,14 @@ namespace Microsoft.AspNet.TestHost }); var server = new TestServer(builder); - Assert.Equal(testService, server.Application.Services.GetRequiredService()); + Assert.Equal(testService, server.Host.Services.GetRequiredService()); } [ConditionalFact] [FrameworkSkipCondition(RuntimeFrameworks.Mono, SkipReason = "Hangs randomly (issue #507)")] public async Task RequestServicesAutoCreated() { - var builder = new WebApplicationBuilder().Configure(app => + var builder = new WebHostBuilder().Configure(app => { app.Run(context => { @@ -114,7 +114,7 @@ namespace Microsoft.AspNet.TestHost [FrameworkSkipCondition(RuntimeFrameworks.Mono, SkipReason = "Hangs randomly (issue #507)")] public async Task CustomServiceProviderSetsApplicationServices() { - var builder = new WebApplicationBuilder().UseStartup(); + var builder = new WebHostBuilder().UseStartup(); var server = new TestServer(builder); string result = await server.CreateClient().GetStringAsync("/path"); Assert.Equal("ApplicationServicesEqual:True", result); @@ -157,7 +157,7 @@ namespace Microsoft.AspNet.TestHost [FrameworkSkipCondition(RuntimeFrameworks.Mono, SkipReason = "Hangs randomly (issue #507)")] public async Task ExistingRequestServicesWillNotBeReplaced() { - var builder = new WebApplicationBuilder().Configure(app => + var builder = new WebHostBuilder().Configure(app => { app.Run(context => { @@ -179,7 +179,7 @@ namespace Microsoft.AspNet.TestHost [FrameworkSkipCondition(RuntimeFrameworks.Mono, SkipReason = "Hangs randomly (issue #507)")] public async Task CanSetCustomServiceProvider() { - var builder = new WebApplicationBuilder().Configure(app => + var builder = new WebHostBuilder().Configure(app => { app.Run(context => { @@ -229,7 +229,7 @@ namespace Microsoft.AspNet.TestHost public async Task ExistingServiceProviderFeatureWillNotBeReplaced() { var appServices = new ServiceCollection().BuildServiceProvider(); - var builder = new WebApplicationBuilder().Configure(app => + var builder = new WebHostBuilder().Configure(app => { app.Run(context => { @@ -271,7 +271,7 @@ namespace Microsoft.AspNet.TestHost [FrameworkSkipCondition(RuntimeFrameworks.Mono, SkipReason = "Hangs randomly (issue #507)")] public async Task WillReplaceServiceProviderFeatureWithNullRequestServices() { - var builder = new WebApplicationBuilder().Configure(app => + var builder = new WebHostBuilder().Configure(app => { app.Run(context => { @@ -293,7 +293,7 @@ namespace Microsoft.AspNet.TestHost [FrameworkSkipCondition(RuntimeFrameworks.Mono, SkipReason = "Hangs randomly (issue #507)")] public async Task CanAccessLogger() { - var builder = new WebApplicationBuilder().Configure(app => + var builder = new WebHostBuilder().Configure(app => { app.Run(context => { @@ -311,7 +311,7 @@ namespace Microsoft.AspNet.TestHost [FrameworkSkipCondition(RuntimeFrameworks.Mono, SkipReason = "Hangs randomly (issue #507)")] public async Task CanAccessHttpContext() { - var builder = new WebApplicationBuilder().Configure(app => + var builder = new WebHostBuilder().Configure(app => { app.Run(context => { @@ -343,7 +343,7 @@ namespace Microsoft.AspNet.TestHost [FrameworkSkipCondition(RuntimeFrameworks.Mono, SkipReason = "Hangs randomly (issue #507)")] public async Task CanAddNewHostServices() { - var builder = new WebApplicationBuilder().Configure(app => + var builder = new WebHostBuilder().Configure(app => { app.Run(context => { @@ -366,7 +366,7 @@ namespace Microsoft.AspNet.TestHost [FrameworkSkipCondition(RuntimeFrameworks.Mono, SkipReason = "Hangs randomly (issue #507)")] public async Task CreateInvokesApp() { - var builder = new WebApplicationBuilder().Configure(app => + var builder = new WebHostBuilder().Configure(app => { app.Run(context => { @@ -383,7 +383,7 @@ namespace Microsoft.AspNet.TestHost [FrameworkSkipCondition(RuntimeFrameworks.Mono, SkipReason = "Hangs randomly (issue #507)")] public async Task DisposeStreamIgnored() { - var builder = new WebApplicationBuilder().Configure(app => + var builder = new WebHostBuilder().Configure(app => { app.Run(async context => { @@ -402,7 +402,7 @@ namespace Microsoft.AspNet.TestHost [FrameworkSkipCondition(RuntimeFrameworks.Mono, SkipReason = "Hangs randomly (issue #507)")] public async Task DisposedServerThrows() { - var builder = new WebApplicationBuilder().Configure(app => + var builder = new WebHostBuilder().Configure(app => { app.Run(async context => { @@ -422,7 +422,7 @@ namespace Microsoft.AspNet.TestHost [FrameworkSkipCondition(RuntimeFrameworks.Mono, SkipReason = "Hangs randomly (issue #507)")] public async Task CancelAborts() { - var builder = new WebApplicationBuilder() + var builder = new WebHostBuilder() .Configure(app => { app.Run(context => @@ -441,7 +441,7 @@ namespace Microsoft.AspNet.TestHost [FrameworkSkipCondition(RuntimeFrameworks.Mono, SkipReason = "Hangs randomly (issue #507)")] public async Task CanCreateViaStartupType() { - var builder = new WebApplicationBuilder() + var builder = new WebHostBuilder() .UseStartup(); var server = new TestServer(builder); HttpResponseMessage result = await server.CreateClient().GetAsync("/"); @@ -453,7 +453,7 @@ namespace Microsoft.AspNet.TestHost [FrameworkSkipCondition(RuntimeFrameworks.Mono, SkipReason = "Hangs randomly (issue #507)")] public async Task CanCreateViaStartupTypeAndSpecifyEnv() { - var builder = new WebApplicationBuilder() + var builder = new WebHostBuilder() .UseStartup() .UseEnvironment("Foo"); var server = new TestServer(builder); @@ -469,7 +469,7 @@ namespace Microsoft.AspNet.TestHost { DiagnosticListener diagnosticListener = null; - var builder = new WebApplicationBuilder() + var builder = new WebHostBuilder() .Configure(app => { diagnosticListener = app.ApplicationServices.GetRequiredService(); @@ -498,7 +498,7 @@ namespace Microsoft.AspNet.TestHost public async Task ExceptionDiagnosticAvailable() { DiagnosticListener diagnosticListener = null; - var builder = new WebApplicationBuilder().Configure(app => + var builder = new WebHostBuilder().Configure(app => { diagnosticListener = app.ApplicationServices.GetRequiredService(); app.Run(context => From cb029209a386d596b93d531d9ba1baf69aef980d Mon Sep 17 00:00:00 2001 From: David Fowler Date: Wed, 20 Jan 2016 22:14:17 +0000 Subject: [PATCH 501/987] Remove top level environment variables from default config --- src/Microsoft.AspNet.Hosting/WebHostConfiguration.cs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/Microsoft.AspNet.Hosting/WebHostConfiguration.cs b/src/Microsoft.AspNet.Hosting/WebHostConfiguration.cs index 76d539117a..dc331e9adb 100644 --- a/src/Microsoft.AspNet.Hosting/WebHostConfiguration.cs +++ b/src/Microsoft.AspNet.Hosting/WebHostConfiguration.cs @@ -20,12 +20,11 @@ namespace Microsoft.AspNet.Hosting { WebHostDefaults.CaptureStartupErrorsKey, "true" } }; - // We are adding all environment variables first and then adding the ASPNET_ ones - // with the prefix removed to unify with the command line and config file formats + // Setup the default locations for finding hosting configuration options + // hosting.json, ASPNET_ prefixed env variables and command line arguments var configBuilder = new ConfigurationBuilder() .AddInMemoryCollection(defaultSettings) .AddJsonFile(WebHostDefaults.HostingJsonFile, optional: true) - .AddEnvironmentVariables() .AddEnvironmentVariables(prefix: WebHostDefaults.EnvironmentVariablesPrefix); if (args != null) From 802dbea6db20ec978ba9e65c8a7e7637b2bf945f Mon Sep 17 00:00:00 2001 From: Pranav K Date: Wed, 20 Jan 2016 20:50:18 -0800 Subject: [PATCH 502/987] Reacting to CoreCLR package version change --- src/Microsoft.AspNet.Server.Testing/project.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Microsoft.AspNet.Server.Testing/project.json b/src/Microsoft.AspNet.Server.Testing/project.json index e6af8b13d7..cfa8859965 100644 --- a/src/Microsoft.AspNet.Server.Testing/project.json +++ b/src/Microsoft.AspNet.Server.Testing/project.json @@ -30,7 +30,7 @@ "System.IO.FileSystem": "4.0.1-*", "System.Net.Http": "4.0.1-*", "System.Net.Primitives": "4.0.11-*", - "System.Runtime.Extensions": "4.0.11-*", + "System.Runtime.Extensions": "4.1.0-*", "System.Text.RegularExpressions": "4.0.11-*", "System.Threading": "4.0.11-*", "System.Threading.Thread": "4.0.0-*" From 70c69178f69b09d4c59fa9b41d9ee7b99b302541 Mon Sep 17 00:00:00 2001 From: Brennan Date: Thu, 21 Jan 2016 16:54:44 -0800 Subject: [PATCH 503/987] React to Fileprovider namespace changes --- .../IHostingEnvironment.cs | 2 +- src/Microsoft.AspNet.Hosting.Abstractions/project.json | 4 ++-- src/Microsoft.AspNet.Hosting/Internal/HostingEnvironment.cs | 2 +- .../Internal/HostingEnvironmentExtensions.cs | 2 +- src/Microsoft.AspNet.Hosting/Internal/NullFileProvider.cs | 2 +- src/Microsoft.AspNet.Hosting/project.json | 2 +- .../HostingEnvironmentExtensionsTests.cs | 2 +- 7 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/Microsoft.AspNet.Hosting.Abstractions/IHostingEnvironment.cs b/src/Microsoft.AspNet.Hosting.Abstractions/IHostingEnvironment.cs index 6c9ddf464b..5878bd489c 100644 --- a/src/Microsoft.AspNet.Hosting.Abstractions/IHostingEnvironment.cs +++ b/src/Microsoft.AspNet.Hosting.Abstractions/IHostingEnvironment.cs @@ -1,8 +1,8 @@ // 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.FileProviders; using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.FileProviders; namespace Microsoft.AspNet.Hosting { diff --git a/src/Microsoft.AspNet.Hosting.Abstractions/project.json b/src/Microsoft.AspNet.Hosting.Abstractions/project.json index f6a665e878..e23808c2f1 100644 --- a/src/Microsoft.AspNet.Hosting.Abstractions/project.json +++ b/src/Microsoft.AspNet.Hosting.Abstractions/project.json @@ -11,10 +11,10 @@ }, "dependencies": { "Microsoft.AspNet.Http.Abstractions": "1.0.0-*", - "Microsoft.AspNet.FileProviders.Abstractions": "1.0.0-*", "Microsoft.AspNet.Hosting.Server.Abstractions": "1.0.0-*", "Microsoft.Extensions.Configuration.Abstractions": "1.0.0-*", - "Microsoft.Extensions.DependencyInjection.Abstractions": "1.0.0-*" + "Microsoft.Extensions.DependencyInjection.Abstractions": "1.0.0-*", + "Microsoft.Extensions.FileProviders.Abstractions": "1.0.0-*" }, "frameworks": { "net451": {}, diff --git a/src/Microsoft.AspNet.Hosting/Internal/HostingEnvironment.cs b/src/Microsoft.AspNet.Hosting/Internal/HostingEnvironment.cs index 0428ce490b..ac87b19b94 100644 --- a/src/Microsoft.AspNet.Hosting/Internal/HostingEnvironment.cs +++ b/src/Microsoft.AspNet.Hosting/Internal/HostingEnvironment.cs @@ -1,8 +1,8 @@ // 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.FileProviders; using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.FileProviders; namespace Microsoft.AspNet.Hosting.Internal { diff --git a/src/Microsoft.AspNet.Hosting/Internal/HostingEnvironmentExtensions.cs b/src/Microsoft.AspNet.Hosting/Internal/HostingEnvironmentExtensions.cs index 36f8c9bb41..d491a4fef7 100644 --- a/src/Microsoft.AspNet.Hosting/Internal/HostingEnvironmentExtensions.cs +++ b/src/Microsoft.AspNet.Hosting/Internal/HostingEnvironmentExtensions.cs @@ -3,9 +3,9 @@ using System; using System.IO; -using Microsoft.AspNet.FileProviders; using Microsoft.AspNet.Hosting.Internal; using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.FileProviders; namespace Microsoft.AspNet.Hosting.Internal { diff --git a/src/Microsoft.AspNet.Hosting/Internal/NullFileProvider.cs b/src/Microsoft.AspNet.Hosting/Internal/NullFileProvider.cs index 73f0bebc93..5448e6a5ec 100644 --- a/src/Microsoft.AspNet.Hosting/Internal/NullFileProvider.cs +++ b/src/Microsoft.AspNet.Hosting/Internal/NullFileProvider.cs @@ -5,7 +5,7 @@ using System; using System.Collections; using System.Collections.Generic; using System.IO; -using Microsoft.AspNet.FileProviders; +using Microsoft.Extensions.FileProviders; using Microsoft.Extensions.Primitives; namespace Microsoft.AspNet.Hosting.Internal diff --git a/src/Microsoft.AspNet.Hosting/project.json b/src/Microsoft.AspNet.Hosting/project.json index 302aa0ba37..7677512471 100644 --- a/src/Microsoft.AspNet.Hosting/project.json +++ b/src/Microsoft.AspNet.Hosting/project.json @@ -10,11 +10,11 @@ "keyFile": "../../tools/Key.snk" }, "dependencies": { - "Microsoft.AspNet.FileProviders.Physical": "1.0.0-*", "Microsoft.AspNet.Hosting.Abstractions": "1.0.0-*", "Microsoft.AspNet.Hosting.Server.Abstractions": "1.0.0-*", "Microsoft.AspNet.Http": "1.0.0-*", "Microsoft.AspNet.Http.Extensions": "1.0.0-*", + "Microsoft.Extensions.FileProviders.Physical": "1.0.0-*", "Microsoft.Extensions.Options": "1.0.0-*", "Microsoft.Extensions.Configuration": "1.0.0-*", "Microsoft.Extensions.Configuration.CommandLine": "1.0.0-*", diff --git a/test/Microsoft.AspNet.Hosting.Tests/HostingEnvironmentExtensionsTests.cs b/test/Microsoft.AspNet.Hosting.Tests/HostingEnvironmentExtensionsTests.cs index 60a413acf5..709385fc66 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/HostingEnvironmentExtensionsTests.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/HostingEnvironmentExtensionsTests.cs @@ -3,9 +3,9 @@ using System; using System.IO; -using Microsoft.AspNet.FileProviders; using Microsoft.AspNet.Hosting.Internal; using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.FileProviders; using Xunit; namespace Microsoft.AspNet.Hosting.Tests From c24e0297b2f26425cbffc20fe85f30a5b3ad2951 Mon Sep 17 00:00:00 2001 From: "N. Taylor Mullen" Date: Fri, 22 Jan 2016 12:21:33 -0800 Subject: [PATCH 504/987] Rename AspNet 5 folders and files. See https://github.com/aspnet/Announcements/issues/144 for more information. --- .../EnvironmentName.cs | 0 .../HostingEnvironmentExtensions.cs | 0 .../IApplicationLifetime.cs | 0 .../IHostingEnvironment.cs | 0 .../IStartupFilter.cs | 0 .../IWebHost.cs | 0 .../IWebHostBuilder.cs | 0 ...oft.AspNetCore.Hosting.Abstractions.xproj} | 0 .../Properties/AssemblyInfo.cs | 0 .../WebHostDefaults.cs | 0 .../project.json | 0 .../IHttpApplication.cs | 0 .../IServer.cs | 0 .../IServerAddressesFeature.cs | 0 .../IServerFactory.cs | 0 ...NetCore.Hosting.Server.Abstractions.xproj} | 0 .../Properties/AssemblyInfo.cs | 0 .../project.json | 0 ....AspNetCore.Hosting.WindowsServices.xproj} | 36 +++++++-------- .../Properties/AssemblyInfo.cs | 0 .../WebHostService.cs | 0 .../WebHostWindowsServiceExtensions.cs | 0 .../project.json | 44 +++++++++---------- .../Builder/ApplicationBuilderFactory.cs | 0 .../Builder/IApplicationBuilderFactory.cs | 0 .../Internal/ApplicationLifetime.cs | 0 .../AutoRequestServicesStartupFilter.cs | 0 .../Internal/HostingApplication.cs | 0 .../Internal/HostingEnvironment.cs | 0 .../Internal/HostingEnvironmentExtensions.cs | 0 .../Internal/HostingLoggerExtensions.cs | 0 .../Internal/LoggerEventIds.cs | 0 .../Internal/NullFileProvider.cs | 0 .../RequestServicesContainerFeature.cs | 0 .../RequestServicesContainerMiddleware.cs | 0 .../Internal/WebHost.cs | 0 .../Internal/WebHostOptions.cs | 0 .../Microsoft.AspNetCore.Hosting.xproj} | 0 .../Properties/AssemblyInfo.cs | 0 .../Server/IServerLoader.cs | 0 .../Server/ServerLoader.cs | 0 .../Startup/ConfigureDelegate.cs | 0 .../Startup/ConfigureServicesDelegate.cs | 0 .../Startup/IStartupLoader.cs | 0 .../Startup/StartupExceptionPage.cs | 0 .../Startup/StartupLoader.cs | 0 .../Startup/StartupMethods.cs | 0 .../WebHostBuilder.cs | 0 .../WebHostBuilderExtensions.cs | 0 .../WebHostConfiguration.cs | 0 .../WebHostExtensions.cs | 0 .../compiler/resources/GenericError.html | 0 .../resources/GenericError_Exception.html | 0 .../resources/GenericError_Footer.html | 0 .../resources/GenericError_Message.html | 0 .../project.json | 0 .../Common/DeploymentParameters.cs | 0 .../Common/DeploymentResult.cs | 0 .../Common/DotnetArchitecture.cs | 0 .../Common/DotnetFlavor.cs | 0 .../Common/RetryHelper.cs | 0 .../Common/ServerType.cs | 0 .../Common/TestUriHelper.cs | 0 .../Deployers/ApplicationDeployer.cs | 0 .../Deployers/ApplicationDeployerFactory.cs | 0 .../Deployers/IApplicationDeployer.cs | 0 .../Deployers/IISDeployer.cs | 0 .../Deployers/IISExpressDeployer.cs | 0 .../Deployers/SelfHostDeployer.cs | 0 ...Microsoft.AspNetCore.Server.Testing.xproj} | 0 .../Properties/AssemblyInfo.cs | 0 .../project.json | 0 .../xunit/SkipIfCurrentRuntimeIsCoreClr.cs | 0 .../SkipIfIISVariationsNotEnabledAttribute.cs | 0 .../xunit/SkipOn32BitOSAttribute.cs | 0 .../ClientHandler.cs | 0 .../Microsoft.AspNetCore.TestHost.xproj} | 0 .../Properties/AssemblyInfo.cs | 0 .../RequestBuilder.cs | 0 .../RequestFeature.cs | 0 .../ResponseFeature.cs | 0 .../ResponseStream.cs | 0 .../TestServer.cs | 0 .../TestWebSocket.cs | 0 .../WebSocketClient.cs | 0 .../project.json | 0 .../Fakes/FakeOptions.cs | 0 .../Fakes/FakeService.cs | 0 .../Fakes/IFactoryService.cs | 0 .../Fakes/IFakeEveryService.cs | 0 .../Fakes/IFakeScopedService.cs | 0 .../Fakes/IFakeService.cs | 0 .../Fakes/IFakeServiceInstance.cs | 0 .../Fakes/IFakeSingletonService.cs | 0 .../Fakes/IFakeStartupCallback.cs | 0 .../Fakes/INonexistentService.cs | 0 .../Fakes/RuntimeEnvironment.cs | 0 .../Fakes/Startup.cs | 0 .../Fakes/StartupBase.cs | 0 .../Fakes/StartupBoom.cs | 0 .../Fakes/StartupConfigureServicesThrows.cs | 0 .../Fakes/StartupConfigureThrows.cs | 0 .../Fakes/StartupCtorThrows.cs | 0 .../Fakes/StartupNoServices.cs | 0 .../Fakes/StartupPrivateConfigure.cs | 0 .../Fakes/StartupStaticCtorThrows.cs | 0 .../Fakes/StartupThrowTypeLoadException.cs | 0 .../Fakes/StartupTwoConfigureServices.cs | 0 .../Fakes/StartupTwoConfigures.cs | 0 .../Fakes/StartupWithConfigureServices.cs | 0 ...StartupWithConfigureServicesNotResolved.cs | 0 .../Fakes/StartupWithHostingEnvironment.cs | 0 .../Fakes/StartupWithNullConfigureServices.cs | 0 .../Fakes/StartupWithServices.cs | 0 .../HostingEnvironmentExtensionsTests.cs | 0 .../Microsoft.AspNetCore.Hosting.Tests.xproj} | 0 .../StartupManagerTests.cs | 0 .../WebHostBuilderTests.cs | 0 .../WebHostConfigurationsTests.cs | 0 .../WebHostTests.cs | 0 .../project.json | 0 .../testroot/TextFile.txt | 0 .../testroot/wwwroot/README | 0 .../ClientHandlerTests.cs | 0 ...Microsoft.AspNetCore.TestHost.Tests.xproj} | 0 .../Properties/AssemblyInfo.cs | 0 .../RequestBuilderTests.cs | 0 .../ResponseFeatureTests.cs | 0 .../TestClientTests.cs | 0 .../TestServerTests.cs | 0 .../project.json | 0 131 files changed, 40 insertions(+), 40 deletions(-) rename src/{Microsoft.AspNet.Hosting.Abstractions => Microsoft.AspNetCore.Hosting.Abstractions}/EnvironmentName.cs (100%) rename src/{Microsoft.AspNet.Hosting.Abstractions => Microsoft.AspNetCore.Hosting.Abstractions}/HostingEnvironmentExtensions.cs (100%) rename src/{Microsoft.AspNet.Hosting.Abstractions => Microsoft.AspNetCore.Hosting.Abstractions}/IApplicationLifetime.cs (100%) rename src/{Microsoft.AspNet.Hosting.Abstractions => Microsoft.AspNetCore.Hosting.Abstractions}/IHostingEnvironment.cs (100%) rename src/{Microsoft.AspNet.Hosting.Abstractions => Microsoft.AspNetCore.Hosting.Abstractions}/IStartupFilter.cs (100%) rename src/{Microsoft.AspNet.Hosting.Abstractions => Microsoft.AspNetCore.Hosting.Abstractions}/IWebHost.cs (100%) rename src/{Microsoft.AspNet.Hosting.Abstractions => Microsoft.AspNetCore.Hosting.Abstractions}/IWebHostBuilder.cs (100%) rename src/{Microsoft.AspNet.Hosting.Abstractions/Microsoft.AspNet.Hosting.Abstractions.xproj => Microsoft.AspNetCore.Hosting.Abstractions/Microsoft.AspNetCore.Hosting.Abstractions.xproj} (100%) rename src/{Microsoft.AspNet.Hosting.Abstractions => Microsoft.AspNetCore.Hosting.Abstractions}/Properties/AssemblyInfo.cs (100%) rename src/{Microsoft.AspNet.Hosting.Abstractions => Microsoft.AspNetCore.Hosting.Abstractions}/WebHostDefaults.cs (100%) rename src/{Microsoft.AspNet.Hosting.Abstractions => Microsoft.AspNetCore.Hosting.Abstractions}/project.json (100%) rename src/{Microsoft.AspNet.Hosting.Server.Abstractions => Microsoft.AspNetCore.Hosting.Server.Abstractions}/IHttpApplication.cs (100%) rename src/{Microsoft.AspNet.Hosting.Server.Abstractions => Microsoft.AspNetCore.Hosting.Server.Abstractions}/IServer.cs (100%) rename src/{Microsoft.AspNet.Hosting.Server.Abstractions => Microsoft.AspNetCore.Hosting.Server.Abstractions}/IServerAddressesFeature.cs (100%) rename src/{Microsoft.AspNet.Hosting.Server.Abstractions => Microsoft.AspNetCore.Hosting.Server.Abstractions}/IServerFactory.cs (100%) rename src/{Microsoft.AspNet.Hosting.Server.Abstractions/Microsoft.AspNet.Hosting.Server.Abstractions.xproj => Microsoft.AspNetCore.Hosting.Server.Abstractions/Microsoft.AspNetCore.Hosting.Server.Abstractions.xproj} (100%) rename src/{Microsoft.AspNet.Hosting.Server.Abstractions => Microsoft.AspNetCore.Hosting.Server.Abstractions}/Properties/AssemblyInfo.cs (100%) rename src/{Microsoft.AspNet.Hosting.Server.Abstractions => Microsoft.AspNetCore.Hosting.Server.Abstractions}/project.json (100%) rename src/{Microsoft.AspNet.Hosting.WindowsServices/Microsoft.AspNet.Hosting.WindowsServices.xproj => Microsoft.AspNetCore.Hosting.WindowsServices/Microsoft.AspNetCore.Hosting.WindowsServices.xproj} (97%) rename src/{Microsoft.AspNet.Hosting.WindowsServices => Microsoft.AspNetCore.Hosting.WindowsServices}/Properties/AssemblyInfo.cs (100%) rename src/{Microsoft.AspNet.Hosting.WindowsServices => Microsoft.AspNetCore.Hosting.WindowsServices}/WebHostService.cs (100%) rename src/{Microsoft.AspNet.Hosting.WindowsServices => Microsoft.AspNetCore.Hosting.WindowsServices}/WebHostWindowsServiceExtensions.cs (100%) rename src/{Microsoft.AspNet.Hosting.WindowsServices => Microsoft.AspNetCore.Hosting.WindowsServices}/project.json (96%) rename src/{Microsoft.AspNet.Hosting => Microsoft.AspNetCore.Hosting}/Builder/ApplicationBuilderFactory.cs (100%) rename src/{Microsoft.AspNet.Hosting => Microsoft.AspNetCore.Hosting}/Builder/IApplicationBuilderFactory.cs (100%) rename src/{Microsoft.AspNet.Hosting => Microsoft.AspNetCore.Hosting}/Internal/ApplicationLifetime.cs (100%) rename src/{Microsoft.AspNet.Hosting => Microsoft.AspNetCore.Hosting}/Internal/AutoRequestServicesStartupFilter.cs (100%) rename src/{Microsoft.AspNet.Hosting => Microsoft.AspNetCore.Hosting}/Internal/HostingApplication.cs (100%) rename src/{Microsoft.AspNet.Hosting => Microsoft.AspNetCore.Hosting}/Internal/HostingEnvironment.cs (100%) rename src/{Microsoft.AspNet.Hosting => Microsoft.AspNetCore.Hosting}/Internal/HostingEnvironmentExtensions.cs (100%) rename src/{Microsoft.AspNet.Hosting => Microsoft.AspNetCore.Hosting}/Internal/HostingLoggerExtensions.cs (100%) rename src/{Microsoft.AspNet.Hosting => Microsoft.AspNetCore.Hosting}/Internal/LoggerEventIds.cs (100%) rename src/{Microsoft.AspNet.Hosting => Microsoft.AspNetCore.Hosting}/Internal/NullFileProvider.cs (100%) rename src/{Microsoft.AspNet.Hosting => Microsoft.AspNetCore.Hosting}/Internal/RequestServicesContainerFeature.cs (100%) rename src/{Microsoft.AspNet.Hosting => Microsoft.AspNetCore.Hosting}/Internal/RequestServicesContainerMiddleware.cs (100%) rename src/{Microsoft.AspNet.Hosting => Microsoft.AspNetCore.Hosting}/Internal/WebHost.cs (100%) rename src/{Microsoft.AspNet.Hosting => Microsoft.AspNetCore.Hosting}/Internal/WebHostOptions.cs (100%) rename src/{Microsoft.AspNet.Hosting/Microsoft.AspNet.Hosting.xproj => Microsoft.AspNetCore.Hosting/Microsoft.AspNetCore.Hosting.xproj} (100%) rename src/{Microsoft.AspNet.Hosting => Microsoft.AspNetCore.Hosting}/Properties/AssemblyInfo.cs (100%) rename src/{Microsoft.AspNet.Hosting => Microsoft.AspNetCore.Hosting}/Server/IServerLoader.cs (100%) rename src/{Microsoft.AspNet.Hosting => Microsoft.AspNetCore.Hosting}/Server/ServerLoader.cs (100%) rename src/{Microsoft.AspNet.Hosting => Microsoft.AspNetCore.Hosting}/Startup/ConfigureDelegate.cs (100%) rename src/{Microsoft.AspNet.Hosting => Microsoft.AspNetCore.Hosting}/Startup/ConfigureServicesDelegate.cs (100%) rename src/{Microsoft.AspNet.Hosting => Microsoft.AspNetCore.Hosting}/Startup/IStartupLoader.cs (100%) rename src/{Microsoft.AspNet.Hosting => Microsoft.AspNetCore.Hosting}/Startup/StartupExceptionPage.cs (100%) rename src/{Microsoft.AspNet.Hosting => Microsoft.AspNetCore.Hosting}/Startup/StartupLoader.cs (100%) rename src/{Microsoft.AspNet.Hosting => Microsoft.AspNetCore.Hosting}/Startup/StartupMethods.cs (100%) rename src/{Microsoft.AspNet.Hosting => Microsoft.AspNetCore.Hosting}/WebHostBuilder.cs (100%) rename src/{Microsoft.AspNet.Hosting => Microsoft.AspNetCore.Hosting}/WebHostBuilderExtensions.cs (100%) rename src/{Microsoft.AspNet.Hosting => Microsoft.AspNetCore.Hosting}/WebHostConfiguration.cs (100%) rename src/{Microsoft.AspNet.Hosting => Microsoft.AspNetCore.Hosting}/WebHostExtensions.cs (100%) rename src/{Microsoft.AspNet.Hosting => Microsoft.AspNetCore.Hosting}/compiler/resources/GenericError.html (100%) rename src/{Microsoft.AspNet.Hosting => Microsoft.AspNetCore.Hosting}/compiler/resources/GenericError_Exception.html (100%) rename src/{Microsoft.AspNet.Hosting => Microsoft.AspNetCore.Hosting}/compiler/resources/GenericError_Footer.html (100%) rename src/{Microsoft.AspNet.Hosting => Microsoft.AspNetCore.Hosting}/compiler/resources/GenericError_Message.html (100%) rename src/{Microsoft.AspNet.Hosting => Microsoft.AspNetCore.Hosting}/project.json (100%) rename src/{Microsoft.AspNet.Server.Testing => Microsoft.AspNetCore.Server.Testing}/Common/DeploymentParameters.cs (100%) rename src/{Microsoft.AspNet.Server.Testing => Microsoft.AspNetCore.Server.Testing}/Common/DeploymentResult.cs (100%) rename src/{Microsoft.AspNet.Server.Testing => Microsoft.AspNetCore.Server.Testing}/Common/DotnetArchitecture.cs (100%) rename src/{Microsoft.AspNet.Server.Testing => Microsoft.AspNetCore.Server.Testing}/Common/DotnetFlavor.cs (100%) rename src/{Microsoft.AspNet.Server.Testing => Microsoft.AspNetCore.Server.Testing}/Common/RetryHelper.cs (100%) rename src/{Microsoft.AspNet.Server.Testing => Microsoft.AspNetCore.Server.Testing}/Common/ServerType.cs (100%) rename src/{Microsoft.AspNet.Server.Testing => Microsoft.AspNetCore.Server.Testing}/Common/TestUriHelper.cs (100%) rename src/{Microsoft.AspNet.Server.Testing => Microsoft.AspNetCore.Server.Testing}/Deployers/ApplicationDeployer.cs (100%) rename src/{Microsoft.AspNet.Server.Testing => Microsoft.AspNetCore.Server.Testing}/Deployers/ApplicationDeployerFactory.cs (100%) rename src/{Microsoft.AspNet.Server.Testing => Microsoft.AspNetCore.Server.Testing}/Deployers/IApplicationDeployer.cs (100%) rename src/{Microsoft.AspNet.Server.Testing => Microsoft.AspNetCore.Server.Testing}/Deployers/IISDeployer.cs (100%) rename src/{Microsoft.AspNet.Server.Testing => Microsoft.AspNetCore.Server.Testing}/Deployers/IISExpressDeployer.cs (100%) rename src/{Microsoft.AspNet.Server.Testing => Microsoft.AspNetCore.Server.Testing}/Deployers/SelfHostDeployer.cs (100%) rename src/{Microsoft.AspNet.Server.Testing/Microsoft.AspNet.Server.Testing.xproj => Microsoft.AspNetCore.Server.Testing/Microsoft.AspNetCore.Server.Testing.xproj} (100%) rename src/{Microsoft.AspNet.Server.Testing => Microsoft.AspNetCore.Server.Testing}/Properties/AssemblyInfo.cs (100%) rename src/{Microsoft.AspNet.Server.Testing => Microsoft.AspNetCore.Server.Testing}/project.json (100%) rename src/{Microsoft.AspNet.Server.Testing => Microsoft.AspNetCore.Server.Testing}/xunit/SkipIfCurrentRuntimeIsCoreClr.cs (100%) rename src/{Microsoft.AspNet.Server.Testing => Microsoft.AspNetCore.Server.Testing}/xunit/SkipIfIISVariationsNotEnabledAttribute.cs (100%) rename src/{Microsoft.AspNet.Server.Testing => Microsoft.AspNetCore.Server.Testing}/xunit/SkipOn32BitOSAttribute.cs (100%) rename src/{Microsoft.AspNet.TestHost => Microsoft.AspNetCore.TestHost}/ClientHandler.cs (100%) rename src/{Microsoft.AspNet.TestHost/Microsoft.AspNet.TestHost.xproj => Microsoft.AspNetCore.TestHost/Microsoft.AspNetCore.TestHost.xproj} (100%) rename src/{Microsoft.AspNet.TestHost => Microsoft.AspNetCore.TestHost}/Properties/AssemblyInfo.cs (100%) rename src/{Microsoft.AspNet.TestHost => Microsoft.AspNetCore.TestHost}/RequestBuilder.cs (100%) rename src/{Microsoft.AspNet.TestHost => Microsoft.AspNetCore.TestHost}/RequestFeature.cs (100%) rename src/{Microsoft.AspNet.TestHost => Microsoft.AspNetCore.TestHost}/ResponseFeature.cs (100%) rename src/{Microsoft.AspNet.TestHost => Microsoft.AspNetCore.TestHost}/ResponseStream.cs (100%) rename src/{Microsoft.AspNet.TestHost => Microsoft.AspNetCore.TestHost}/TestServer.cs (100%) rename src/{Microsoft.AspNet.TestHost => Microsoft.AspNetCore.TestHost}/TestWebSocket.cs (100%) rename src/{Microsoft.AspNet.TestHost => Microsoft.AspNetCore.TestHost}/WebSocketClient.cs (100%) rename src/{Microsoft.AspNet.TestHost => Microsoft.AspNetCore.TestHost}/project.json (100%) rename test/{Microsoft.AspNet.Hosting.Tests => Microsoft.AspNetCore.Hosting.Tests}/Fakes/FakeOptions.cs (100%) rename test/{Microsoft.AspNet.Hosting.Tests => Microsoft.AspNetCore.Hosting.Tests}/Fakes/FakeService.cs (100%) rename test/{Microsoft.AspNet.Hosting.Tests => Microsoft.AspNetCore.Hosting.Tests}/Fakes/IFactoryService.cs (100%) rename test/{Microsoft.AspNet.Hosting.Tests => Microsoft.AspNetCore.Hosting.Tests}/Fakes/IFakeEveryService.cs (100%) rename test/{Microsoft.AspNet.Hosting.Tests => Microsoft.AspNetCore.Hosting.Tests}/Fakes/IFakeScopedService.cs (100%) rename test/{Microsoft.AspNet.Hosting.Tests => Microsoft.AspNetCore.Hosting.Tests}/Fakes/IFakeService.cs (100%) rename test/{Microsoft.AspNet.Hosting.Tests => Microsoft.AspNetCore.Hosting.Tests}/Fakes/IFakeServiceInstance.cs (100%) rename test/{Microsoft.AspNet.Hosting.Tests => Microsoft.AspNetCore.Hosting.Tests}/Fakes/IFakeSingletonService.cs (100%) rename test/{Microsoft.AspNet.Hosting.Tests => Microsoft.AspNetCore.Hosting.Tests}/Fakes/IFakeStartupCallback.cs (100%) rename test/{Microsoft.AspNet.Hosting.Tests => Microsoft.AspNetCore.Hosting.Tests}/Fakes/INonexistentService.cs (100%) rename test/{Microsoft.AspNet.Hosting.Tests => Microsoft.AspNetCore.Hosting.Tests}/Fakes/RuntimeEnvironment.cs (100%) rename test/{Microsoft.AspNet.Hosting.Tests => Microsoft.AspNetCore.Hosting.Tests}/Fakes/Startup.cs (100%) rename test/{Microsoft.AspNet.Hosting.Tests => Microsoft.AspNetCore.Hosting.Tests}/Fakes/StartupBase.cs (100%) rename test/{Microsoft.AspNet.Hosting.Tests => Microsoft.AspNetCore.Hosting.Tests}/Fakes/StartupBoom.cs (100%) rename test/{Microsoft.AspNet.Hosting.Tests => Microsoft.AspNetCore.Hosting.Tests}/Fakes/StartupConfigureServicesThrows.cs (100%) rename test/{Microsoft.AspNet.Hosting.Tests => Microsoft.AspNetCore.Hosting.Tests}/Fakes/StartupConfigureThrows.cs (100%) rename test/{Microsoft.AspNet.Hosting.Tests => Microsoft.AspNetCore.Hosting.Tests}/Fakes/StartupCtorThrows.cs (100%) rename test/{Microsoft.AspNet.Hosting.Tests => Microsoft.AspNetCore.Hosting.Tests}/Fakes/StartupNoServices.cs (100%) rename test/{Microsoft.AspNet.Hosting.Tests => Microsoft.AspNetCore.Hosting.Tests}/Fakes/StartupPrivateConfigure.cs (100%) rename test/{Microsoft.AspNet.Hosting.Tests => Microsoft.AspNetCore.Hosting.Tests}/Fakes/StartupStaticCtorThrows.cs (100%) rename test/{Microsoft.AspNet.Hosting.Tests => Microsoft.AspNetCore.Hosting.Tests}/Fakes/StartupThrowTypeLoadException.cs (100%) rename test/{Microsoft.AspNet.Hosting.Tests => Microsoft.AspNetCore.Hosting.Tests}/Fakes/StartupTwoConfigureServices.cs (100%) rename test/{Microsoft.AspNet.Hosting.Tests => Microsoft.AspNetCore.Hosting.Tests}/Fakes/StartupTwoConfigures.cs (100%) rename test/{Microsoft.AspNet.Hosting.Tests => Microsoft.AspNetCore.Hosting.Tests}/Fakes/StartupWithConfigureServices.cs (100%) rename test/{Microsoft.AspNet.Hosting.Tests => Microsoft.AspNetCore.Hosting.Tests}/Fakes/StartupWithConfigureServicesNotResolved.cs (100%) rename test/{Microsoft.AspNet.Hosting.Tests => Microsoft.AspNetCore.Hosting.Tests}/Fakes/StartupWithHostingEnvironment.cs (100%) rename test/{Microsoft.AspNet.Hosting.Tests => Microsoft.AspNetCore.Hosting.Tests}/Fakes/StartupWithNullConfigureServices.cs (100%) rename test/{Microsoft.AspNet.Hosting.Tests => Microsoft.AspNetCore.Hosting.Tests}/Fakes/StartupWithServices.cs (100%) rename test/{Microsoft.AspNet.Hosting.Tests => Microsoft.AspNetCore.Hosting.Tests}/HostingEnvironmentExtensionsTests.cs (100%) rename test/{Microsoft.AspNet.Hosting.Tests/Microsoft.AspNet.Hosting.Tests.xproj => Microsoft.AspNetCore.Hosting.Tests/Microsoft.AspNetCore.Hosting.Tests.xproj} (100%) rename test/{Microsoft.AspNet.Hosting.Tests => Microsoft.AspNetCore.Hosting.Tests}/StartupManagerTests.cs (100%) rename test/{Microsoft.AspNet.Hosting.Tests => Microsoft.AspNetCore.Hosting.Tests}/WebHostBuilderTests.cs (100%) rename test/{Microsoft.AspNet.Hosting.Tests => Microsoft.AspNetCore.Hosting.Tests}/WebHostConfigurationsTests.cs (100%) rename test/{Microsoft.AspNet.Hosting.Tests => Microsoft.AspNetCore.Hosting.Tests}/WebHostTests.cs (100%) rename test/{Microsoft.AspNet.Hosting.Tests => Microsoft.AspNetCore.Hosting.Tests}/project.json (100%) rename test/{Microsoft.AspNet.Hosting.Tests => Microsoft.AspNetCore.Hosting.Tests}/testroot/TextFile.txt (100%) rename test/{Microsoft.AspNet.Hosting.Tests => Microsoft.AspNetCore.Hosting.Tests}/testroot/wwwroot/README (100%) rename test/{Microsoft.AspNet.TestHost.Tests => Microsoft.AspNetCore.TestHost.Tests}/ClientHandlerTests.cs (100%) rename test/{Microsoft.AspNet.TestHost.Tests/Microsoft.AspNet.TestHost.Tests.xproj => Microsoft.AspNetCore.TestHost.Tests/Microsoft.AspNetCore.TestHost.Tests.xproj} (100%) rename test/{Microsoft.AspNet.TestHost.Tests => Microsoft.AspNetCore.TestHost.Tests}/Properties/AssemblyInfo.cs (100%) rename test/{Microsoft.AspNet.TestHost.Tests => Microsoft.AspNetCore.TestHost.Tests}/RequestBuilderTests.cs (100%) rename test/{Microsoft.AspNet.TestHost.Tests => Microsoft.AspNetCore.TestHost.Tests}/ResponseFeatureTests.cs (100%) rename test/{Microsoft.AspNet.TestHost.Tests => Microsoft.AspNetCore.TestHost.Tests}/TestClientTests.cs (100%) rename test/{Microsoft.AspNet.TestHost.Tests => Microsoft.AspNetCore.TestHost.Tests}/TestServerTests.cs (100%) rename test/{Microsoft.AspNet.TestHost.Tests => Microsoft.AspNetCore.TestHost.Tests}/project.json (100%) diff --git a/src/Microsoft.AspNet.Hosting.Abstractions/EnvironmentName.cs b/src/Microsoft.AspNetCore.Hosting.Abstractions/EnvironmentName.cs similarity index 100% rename from src/Microsoft.AspNet.Hosting.Abstractions/EnvironmentName.cs rename to src/Microsoft.AspNetCore.Hosting.Abstractions/EnvironmentName.cs diff --git a/src/Microsoft.AspNet.Hosting.Abstractions/HostingEnvironmentExtensions.cs b/src/Microsoft.AspNetCore.Hosting.Abstractions/HostingEnvironmentExtensions.cs similarity index 100% rename from src/Microsoft.AspNet.Hosting.Abstractions/HostingEnvironmentExtensions.cs rename to src/Microsoft.AspNetCore.Hosting.Abstractions/HostingEnvironmentExtensions.cs diff --git a/src/Microsoft.AspNet.Hosting.Abstractions/IApplicationLifetime.cs b/src/Microsoft.AspNetCore.Hosting.Abstractions/IApplicationLifetime.cs similarity index 100% rename from src/Microsoft.AspNet.Hosting.Abstractions/IApplicationLifetime.cs rename to src/Microsoft.AspNetCore.Hosting.Abstractions/IApplicationLifetime.cs diff --git a/src/Microsoft.AspNet.Hosting.Abstractions/IHostingEnvironment.cs b/src/Microsoft.AspNetCore.Hosting.Abstractions/IHostingEnvironment.cs similarity index 100% rename from src/Microsoft.AspNet.Hosting.Abstractions/IHostingEnvironment.cs rename to src/Microsoft.AspNetCore.Hosting.Abstractions/IHostingEnvironment.cs diff --git a/src/Microsoft.AspNet.Hosting.Abstractions/IStartupFilter.cs b/src/Microsoft.AspNetCore.Hosting.Abstractions/IStartupFilter.cs similarity index 100% rename from src/Microsoft.AspNet.Hosting.Abstractions/IStartupFilter.cs rename to src/Microsoft.AspNetCore.Hosting.Abstractions/IStartupFilter.cs diff --git a/src/Microsoft.AspNet.Hosting.Abstractions/IWebHost.cs b/src/Microsoft.AspNetCore.Hosting.Abstractions/IWebHost.cs similarity index 100% rename from src/Microsoft.AspNet.Hosting.Abstractions/IWebHost.cs rename to src/Microsoft.AspNetCore.Hosting.Abstractions/IWebHost.cs diff --git a/src/Microsoft.AspNet.Hosting.Abstractions/IWebHostBuilder.cs b/src/Microsoft.AspNetCore.Hosting.Abstractions/IWebHostBuilder.cs similarity index 100% rename from src/Microsoft.AspNet.Hosting.Abstractions/IWebHostBuilder.cs rename to src/Microsoft.AspNetCore.Hosting.Abstractions/IWebHostBuilder.cs diff --git a/src/Microsoft.AspNet.Hosting.Abstractions/Microsoft.AspNet.Hosting.Abstractions.xproj b/src/Microsoft.AspNetCore.Hosting.Abstractions/Microsoft.AspNetCore.Hosting.Abstractions.xproj similarity index 100% rename from src/Microsoft.AspNet.Hosting.Abstractions/Microsoft.AspNet.Hosting.Abstractions.xproj rename to src/Microsoft.AspNetCore.Hosting.Abstractions/Microsoft.AspNetCore.Hosting.Abstractions.xproj diff --git a/src/Microsoft.AspNet.Hosting.Abstractions/Properties/AssemblyInfo.cs b/src/Microsoft.AspNetCore.Hosting.Abstractions/Properties/AssemblyInfo.cs similarity index 100% rename from src/Microsoft.AspNet.Hosting.Abstractions/Properties/AssemblyInfo.cs rename to src/Microsoft.AspNetCore.Hosting.Abstractions/Properties/AssemblyInfo.cs diff --git a/src/Microsoft.AspNet.Hosting.Abstractions/WebHostDefaults.cs b/src/Microsoft.AspNetCore.Hosting.Abstractions/WebHostDefaults.cs similarity index 100% rename from src/Microsoft.AspNet.Hosting.Abstractions/WebHostDefaults.cs rename to src/Microsoft.AspNetCore.Hosting.Abstractions/WebHostDefaults.cs diff --git a/src/Microsoft.AspNet.Hosting.Abstractions/project.json b/src/Microsoft.AspNetCore.Hosting.Abstractions/project.json similarity index 100% rename from src/Microsoft.AspNet.Hosting.Abstractions/project.json rename to src/Microsoft.AspNetCore.Hosting.Abstractions/project.json diff --git a/src/Microsoft.AspNet.Hosting.Server.Abstractions/IHttpApplication.cs b/src/Microsoft.AspNetCore.Hosting.Server.Abstractions/IHttpApplication.cs similarity index 100% rename from src/Microsoft.AspNet.Hosting.Server.Abstractions/IHttpApplication.cs rename to src/Microsoft.AspNetCore.Hosting.Server.Abstractions/IHttpApplication.cs diff --git a/src/Microsoft.AspNet.Hosting.Server.Abstractions/IServer.cs b/src/Microsoft.AspNetCore.Hosting.Server.Abstractions/IServer.cs similarity index 100% rename from src/Microsoft.AspNet.Hosting.Server.Abstractions/IServer.cs rename to src/Microsoft.AspNetCore.Hosting.Server.Abstractions/IServer.cs diff --git a/src/Microsoft.AspNet.Hosting.Server.Abstractions/IServerAddressesFeature.cs b/src/Microsoft.AspNetCore.Hosting.Server.Abstractions/IServerAddressesFeature.cs similarity index 100% rename from src/Microsoft.AspNet.Hosting.Server.Abstractions/IServerAddressesFeature.cs rename to src/Microsoft.AspNetCore.Hosting.Server.Abstractions/IServerAddressesFeature.cs diff --git a/src/Microsoft.AspNet.Hosting.Server.Abstractions/IServerFactory.cs b/src/Microsoft.AspNetCore.Hosting.Server.Abstractions/IServerFactory.cs similarity index 100% rename from src/Microsoft.AspNet.Hosting.Server.Abstractions/IServerFactory.cs rename to src/Microsoft.AspNetCore.Hosting.Server.Abstractions/IServerFactory.cs diff --git a/src/Microsoft.AspNet.Hosting.Server.Abstractions/Microsoft.AspNet.Hosting.Server.Abstractions.xproj b/src/Microsoft.AspNetCore.Hosting.Server.Abstractions/Microsoft.AspNetCore.Hosting.Server.Abstractions.xproj similarity index 100% rename from src/Microsoft.AspNet.Hosting.Server.Abstractions/Microsoft.AspNet.Hosting.Server.Abstractions.xproj rename to src/Microsoft.AspNetCore.Hosting.Server.Abstractions/Microsoft.AspNetCore.Hosting.Server.Abstractions.xproj diff --git a/src/Microsoft.AspNet.Hosting.Server.Abstractions/Properties/AssemblyInfo.cs b/src/Microsoft.AspNetCore.Hosting.Server.Abstractions/Properties/AssemblyInfo.cs similarity index 100% rename from src/Microsoft.AspNet.Hosting.Server.Abstractions/Properties/AssemblyInfo.cs rename to src/Microsoft.AspNetCore.Hosting.Server.Abstractions/Properties/AssemblyInfo.cs diff --git a/src/Microsoft.AspNet.Hosting.Server.Abstractions/project.json b/src/Microsoft.AspNetCore.Hosting.Server.Abstractions/project.json similarity index 100% rename from src/Microsoft.AspNet.Hosting.Server.Abstractions/project.json rename to src/Microsoft.AspNetCore.Hosting.Server.Abstractions/project.json diff --git a/src/Microsoft.AspNet.Hosting.WindowsServices/Microsoft.AspNet.Hosting.WindowsServices.xproj b/src/Microsoft.AspNetCore.Hosting.WindowsServices/Microsoft.AspNetCore.Hosting.WindowsServices.xproj similarity index 97% rename from src/Microsoft.AspNet.Hosting.WindowsServices/Microsoft.AspNet.Hosting.WindowsServices.xproj rename to src/Microsoft.AspNetCore.Hosting.WindowsServices/Microsoft.AspNetCore.Hosting.WindowsServices.xproj index 39ccb16031..8131586c81 100644 --- a/src/Microsoft.AspNet.Hosting.WindowsServices/Microsoft.AspNet.Hosting.WindowsServices.xproj +++ b/src/Microsoft.AspNetCore.Hosting.WindowsServices/Microsoft.AspNetCore.Hosting.WindowsServices.xproj @@ -1,19 +1,19 @@ - - - - 14.0 - $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) - - - - 03148731-ea95-40a2-bae8-a12315ea1748 - Microsoft.AspNet.Hosting.WindowsServices - ..\..\artifacts\obj\$(MSBuildProjectName) - ..\..\artifacts\bin\$(MSBuildProjectName)\ - - - 2.0 - - - + + + + 14.0 + $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) + + + + 03148731-ea95-40a2-bae8-a12315ea1748 + Microsoft.AspNet.Hosting.WindowsServices + ..\..\artifacts\obj\$(MSBuildProjectName) + ..\..\artifacts\bin\$(MSBuildProjectName)\ + + + 2.0 + + + \ No newline at end of file diff --git a/src/Microsoft.AspNet.Hosting.WindowsServices/Properties/AssemblyInfo.cs b/src/Microsoft.AspNetCore.Hosting.WindowsServices/Properties/AssemblyInfo.cs similarity index 100% rename from src/Microsoft.AspNet.Hosting.WindowsServices/Properties/AssemblyInfo.cs rename to src/Microsoft.AspNetCore.Hosting.WindowsServices/Properties/AssemblyInfo.cs diff --git a/src/Microsoft.AspNet.Hosting.WindowsServices/WebHostService.cs b/src/Microsoft.AspNetCore.Hosting.WindowsServices/WebHostService.cs similarity index 100% rename from src/Microsoft.AspNet.Hosting.WindowsServices/WebHostService.cs rename to src/Microsoft.AspNetCore.Hosting.WindowsServices/WebHostService.cs diff --git a/src/Microsoft.AspNet.Hosting.WindowsServices/WebHostWindowsServiceExtensions.cs b/src/Microsoft.AspNetCore.Hosting.WindowsServices/WebHostWindowsServiceExtensions.cs similarity index 100% rename from src/Microsoft.AspNet.Hosting.WindowsServices/WebHostWindowsServiceExtensions.cs rename to src/Microsoft.AspNetCore.Hosting.WindowsServices/WebHostWindowsServiceExtensions.cs diff --git a/src/Microsoft.AspNet.Hosting.WindowsServices/project.json b/src/Microsoft.AspNetCore.Hosting.WindowsServices/project.json similarity index 96% rename from src/Microsoft.AspNet.Hosting.WindowsServices/project.json rename to src/Microsoft.AspNetCore.Hosting.WindowsServices/project.json index 3da4890272..91b2eb21c2 100644 --- a/src/Microsoft.AspNet.Hosting.WindowsServices/project.json +++ b/src/Microsoft.AspNetCore.Hosting.WindowsServices/project.json @@ -1,22 +1,22 @@ -{ - "version": "1.0.0-*", - "description": "ASP.NET 5 core hosting infrastructure and startup logic for web applications running within a Windows service.", - "repository": { - "type": "git", - "url": "git://github.com/aspnet/hosting" - }, - "compilationOptions": { - "warningsAsErrors": true, - "keyFile": "../../tools/Key.snk" - }, - "dependencies": { - "Microsoft.AspNet.Hosting": "1.0.0-*" - }, - "frameworks": { - "net451": { - "frameworkAssemblies": { - "System.ServiceProcess": "" - } - } - } -} +{ + "version": "1.0.0-*", + "description": "ASP.NET 5 core hosting infrastructure and startup logic for web applications running within a Windows service.", + "repository": { + "type": "git", + "url": "git://github.com/aspnet/hosting" + }, + "compilationOptions": { + "warningsAsErrors": true, + "keyFile": "../../tools/Key.snk" + }, + "dependencies": { + "Microsoft.AspNet.Hosting": "1.0.0-*" + }, + "frameworks": { + "net451": { + "frameworkAssemblies": { + "System.ServiceProcess": "" + } + } + } +} diff --git a/src/Microsoft.AspNet.Hosting/Builder/ApplicationBuilderFactory.cs b/src/Microsoft.AspNetCore.Hosting/Builder/ApplicationBuilderFactory.cs similarity index 100% rename from src/Microsoft.AspNet.Hosting/Builder/ApplicationBuilderFactory.cs rename to src/Microsoft.AspNetCore.Hosting/Builder/ApplicationBuilderFactory.cs diff --git a/src/Microsoft.AspNet.Hosting/Builder/IApplicationBuilderFactory.cs b/src/Microsoft.AspNetCore.Hosting/Builder/IApplicationBuilderFactory.cs similarity index 100% rename from src/Microsoft.AspNet.Hosting/Builder/IApplicationBuilderFactory.cs rename to src/Microsoft.AspNetCore.Hosting/Builder/IApplicationBuilderFactory.cs diff --git a/src/Microsoft.AspNet.Hosting/Internal/ApplicationLifetime.cs b/src/Microsoft.AspNetCore.Hosting/Internal/ApplicationLifetime.cs similarity index 100% rename from src/Microsoft.AspNet.Hosting/Internal/ApplicationLifetime.cs rename to src/Microsoft.AspNetCore.Hosting/Internal/ApplicationLifetime.cs diff --git a/src/Microsoft.AspNet.Hosting/Internal/AutoRequestServicesStartupFilter.cs b/src/Microsoft.AspNetCore.Hosting/Internal/AutoRequestServicesStartupFilter.cs similarity index 100% rename from src/Microsoft.AspNet.Hosting/Internal/AutoRequestServicesStartupFilter.cs rename to src/Microsoft.AspNetCore.Hosting/Internal/AutoRequestServicesStartupFilter.cs diff --git a/src/Microsoft.AspNet.Hosting/Internal/HostingApplication.cs b/src/Microsoft.AspNetCore.Hosting/Internal/HostingApplication.cs similarity index 100% rename from src/Microsoft.AspNet.Hosting/Internal/HostingApplication.cs rename to src/Microsoft.AspNetCore.Hosting/Internal/HostingApplication.cs diff --git a/src/Microsoft.AspNet.Hosting/Internal/HostingEnvironment.cs b/src/Microsoft.AspNetCore.Hosting/Internal/HostingEnvironment.cs similarity index 100% rename from src/Microsoft.AspNet.Hosting/Internal/HostingEnvironment.cs rename to src/Microsoft.AspNetCore.Hosting/Internal/HostingEnvironment.cs diff --git a/src/Microsoft.AspNet.Hosting/Internal/HostingEnvironmentExtensions.cs b/src/Microsoft.AspNetCore.Hosting/Internal/HostingEnvironmentExtensions.cs similarity index 100% rename from src/Microsoft.AspNet.Hosting/Internal/HostingEnvironmentExtensions.cs rename to src/Microsoft.AspNetCore.Hosting/Internal/HostingEnvironmentExtensions.cs diff --git a/src/Microsoft.AspNet.Hosting/Internal/HostingLoggerExtensions.cs b/src/Microsoft.AspNetCore.Hosting/Internal/HostingLoggerExtensions.cs similarity index 100% rename from src/Microsoft.AspNet.Hosting/Internal/HostingLoggerExtensions.cs rename to src/Microsoft.AspNetCore.Hosting/Internal/HostingLoggerExtensions.cs diff --git a/src/Microsoft.AspNet.Hosting/Internal/LoggerEventIds.cs b/src/Microsoft.AspNetCore.Hosting/Internal/LoggerEventIds.cs similarity index 100% rename from src/Microsoft.AspNet.Hosting/Internal/LoggerEventIds.cs rename to src/Microsoft.AspNetCore.Hosting/Internal/LoggerEventIds.cs diff --git a/src/Microsoft.AspNet.Hosting/Internal/NullFileProvider.cs b/src/Microsoft.AspNetCore.Hosting/Internal/NullFileProvider.cs similarity index 100% rename from src/Microsoft.AspNet.Hosting/Internal/NullFileProvider.cs rename to src/Microsoft.AspNetCore.Hosting/Internal/NullFileProvider.cs diff --git a/src/Microsoft.AspNet.Hosting/Internal/RequestServicesContainerFeature.cs b/src/Microsoft.AspNetCore.Hosting/Internal/RequestServicesContainerFeature.cs similarity index 100% rename from src/Microsoft.AspNet.Hosting/Internal/RequestServicesContainerFeature.cs rename to src/Microsoft.AspNetCore.Hosting/Internal/RequestServicesContainerFeature.cs diff --git a/src/Microsoft.AspNet.Hosting/Internal/RequestServicesContainerMiddleware.cs b/src/Microsoft.AspNetCore.Hosting/Internal/RequestServicesContainerMiddleware.cs similarity index 100% rename from src/Microsoft.AspNet.Hosting/Internal/RequestServicesContainerMiddleware.cs rename to src/Microsoft.AspNetCore.Hosting/Internal/RequestServicesContainerMiddleware.cs diff --git a/src/Microsoft.AspNet.Hosting/Internal/WebHost.cs b/src/Microsoft.AspNetCore.Hosting/Internal/WebHost.cs similarity index 100% rename from src/Microsoft.AspNet.Hosting/Internal/WebHost.cs rename to src/Microsoft.AspNetCore.Hosting/Internal/WebHost.cs diff --git a/src/Microsoft.AspNet.Hosting/Internal/WebHostOptions.cs b/src/Microsoft.AspNetCore.Hosting/Internal/WebHostOptions.cs similarity index 100% rename from src/Microsoft.AspNet.Hosting/Internal/WebHostOptions.cs rename to src/Microsoft.AspNetCore.Hosting/Internal/WebHostOptions.cs diff --git a/src/Microsoft.AspNet.Hosting/Microsoft.AspNet.Hosting.xproj b/src/Microsoft.AspNetCore.Hosting/Microsoft.AspNetCore.Hosting.xproj similarity index 100% rename from src/Microsoft.AspNet.Hosting/Microsoft.AspNet.Hosting.xproj rename to src/Microsoft.AspNetCore.Hosting/Microsoft.AspNetCore.Hosting.xproj diff --git a/src/Microsoft.AspNet.Hosting/Properties/AssemblyInfo.cs b/src/Microsoft.AspNetCore.Hosting/Properties/AssemblyInfo.cs similarity index 100% rename from src/Microsoft.AspNet.Hosting/Properties/AssemblyInfo.cs rename to src/Microsoft.AspNetCore.Hosting/Properties/AssemblyInfo.cs diff --git a/src/Microsoft.AspNet.Hosting/Server/IServerLoader.cs b/src/Microsoft.AspNetCore.Hosting/Server/IServerLoader.cs similarity index 100% rename from src/Microsoft.AspNet.Hosting/Server/IServerLoader.cs rename to src/Microsoft.AspNetCore.Hosting/Server/IServerLoader.cs diff --git a/src/Microsoft.AspNet.Hosting/Server/ServerLoader.cs b/src/Microsoft.AspNetCore.Hosting/Server/ServerLoader.cs similarity index 100% rename from src/Microsoft.AspNet.Hosting/Server/ServerLoader.cs rename to src/Microsoft.AspNetCore.Hosting/Server/ServerLoader.cs diff --git a/src/Microsoft.AspNet.Hosting/Startup/ConfigureDelegate.cs b/src/Microsoft.AspNetCore.Hosting/Startup/ConfigureDelegate.cs similarity index 100% rename from src/Microsoft.AspNet.Hosting/Startup/ConfigureDelegate.cs rename to src/Microsoft.AspNetCore.Hosting/Startup/ConfigureDelegate.cs diff --git a/src/Microsoft.AspNet.Hosting/Startup/ConfigureServicesDelegate.cs b/src/Microsoft.AspNetCore.Hosting/Startup/ConfigureServicesDelegate.cs similarity index 100% rename from src/Microsoft.AspNet.Hosting/Startup/ConfigureServicesDelegate.cs rename to src/Microsoft.AspNetCore.Hosting/Startup/ConfigureServicesDelegate.cs diff --git a/src/Microsoft.AspNet.Hosting/Startup/IStartupLoader.cs b/src/Microsoft.AspNetCore.Hosting/Startup/IStartupLoader.cs similarity index 100% rename from src/Microsoft.AspNet.Hosting/Startup/IStartupLoader.cs rename to src/Microsoft.AspNetCore.Hosting/Startup/IStartupLoader.cs diff --git a/src/Microsoft.AspNet.Hosting/Startup/StartupExceptionPage.cs b/src/Microsoft.AspNetCore.Hosting/Startup/StartupExceptionPage.cs similarity index 100% rename from src/Microsoft.AspNet.Hosting/Startup/StartupExceptionPage.cs rename to src/Microsoft.AspNetCore.Hosting/Startup/StartupExceptionPage.cs diff --git a/src/Microsoft.AspNet.Hosting/Startup/StartupLoader.cs b/src/Microsoft.AspNetCore.Hosting/Startup/StartupLoader.cs similarity index 100% rename from src/Microsoft.AspNet.Hosting/Startup/StartupLoader.cs rename to src/Microsoft.AspNetCore.Hosting/Startup/StartupLoader.cs diff --git a/src/Microsoft.AspNet.Hosting/Startup/StartupMethods.cs b/src/Microsoft.AspNetCore.Hosting/Startup/StartupMethods.cs similarity index 100% rename from src/Microsoft.AspNet.Hosting/Startup/StartupMethods.cs rename to src/Microsoft.AspNetCore.Hosting/Startup/StartupMethods.cs diff --git a/src/Microsoft.AspNet.Hosting/WebHostBuilder.cs b/src/Microsoft.AspNetCore.Hosting/WebHostBuilder.cs similarity index 100% rename from src/Microsoft.AspNet.Hosting/WebHostBuilder.cs rename to src/Microsoft.AspNetCore.Hosting/WebHostBuilder.cs diff --git a/src/Microsoft.AspNet.Hosting/WebHostBuilderExtensions.cs b/src/Microsoft.AspNetCore.Hosting/WebHostBuilderExtensions.cs similarity index 100% rename from src/Microsoft.AspNet.Hosting/WebHostBuilderExtensions.cs rename to src/Microsoft.AspNetCore.Hosting/WebHostBuilderExtensions.cs diff --git a/src/Microsoft.AspNet.Hosting/WebHostConfiguration.cs b/src/Microsoft.AspNetCore.Hosting/WebHostConfiguration.cs similarity index 100% rename from src/Microsoft.AspNet.Hosting/WebHostConfiguration.cs rename to src/Microsoft.AspNetCore.Hosting/WebHostConfiguration.cs diff --git a/src/Microsoft.AspNet.Hosting/WebHostExtensions.cs b/src/Microsoft.AspNetCore.Hosting/WebHostExtensions.cs similarity index 100% rename from src/Microsoft.AspNet.Hosting/WebHostExtensions.cs rename to src/Microsoft.AspNetCore.Hosting/WebHostExtensions.cs diff --git a/src/Microsoft.AspNet.Hosting/compiler/resources/GenericError.html b/src/Microsoft.AspNetCore.Hosting/compiler/resources/GenericError.html similarity index 100% rename from src/Microsoft.AspNet.Hosting/compiler/resources/GenericError.html rename to src/Microsoft.AspNetCore.Hosting/compiler/resources/GenericError.html diff --git a/src/Microsoft.AspNet.Hosting/compiler/resources/GenericError_Exception.html b/src/Microsoft.AspNetCore.Hosting/compiler/resources/GenericError_Exception.html similarity index 100% rename from src/Microsoft.AspNet.Hosting/compiler/resources/GenericError_Exception.html rename to src/Microsoft.AspNetCore.Hosting/compiler/resources/GenericError_Exception.html diff --git a/src/Microsoft.AspNet.Hosting/compiler/resources/GenericError_Footer.html b/src/Microsoft.AspNetCore.Hosting/compiler/resources/GenericError_Footer.html similarity index 100% rename from src/Microsoft.AspNet.Hosting/compiler/resources/GenericError_Footer.html rename to src/Microsoft.AspNetCore.Hosting/compiler/resources/GenericError_Footer.html diff --git a/src/Microsoft.AspNet.Hosting/compiler/resources/GenericError_Message.html b/src/Microsoft.AspNetCore.Hosting/compiler/resources/GenericError_Message.html similarity index 100% rename from src/Microsoft.AspNet.Hosting/compiler/resources/GenericError_Message.html rename to src/Microsoft.AspNetCore.Hosting/compiler/resources/GenericError_Message.html diff --git a/src/Microsoft.AspNet.Hosting/project.json b/src/Microsoft.AspNetCore.Hosting/project.json similarity index 100% rename from src/Microsoft.AspNet.Hosting/project.json rename to src/Microsoft.AspNetCore.Hosting/project.json diff --git a/src/Microsoft.AspNet.Server.Testing/Common/DeploymentParameters.cs b/src/Microsoft.AspNetCore.Server.Testing/Common/DeploymentParameters.cs similarity index 100% rename from src/Microsoft.AspNet.Server.Testing/Common/DeploymentParameters.cs rename to src/Microsoft.AspNetCore.Server.Testing/Common/DeploymentParameters.cs diff --git a/src/Microsoft.AspNet.Server.Testing/Common/DeploymentResult.cs b/src/Microsoft.AspNetCore.Server.Testing/Common/DeploymentResult.cs similarity index 100% rename from src/Microsoft.AspNet.Server.Testing/Common/DeploymentResult.cs rename to src/Microsoft.AspNetCore.Server.Testing/Common/DeploymentResult.cs diff --git a/src/Microsoft.AspNet.Server.Testing/Common/DotnetArchitecture.cs b/src/Microsoft.AspNetCore.Server.Testing/Common/DotnetArchitecture.cs similarity index 100% rename from src/Microsoft.AspNet.Server.Testing/Common/DotnetArchitecture.cs rename to src/Microsoft.AspNetCore.Server.Testing/Common/DotnetArchitecture.cs diff --git a/src/Microsoft.AspNet.Server.Testing/Common/DotnetFlavor.cs b/src/Microsoft.AspNetCore.Server.Testing/Common/DotnetFlavor.cs similarity index 100% rename from src/Microsoft.AspNet.Server.Testing/Common/DotnetFlavor.cs rename to src/Microsoft.AspNetCore.Server.Testing/Common/DotnetFlavor.cs diff --git a/src/Microsoft.AspNet.Server.Testing/Common/RetryHelper.cs b/src/Microsoft.AspNetCore.Server.Testing/Common/RetryHelper.cs similarity index 100% rename from src/Microsoft.AspNet.Server.Testing/Common/RetryHelper.cs rename to src/Microsoft.AspNetCore.Server.Testing/Common/RetryHelper.cs diff --git a/src/Microsoft.AspNet.Server.Testing/Common/ServerType.cs b/src/Microsoft.AspNetCore.Server.Testing/Common/ServerType.cs similarity index 100% rename from src/Microsoft.AspNet.Server.Testing/Common/ServerType.cs rename to src/Microsoft.AspNetCore.Server.Testing/Common/ServerType.cs diff --git a/src/Microsoft.AspNet.Server.Testing/Common/TestUriHelper.cs b/src/Microsoft.AspNetCore.Server.Testing/Common/TestUriHelper.cs similarity index 100% rename from src/Microsoft.AspNet.Server.Testing/Common/TestUriHelper.cs rename to src/Microsoft.AspNetCore.Server.Testing/Common/TestUriHelper.cs diff --git a/src/Microsoft.AspNet.Server.Testing/Deployers/ApplicationDeployer.cs b/src/Microsoft.AspNetCore.Server.Testing/Deployers/ApplicationDeployer.cs similarity index 100% rename from src/Microsoft.AspNet.Server.Testing/Deployers/ApplicationDeployer.cs rename to src/Microsoft.AspNetCore.Server.Testing/Deployers/ApplicationDeployer.cs diff --git a/src/Microsoft.AspNet.Server.Testing/Deployers/ApplicationDeployerFactory.cs b/src/Microsoft.AspNetCore.Server.Testing/Deployers/ApplicationDeployerFactory.cs similarity index 100% rename from src/Microsoft.AspNet.Server.Testing/Deployers/ApplicationDeployerFactory.cs rename to src/Microsoft.AspNetCore.Server.Testing/Deployers/ApplicationDeployerFactory.cs diff --git a/src/Microsoft.AspNet.Server.Testing/Deployers/IApplicationDeployer.cs b/src/Microsoft.AspNetCore.Server.Testing/Deployers/IApplicationDeployer.cs similarity index 100% rename from src/Microsoft.AspNet.Server.Testing/Deployers/IApplicationDeployer.cs rename to src/Microsoft.AspNetCore.Server.Testing/Deployers/IApplicationDeployer.cs diff --git a/src/Microsoft.AspNet.Server.Testing/Deployers/IISDeployer.cs b/src/Microsoft.AspNetCore.Server.Testing/Deployers/IISDeployer.cs similarity index 100% rename from src/Microsoft.AspNet.Server.Testing/Deployers/IISDeployer.cs rename to src/Microsoft.AspNetCore.Server.Testing/Deployers/IISDeployer.cs diff --git a/src/Microsoft.AspNet.Server.Testing/Deployers/IISExpressDeployer.cs b/src/Microsoft.AspNetCore.Server.Testing/Deployers/IISExpressDeployer.cs similarity index 100% rename from src/Microsoft.AspNet.Server.Testing/Deployers/IISExpressDeployer.cs rename to src/Microsoft.AspNetCore.Server.Testing/Deployers/IISExpressDeployer.cs diff --git a/src/Microsoft.AspNet.Server.Testing/Deployers/SelfHostDeployer.cs b/src/Microsoft.AspNetCore.Server.Testing/Deployers/SelfHostDeployer.cs similarity index 100% rename from src/Microsoft.AspNet.Server.Testing/Deployers/SelfHostDeployer.cs rename to src/Microsoft.AspNetCore.Server.Testing/Deployers/SelfHostDeployer.cs diff --git a/src/Microsoft.AspNet.Server.Testing/Microsoft.AspNet.Server.Testing.xproj b/src/Microsoft.AspNetCore.Server.Testing/Microsoft.AspNetCore.Server.Testing.xproj similarity index 100% rename from src/Microsoft.AspNet.Server.Testing/Microsoft.AspNet.Server.Testing.xproj rename to src/Microsoft.AspNetCore.Server.Testing/Microsoft.AspNetCore.Server.Testing.xproj diff --git a/src/Microsoft.AspNet.Server.Testing/Properties/AssemblyInfo.cs b/src/Microsoft.AspNetCore.Server.Testing/Properties/AssemblyInfo.cs similarity index 100% rename from src/Microsoft.AspNet.Server.Testing/Properties/AssemblyInfo.cs rename to src/Microsoft.AspNetCore.Server.Testing/Properties/AssemblyInfo.cs diff --git a/src/Microsoft.AspNet.Server.Testing/project.json b/src/Microsoft.AspNetCore.Server.Testing/project.json similarity index 100% rename from src/Microsoft.AspNet.Server.Testing/project.json rename to src/Microsoft.AspNetCore.Server.Testing/project.json diff --git a/src/Microsoft.AspNet.Server.Testing/xunit/SkipIfCurrentRuntimeIsCoreClr.cs b/src/Microsoft.AspNetCore.Server.Testing/xunit/SkipIfCurrentRuntimeIsCoreClr.cs similarity index 100% rename from src/Microsoft.AspNet.Server.Testing/xunit/SkipIfCurrentRuntimeIsCoreClr.cs rename to src/Microsoft.AspNetCore.Server.Testing/xunit/SkipIfCurrentRuntimeIsCoreClr.cs diff --git a/src/Microsoft.AspNet.Server.Testing/xunit/SkipIfIISVariationsNotEnabledAttribute.cs b/src/Microsoft.AspNetCore.Server.Testing/xunit/SkipIfIISVariationsNotEnabledAttribute.cs similarity index 100% rename from src/Microsoft.AspNet.Server.Testing/xunit/SkipIfIISVariationsNotEnabledAttribute.cs rename to src/Microsoft.AspNetCore.Server.Testing/xunit/SkipIfIISVariationsNotEnabledAttribute.cs diff --git a/src/Microsoft.AspNet.Server.Testing/xunit/SkipOn32BitOSAttribute.cs b/src/Microsoft.AspNetCore.Server.Testing/xunit/SkipOn32BitOSAttribute.cs similarity index 100% rename from src/Microsoft.AspNet.Server.Testing/xunit/SkipOn32BitOSAttribute.cs rename to src/Microsoft.AspNetCore.Server.Testing/xunit/SkipOn32BitOSAttribute.cs diff --git a/src/Microsoft.AspNet.TestHost/ClientHandler.cs b/src/Microsoft.AspNetCore.TestHost/ClientHandler.cs similarity index 100% rename from src/Microsoft.AspNet.TestHost/ClientHandler.cs rename to src/Microsoft.AspNetCore.TestHost/ClientHandler.cs diff --git a/src/Microsoft.AspNet.TestHost/Microsoft.AspNet.TestHost.xproj b/src/Microsoft.AspNetCore.TestHost/Microsoft.AspNetCore.TestHost.xproj similarity index 100% rename from src/Microsoft.AspNet.TestHost/Microsoft.AspNet.TestHost.xproj rename to src/Microsoft.AspNetCore.TestHost/Microsoft.AspNetCore.TestHost.xproj diff --git a/src/Microsoft.AspNet.TestHost/Properties/AssemblyInfo.cs b/src/Microsoft.AspNetCore.TestHost/Properties/AssemblyInfo.cs similarity index 100% rename from src/Microsoft.AspNet.TestHost/Properties/AssemblyInfo.cs rename to src/Microsoft.AspNetCore.TestHost/Properties/AssemblyInfo.cs diff --git a/src/Microsoft.AspNet.TestHost/RequestBuilder.cs b/src/Microsoft.AspNetCore.TestHost/RequestBuilder.cs similarity index 100% rename from src/Microsoft.AspNet.TestHost/RequestBuilder.cs rename to src/Microsoft.AspNetCore.TestHost/RequestBuilder.cs diff --git a/src/Microsoft.AspNet.TestHost/RequestFeature.cs b/src/Microsoft.AspNetCore.TestHost/RequestFeature.cs similarity index 100% rename from src/Microsoft.AspNet.TestHost/RequestFeature.cs rename to src/Microsoft.AspNetCore.TestHost/RequestFeature.cs diff --git a/src/Microsoft.AspNet.TestHost/ResponseFeature.cs b/src/Microsoft.AspNetCore.TestHost/ResponseFeature.cs similarity index 100% rename from src/Microsoft.AspNet.TestHost/ResponseFeature.cs rename to src/Microsoft.AspNetCore.TestHost/ResponseFeature.cs diff --git a/src/Microsoft.AspNet.TestHost/ResponseStream.cs b/src/Microsoft.AspNetCore.TestHost/ResponseStream.cs similarity index 100% rename from src/Microsoft.AspNet.TestHost/ResponseStream.cs rename to src/Microsoft.AspNetCore.TestHost/ResponseStream.cs diff --git a/src/Microsoft.AspNet.TestHost/TestServer.cs b/src/Microsoft.AspNetCore.TestHost/TestServer.cs similarity index 100% rename from src/Microsoft.AspNet.TestHost/TestServer.cs rename to src/Microsoft.AspNetCore.TestHost/TestServer.cs diff --git a/src/Microsoft.AspNet.TestHost/TestWebSocket.cs b/src/Microsoft.AspNetCore.TestHost/TestWebSocket.cs similarity index 100% rename from src/Microsoft.AspNet.TestHost/TestWebSocket.cs rename to src/Microsoft.AspNetCore.TestHost/TestWebSocket.cs diff --git a/src/Microsoft.AspNet.TestHost/WebSocketClient.cs b/src/Microsoft.AspNetCore.TestHost/WebSocketClient.cs similarity index 100% rename from src/Microsoft.AspNet.TestHost/WebSocketClient.cs rename to src/Microsoft.AspNetCore.TestHost/WebSocketClient.cs diff --git a/src/Microsoft.AspNet.TestHost/project.json b/src/Microsoft.AspNetCore.TestHost/project.json similarity index 100% rename from src/Microsoft.AspNet.TestHost/project.json rename to src/Microsoft.AspNetCore.TestHost/project.json diff --git a/test/Microsoft.AspNet.Hosting.Tests/Fakes/FakeOptions.cs b/test/Microsoft.AspNetCore.Hosting.Tests/Fakes/FakeOptions.cs similarity index 100% rename from test/Microsoft.AspNet.Hosting.Tests/Fakes/FakeOptions.cs rename to test/Microsoft.AspNetCore.Hosting.Tests/Fakes/FakeOptions.cs diff --git a/test/Microsoft.AspNet.Hosting.Tests/Fakes/FakeService.cs b/test/Microsoft.AspNetCore.Hosting.Tests/Fakes/FakeService.cs similarity index 100% rename from test/Microsoft.AspNet.Hosting.Tests/Fakes/FakeService.cs rename to test/Microsoft.AspNetCore.Hosting.Tests/Fakes/FakeService.cs diff --git a/test/Microsoft.AspNet.Hosting.Tests/Fakes/IFactoryService.cs b/test/Microsoft.AspNetCore.Hosting.Tests/Fakes/IFactoryService.cs similarity index 100% rename from test/Microsoft.AspNet.Hosting.Tests/Fakes/IFactoryService.cs rename to test/Microsoft.AspNetCore.Hosting.Tests/Fakes/IFactoryService.cs diff --git a/test/Microsoft.AspNet.Hosting.Tests/Fakes/IFakeEveryService.cs b/test/Microsoft.AspNetCore.Hosting.Tests/Fakes/IFakeEveryService.cs similarity index 100% rename from test/Microsoft.AspNet.Hosting.Tests/Fakes/IFakeEveryService.cs rename to test/Microsoft.AspNetCore.Hosting.Tests/Fakes/IFakeEveryService.cs diff --git a/test/Microsoft.AspNet.Hosting.Tests/Fakes/IFakeScopedService.cs b/test/Microsoft.AspNetCore.Hosting.Tests/Fakes/IFakeScopedService.cs similarity index 100% rename from test/Microsoft.AspNet.Hosting.Tests/Fakes/IFakeScopedService.cs rename to test/Microsoft.AspNetCore.Hosting.Tests/Fakes/IFakeScopedService.cs diff --git a/test/Microsoft.AspNet.Hosting.Tests/Fakes/IFakeService.cs b/test/Microsoft.AspNetCore.Hosting.Tests/Fakes/IFakeService.cs similarity index 100% rename from test/Microsoft.AspNet.Hosting.Tests/Fakes/IFakeService.cs rename to test/Microsoft.AspNetCore.Hosting.Tests/Fakes/IFakeService.cs diff --git a/test/Microsoft.AspNet.Hosting.Tests/Fakes/IFakeServiceInstance.cs b/test/Microsoft.AspNetCore.Hosting.Tests/Fakes/IFakeServiceInstance.cs similarity index 100% rename from test/Microsoft.AspNet.Hosting.Tests/Fakes/IFakeServiceInstance.cs rename to test/Microsoft.AspNetCore.Hosting.Tests/Fakes/IFakeServiceInstance.cs diff --git a/test/Microsoft.AspNet.Hosting.Tests/Fakes/IFakeSingletonService.cs b/test/Microsoft.AspNetCore.Hosting.Tests/Fakes/IFakeSingletonService.cs similarity index 100% rename from test/Microsoft.AspNet.Hosting.Tests/Fakes/IFakeSingletonService.cs rename to test/Microsoft.AspNetCore.Hosting.Tests/Fakes/IFakeSingletonService.cs diff --git a/test/Microsoft.AspNet.Hosting.Tests/Fakes/IFakeStartupCallback.cs b/test/Microsoft.AspNetCore.Hosting.Tests/Fakes/IFakeStartupCallback.cs similarity index 100% rename from test/Microsoft.AspNet.Hosting.Tests/Fakes/IFakeStartupCallback.cs rename to test/Microsoft.AspNetCore.Hosting.Tests/Fakes/IFakeStartupCallback.cs diff --git a/test/Microsoft.AspNet.Hosting.Tests/Fakes/INonexistentService.cs b/test/Microsoft.AspNetCore.Hosting.Tests/Fakes/INonexistentService.cs similarity index 100% rename from test/Microsoft.AspNet.Hosting.Tests/Fakes/INonexistentService.cs rename to test/Microsoft.AspNetCore.Hosting.Tests/Fakes/INonexistentService.cs diff --git a/test/Microsoft.AspNet.Hosting.Tests/Fakes/RuntimeEnvironment.cs b/test/Microsoft.AspNetCore.Hosting.Tests/Fakes/RuntimeEnvironment.cs similarity index 100% rename from test/Microsoft.AspNet.Hosting.Tests/Fakes/RuntimeEnvironment.cs rename to test/Microsoft.AspNetCore.Hosting.Tests/Fakes/RuntimeEnvironment.cs diff --git a/test/Microsoft.AspNet.Hosting.Tests/Fakes/Startup.cs b/test/Microsoft.AspNetCore.Hosting.Tests/Fakes/Startup.cs similarity index 100% rename from test/Microsoft.AspNet.Hosting.Tests/Fakes/Startup.cs rename to test/Microsoft.AspNetCore.Hosting.Tests/Fakes/Startup.cs diff --git a/test/Microsoft.AspNet.Hosting.Tests/Fakes/StartupBase.cs b/test/Microsoft.AspNetCore.Hosting.Tests/Fakes/StartupBase.cs similarity index 100% rename from test/Microsoft.AspNet.Hosting.Tests/Fakes/StartupBase.cs rename to test/Microsoft.AspNetCore.Hosting.Tests/Fakes/StartupBase.cs diff --git a/test/Microsoft.AspNet.Hosting.Tests/Fakes/StartupBoom.cs b/test/Microsoft.AspNetCore.Hosting.Tests/Fakes/StartupBoom.cs similarity index 100% rename from test/Microsoft.AspNet.Hosting.Tests/Fakes/StartupBoom.cs rename to test/Microsoft.AspNetCore.Hosting.Tests/Fakes/StartupBoom.cs diff --git a/test/Microsoft.AspNet.Hosting.Tests/Fakes/StartupConfigureServicesThrows.cs b/test/Microsoft.AspNetCore.Hosting.Tests/Fakes/StartupConfigureServicesThrows.cs similarity index 100% rename from test/Microsoft.AspNet.Hosting.Tests/Fakes/StartupConfigureServicesThrows.cs rename to test/Microsoft.AspNetCore.Hosting.Tests/Fakes/StartupConfigureServicesThrows.cs diff --git a/test/Microsoft.AspNet.Hosting.Tests/Fakes/StartupConfigureThrows.cs b/test/Microsoft.AspNetCore.Hosting.Tests/Fakes/StartupConfigureThrows.cs similarity index 100% rename from test/Microsoft.AspNet.Hosting.Tests/Fakes/StartupConfigureThrows.cs rename to test/Microsoft.AspNetCore.Hosting.Tests/Fakes/StartupConfigureThrows.cs diff --git a/test/Microsoft.AspNet.Hosting.Tests/Fakes/StartupCtorThrows.cs b/test/Microsoft.AspNetCore.Hosting.Tests/Fakes/StartupCtorThrows.cs similarity index 100% rename from test/Microsoft.AspNet.Hosting.Tests/Fakes/StartupCtorThrows.cs rename to test/Microsoft.AspNetCore.Hosting.Tests/Fakes/StartupCtorThrows.cs diff --git a/test/Microsoft.AspNet.Hosting.Tests/Fakes/StartupNoServices.cs b/test/Microsoft.AspNetCore.Hosting.Tests/Fakes/StartupNoServices.cs similarity index 100% rename from test/Microsoft.AspNet.Hosting.Tests/Fakes/StartupNoServices.cs rename to test/Microsoft.AspNetCore.Hosting.Tests/Fakes/StartupNoServices.cs diff --git a/test/Microsoft.AspNet.Hosting.Tests/Fakes/StartupPrivateConfigure.cs b/test/Microsoft.AspNetCore.Hosting.Tests/Fakes/StartupPrivateConfigure.cs similarity index 100% rename from test/Microsoft.AspNet.Hosting.Tests/Fakes/StartupPrivateConfigure.cs rename to test/Microsoft.AspNetCore.Hosting.Tests/Fakes/StartupPrivateConfigure.cs diff --git a/test/Microsoft.AspNet.Hosting.Tests/Fakes/StartupStaticCtorThrows.cs b/test/Microsoft.AspNetCore.Hosting.Tests/Fakes/StartupStaticCtorThrows.cs similarity index 100% rename from test/Microsoft.AspNet.Hosting.Tests/Fakes/StartupStaticCtorThrows.cs rename to test/Microsoft.AspNetCore.Hosting.Tests/Fakes/StartupStaticCtorThrows.cs diff --git a/test/Microsoft.AspNet.Hosting.Tests/Fakes/StartupThrowTypeLoadException.cs b/test/Microsoft.AspNetCore.Hosting.Tests/Fakes/StartupThrowTypeLoadException.cs similarity index 100% rename from test/Microsoft.AspNet.Hosting.Tests/Fakes/StartupThrowTypeLoadException.cs rename to test/Microsoft.AspNetCore.Hosting.Tests/Fakes/StartupThrowTypeLoadException.cs diff --git a/test/Microsoft.AspNet.Hosting.Tests/Fakes/StartupTwoConfigureServices.cs b/test/Microsoft.AspNetCore.Hosting.Tests/Fakes/StartupTwoConfigureServices.cs similarity index 100% rename from test/Microsoft.AspNet.Hosting.Tests/Fakes/StartupTwoConfigureServices.cs rename to test/Microsoft.AspNetCore.Hosting.Tests/Fakes/StartupTwoConfigureServices.cs diff --git a/test/Microsoft.AspNet.Hosting.Tests/Fakes/StartupTwoConfigures.cs b/test/Microsoft.AspNetCore.Hosting.Tests/Fakes/StartupTwoConfigures.cs similarity index 100% rename from test/Microsoft.AspNet.Hosting.Tests/Fakes/StartupTwoConfigures.cs rename to test/Microsoft.AspNetCore.Hosting.Tests/Fakes/StartupTwoConfigures.cs diff --git a/test/Microsoft.AspNet.Hosting.Tests/Fakes/StartupWithConfigureServices.cs b/test/Microsoft.AspNetCore.Hosting.Tests/Fakes/StartupWithConfigureServices.cs similarity index 100% rename from test/Microsoft.AspNet.Hosting.Tests/Fakes/StartupWithConfigureServices.cs rename to test/Microsoft.AspNetCore.Hosting.Tests/Fakes/StartupWithConfigureServices.cs diff --git a/test/Microsoft.AspNet.Hosting.Tests/Fakes/StartupWithConfigureServicesNotResolved.cs b/test/Microsoft.AspNetCore.Hosting.Tests/Fakes/StartupWithConfigureServicesNotResolved.cs similarity index 100% rename from test/Microsoft.AspNet.Hosting.Tests/Fakes/StartupWithConfigureServicesNotResolved.cs rename to test/Microsoft.AspNetCore.Hosting.Tests/Fakes/StartupWithConfigureServicesNotResolved.cs diff --git a/test/Microsoft.AspNet.Hosting.Tests/Fakes/StartupWithHostingEnvironment.cs b/test/Microsoft.AspNetCore.Hosting.Tests/Fakes/StartupWithHostingEnvironment.cs similarity index 100% rename from test/Microsoft.AspNet.Hosting.Tests/Fakes/StartupWithHostingEnvironment.cs rename to test/Microsoft.AspNetCore.Hosting.Tests/Fakes/StartupWithHostingEnvironment.cs diff --git a/test/Microsoft.AspNet.Hosting.Tests/Fakes/StartupWithNullConfigureServices.cs b/test/Microsoft.AspNetCore.Hosting.Tests/Fakes/StartupWithNullConfigureServices.cs similarity index 100% rename from test/Microsoft.AspNet.Hosting.Tests/Fakes/StartupWithNullConfigureServices.cs rename to test/Microsoft.AspNetCore.Hosting.Tests/Fakes/StartupWithNullConfigureServices.cs diff --git a/test/Microsoft.AspNet.Hosting.Tests/Fakes/StartupWithServices.cs b/test/Microsoft.AspNetCore.Hosting.Tests/Fakes/StartupWithServices.cs similarity index 100% rename from test/Microsoft.AspNet.Hosting.Tests/Fakes/StartupWithServices.cs rename to test/Microsoft.AspNetCore.Hosting.Tests/Fakes/StartupWithServices.cs diff --git a/test/Microsoft.AspNet.Hosting.Tests/HostingEnvironmentExtensionsTests.cs b/test/Microsoft.AspNetCore.Hosting.Tests/HostingEnvironmentExtensionsTests.cs similarity index 100% rename from test/Microsoft.AspNet.Hosting.Tests/HostingEnvironmentExtensionsTests.cs rename to test/Microsoft.AspNetCore.Hosting.Tests/HostingEnvironmentExtensionsTests.cs diff --git a/test/Microsoft.AspNet.Hosting.Tests/Microsoft.AspNet.Hosting.Tests.xproj b/test/Microsoft.AspNetCore.Hosting.Tests/Microsoft.AspNetCore.Hosting.Tests.xproj similarity index 100% rename from test/Microsoft.AspNet.Hosting.Tests/Microsoft.AspNet.Hosting.Tests.xproj rename to test/Microsoft.AspNetCore.Hosting.Tests/Microsoft.AspNetCore.Hosting.Tests.xproj diff --git a/test/Microsoft.AspNet.Hosting.Tests/StartupManagerTests.cs b/test/Microsoft.AspNetCore.Hosting.Tests/StartupManagerTests.cs similarity index 100% rename from test/Microsoft.AspNet.Hosting.Tests/StartupManagerTests.cs rename to test/Microsoft.AspNetCore.Hosting.Tests/StartupManagerTests.cs diff --git a/test/Microsoft.AspNet.Hosting.Tests/WebHostBuilderTests.cs b/test/Microsoft.AspNetCore.Hosting.Tests/WebHostBuilderTests.cs similarity index 100% rename from test/Microsoft.AspNet.Hosting.Tests/WebHostBuilderTests.cs rename to test/Microsoft.AspNetCore.Hosting.Tests/WebHostBuilderTests.cs diff --git a/test/Microsoft.AspNet.Hosting.Tests/WebHostConfigurationsTests.cs b/test/Microsoft.AspNetCore.Hosting.Tests/WebHostConfigurationsTests.cs similarity index 100% rename from test/Microsoft.AspNet.Hosting.Tests/WebHostConfigurationsTests.cs rename to test/Microsoft.AspNetCore.Hosting.Tests/WebHostConfigurationsTests.cs diff --git a/test/Microsoft.AspNet.Hosting.Tests/WebHostTests.cs b/test/Microsoft.AspNetCore.Hosting.Tests/WebHostTests.cs similarity index 100% rename from test/Microsoft.AspNet.Hosting.Tests/WebHostTests.cs rename to test/Microsoft.AspNetCore.Hosting.Tests/WebHostTests.cs diff --git a/test/Microsoft.AspNet.Hosting.Tests/project.json b/test/Microsoft.AspNetCore.Hosting.Tests/project.json similarity index 100% rename from test/Microsoft.AspNet.Hosting.Tests/project.json rename to test/Microsoft.AspNetCore.Hosting.Tests/project.json diff --git a/test/Microsoft.AspNet.Hosting.Tests/testroot/TextFile.txt b/test/Microsoft.AspNetCore.Hosting.Tests/testroot/TextFile.txt similarity index 100% rename from test/Microsoft.AspNet.Hosting.Tests/testroot/TextFile.txt rename to test/Microsoft.AspNetCore.Hosting.Tests/testroot/TextFile.txt diff --git a/test/Microsoft.AspNet.Hosting.Tests/testroot/wwwroot/README b/test/Microsoft.AspNetCore.Hosting.Tests/testroot/wwwroot/README similarity index 100% rename from test/Microsoft.AspNet.Hosting.Tests/testroot/wwwroot/README rename to test/Microsoft.AspNetCore.Hosting.Tests/testroot/wwwroot/README diff --git a/test/Microsoft.AspNet.TestHost.Tests/ClientHandlerTests.cs b/test/Microsoft.AspNetCore.TestHost.Tests/ClientHandlerTests.cs similarity index 100% rename from test/Microsoft.AspNet.TestHost.Tests/ClientHandlerTests.cs rename to test/Microsoft.AspNetCore.TestHost.Tests/ClientHandlerTests.cs diff --git a/test/Microsoft.AspNet.TestHost.Tests/Microsoft.AspNet.TestHost.Tests.xproj b/test/Microsoft.AspNetCore.TestHost.Tests/Microsoft.AspNetCore.TestHost.Tests.xproj similarity index 100% rename from test/Microsoft.AspNet.TestHost.Tests/Microsoft.AspNet.TestHost.Tests.xproj rename to test/Microsoft.AspNetCore.TestHost.Tests/Microsoft.AspNetCore.TestHost.Tests.xproj diff --git a/test/Microsoft.AspNet.TestHost.Tests/Properties/AssemblyInfo.cs b/test/Microsoft.AspNetCore.TestHost.Tests/Properties/AssemblyInfo.cs similarity index 100% rename from test/Microsoft.AspNet.TestHost.Tests/Properties/AssemblyInfo.cs rename to test/Microsoft.AspNetCore.TestHost.Tests/Properties/AssemblyInfo.cs diff --git a/test/Microsoft.AspNet.TestHost.Tests/RequestBuilderTests.cs b/test/Microsoft.AspNetCore.TestHost.Tests/RequestBuilderTests.cs similarity index 100% rename from test/Microsoft.AspNet.TestHost.Tests/RequestBuilderTests.cs rename to test/Microsoft.AspNetCore.TestHost.Tests/RequestBuilderTests.cs diff --git a/test/Microsoft.AspNet.TestHost.Tests/ResponseFeatureTests.cs b/test/Microsoft.AspNetCore.TestHost.Tests/ResponseFeatureTests.cs similarity index 100% rename from test/Microsoft.AspNet.TestHost.Tests/ResponseFeatureTests.cs rename to test/Microsoft.AspNetCore.TestHost.Tests/ResponseFeatureTests.cs diff --git a/test/Microsoft.AspNet.TestHost.Tests/TestClientTests.cs b/test/Microsoft.AspNetCore.TestHost.Tests/TestClientTests.cs similarity index 100% rename from test/Microsoft.AspNet.TestHost.Tests/TestClientTests.cs rename to test/Microsoft.AspNetCore.TestHost.Tests/TestClientTests.cs diff --git a/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs b/test/Microsoft.AspNetCore.TestHost.Tests/TestServerTests.cs similarity index 100% rename from test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs rename to test/Microsoft.AspNetCore.TestHost.Tests/TestServerTests.cs diff --git a/test/Microsoft.AspNet.TestHost.Tests/project.json b/test/Microsoft.AspNetCore.TestHost.Tests/project.json similarity index 100% rename from test/Microsoft.AspNet.TestHost.Tests/project.json rename to test/Microsoft.AspNetCore.TestHost.Tests/project.json From e62ceb852827d386b492abc9cc6801b1a8c70263 Mon Sep 17 00:00:00 2001 From: "N. Taylor Mullen" Date: Fri, 22 Jan 2016 12:21:40 -0800 Subject: [PATCH 505/987] Rename AspNet 5 file contents. See https://github.com/aspnet/Announcements/issues/144 for more information. --- Hosting.sln | 18 ++++----- NuGetPackageVerifier.json | 10 ++--- .../SampleStartups/StartupBlockingOnStart.cs | 8 ++-- .../StartupConfigureAddresses.cs | 6 +-- .../StartupExternallyControlled.cs | 8 ++-- samples/SampleStartups/StartupFullControl.cs | 8 ++-- samples/SampleStartups/StartupHelloWorld.cs | 6 +-- samples/SampleStartups/project.json | 4 +- .../EnvironmentName.cs | 2 +- .../HostingEnvironmentExtensions.cs | 2 +- .../IApplicationLifetime.cs | 2 +- .../IHostingEnvironment.cs | 2 +- .../IStartupFilter.cs | 4 +- .../IWebHost.cs | 6 +-- .../IWebHostBuilder.cs | 8 ++-- .../WebHostDefaults.cs | 4 +- .../project.json | 4 +- .../IHttpApplication.cs | 6 +-- .../IServer.cs | 6 +-- .../IServerAddressesFeature.cs | 4 +- .../IServerFactory.cs | 2 +- .../project.json | 2 +- ...t.AspNetCore.Hosting.WindowsServices.xproj | 4 +- .../WebHostService.cs | 4 +- .../WebHostWindowsServiceExtensions.cs | 4 +- .../project.json | 4 +- .../Builder/ApplicationBuilderFactory.cs | 8 ++-- .../Builder/IApplicationBuilderFactory.cs | 6 +-- .../Internal/ApplicationLifetime.cs | 2 +- .../AutoRequestServicesStartupFilter.cs | 6 +-- .../Internal/HostingApplication.cs | 22 +++++----- .../Internal/HostingEnvironment.cs | 4 +- .../Internal/HostingEnvironmentExtensions.cs | 4 +- .../Internal/HostingLoggerExtensions.cs | 6 +-- .../Internal/LoggerEventIds.cs | 4 +- .../Internal/NullFileProvider.cs | 4 +- .../RequestServicesContainerFeature.cs | 4 +- .../RequestServicesContainerMiddleware.cs | 10 ++--- .../Internal/WebHost.cs | 14 +++---- .../Internal/WebHostOptions.cs | 4 +- .../Properties/AssemblyInfo.cs | 2 +- .../Server/IServerLoader.cs | 2 +- .../Server/ServerLoader.cs | 2 +- .../Startup/ConfigureDelegate.cs | 4 +- .../Startup/ConfigureServicesDelegate.cs | 2 +- .../Startup/IStartupLoader.cs | 2 +- .../Startup/StartupExceptionPage.cs | 2 +- .../Startup/StartupLoader.cs | 2 +- .../Startup/StartupMethods.cs | 4 +- .../WebHostBuilder.cs | 18 ++++----- .../WebHostBuilderExtensions.cs | 4 +- .../WebHostConfiguration.cs | 4 +- .../WebHostExtensions.cs | 6 +-- .../resources/GenericError_Footer.html | 4 +- src/Microsoft.AspNetCore.Hosting/project.json | 8 ++-- .../Common/DeploymentParameters.cs | 2 +- .../Common/DeploymentResult.cs | 2 +- .../Common/DotnetArchitecture.cs | 2 +- .../Common/DotnetFlavor.cs | 2 +- .../Common/RetryHelper.cs | 2 +- .../Common/ServerType.cs | 2 +- .../Common/TestUriHelper.cs | 4 +- .../Deployers/ApplicationDeployer.cs | 4 +- .../Deployers/ApplicationDeployerFactory.cs | 2 +- .../Deployers/IApplicationDeployer.cs | 2 +- .../Deployers/IISDeployer.cs | 4 +- .../Deployers/IISExpressDeployer.cs | 4 +- .../Deployers/SelfHostDeployer.cs | 6 +-- .../project.json | 2 +- .../xunit/SkipIfCurrentRuntimeIsCoreClr.cs | 4 +- .../SkipIfIISVariationsNotEnabledAttribute.cs | 4 +- .../xunit/SkipOn32BitOSAttribute.cs | 4 +- .../ClientHandler.cs | 10 ++--- .../Properties/AssemblyInfo.cs | 6 +-- .../RequestBuilder.cs | 2 +- .../RequestFeature.cs | 8 ++-- .../ResponseFeature.cs | 8 ++-- .../ResponseStream.cs | 2 +- .../TestServer.cs | 14 +++---- .../TestWebSocket.cs | 4 +- .../WebSocketClient.cs | 10 ++--- .../project.json | 2 +- .../Fakes/FakeOptions.cs | 2 +- .../Fakes/FakeService.cs | 2 +- .../Fakes/IFactoryService.cs | 2 +- .../Fakes/IFakeEveryService.cs | 2 +- .../Fakes/IFakeScopedService.cs | 2 +- .../Fakes/IFakeService.cs | 2 +- .../Fakes/IFakeServiceInstance.cs | 2 +- .../Fakes/IFakeSingletonService.cs | 2 +- .../Fakes/IFakeStartupCallback.cs | 2 +- .../Fakes/INonexistentService.cs | 2 +- .../Fakes/RuntimeEnvironment.cs | 4 +- .../Fakes/Startup.cs | 4 +- .../Fakes/StartupBase.cs | 2 +- .../Fakes/StartupBoom.cs | 2 +- .../Fakes/StartupConfigureServicesThrows.cs | 4 +- .../Fakes/StartupConfigureThrows.cs | 4 +- .../Fakes/StartupCtorThrows.cs | 4 +- .../Fakes/StartupNoServices.cs | 4 +- .../Fakes/StartupPrivateConfigure.cs | 6 +-- .../Fakes/StartupStaticCtorThrows.cs | 4 +- .../Fakes/StartupThrowTypeLoadException.cs | 4 +- .../Fakes/StartupTwoConfigureServices.cs | 4 +- .../Fakes/StartupTwoConfigures.cs | 4 +- .../Fakes/StartupWithConfigureServices.cs | 4 +- ...StartupWithConfigureServicesNotResolved.cs | 4 +- .../Fakes/StartupWithHostingEnvironment.cs | 6 +-- .../Fakes/StartupWithNullConfigureServices.cs | 4 +- .../Fakes/StartupWithServices.cs | 4 +- .../HostingEnvironmentExtensionsTests.cs | 6 +-- .../StartupManagerTests.cs | 32 +++++++-------- .../WebHostBuilderTests.cs | 22 +++++----- .../WebHostConfigurationsTests.cs | 8 ++-- .../WebHostTests.cs | 40 +++++++++---------- .../project.json | 6 +-- .../ClientHandlerTests.cs | 20 +++++----- .../Properties/AssemblyInfo.cs | 4 +- .../RequestBuilderTests.cs | 6 +-- .../ResponseFeatureTests.cs | 2 +- .../TestClientTests.cs | 12 +++--- .../TestServerTests.cs | 20 +++++----- .../project.json | 4 +- 123 files changed, 347 insertions(+), 347 deletions(-) diff --git a/Hosting.sln b/Hosting.sln index ea81db18f9..a4330f5c38 100644 --- a/Hosting.sln +++ b/Hosting.sln @@ -1,4 +1,4 @@ - + Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 14 VisualStudioVersion = 14.0.24720.0 @@ -7,30 +7,30 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{E0497F39-AFF EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{FEB39027-9158-4DE2-997F-7ADAEF8188D0}" EndProject -Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNet.TestHost.Tests", "test\Microsoft.AspNet.TestHost.Tests\Microsoft.AspNet.TestHost.Tests.xproj", "{0ACB2719-9484-49B5-B8E3-117091192511}" +Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNetCore.TestHost.Tests", "test\Microsoft.AspNetCore.TestHost.Tests\Microsoft.AspNetCore.TestHost.Tests.xproj", "{0ACB2719-9484-49B5-B8E3-117091192511}" EndProject -Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNet.TestHost", "src\Microsoft.AspNet.TestHost\Microsoft.AspNet.TestHost.xproj", "{1A415A3F-1081-45DB-809B-EE19CEA02DC0}" +Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNetCore.TestHost", "src\Microsoft.AspNetCore.TestHost\Microsoft.AspNetCore.TestHost.xproj", "{1A415A3F-1081-45DB-809B-EE19CEA02DC0}" EndProject -Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNet.Hosting", "src\Microsoft.AspNet.Hosting\Microsoft.AspNet.Hosting.xproj", "{3944F036-7E75-47E8-AA52-C4B89A64EC3A}" +Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNetCore.Hosting", "src\Microsoft.AspNetCore.Hosting\Microsoft.AspNetCore.Hosting.xproj", "{3944F036-7E75-47E8-AA52-C4B89A64EC3A}" EndProject -Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNet.Hosting.Tests", "test\Microsoft.AspNet.Hosting.Tests\Microsoft.AspNet.Hosting.Tests.xproj", "{D4F18D58-52B1-435D-A012-10F2CDF158C4}" +Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNetCore.Hosting.Tests", "test\Microsoft.AspNetCore.Hosting.Tests\Microsoft.AspNetCore.Hosting.Tests.xproj", "{D4F18D58-52B1-435D-A012-10F2CDF158C4}" EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{A66E3673-3976-4152-B902-2D0EC1428EA2}" ProjectSection(SolutionItems) = preProject global.json = global.json EndProjectSection EndProject -Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNet.Hosting.Abstractions", "src\Microsoft.AspNet.Hosting.Abstractions\Microsoft.AspNet.Hosting.Abstractions.xproj", "{BB780FBB-7842-4759-8DE7-96FA2E5571C1}" +Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNetCore.Hosting.Abstractions", "src\Microsoft.AspNetCore.Hosting.Abstractions\Microsoft.AspNetCore.Hosting.Abstractions.xproj", "{BB780FBB-7842-4759-8DE7-96FA2E5571C1}" EndProject -Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNet.Hosting.Server.Abstractions", "src\Microsoft.AspNet.Hosting.Server.Abstractions\Microsoft.AspNet.Hosting.Server.Abstractions.xproj", "{FDBBA081-5248-4FC0-9E08-B46BEF3FA438}" +Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNetCore.Hosting.Server.Abstractions", "src\Microsoft.AspNetCore.Hosting.Server.Abstractions\Microsoft.AspNetCore.Hosting.Server.Abstractions.xproj", "{FDBBA081-5248-4FC0-9E08-B46BEF3FA438}" EndProject -Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNet.Server.Testing", "src\Microsoft.AspNet.Server.Testing\Microsoft.AspNet.Server.Testing.xproj", "{3DA89347-6731-4366-80C4-548F24E8607B}" +Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNetCore.Server.Testing", "src\Microsoft.AspNetCore.Server.Testing\Microsoft.AspNetCore.Server.Testing.xproj", "{3DA89347-6731-4366-80C4-548F24E8607B}" EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "samples", "samples", "{9C7520A0-F2EB-411C-8BB2-80B39C937217}" EndProject Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "SampleStartups", "samples\SampleStartups\SampleStartups.xproj", "{485B6745-7648-400A-A969-F68FCF194E46}" EndProject -Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNet.Hosting.WindowsServices", "src\Microsoft.AspNet.Hosting.WindowsServices\Microsoft.AspNet.Hosting.WindowsServices.xproj", "{03148731-EA95-40A2-BAE8-A12315EA1748}" +Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNetCore.Hosting.WindowsServices", "src\Microsoft.AspNetCore.Hosting.WindowsServices\Microsoft.AspNetCore.Hosting.WindowsServices.xproj", "{03148731-EA95-40A2-BAE8-A12315EA1748}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution diff --git a/NuGetPackageVerifier.json b/NuGetPackageVerifier.json index c599e23fea..a41c932dae 100644 --- a/NuGetPackageVerifier.json +++ b/NuGetPackageVerifier.json @@ -9,11 +9,11 @@ "StrictSemanticVersionValidationRule" ], "packages": { - "Microsoft.AspNet.Hosting": { }, - "Microsoft.AspNet.Hosting.Abstractions": { }, - "Microsoft.AspNet.Hosting.Server.Abstractions": { }, - "Microsoft.AspNet.Server.Testing": { }, - "Microsoft.AspNet.TestHost": { } + "Microsoft.AspNetCore.Hosting": { }, + "Microsoft.AspNetCore.Hosting.Abstractions": { }, + "Microsoft.AspNetCore.Hosting.Server.Abstractions": { }, + "Microsoft.AspNetCore.Server.Testing": { }, + "Microsoft.AspNetCore.TestHost": { } } }, "Default": { // Rules to run for packages not listed in any other set. diff --git a/samples/SampleStartups/StartupBlockingOnStart.cs b/samples/SampleStartups/StartupBlockingOnStart.cs index 40d914f379..2f7b3bc6ee 100644 --- a/samples/SampleStartups/StartupBlockingOnStart.cs +++ b/samples/SampleStartups/StartupBlockingOnStart.cs @@ -1,7 +1,7 @@ -using System; -using Microsoft.AspNet.Builder; -using Microsoft.AspNet.Hosting; -using Microsoft.AspNet.Http; +using System; +using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.Http; using Microsoft.Extensions.DependencyInjection; // Note that this sample will not run. It is only here to illustrate usage patterns. diff --git a/samples/SampleStartups/StartupConfigureAddresses.cs b/samples/SampleStartups/StartupConfigureAddresses.cs index 31a9a38a43..418e611691 100644 --- a/samples/SampleStartups/StartupConfigureAddresses.cs +++ b/samples/SampleStartups/StartupConfigureAddresses.cs @@ -1,6 +1,6 @@ -using Microsoft.AspNet.Builder; -using Microsoft.AspNet.Hosting; -using Microsoft.AspNet.Http; +using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.Http; using Microsoft.Extensions.DependencyInjection; // Note that this sample will not run. It is only here to illustrate usage patterns. diff --git a/samples/SampleStartups/StartupExternallyControlled.cs b/samples/SampleStartups/StartupExternallyControlled.cs index b024ede322..e0301d865c 100644 --- a/samples/SampleStartups/StartupExternallyControlled.cs +++ b/samples/SampleStartups/StartupExternallyControlled.cs @@ -1,8 +1,8 @@ -using System; +using System; using System.Collections.Generic; -using Microsoft.AspNet.Builder; -using Microsoft.AspNet.Hosting; -using Microsoft.AspNet.Http; +using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.Http; using Microsoft.Extensions.DependencyInjection; // Note that this sample will not run. It is only here to illustrate usage patterns. diff --git a/samples/SampleStartups/StartupFullControl.cs b/samples/SampleStartups/StartupFullControl.cs index 6445a77bc4..838aa74ce7 100644 --- a/samples/SampleStartups/StartupFullControl.cs +++ b/samples/SampleStartups/StartupFullControl.cs @@ -1,7 +1,7 @@ -using System; +using System; using System.IO; -using Microsoft.AspNet.Builder; -using Microsoft.AspNet.Hosting; +using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; @@ -14,7 +14,7 @@ namespace SampleStartups public static void Main(string[] args) { var host = new WebHostBuilder() - .UseServer("Microsoft.AspNet.Server.Kestrel") // Set the server manually + .UseServer("Microsoft.AspNetCore.Server.Kestrel") // Set the server manually .UseApplicationBasePath(Directory.GetCurrentDirectory()) // Override the application base with the current directory .UseUrls("http://*:1000", "https://*:902") .UseEnvironment("Development") diff --git a/samples/SampleStartups/StartupHelloWorld.cs b/samples/SampleStartups/StartupHelloWorld.cs index 7a76ca4563..0c9d56632b 100644 --- a/samples/SampleStartups/StartupHelloWorld.cs +++ b/samples/SampleStartups/StartupHelloWorld.cs @@ -1,6 +1,6 @@ -using Microsoft.AspNet.Builder; -using Microsoft.AspNet.Hosting; -using Microsoft.AspNet.Http; +using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.Http; using Microsoft.Extensions.DependencyInjection; // Note that this sample will not run. It is only here to illustrate usage patterns. diff --git a/samples/SampleStartups/project.json b/samples/SampleStartups/project.json index 4fb88a1477..f26e655e65 100644 --- a/samples/SampleStartups/project.json +++ b/samples/SampleStartups/project.json @@ -1,7 +1,7 @@ -{ +{ "version": "1.0.0-*", "dependencies": { - "Microsoft.AspNet.Hosting": "1.0.0-*" + "Microsoft.AspNetCore.Hosting": "1.0.0-*" }, "frameworks": { "dnx451": { }, diff --git a/src/Microsoft.AspNetCore.Hosting.Abstractions/EnvironmentName.cs b/src/Microsoft.AspNetCore.Hosting.Abstractions/EnvironmentName.cs index 6ab7b945c1..d5522d1124 100644 --- a/src/Microsoft.AspNetCore.Hosting.Abstractions/EnvironmentName.cs +++ b/src/Microsoft.AspNetCore.Hosting.Abstractions/EnvironmentName.cs @@ -1,7 +1,7 @@ // 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. -namespace Microsoft.AspNet.Hosting +namespace Microsoft.AspNetCore.Hosting { /// /// Commonly used environment names. diff --git a/src/Microsoft.AspNetCore.Hosting.Abstractions/HostingEnvironmentExtensions.cs b/src/Microsoft.AspNetCore.Hosting.Abstractions/HostingEnvironmentExtensions.cs index 05cf2c9ceb..742001c2c9 100644 --- a/src/Microsoft.AspNetCore.Hosting.Abstractions/HostingEnvironmentExtensions.cs +++ b/src/Microsoft.AspNetCore.Hosting.Abstractions/HostingEnvironmentExtensions.cs @@ -4,7 +4,7 @@ using System; using System.IO; -namespace Microsoft.AspNet.Hosting +namespace Microsoft.AspNetCore.Hosting { /// /// Extension methods for . diff --git a/src/Microsoft.AspNetCore.Hosting.Abstractions/IApplicationLifetime.cs b/src/Microsoft.AspNetCore.Hosting.Abstractions/IApplicationLifetime.cs index 3dd7bcf8aa..c3e4336521 100644 --- a/src/Microsoft.AspNetCore.Hosting.Abstractions/IApplicationLifetime.cs +++ b/src/Microsoft.AspNetCore.Hosting.Abstractions/IApplicationLifetime.cs @@ -3,7 +3,7 @@ using System.Threading; -namespace Microsoft.AspNet.Hosting +namespace Microsoft.AspNetCore.Hosting { /// /// Allows consumers to perform cleanup during a graceful shutdown. diff --git a/src/Microsoft.AspNetCore.Hosting.Abstractions/IHostingEnvironment.cs b/src/Microsoft.AspNetCore.Hosting.Abstractions/IHostingEnvironment.cs index 5878bd489c..ba1ef3db98 100644 --- a/src/Microsoft.AspNetCore.Hosting.Abstractions/IHostingEnvironment.cs +++ b/src/Microsoft.AspNetCore.Hosting.Abstractions/IHostingEnvironment.cs @@ -4,7 +4,7 @@ using Microsoft.Extensions.Configuration; using Microsoft.Extensions.FileProviders; -namespace Microsoft.AspNet.Hosting +namespace Microsoft.AspNetCore.Hosting { /// /// Provides information about the web hosting environment an application is running in. diff --git a/src/Microsoft.AspNetCore.Hosting.Abstractions/IStartupFilter.cs b/src/Microsoft.AspNetCore.Hosting.Abstractions/IStartupFilter.cs index f89fba525c..2f0a3cf39d 100644 --- a/src/Microsoft.AspNetCore.Hosting.Abstractions/IStartupFilter.cs +++ b/src/Microsoft.AspNetCore.Hosting.Abstractions/IStartupFilter.cs @@ -2,9 +2,9 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using Microsoft.AspNet.Builder; +using Microsoft.AspNetCore.Builder; -namespace Microsoft.AspNet.Hosting +namespace Microsoft.AspNetCore.Hosting { public interface IStartupFilter { diff --git a/src/Microsoft.AspNetCore.Hosting.Abstractions/IWebHost.cs b/src/Microsoft.AspNetCore.Hosting.Abstractions/IWebHost.cs index 45522b6b4c..dbf80ea53a 100644 --- a/src/Microsoft.AspNetCore.Hosting.Abstractions/IWebHost.cs +++ b/src/Microsoft.AspNetCore.Hosting.Abstractions/IWebHost.cs @@ -1,10 +1,10 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// 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; -using Microsoft.AspNet.Http.Features; +using Microsoft.AspNetCore.Http.Features; -namespace Microsoft.AspNet.Hosting +namespace Microsoft.AspNetCore.Hosting { /// /// Represents a configured web host diff --git a/src/Microsoft.AspNetCore.Hosting.Abstractions/IWebHostBuilder.cs b/src/Microsoft.AspNetCore.Hosting.Abstractions/IWebHostBuilder.cs index 60017adb17..35f9950567 100644 --- a/src/Microsoft.AspNetCore.Hosting.Abstractions/IWebHostBuilder.cs +++ b/src/Microsoft.AspNetCore.Hosting.Abstractions/IWebHostBuilder.cs @@ -1,14 +1,14 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// 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; using System.Collections.Generic; -using Microsoft.AspNet.Builder; -using Microsoft.AspNet.Hosting.Server; +using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Hosting.Server; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; -namespace Microsoft.AspNet.Hosting +namespace Microsoft.AspNetCore.Hosting { /// /// A builder for diff --git a/src/Microsoft.AspNetCore.Hosting.Abstractions/WebHostDefaults.cs b/src/Microsoft.AspNetCore.Hosting.Abstractions/WebHostDefaults.cs index c87cff6476..9a4cfca8ce 100644 --- a/src/Microsoft.AspNetCore.Hosting.Abstractions/WebHostDefaults.cs +++ b/src/Microsoft.AspNetCore.Hosting.Abstractions/WebHostDefaults.cs @@ -1,7 +1,7 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// 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. -namespace Microsoft.AspNet.Hosting +namespace Microsoft.AspNetCore.Hosting { public static class WebHostDefaults { diff --git a/src/Microsoft.AspNetCore.Hosting.Abstractions/project.json b/src/Microsoft.AspNetCore.Hosting.Abstractions/project.json index e23808c2f1..b777403585 100644 --- a/src/Microsoft.AspNetCore.Hosting.Abstractions/project.json +++ b/src/Microsoft.AspNetCore.Hosting.Abstractions/project.json @@ -10,8 +10,8 @@ "url": "git://github.com/aspnet/hosting" }, "dependencies": { - "Microsoft.AspNet.Http.Abstractions": "1.0.0-*", - "Microsoft.AspNet.Hosting.Server.Abstractions": "1.0.0-*", + "Microsoft.AspNetCore.Http.Abstractions": "1.0.0-*", + "Microsoft.AspNetCore.Hosting.Server.Abstractions": "1.0.0-*", "Microsoft.Extensions.Configuration.Abstractions": "1.0.0-*", "Microsoft.Extensions.DependencyInjection.Abstractions": "1.0.0-*", "Microsoft.Extensions.FileProviders.Abstractions": "1.0.0-*" diff --git a/src/Microsoft.AspNetCore.Hosting.Server.Abstractions/IHttpApplication.cs b/src/Microsoft.AspNetCore.Hosting.Server.Abstractions/IHttpApplication.cs index 07cbe53f82..e35d4b6d56 100644 --- a/src/Microsoft.AspNetCore.Hosting.Server.Abstractions/IHttpApplication.cs +++ b/src/Microsoft.AspNetCore.Hosting.Server.Abstractions/IHttpApplication.cs @@ -1,11 +1,11 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// 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; using System.Threading.Tasks; -using Microsoft.AspNet.Http.Features; +using Microsoft.AspNetCore.Http.Features; -namespace Microsoft.AspNet.Hosting.Server +namespace Microsoft.AspNetCore.Hosting.Server { /// /// Represents an HttpApplication. diff --git a/src/Microsoft.AspNetCore.Hosting.Server.Abstractions/IServer.cs b/src/Microsoft.AspNetCore.Hosting.Server.Abstractions/IServer.cs index cc1a88d519..529ca34427 100644 --- a/src/Microsoft.AspNetCore.Hosting.Server.Abstractions/IServer.cs +++ b/src/Microsoft.AspNetCore.Hosting.Server.Abstractions/IServer.cs @@ -1,10 +1,10 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// 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; -using Microsoft.AspNet.Http.Features; +using Microsoft.AspNetCore.Http.Features; -namespace Microsoft.AspNet.Hosting.Server +namespace Microsoft.AspNetCore.Hosting.Server { /// /// Represents a server. diff --git a/src/Microsoft.AspNetCore.Hosting.Server.Abstractions/IServerAddressesFeature.cs b/src/Microsoft.AspNetCore.Hosting.Server.Abstractions/IServerAddressesFeature.cs index 1afbfe7c92..5a464cb75c 100644 --- a/src/Microsoft.AspNetCore.Hosting.Server.Abstractions/IServerAddressesFeature.cs +++ b/src/Microsoft.AspNetCore.Hosting.Server.Abstractions/IServerAddressesFeature.cs @@ -1,9 +1,9 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// 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.Collections.Generic; -namespace Microsoft.AspNet.Server.Features +namespace Microsoft.AspNetCore.Server.Features { public interface IServerAddressesFeature { diff --git a/src/Microsoft.AspNetCore.Hosting.Server.Abstractions/IServerFactory.cs b/src/Microsoft.AspNetCore.Hosting.Server.Abstractions/IServerFactory.cs index 163d39f1c0..1f28b5bacf 100644 --- a/src/Microsoft.AspNetCore.Hosting.Server.Abstractions/IServerFactory.cs +++ b/src/Microsoft.AspNetCore.Hosting.Server.Abstractions/IServerFactory.cs @@ -3,7 +3,7 @@ using Microsoft.Extensions.Configuration; -namespace Microsoft.AspNet.Hosting.Server +namespace Microsoft.AspNetCore.Hosting.Server { /// /// Represents a factory for creating servers. diff --git a/src/Microsoft.AspNetCore.Hosting.Server.Abstractions/project.json b/src/Microsoft.AspNetCore.Hosting.Server.Abstractions/project.json index 8e443d8c77..b329bc3cd5 100644 --- a/src/Microsoft.AspNetCore.Hosting.Server.Abstractions/project.json +++ b/src/Microsoft.AspNetCore.Hosting.Server.Abstractions/project.json @@ -10,7 +10,7 @@ "url": "git://github.com/aspnet/hosting" }, "dependencies": { - "Microsoft.AspNet.Http.Abstractions": "1.0.0-*", + "Microsoft.AspNetCore.Http.Abstractions": "1.0.0-*", "Microsoft.Extensions.Configuration.Abstractions": "1.0.0-*" }, "frameworks": { diff --git a/src/Microsoft.AspNetCore.Hosting.WindowsServices/Microsoft.AspNetCore.Hosting.WindowsServices.xproj b/src/Microsoft.AspNetCore.Hosting.WindowsServices/Microsoft.AspNetCore.Hosting.WindowsServices.xproj index 8131586c81..ef34852e4d 100644 --- a/src/Microsoft.AspNetCore.Hosting.WindowsServices/Microsoft.AspNetCore.Hosting.WindowsServices.xproj +++ b/src/Microsoft.AspNetCore.Hosting.WindowsServices/Microsoft.AspNetCore.Hosting.WindowsServices.xproj @@ -1,4 +1,4 @@ - + 14.0 @@ -7,7 +7,7 @@ 03148731-ea95-40a2-bae8-a12315ea1748 - Microsoft.AspNet.Hosting.WindowsServices + Microsoft.AspNetCore.Hosting.WindowsServices ..\..\artifacts\obj\$(MSBuildProjectName) ..\..\artifacts\bin\$(MSBuildProjectName)\ diff --git a/src/Microsoft.AspNetCore.Hosting.WindowsServices/WebHostService.cs b/src/Microsoft.AspNetCore.Hosting.WindowsServices/WebHostService.cs index 590f54cc63..5e15137ebf 100644 --- a/src/Microsoft.AspNetCore.Hosting.WindowsServices/WebHostService.cs +++ b/src/Microsoft.AspNetCore.Hosting.WindowsServices/WebHostService.cs @@ -1,10 +1,10 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// 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.ServiceProcess; using Microsoft.Extensions.DependencyInjection; -namespace Microsoft.AspNet.Hosting.WindowsServices +namespace Microsoft.AspNetCore.Hosting.WindowsServices { /// /// Provides an implementation of a Windows service that hosts ASP.NET. diff --git a/src/Microsoft.AspNetCore.Hosting.WindowsServices/WebHostWindowsServiceExtensions.cs b/src/Microsoft.AspNetCore.Hosting.WindowsServices/WebHostWindowsServiceExtensions.cs index 4034c5976f..a54cc59961 100644 --- a/src/Microsoft.AspNetCore.Hosting.WindowsServices/WebHostWindowsServiceExtensions.cs +++ b/src/Microsoft.AspNetCore.Hosting.WindowsServices/WebHostWindowsServiceExtensions.cs @@ -1,9 +1,9 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// 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.ServiceProcess; -namespace Microsoft.AspNet.Hosting.WindowsServices +namespace Microsoft.AspNetCore.Hosting.WindowsServices { /// /// Extensions to diff --git a/src/Microsoft.AspNetCore.Hosting.WindowsServices/project.json b/src/Microsoft.AspNetCore.Hosting.WindowsServices/project.json index 91b2eb21c2..0c21602221 100644 --- a/src/Microsoft.AspNetCore.Hosting.WindowsServices/project.json +++ b/src/Microsoft.AspNetCore.Hosting.WindowsServices/project.json @@ -1,4 +1,4 @@ -{ +{ "version": "1.0.0-*", "description": "ASP.NET 5 core hosting infrastructure and startup logic for web applications running within a Windows service.", "repository": { @@ -10,7 +10,7 @@ "keyFile": "../../tools/Key.snk" }, "dependencies": { - "Microsoft.AspNet.Hosting": "1.0.0-*" + "Microsoft.AspNetCore.Hosting": "1.0.0-*" }, "frameworks": { "net451": { diff --git a/src/Microsoft.AspNetCore.Hosting/Builder/ApplicationBuilderFactory.cs b/src/Microsoft.AspNetCore.Hosting/Builder/ApplicationBuilderFactory.cs index eaf8d178d4..e188c0b7fd 100644 --- a/src/Microsoft.AspNetCore.Hosting/Builder/ApplicationBuilderFactory.cs +++ b/src/Microsoft.AspNetCore.Hosting/Builder/ApplicationBuilderFactory.cs @@ -2,11 +2,11 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using Microsoft.AspNet.Builder; -using Microsoft.AspNet.Builder.Internal; -using Microsoft.AspNet.Http.Features; +using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Builder.Internal; +using Microsoft.AspNetCore.Http.Features; -namespace Microsoft.AspNet.Hosting.Builder +namespace Microsoft.AspNetCore.Hosting.Builder { public class ApplicationBuilderFactory : IApplicationBuilderFactory { diff --git a/src/Microsoft.AspNetCore.Hosting/Builder/IApplicationBuilderFactory.cs b/src/Microsoft.AspNetCore.Hosting/Builder/IApplicationBuilderFactory.cs index 00e64a0a2c..d44398fb69 100644 --- a/src/Microsoft.AspNetCore.Hosting/Builder/IApplicationBuilderFactory.cs +++ b/src/Microsoft.AspNetCore.Hosting/Builder/IApplicationBuilderFactory.cs @@ -1,10 +1,10 @@ // 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.Builder; -using Microsoft.AspNet.Http.Features; +using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Http.Features; -namespace Microsoft.AspNet.Hosting.Builder +namespace Microsoft.AspNetCore.Hosting.Builder { public interface IApplicationBuilderFactory { diff --git a/src/Microsoft.AspNetCore.Hosting/Internal/ApplicationLifetime.cs b/src/Microsoft.AspNetCore.Hosting/Internal/ApplicationLifetime.cs index 8955cf8d1e..5f3e7cc960 100644 --- a/src/Microsoft.AspNetCore.Hosting/Internal/ApplicationLifetime.cs +++ b/src/Microsoft.AspNetCore.Hosting/Internal/ApplicationLifetime.cs @@ -4,7 +4,7 @@ using System; using System.Threading; -namespace Microsoft.AspNet.Hosting.Internal +namespace Microsoft.AspNetCore.Hosting.Internal { /// /// Allows consumers to perform cleanup during a graceful shutdown. diff --git a/src/Microsoft.AspNetCore.Hosting/Internal/AutoRequestServicesStartupFilter.cs b/src/Microsoft.AspNetCore.Hosting/Internal/AutoRequestServicesStartupFilter.cs index 2ae344670e..daca6b2674 100644 --- a/src/Microsoft.AspNetCore.Hosting/Internal/AutoRequestServicesStartupFilter.cs +++ b/src/Microsoft.AspNetCore.Hosting/Internal/AutoRequestServicesStartupFilter.cs @@ -2,10 +2,10 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using Microsoft.AspNet.Builder; -using Microsoft.AspNet.Hosting.Startup; +using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Hosting.Startup; -namespace Microsoft.AspNet.Hosting.Internal +namespace Microsoft.AspNetCore.Hosting.Internal { public class AutoRequestServicesStartupFilter : IStartupFilter { diff --git a/src/Microsoft.AspNetCore.Hosting/Internal/HostingApplication.cs b/src/Microsoft.AspNetCore.Hosting/Internal/HostingApplication.cs index 7b77757e7f..c70c319b4c 100644 --- a/src/Microsoft.AspNetCore.Hosting/Internal/HostingApplication.cs +++ b/src/Microsoft.AspNetCore.Hosting/Internal/HostingApplication.cs @@ -1,15 +1,15 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// 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; using System.Diagnostics; using System.Threading.Tasks; -using Microsoft.AspNet.Hosting.Server; -using Microsoft.AspNet.Http; -using Microsoft.AspNet.Http.Features; +using Microsoft.AspNetCore.Hosting.Server; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Http.Features; using Microsoft.Extensions.Logging; -namespace Microsoft.AspNet.Hosting.Internal +namespace Microsoft.AspNetCore.Hosting.Internal { public class HostingApplication : IHttpApplication { @@ -33,14 +33,14 @@ namespace Microsoft.AspNet.Hosting.Internal public Context CreateContext(IFeatureCollection contextFeatures) { var httpContext = _httpContextFactory.Create(contextFeatures); - var diagnoticsEnabled = _diagnosticSource.IsEnabled("Microsoft.AspNet.Hosting.BeginRequest"); + var diagnoticsEnabled = _diagnosticSource.IsEnabled("Microsoft.AspNetCore.Hosting.BeginRequest"); var startTimestamp = (diagnoticsEnabled || _logger.IsEnabled(LogLevel.Information)) ? Stopwatch.GetTimestamp() : 0; var scope = _logger.RequestScope(httpContext); _logger.RequestStarting(httpContext); if (diagnoticsEnabled) { - _diagnosticSource.Write("Microsoft.AspNet.Hosting.BeginRequest", new { httpContext = httpContext, timestamp = startTimestamp }); + _diagnosticSource.Write("Microsoft.AspNetCore.Hosting.BeginRequest", new { httpContext = httpContext, timestamp = startTimestamp }); } return new Context @@ -57,26 +57,26 @@ namespace Microsoft.AspNet.Hosting.Internal if (exception == null) { - var diagnoticsEnabled = _diagnosticSource.IsEnabled("Microsoft.AspNet.Hosting.EndRequest"); + var diagnoticsEnabled = _diagnosticSource.IsEnabled("Microsoft.AspNetCore.Hosting.EndRequest"); var currentTimestamp = (diagnoticsEnabled || context.StartTimestamp != 0) ? Stopwatch.GetTimestamp() : 0; _logger.RequestFinished(httpContext, context.StartTimestamp, currentTimestamp); if (diagnoticsEnabled) { - _diagnosticSource.Write("Microsoft.AspNet.Hosting.EndRequest", new { httpContext = httpContext, timestamp = currentTimestamp }); + _diagnosticSource.Write("Microsoft.AspNetCore.Hosting.EndRequest", new { httpContext = httpContext, timestamp = currentTimestamp }); } } else { - var diagnoticsEnabled = _diagnosticSource.IsEnabled("Microsoft.AspNet.Hosting.UnhandledException"); + var diagnoticsEnabled = _diagnosticSource.IsEnabled("Microsoft.AspNetCore.Hosting.UnhandledException"); var currentTimestamp = (diagnoticsEnabled || context.StartTimestamp != 0) ? Stopwatch.GetTimestamp() : 0; _logger.RequestFinished(httpContext, context.StartTimestamp, currentTimestamp); if (diagnoticsEnabled) { - _diagnosticSource.Write("Microsoft.AspNet.Hosting.UnhandledException", new { httpContext = httpContext, timestamp = currentTimestamp, exception = exception }); + _diagnosticSource.Write("Microsoft.AspNetCore.Hosting.UnhandledException", new { httpContext = httpContext, timestamp = currentTimestamp, exception = exception }); } } diff --git a/src/Microsoft.AspNetCore.Hosting/Internal/HostingEnvironment.cs b/src/Microsoft.AspNetCore.Hosting/Internal/HostingEnvironment.cs index ac87b19b94..e69682ea89 100644 --- a/src/Microsoft.AspNetCore.Hosting/Internal/HostingEnvironment.cs +++ b/src/Microsoft.AspNetCore.Hosting/Internal/HostingEnvironment.cs @@ -4,11 +4,11 @@ using Microsoft.Extensions.Configuration; using Microsoft.Extensions.FileProviders; -namespace Microsoft.AspNet.Hosting.Internal +namespace Microsoft.AspNetCore.Hosting.Internal { public class HostingEnvironment : IHostingEnvironment { - public string EnvironmentName { get; set; } = Microsoft.AspNet.Hosting.EnvironmentName.Production; + public string EnvironmentName { get; set; } = Microsoft.AspNetCore.Hosting.EnvironmentName.Production; public string WebRootPath { get; set; } diff --git a/src/Microsoft.AspNetCore.Hosting/Internal/HostingEnvironmentExtensions.cs b/src/Microsoft.AspNetCore.Hosting/Internal/HostingEnvironmentExtensions.cs index d491a4fef7..189d64f0d8 100644 --- a/src/Microsoft.AspNetCore.Hosting/Internal/HostingEnvironmentExtensions.cs +++ b/src/Microsoft.AspNetCore.Hosting/Internal/HostingEnvironmentExtensions.cs @@ -3,11 +3,11 @@ using System; using System.IO; -using Microsoft.AspNet.Hosting.Internal; +using Microsoft.AspNetCore.Hosting.Internal; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.FileProviders; -namespace Microsoft.AspNet.Hosting.Internal +namespace Microsoft.AspNetCore.Hosting.Internal { public static class HostingEnvironmentExtensions { diff --git a/src/Microsoft.AspNetCore.Hosting/Internal/HostingLoggerExtensions.cs b/src/Microsoft.AspNetCore.Hosting/Internal/HostingLoggerExtensions.cs index 0fdf122848..50d5b01079 100644 --- a/src/Microsoft.AspNetCore.Hosting/Internal/HostingLoggerExtensions.cs +++ b/src/Microsoft.AspNetCore.Hosting/Internal/HostingLoggerExtensions.cs @@ -1,13 +1,13 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// 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; using System.Diagnostics; using System.Collections.Generic; -using Microsoft.AspNet.Http; +using Microsoft.AspNetCore.Http; using Microsoft.Extensions.Logging; -namespace Microsoft.AspNet.Hosting.Internal +namespace Microsoft.AspNetCore.Hosting.Internal { internal static class HostingLoggerExtensions { diff --git a/src/Microsoft.AspNetCore.Hosting/Internal/LoggerEventIds.cs b/src/Microsoft.AspNetCore.Hosting/Internal/LoggerEventIds.cs index 0b23c81e2a..f2978b0d20 100644 --- a/src/Microsoft.AspNetCore.Hosting/Internal/LoggerEventIds.cs +++ b/src/Microsoft.AspNetCore.Hosting/Internal/LoggerEventIds.cs @@ -1,7 +1,7 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// 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. -namespace Microsoft.AspNet.Hosting.Internal +namespace Microsoft.AspNetCore.Hosting.Internal { internal static class LoggerEventIds { diff --git a/src/Microsoft.AspNetCore.Hosting/Internal/NullFileProvider.cs b/src/Microsoft.AspNetCore.Hosting/Internal/NullFileProvider.cs index 5448e6a5ec..6e27bba6f8 100644 --- a/src/Microsoft.AspNetCore.Hosting/Internal/NullFileProvider.cs +++ b/src/Microsoft.AspNetCore.Hosting/Internal/NullFileProvider.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// 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; @@ -8,7 +8,7 @@ using System.IO; using Microsoft.Extensions.FileProviders; using Microsoft.Extensions.Primitives; -namespace Microsoft.AspNet.Hosting.Internal +namespace Microsoft.AspNetCore.Hosting.Internal { internal class NullFileProvider : IFileProvider { diff --git a/src/Microsoft.AspNetCore.Hosting/Internal/RequestServicesContainerFeature.cs b/src/Microsoft.AspNetCore.Hosting/Internal/RequestServicesContainerFeature.cs index 455be554b4..7b21dd3ce6 100644 --- a/src/Microsoft.AspNetCore.Hosting/Internal/RequestServicesContainerFeature.cs +++ b/src/Microsoft.AspNetCore.Hosting/Internal/RequestServicesContainerFeature.cs @@ -2,10 +2,10 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using Microsoft.AspNet.Http.Features.Internal; +using Microsoft.AspNetCore.Http.Features.Internal; using Microsoft.Extensions.DependencyInjection; -namespace Microsoft.AspNet.Hosting.Internal +namespace Microsoft.AspNetCore.Hosting.Internal { public class RequestServicesFeature : IServiceProvidersFeature, IDisposable { diff --git a/src/Microsoft.AspNetCore.Hosting/Internal/RequestServicesContainerMiddleware.cs b/src/Microsoft.AspNetCore.Hosting/Internal/RequestServicesContainerMiddleware.cs index 8cf659227e..fffbd88a56 100644 --- a/src/Microsoft.AspNetCore.Hosting/Internal/RequestServicesContainerMiddleware.cs +++ b/src/Microsoft.AspNetCore.Hosting/Internal/RequestServicesContainerMiddleware.cs @@ -3,13 +3,13 @@ using System; using System.Threading.Tasks; -using Microsoft.AspNet.Builder; -using Microsoft.AspNet.Http; -using Microsoft.AspNet.Http.Features; -using Microsoft.AspNet.Http.Features.Internal; +using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Http.Features; +using Microsoft.AspNetCore.Http.Features.Internal; using Microsoft.Extensions.DependencyInjection; -namespace Microsoft.AspNet.Hosting.Internal +namespace Microsoft.AspNetCore.Hosting.Internal { public class RequestServicesContainerMiddleware { diff --git a/src/Microsoft.AspNetCore.Hosting/Internal/WebHost.cs b/src/Microsoft.AspNetCore.Hosting/Internal/WebHost.cs index d68d6604b7..0af6943995 100644 --- a/src/Microsoft.AspNetCore.Hosting/Internal/WebHost.cs +++ b/src/Microsoft.AspNetCore.Hosting/Internal/WebHost.cs @@ -6,18 +6,18 @@ using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Threading; -using Microsoft.AspNet.Hosting.Builder; -using Microsoft.AspNet.Hosting.Server; -using Microsoft.AspNet.Hosting.Startup; -using Microsoft.AspNet.Http; -using Microsoft.AspNet.Http.Features; -using Microsoft.AspNet.Server.Features; +using Microsoft.AspNetCore.Hosting.Builder; +using Microsoft.AspNetCore.Hosting.Server; +using Microsoft.AspNetCore.Hosting.Startup; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Http.Features; +using Microsoft.AspNetCore.Server.Features; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using Microsoft.Extensions.PlatformAbstractions; -namespace Microsoft.AspNet.Hosting.Internal +namespace Microsoft.AspNetCore.Hosting.Internal { public class WebHost : IWebHost { diff --git a/src/Microsoft.AspNetCore.Hosting/Internal/WebHostOptions.cs b/src/Microsoft.AspNetCore.Hosting/Internal/WebHostOptions.cs index a5e6ffeec3..53a8f5eb64 100644 --- a/src/Microsoft.AspNetCore.Hosting/Internal/WebHostOptions.cs +++ b/src/Microsoft.AspNetCore.Hosting/Internal/WebHostOptions.cs @@ -1,10 +1,10 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// 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; using Microsoft.Extensions.Configuration; -namespace Microsoft.AspNet.Hosting.Internal +namespace Microsoft.AspNetCore.Hosting.Internal { public class WebHostOptions { diff --git a/src/Microsoft.AspNetCore.Hosting/Properties/AssemblyInfo.cs b/src/Microsoft.AspNetCore.Hosting/Properties/AssemblyInfo.cs index 4f51e0868a..303723511f 100644 --- a/src/Microsoft.AspNetCore.Hosting/Properties/AssemblyInfo.cs +++ b/src/Microsoft.AspNetCore.Hosting/Properties/AssemblyInfo.cs @@ -6,5 +6,5 @@ using System.Resources; using System.Runtime.CompilerServices; [assembly: AssemblyMetadata("Serviceable", "True")] -[assembly: InternalsVisibleTo("Microsoft.AspNet.Hosting.Tests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f33a29044fa9d740c9b3213a93e57c84b472c84e0b8a0e1ae48e67a9f8f6de9d5f7f3d52ac23e48ac51801f1dc950abe901da34d2a9e3baadb141a17c77ef3c565dd5ee5054b91cf63bb3c6ab83f72ab3aafe93d0fc3c2348b764fafb0b1c0733de51459aeab46580384bf9d74c4e28164b7cde247f891ba07891c9d872ad2bb")] +[assembly: InternalsVisibleTo("Microsoft.AspNetCore.Hosting.Tests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f33a29044fa9d740c9b3213a93e57c84b472c84e0b8a0e1ae48e67a9f8f6de9d5f7f3d52ac23e48ac51801f1dc950abe901da34d2a9e3baadb141a17c77ef3c565dd5ee5054b91cf63bb3c6ab83f72ab3aafe93d0fc3c2348b764fafb0b1c0733de51459aeab46580384bf9d74c4e28164b7cde247f891ba07891c9d872ad2bb")] [assembly: NeutralResourcesLanguage("en-us")] diff --git a/src/Microsoft.AspNetCore.Hosting/Server/IServerLoader.cs b/src/Microsoft.AspNetCore.Hosting/Server/IServerLoader.cs index 3902135cab..a6afea0aea 100644 --- a/src/Microsoft.AspNetCore.Hosting/Server/IServerLoader.cs +++ b/src/Microsoft.AspNetCore.Hosting/Server/IServerLoader.cs @@ -1,7 +1,7 @@ // 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. -namespace Microsoft.AspNet.Hosting.Server +namespace Microsoft.AspNetCore.Hosting.Server { public interface IServerLoader { diff --git a/src/Microsoft.AspNetCore.Hosting/Server/ServerLoader.cs b/src/Microsoft.AspNetCore.Hosting/Server/ServerLoader.cs index 4f3b5fe4f0..3868cc1373 100644 --- a/src/Microsoft.AspNetCore.Hosting/Server/ServerLoader.cs +++ b/src/Microsoft.AspNetCore.Hosting/Server/ServerLoader.cs @@ -6,7 +6,7 @@ using System.Linq; using System.Reflection; using Microsoft.Extensions.DependencyInjection; -namespace Microsoft.AspNet.Hosting.Server +namespace Microsoft.AspNetCore.Hosting.Server { public class ServerLoader : IServerLoader { diff --git a/src/Microsoft.AspNetCore.Hosting/Startup/ConfigureDelegate.cs b/src/Microsoft.AspNetCore.Hosting/Startup/ConfigureDelegate.cs index da39fa6d3c..156707c277 100644 --- a/src/Microsoft.AspNetCore.Hosting/Startup/ConfigureDelegate.cs +++ b/src/Microsoft.AspNetCore.Hosting/Startup/ConfigureDelegate.cs @@ -3,10 +3,10 @@ using System; using System.Reflection; -using Microsoft.AspNet.Builder; +using Microsoft.AspNetCore.Builder; using Microsoft.Extensions.DependencyInjection; -namespace Microsoft.AspNet.Hosting.Startup +namespace Microsoft.AspNetCore.Hosting.Startup { // TODO: replace all Action eventually with this public delegate void ConfigureDelegate(IApplicationBuilder builder); diff --git a/src/Microsoft.AspNetCore.Hosting/Startup/ConfigureServicesDelegate.cs b/src/Microsoft.AspNetCore.Hosting/Startup/ConfigureServicesDelegate.cs index f5eaea5aed..ffa606b6da 100644 --- a/src/Microsoft.AspNetCore.Hosting/Startup/ConfigureServicesDelegate.cs +++ b/src/Microsoft.AspNetCore.Hosting/Startup/ConfigureServicesDelegate.cs @@ -6,7 +6,7 @@ using System.Linq; using System.Reflection; using Microsoft.Extensions.DependencyInjection; -namespace Microsoft.AspNet.Hosting.Startup +namespace Microsoft.AspNetCore.Hosting.Startup { public class ConfigureServicesBuilder { diff --git a/src/Microsoft.AspNetCore.Hosting/Startup/IStartupLoader.cs b/src/Microsoft.AspNetCore.Hosting/Startup/IStartupLoader.cs index ee1db50c8e..9c7ee34eed 100644 --- a/src/Microsoft.AspNetCore.Hosting/Startup/IStartupLoader.cs +++ b/src/Microsoft.AspNetCore.Hosting/Startup/IStartupLoader.cs @@ -4,7 +4,7 @@ using System; using System.Collections.Generic; -namespace Microsoft.AspNet.Hosting.Startup +namespace Microsoft.AspNetCore.Hosting.Startup { public interface IStartupLoader { diff --git a/src/Microsoft.AspNetCore.Hosting/Startup/StartupExceptionPage.cs b/src/Microsoft.AspNetCore.Hosting/Startup/StartupExceptionPage.cs index bed39a6241..8750199eba 100644 --- a/src/Microsoft.AspNetCore.Hosting/Startup/StartupExceptionPage.cs +++ b/src/Microsoft.AspNetCore.Hosting/Startup/StartupExceptionPage.cs @@ -15,7 +15,7 @@ using System.Text.Encodings.Web; using Microsoft.Extensions.Internal; using Microsoft.Extensions.PlatformAbstractions; -namespace Microsoft.AspNet.Hosting.Startup +namespace Microsoft.AspNetCore.Hosting.Startup { internal static class StartupExceptionPage { diff --git a/src/Microsoft.AspNetCore.Hosting/Startup/StartupLoader.cs b/src/Microsoft.AspNetCore.Hosting/Startup/StartupLoader.cs index c77cbced34..2b7a641a10 100644 --- a/src/Microsoft.AspNetCore.Hosting/Startup/StartupLoader.cs +++ b/src/Microsoft.AspNetCore.Hosting/Startup/StartupLoader.cs @@ -8,7 +8,7 @@ using System.Linq; using System.Reflection; using Microsoft.Extensions.DependencyInjection; -namespace Microsoft.AspNet.Hosting.Startup +namespace Microsoft.AspNetCore.Hosting.Startup { public class StartupLoader : IStartupLoader { diff --git a/src/Microsoft.AspNetCore.Hosting/Startup/StartupMethods.cs b/src/Microsoft.AspNetCore.Hosting/Startup/StartupMethods.cs index b62dae27f7..d019a6aa24 100644 --- a/src/Microsoft.AspNetCore.Hosting/Startup/StartupMethods.cs +++ b/src/Microsoft.AspNetCore.Hosting/Startup/StartupMethods.cs @@ -2,10 +2,10 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using Microsoft.AspNet.Builder; +using Microsoft.AspNetCore.Builder; using Microsoft.Extensions.DependencyInjection; -namespace Microsoft.AspNet.Hosting.Startup +namespace Microsoft.AspNetCore.Hosting.Startup { public class StartupMethods { diff --git a/src/Microsoft.AspNetCore.Hosting/WebHostBuilder.cs b/src/Microsoft.AspNetCore.Hosting/WebHostBuilder.cs index 0f385a8ac6..46ebe789fd 100644 --- a/src/Microsoft.AspNetCore.Hosting/WebHostBuilder.cs +++ b/src/Microsoft.AspNetCore.Hosting/WebHostBuilder.cs @@ -5,20 +5,20 @@ using System; using System.Collections.Generic; using System.Diagnostics; using System.Runtime.Versioning; -using Microsoft.AspNet.Builder; -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.AspNetCore.Builder; +using Microsoft.AspNetCore.Hosting.Builder; +using Microsoft.AspNetCore.Hosting.Internal; +using Microsoft.AspNetCore.Hosting.Server; +using Microsoft.AspNetCore.Hosting.Startup; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Http.Internal; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection.Extensions; using Microsoft.Extensions.Logging; using Microsoft.Extensions.PlatformAbstractions; -namespace Microsoft.AspNet.Hosting +namespace Microsoft.AspNetCore.Hosting { /// /// A builder for @@ -210,7 +210,7 @@ namespace Microsoft.AspNet.Hosting services.AddLogging(); services.AddOptions(); - var diagnosticSource = new DiagnosticListener("Microsoft.AspNet"); + var diagnosticSource = new DiagnosticListener("Microsoft.AspNetCore"); services.AddSingleton(diagnosticSource); services.AddSingleton(diagnosticSource); diff --git a/src/Microsoft.AspNetCore.Hosting/WebHostBuilderExtensions.cs b/src/Microsoft.AspNetCore.Hosting/WebHostBuilderExtensions.cs index db10bdd6d1..93a00ccd68 100644 --- a/src/Microsoft.AspNetCore.Hosting/WebHostBuilderExtensions.cs +++ b/src/Microsoft.AspNetCore.Hosting/WebHostBuilderExtensions.cs @@ -2,10 +2,10 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using Microsoft.AspNet.Hosting.Server; +using Microsoft.AspNetCore.Hosting.Server; using Microsoft.Extensions.Configuration; -namespace Microsoft.AspNet.Hosting +namespace Microsoft.AspNetCore.Hosting { public static class WebHostBuilderExtensions { diff --git a/src/Microsoft.AspNetCore.Hosting/WebHostConfiguration.cs b/src/Microsoft.AspNetCore.Hosting/WebHostConfiguration.cs index dc331e9adb..3a6cd02a4e 100644 --- a/src/Microsoft.AspNetCore.Hosting/WebHostConfiguration.cs +++ b/src/Microsoft.AspNetCore.Hosting/WebHostConfiguration.cs @@ -1,10 +1,10 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// 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.Collections.Generic; using Microsoft.Extensions.Configuration; -namespace Microsoft.AspNet.Hosting +namespace Microsoft.AspNetCore.Hosting { public class WebHostConfiguration { diff --git a/src/Microsoft.AspNetCore.Hosting/WebHostExtensions.cs b/src/Microsoft.AspNetCore.Hosting/WebHostExtensions.cs index 0e2f6480fe..2efdfb273f 100644 --- a/src/Microsoft.AspNetCore.Hosting/WebHostExtensions.cs +++ b/src/Microsoft.AspNetCore.Hosting/WebHostExtensions.cs @@ -1,12 +1,12 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// 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; using System.Threading; -using Microsoft.AspNet.Server.Features; +using Microsoft.AspNetCore.Server.Features; using Microsoft.Extensions.DependencyInjection; -namespace Microsoft.AspNet.Hosting +namespace Microsoft.AspNetCore.Hosting { public static class WebHostExtensions { diff --git a/src/Microsoft.AspNetCore.Hosting/compiler/resources/GenericError_Footer.html b/src/Microsoft.AspNetCore.Hosting/compiler/resources/GenericError_Footer.html index 54042e8bf9..4a30ed8e1f 100644 --- a/src/Microsoft.AspNetCore.Hosting/compiler/resources/GenericError_Footer.html +++ b/src/Microsoft.AspNetCore.Hosting/compiler/resources/GenericError_Footer.html @@ -1,3 +1,3 @@ -