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))]