From c5e8120e39583042b2cd72f067e6ff0e1329a9da Mon Sep 17 00:00:00 2001 From: David Fowler Date: Thu, 19 May 2016 15:05:53 -0700 Subject: [PATCH] Remove UseServer(string) overload - Removed the overload that takes a string because it's broken #731 --- .../StartupExternallyControlled.cs | 4 +-- samples/SampleStartups/StartupFullControl.cs | 2 +- samples/SampleStartups/StartupHelloWorld.cs | 2 +- .../WebHostDefaults.cs | 1 - .../Internal/WebHostOptions.cs | 3 -- .../WebHostBuilder.cs | 19 ----------- .../WebHostBuilderExtensions.cs | 34 +++++-------------- .../WebHostConfigurationsTests.cs | 2 -- .../WebHostTests.cs | 9 ++--- 9 files changed, 16 insertions(+), 60 deletions(-) diff --git a/samples/SampleStartups/StartupExternallyControlled.cs b/samples/SampleStartups/StartupExternallyControlled.cs index 0f91856701..69263877b7 100644 --- a/samples/SampleStartups/StartupExternallyControlled.cs +++ b/samples/SampleStartups/StartupExternallyControlled.cs @@ -12,7 +12,7 @@ namespace SampleStartups { private IWebHost _host; private readonly List _urls = new List(); - + // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public override void Configure(IApplicationBuilder app) { @@ -29,7 +29,7 @@ namespace SampleStartups public void Start() { _host = new WebHostBuilder() - .UseServer("Microsoft.AspNetCore.Server.Kestrel") + //.UseKestrel() .UseStartup() .Start(_urls.ToArray()); } diff --git a/samples/SampleStartups/StartupFullControl.cs b/samples/SampleStartups/StartupFullControl.cs index 200d7c932d..a9254e482b 100644 --- a/samples/SampleStartups/StartupFullControl.cs +++ b/samples/SampleStartups/StartupFullControl.cs @@ -22,7 +22,7 @@ namespace SampleStartups var host = new WebHostBuilder() .UseConfiguration(config) // Default set of configurations to use, may be subsequently overridden - .UseServer("Microsoft.AspNetCore.Server.Kestrel") // Set the server manually + //.UseKestrel() .UseContentRoot(Directory.GetCurrentDirectory()) // Override the content root with the current directory .UseUrls("http://*:1000", "https://*:902") .UseEnvironment("Development") diff --git a/samples/SampleStartups/StartupHelloWorld.cs b/samples/SampleStartups/StartupHelloWorld.cs index 3ac09bcb63..a2f806f661 100644 --- a/samples/SampleStartups/StartupHelloWorld.cs +++ b/samples/SampleStartups/StartupHelloWorld.cs @@ -21,7 +21,7 @@ namespace SampleStartups public static void Main(string[] args) { var host = new WebHostBuilder() - .UseServer("Microsoft.AspNetCore.Server.Kestrel") + //.UseKestrel() .UseStartup() .Build(); diff --git a/src/Microsoft.AspNetCore.Hosting.Abstractions/WebHostDefaults.cs b/src/Microsoft.AspNetCore.Hosting.Abstractions/WebHostDefaults.cs index 9fd517159a..208a8311e0 100644 --- a/src/Microsoft.AspNetCore.Hosting.Abstractions/WebHostDefaults.cs +++ b/src/Microsoft.AspNetCore.Hosting.Abstractions/WebHostDefaults.cs @@ -10,7 +10,6 @@ namespace Microsoft.AspNetCore.Hosting public static readonly string DetailedErrorsKey = "detailedErrors"; public static readonly string EnvironmentKey = "environment"; - public static readonly string ServerKey = "server"; public static readonly string WebRootKey = "webroot"; public static readonly string CaptureStartupErrorsKey = "captureStartupErrors"; public static readonly string ServerUrlsKey = "server.urls"; diff --git a/src/Microsoft.AspNetCore.Hosting/Internal/WebHostOptions.cs b/src/Microsoft.AspNetCore.Hosting/Internal/WebHostOptions.cs index 156f5eba78..368b465180 100644 --- a/src/Microsoft.AspNetCore.Hosting/Internal/WebHostOptions.cs +++ b/src/Microsoft.AspNetCore.Hosting/Internal/WebHostOptions.cs @@ -24,7 +24,6 @@ namespace Microsoft.AspNetCore.Hosting.Internal DetailedErrors = ParseBool(configuration, WebHostDefaults.DetailedErrorsKey); CaptureStartupErrors = ParseBool(configuration, WebHostDefaults.CaptureStartupErrorsKey); Environment = configuration[WebHostDefaults.EnvironmentKey]; - ServerAssembly = configuration[WebHostDefaults.ServerKey]; WebRoot = configuration[WebHostDefaults.WebRootKey]; ContentRootPath = configuration[WebHostDefaults.ContentRootKey]; } @@ -36,8 +35,6 @@ namespace Microsoft.AspNetCore.Hosting.Internal public bool CaptureStartupErrors { get; set; } public string Environment { get; set; } - - public string ServerAssembly { get; set; } public string StartupAssembly { get; set; } diff --git a/src/Microsoft.AspNetCore.Hosting/WebHostBuilder.cs b/src/Microsoft.AspNetCore.Hosting/WebHostBuilder.cs index fae25a30ed..df2c8f5e41 100644 --- a/src/Microsoft.AspNetCore.Hosting/WebHostBuilder.cs +++ b/src/Microsoft.AspNetCore.Hosting/WebHostBuilder.cs @@ -187,25 +187,6 @@ namespace Microsoft.AspNetCore.Hosting // Ensure object pooling is available everywhere. services.AddSingleton(); - if (!string.IsNullOrEmpty(_options.ServerAssembly)) - { - // Add the server - try - { - var serverType = ServerLoader.ResolveServerType(_options.ServerAssembly); - services.AddSingleton(typeof(IServer), serverType); - } - catch (Exception ex) - { - var capture = ExceptionDispatchInfo.Capture(ex); - services.AddSingleton(_ => - { - capture.Throw(); - return null; - }); - } - } - if (!string.IsNullOrEmpty(_options.StartupAssembly)) { try diff --git a/src/Microsoft.AspNetCore.Hosting/WebHostBuilderExtensions.cs b/src/Microsoft.AspNetCore.Hosting/WebHostBuilderExtensions.cs index 3f9adfae4f..7d64c8aaca 100644 --- a/src/Microsoft.AspNetCore.Hosting/WebHostBuilderExtensions.cs +++ b/src/Microsoft.AspNetCore.Hosting/WebHostBuilderExtensions.cs @@ -43,7 +43,7 @@ namespace Microsoft.AspNetCore.Hosting { return hostBuilder.UseSetting(WebHostDefaults.CaptureStartupErrorsKey, captureStartupErrors ? "true" : "false"); } - + /// /// Specify the startup method to be used to configure the web application. /// @@ -56,17 +56,17 @@ namespace Microsoft.AspNetCore.Hosting { throw new ArgumentNullException(nameof(configureApp)); } - + var startupAssemblyName = configureApp.GetMethodInfo().DeclaringType.GetTypeInfo().Assembly.GetName().Name; - + return hostBuilder.UseSetting(WebHostDefaults.ApplicationKey, startupAssemblyName) .ConfigureServices(services => { services.AddSingleton(new DelegateStartup(configureApp)); }); } - - + + /// /// Specify the startup type to be used by the web host. /// @@ -76,7 +76,7 @@ namespace Microsoft.AspNetCore.Hosting public static IWebHostBuilder UseStartup(this IWebHostBuilder hostBuilder, Type startupType) { var startupAssemblyName = startupType.GetTypeInfo().Assembly.GetName().Name; - + return hostBuilder.UseSetting(WebHostDefaults.ApplicationKey, startupAssemblyName) .ConfigureServices(services => { @@ -86,7 +86,7 @@ namespace Microsoft.AspNetCore.Hosting } else { - services.AddSingleton(typeof(IStartup), sp => + services.AddSingleton(typeof(IStartup), sp => { var hostingEnvironment = sp.GetRequiredService(); return new ConventionBasedStartup(StartupLoader.LoadMethods(sp, startupType, hostingEnvironment.EnvironmentName)); @@ -94,7 +94,7 @@ namespace Microsoft.AspNetCore.Hosting } }); } - + /// /// Specify the startup type to be used by the web host. /// @@ -119,28 +119,12 @@ namespace Microsoft.AspNetCore.Hosting throw new ArgumentNullException(nameof(startupAssemblyName)); } - + return hostBuilder .UseSetting(WebHostDefaults.ApplicationKey, startupAssemblyName) .UseSetting(WebHostDefaults.StartupAssemblyKey, startupAssemblyName); } - /// - /// Specify the assembly containing the server to be used by the web host. - /// - /// The to configure. - /// The name of the assembly containing the server to be used. - /// The . - public static IWebHostBuilder UseServer(this IWebHostBuilder hostBuilder, string assemblyName) - { - if (assemblyName == null) - { - throw new ArgumentNullException(nameof(assemblyName)); - } - - return hostBuilder.UseSetting(WebHostDefaults.ServerKey, assemblyName); - } - /// /// Specify the server to be used by the web host. /// diff --git a/test/Microsoft.AspNetCore.Hosting.Tests/WebHostConfigurationsTests.cs b/test/Microsoft.AspNetCore.Hosting.Tests/WebHostConfigurationsTests.cs index 1c4d3c9cf7..5f4291d75e 100644 --- a/test/Microsoft.AspNetCore.Hosting.Tests/WebHostConfigurationsTests.cs +++ b/test/Microsoft.AspNetCore.Hosting.Tests/WebHostConfigurationsTests.cs @@ -16,7 +16,6 @@ namespace Microsoft.AspNetCore.Hosting.Tests var parameters = new Dictionary() { { "webroot", "wwwroot"}, - { "server", "Microsoft.AspNetCore.Server.Kestrel"}, { "applicationName", "MyProjectReference"}, { "startupAssembly", "MyProjectReference" }, { "environment", "Development"}, @@ -27,7 +26,6 @@ namespace Microsoft.AspNetCore.Hosting.Tests var config = new WebHostOptions(new ConfigurationBuilder().AddInMemoryCollection(parameters).Build()); Assert.Equal("wwwroot", config.WebRoot); - Assert.Equal("Microsoft.AspNetCore.Server.Kestrel", config.ServerAssembly); Assert.Equal("MyProjectReference", config.ApplicationName); Assert.Equal("MyProjectReference", config.StartupAssembly); Assert.Equal("Development", config.Environment); diff --git a/test/Microsoft.AspNetCore.Hosting.Tests/WebHostTests.cs b/test/Microsoft.AspNetCore.Hosting.Tests/WebHostTests.cs index c311083234..504a87b8fd 100644 --- a/test/Microsoft.AspNetCore.Hosting.Tests/WebHostTests.cs +++ b/test/Microsoft.AspNetCore.Hosting.Tests/WebHostTests.cs @@ -71,13 +71,12 @@ namespace Microsoft.AspNetCore.Hosting { var vals = new Dictionary { - { "server", "Microsoft.AspNetCore.Hosting.Tests" } }; var builder = new ConfigurationBuilder() .AddInMemoryCollection(vals); var config = builder.Build(); - var host = CreateBuilder(config).Build(); + var host = CreateBuilder(config).UseServer(this).Build(); host.Start(); Assert.NotNull(host.Services.GetService()); } @@ -87,13 +86,12 @@ namespace Microsoft.AspNetCore.Hosting { var vals = new Dictionary { - { "Server", "Microsoft.AspNetCore.Hosting.Tests" } }; var builder = new ConfigurationBuilder() .AddInMemoryCollection(vals); var config = builder.Build(); - var host = CreateBuilder(config).Build(); + var host = CreateBuilder(config).UseServer(this).Build(); host.Start(); Assert.NotNull(host.Services.GetService()); } @@ -103,13 +101,12 @@ namespace Microsoft.AspNetCore.Hosting { var vals = new Dictionary { - { "Server", "Microsoft.AspNetCore.Hosting.Tests" } }; var builder = new ConfigurationBuilder() .AddInMemoryCollection(vals); var config = builder.Build(); - var host = CreateBuilder(config).Build(); + var host = CreateBuilder(config).UseServer(this).Build(); host.Start(); Assert.NotNull(host.Services.GetService()); Assert.Equal("http://localhost:5000", host.ServerFeatures.Get().Addresses.First());