Remove UseServer(string) overload

- Removed the overload that takes a string because it's broken

#731
This commit is contained in:
David Fowler 2016-05-19 15:05:53 -07:00
parent bdc3959938
commit c5e8120e39
9 changed files with 16 additions and 60 deletions

View File

@ -12,7 +12,7 @@ namespace SampleStartups
{ {
private IWebHost _host; private IWebHost _host;
private readonly List<string> _urls = new List<string>(); private readonly List<string> _urls = new List<string>();
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public override void Configure(IApplicationBuilder app) public override void Configure(IApplicationBuilder app)
{ {
@ -29,7 +29,7 @@ namespace SampleStartups
public void Start() public void Start()
{ {
_host = new WebHostBuilder() _host = new WebHostBuilder()
.UseServer("Microsoft.AspNetCore.Server.Kestrel") //.UseKestrel()
.UseStartup<StartupExternallyControlled>() .UseStartup<StartupExternallyControlled>()
.Start(_urls.ToArray()); .Start(_urls.ToArray());
} }

View File

@ -22,7 +22,7 @@ namespace SampleStartups
var host = new WebHostBuilder() var host = new WebHostBuilder()
.UseConfiguration(config) // Default set of configurations to use, may be subsequently overridden .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 .UseContentRoot(Directory.GetCurrentDirectory()) // Override the content root with the current directory
.UseUrls("http://*:1000", "https://*:902") .UseUrls("http://*:1000", "https://*:902")
.UseEnvironment("Development") .UseEnvironment("Development")

View File

@ -21,7 +21,7 @@ namespace SampleStartups
public static void Main(string[] args) public static void Main(string[] args)
{ {
var host = new WebHostBuilder() var host = new WebHostBuilder()
.UseServer("Microsoft.AspNetCore.Server.Kestrel") //.UseKestrel()
.UseStartup<StartupHelloWorld>() .UseStartup<StartupHelloWorld>()
.Build(); .Build();

View File

@ -10,7 +10,6 @@ namespace Microsoft.AspNetCore.Hosting
public static readonly string DetailedErrorsKey = "detailedErrors"; public static readonly string DetailedErrorsKey = "detailedErrors";
public static readonly string EnvironmentKey = "environment"; public static readonly string EnvironmentKey = "environment";
public static readonly string ServerKey = "server";
public static readonly string WebRootKey = "webroot"; public static readonly string WebRootKey = "webroot";
public static readonly string CaptureStartupErrorsKey = "captureStartupErrors"; public static readonly string CaptureStartupErrorsKey = "captureStartupErrors";
public static readonly string ServerUrlsKey = "server.urls"; public static readonly string ServerUrlsKey = "server.urls";

View File

@ -24,7 +24,6 @@ namespace Microsoft.AspNetCore.Hosting.Internal
DetailedErrors = ParseBool(configuration, WebHostDefaults.DetailedErrorsKey); DetailedErrors = ParseBool(configuration, WebHostDefaults.DetailedErrorsKey);
CaptureStartupErrors = ParseBool(configuration, WebHostDefaults.CaptureStartupErrorsKey); CaptureStartupErrors = ParseBool(configuration, WebHostDefaults.CaptureStartupErrorsKey);
Environment = configuration[WebHostDefaults.EnvironmentKey]; Environment = configuration[WebHostDefaults.EnvironmentKey];
ServerAssembly = configuration[WebHostDefaults.ServerKey];
WebRoot = configuration[WebHostDefaults.WebRootKey]; WebRoot = configuration[WebHostDefaults.WebRootKey];
ContentRootPath = configuration[WebHostDefaults.ContentRootKey]; ContentRootPath = configuration[WebHostDefaults.ContentRootKey];
} }
@ -36,8 +35,6 @@ namespace Microsoft.AspNetCore.Hosting.Internal
public bool CaptureStartupErrors { get; set; } public bool CaptureStartupErrors { get; set; }
public string Environment { get; set; } public string Environment { get; set; }
public string ServerAssembly { get; set; }
public string StartupAssembly { get; set; } public string StartupAssembly { get; set; }

View File

@ -187,25 +187,6 @@ namespace Microsoft.AspNetCore.Hosting
// Ensure object pooling is available everywhere. // Ensure object pooling is available everywhere.
services.AddSingleton<ObjectPoolProvider, DefaultObjectPoolProvider>(); services.AddSingleton<ObjectPoolProvider, DefaultObjectPoolProvider>();
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<IServer>(_ =>
{
capture.Throw();
return null;
});
}
}
if (!string.IsNullOrEmpty(_options.StartupAssembly)) if (!string.IsNullOrEmpty(_options.StartupAssembly))
{ {
try try

View File

@ -43,7 +43,7 @@ namespace Microsoft.AspNetCore.Hosting
{ {
return hostBuilder.UseSetting(WebHostDefaults.CaptureStartupErrorsKey, captureStartupErrors ? "true" : "false"); return hostBuilder.UseSetting(WebHostDefaults.CaptureStartupErrorsKey, captureStartupErrors ? "true" : "false");
} }
/// <summary> /// <summary>
/// Specify the startup method to be used to configure the web application. /// Specify the startup method to be used to configure the web application.
/// </summary> /// </summary>
@ -56,17 +56,17 @@ namespace Microsoft.AspNetCore.Hosting
{ {
throw new ArgumentNullException(nameof(configureApp)); throw new ArgumentNullException(nameof(configureApp));
} }
var startupAssemblyName = configureApp.GetMethodInfo().DeclaringType.GetTypeInfo().Assembly.GetName().Name; var startupAssemblyName = configureApp.GetMethodInfo().DeclaringType.GetTypeInfo().Assembly.GetName().Name;
return hostBuilder.UseSetting(WebHostDefaults.ApplicationKey, startupAssemblyName) return hostBuilder.UseSetting(WebHostDefaults.ApplicationKey, startupAssemblyName)
.ConfigureServices(services => .ConfigureServices(services =>
{ {
services.AddSingleton<IStartup>(new DelegateStartup(configureApp)); services.AddSingleton<IStartup>(new DelegateStartup(configureApp));
}); });
} }
/// <summary> /// <summary>
/// Specify the startup type to be used by the web host. /// Specify the startup type to be used by the web host.
/// </summary> /// </summary>
@ -76,7 +76,7 @@ namespace Microsoft.AspNetCore.Hosting
public static IWebHostBuilder UseStartup(this IWebHostBuilder hostBuilder, Type startupType) public static IWebHostBuilder UseStartup(this IWebHostBuilder hostBuilder, Type startupType)
{ {
var startupAssemblyName = startupType.GetTypeInfo().Assembly.GetName().Name; var startupAssemblyName = startupType.GetTypeInfo().Assembly.GetName().Name;
return hostBuilder.UseSetting(WebHostDefaults.ApplicationKey, startupAssemblyName) return hostBuilder.UseSetting(WebHostDefaults.ApplicationKey, startupAssemblyName)
.ConfigureServices(services => .ConfigureServices(services =>
{ {
@ -86,7 +86,7 @@ namespace Microsoft.AspNetCore.Hosting
} }
else else
{ {
services.AddSingleton(typeof(IStartup), sp => services.AddSingleton(typeof(IStartup), sp =>
{ {
var hostingEnvironment = sp.GetRequiredService<IHostingEnvironment>(); var hostingEnvironment = sp.GetRequiredService<IHostingEnvironment>();
return new ConventionBasedStartup(StartupLoader.LoadMethods(sp, startupType, hostingEnvironment.EnvironmentName)); return new ConventionBasedStartup(StartupLoader.LoadMethods(sp, startupType, hostingEnvironment.EnvironmentName));
@ -94,7 +94,7 @@ namespace Microsoft.AspNetCore.Hosting
} }
}); });
} }
/// <summary> /// <summary>
/// Specify the startup type to be used by the web host. /// Specify the startup type to be used by the web host.
/// </summary> /// </summary>
@ -119,28 +119,12 @@ namespace Microsoft.AspNetCore.Hosting
throw new ArgumentNullException(nameof(startupAssemblyName)); throw new ArgumentNullException(nameof(startupAssemblyName));
} }
return hostBuilder return hostBuilder
.UseSetting(WebHostDefaults.ApplicationKey, startupAssemblyName) .UseSetting(WebHostDefaults.ApplicationKey, startupAssemblyName)
.UseSetting(WebHostDefaults.StartupAssemblyKey, startupAssemblyName); .UseSetting(WebHostDefaults.StartupAssemblyKey, startupAssemblyName);
} }
/// <summary>
/// Specify the assembly containing the server to be used by the web host.
/// </summary>
/// <param name="hostBuilder">The <see cref="IWebHostBuilder"/> to configure.</param>
/// <param name="assemblyName">The name of the assembly containing the server to be used.</param>
/// <returns>The <see cref="IWebHostBuilder"/>.</returns>
public static IWebHostBuilder UseServer(this IWebHostBuilder hostBuilder, string assemblyName)
{
if (assemblyName == null)
{
throw new ArgumentNullException(nameof(assemblyName));
}
return hostBuilder.UseSetting(WebHostDefaults.ServerKey, assemblyName);
}
/// <summary> /// <summary>
/// Specify the server to be used by the web host. /// Specify the server to be used by the web host.
/// </summary> /// </summary>

View File

@ -16,7 +16,6 @@ namespace Microsoft.AspNetCore.Hosting.Tests
var parameters = new Dictionary<string, string>() var parameters = new Dictionary<string, string>()
{ {
{ "webroot", "wwwroot"}, { "webroot", "wwwroot"},
{ "server", "Microsoft.AspNetCore.Server.Kestrel"},
{ "applicationName", "MyProjectReference"}, { "applicationName", "MyProjectReference"},
{ "startupAssembly", "MyProjectReference" }, { "startupAssembly", "MyProjectReference" },
{ "environment", "Development"}, { "environment", "Development"},
@ -27,7 +26,6 @@ namespace Microsoft.AspNetCore.Hosting.Tests
var config = new WebHostOptions(new ConfigurationBuilder().AddInMemoryCollection(parameters).Build()); var config = new WebHostOptions(new ConfigurationBuilder().AddInMemoryCollection(parameters).Build());
Assert.Equal("wwwroot", config.WebRoot); Assert.Equal("wwwroot", config.WebRoot);
Assert.Equal("Microsoft.AspNetCore.Server.Kestrel", config.ServerAssembly);
Assert.Equal("MyProjectReference", config.ApplicationName); Assert.Equal("MyProjectReference", config.ApplicationName);
Assert.Equal("MyProjectReference", config.StartupAssembly); Assert.Equal("MyProjectReference", config.StartupAssembly);
Assert.Equal("Development", config.Environment); Assert.Equal("Development", config.Environment);

View File

@ -71,13 +71,12 @@ namespace Microsoft.AspNetCore.Hosting
{ {
var vals = new Dictionary<string, string> var vals = new Dictionary<string, string>
{ {
{ "server", "Microsoft.AspNetCore.Hosting.Tests" }
}; };
var builder = new ConfigurationBuilder() var builder = new ConfigurationBuilder()
.AddInMemoryCollection(vals); .AddInMemoryCollection(vals);
var config = builder.Build(); var config = builder.Build();
var host = CreateBuilder(config).Build(); var host = CreateBuilder(config).UseServer(this).Build();
host.Start(); host.Start();
Assert.NotNull(host.Services.GetService<IHostingEnvironment>()); Assert.NotNull(host.Services.GetService<IHostingEnvironment>());
} }
@ -87,13 +86,12 @@ namespace Microsoft.AspNetCore.Hosting
{ {
var vals = new Dictionary<string, string> var vals = new Dictionary<string, string>
{ {
{ "Server", "Microsoft.AspNetCore.Hosting.Tests" }
}; };
var builder = new ConfigurationBuilder() var builder = new ConfigurationBuilder()
.AddInMemoryCollection(vals); .AddInMemoryCollection(vals);
var config = builder.Build(); var config = builder.Build();
var host = CreateBuilder(config).Build(); var host = CreateBuilder(config).UseServer(this).Build();
host.Start(); host.Start();
Assert.NotNull(host.Services.GetService<IHostingEnvironment>()); Assert.NotNull(host.Services.GetService<IHostingEnvironment>());
} }
@ -103,13 +101,12 @@ namespace Microsoft.AspNetCore.Hosting
{ {
var vals = new Dictionary<string, string> var vals = new Dictionary<string, string>
{ {
{ "Server", "Microsoft.AspNetCore.Hosting.Tests" }
}; };
var builder = new ConfigurationBuilder() var builder = new ConfigurationBuilder()
.AddInMemoryCollection(vals); .AddInMemoryCollection(vals);
var config = builder.Build(); var config = builder.Build();
var host = CreateBuilder(config).Build(); var host = CreateBuilder(config).UseServer(this).Build();
host.Start(); host.Start();
Assert.NotNull(host.Services.GetService<IHostingEnvironment>()); Assert.NotNull(host.Services.GetService<IHostingEnvironment>());
Assert.Equal("http://localhost:5000", host.ServerFeatures.Get<IServerAddressesFeature>().Addresses.First()); Assert.Equal("http://localhost:5000", host.ServerFeatures.Get<IServerAddressesFeature>().Addresses.First());