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