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