React to hosting

This commit is contained in:
Hao Kung 2015-03-19 12:44:25 -07:00
parent 9faa6f8230
commit 4162a8ce89
1 changed files with 1 additions and 20 deletions

View File

@ -2,7 +2,6 @@
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNet.Hosting; using Microsoft.AspNet.Hosting;
using Microsoft.Framework.ConfigurationModel; using Microsoft.Framework.ConfigurationModel;
using Microsoft.Framework.DependencyInjection;
namespace MusicStore namespace MusicStore
{ {
@ -12,38 +11,20 @@ namespace MusicStore
/// </summary> /// </summary>
public class Program public class Program
{ {
private readonly IServiceProvider _hostServiceProvider;
public Program(IServiceProvider hostServiceProvider)
{
_hostServiceProvider = hostServiceProvider;
}
public Task<int> Main(string[] args) public Task<int> Main(string[] args)
{ {
//Add command line configuration source to read command line parameters. //Add command line configuration source to read command line parameters.
var config = new Configuration(); var config = new Configuration();
config.AddCommandLine(args); config.AddCommandLine(args);
var serviceCollection = HostingServices.Create(_hostServiceProvider);
var services = serviceCollection.BuildServiceProvider();
var applicationLifetime = services.GetRequiredService<IApplicationLifetime>();
var context = new HostingContext() var context = new HostingContext()
{ {
ApplicationLifetime = applicationLifetime,
Configuration = config, Configuration = config,
ServerFactoryLocation = "Microsoft.AspNet.Server.WebListener", ServerFactoryLocation = "Microsoft.AspNet.Server.WebListener",
ApplicationName = "MusicStore" ApplicationName = "MusicStore"
}; };
var engine = services.GetService<IHostingEngine>(); using (new HostingEngine().Start(context))
if (engine == null)
{
throw new Exception("TODO: IHostingEngine service not available exception");
}
using (engine.Start(context))
{ {
Console.WriteLine("Started the server.."); Console.WriteLine("Started the server..");
Console.WriteLine("Press any key to stop the server"); Console.WriteLine("Press any key to stop the server");