Add an Initialize step to IServerFactory.

This commit is contained in:
Chris Ross 2014-03-19 11:43:13 -07:00
parent ff19628832
commit 11762840cd
7 changed files with 32 additions and 6 deletions

View File

@ -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": {
},

View File

@ -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; }
}
}

View File

@ -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();

View File

@ -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,

View File

@ -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<object, Task> application);
IServerInformation Initialize(IConfiguration configuraiton);
IDisposable Start(IServerInformation serverInformation, Func<object, Task> application);
}
}

View File

@ -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<object, Task> application)
public IServerInformation Initialize(IConfiguration configuraiton)
{
return null;
}
public IDisposable Start(IServerInformation serverInformation, Func<object, Task> application)
{
var startInstance = new StartInstance(application);
_startInstances.Add(startInstance);

View File

@ -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-*",