diff --git a/test/Microsoft.AspNetCore.Hosting.Tests/Internal/MyBadContainerFactory.cs b/test/Microsoft.AspNetCore.Hosting.Tests/Internal/MyBadContainerFactory.cs new file mode 100644 index 00000000..058abc89 --- /dev/null +++ b/test/Microsoft.AspNetCore.Hosting.Tests/Internal/MyBadContainerFactory.cs @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.Extensions.DependencyInjection; + +namespace Microsoft.AspNetCore.Hosting.Tests.Internal +{ + public class MyBadContainerFactory : IServiceProviderFactory + { + public MyContainer CreateBuilder(IServiceCollection services) + { + var container = new MyContainer(); + container.Populate(services); + return container; + } + + public IServiceProvider CreateServiceProvider(MyContainer containerBuilder) + { + containerBuilder.Build(); + return null; + } + } +} diff --git a/test/Microsoft.AspNetCore.Hosting.Tests/Internal/MyContainerFactory.cs b/test/Microsoft.AspNetCore.Hosting.Tests/Internal/MyContainerFactory.cs index 9819f69e..06a1ad61 100644 --- a/test/Microsoft.AspNetCore.Hosting.Tests/Internal/MyContainerFactory.cs +++ b/test/Microsoft.AspNetCore.Hosting.Tests/Internal/MyContainerFactory.cs @@ -21,5 +21,4 @@ public IServiceProvider CreateServiceProvider(MyContainer containerBuilder) return containerBuilder; } } - } diff --git a/test/Microsoft.AspNetCore.Hosting.Tests/StartupManagerTests.cs b/test/Microsoft.AspNetCore.Hosting.Tests/StartupManagerTests.cs index b3eccc2e..974e5ffa 100644 --- a/test/Microsoft.AspNetCore.Hosting.Tests/StartupManagerTests.cs +++ b/test/Microsoft.AspNetCore.Hosting.Tests/StartupManagerTests.cs @@ -266,6 +266,22 @@ public void CustomServiceProviderFactoryFailsWithOverloadsInStartup() Assert.Throws(() => StartupLoader.LoadMethods(services, typeof(MyContainerStartupWithOverloads), "Development")); } + [Fact] + public void BadServiceProviderFactoryFailsThatReturnsNullServiceProviderOverriddenByDefault() + { + var serviceCollection = new ServiceCollection(); + serviceCollection.AddSingleton, MyBadContainerFactory>(); + var services = serviceCollection.BuildServiceProvider(); + + var startup = StartupLoader.LoadMethods(services, typeof(MyContainerStartup), "Development"); + + var app = new ApplicationBuilder(services); + app.ApplicationServices = startup.ConfigureServicesDelegate(serviceCollection); + + Assert.NotNull(app.ApplicationServices); + Assert.IsNotType(typeof(MyContainer), app.ApplicationServices); + } + public class MyContainerStartupWithOverloads { public void ConfigureServices(IServiceCollection services)