Skip to content
This repository has been archived by the owner on Dec 19, 2018. It is now read-only.

Commit

Permalink
Remove UseServer(string) overload
Browse files Browse the repository at this point in the history
- Removed the overload that takes a string because it's broken

#731
  • Loading branch information
davidfowl committed May 19, 2016
1 parent d42df96 commit 626cb55
Show file tree
Hide file tree
Showing 9 changed files with 16 additions and 60 deletions.
4 changes: 2 additions & 2 deletions samples/SampleStartups/StartupExternallyControlled.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class StartupExternallyControlled : StartupBase
{
private IWebHost _host;
private readonly List<string> _urls = new List<string>();

// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public override void Configure(IApplicationBuilder app)
{
Expand All @@ -29,7 +29,7 @@ public StartupExternallyControlled()
public void Start()
{
_host = new WebHostBuilder()
.UseServer("Microsoft.AspNetCore.Server.Kestrel")
//.UseKestrel()
.UseStartup<StartupExternallyControlled>()
.Start(_urls.ToArray());
}
Expand Down
2 changes: 1 addition & 1 deletion samples/SampleStartups/StartupFullControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public static void Main(string[] args)

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")
Expand Down
2 changes: 1 addition & 1 deletion samples/SampleStartups/StartupHelloWorld.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public override void Configure(IApplicationBuilder app)
public static void Main(string[] args)
{
var host = new WebHostBuilder()
.UseServer("Microsoft.AspNetCore.Server.Kestrel")
//.UseKestrel()
.UseStartup<StartupHelloWorld>()
.Build();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ public static class WebHostDefaults

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";
Expand Down
3 changes: 0 additions & 3 deletions src/Microsoft.AspNetCore.Hosting/Internal/WebHostOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ public WebHostOptions(IConfiguration configuration)
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];
}
Expand All @@ -36,8 +35,6 @@ public WebHostOptions(IConfiguration configuration)
public bool CaptureStartupErrors { get; set; }

public string Environment { get; set; }

public string ServerAssembly { get; set; }

public string StartupAssembly { get; set; }

Expand Down
19 changes: 0 additions & 19 deletions src/Microsoft.AspNetCore.Hosting/WebHostBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -187,25 +187,6 @@ private IServiceCollection BuildHostingServices()
// Ensure object pooling is available everywhere.
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))
{
try
Expand Down
34 changes: 9 additions & 25 deletions src/Microsoft.AspNetCore.Hosting/WebHostBuilderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public static IWebHostBuilder CaptureStartupErrors(this IWebHostBuilder hostBuil
{
return hostBuilder.UseSetting(WebHostDefaults.CaptureStartupErrorsKey, captureStartupErrors ? "true" : "false");
}

/// <summary>
/// Specify the startup method to be used to configure the web application.
/// </summary>
Expand All @@ -56,17 +56,17 @@ public static IWebHostBuilder Configure(this IWebHostBuilder hostBuilder, Action
{
throw new ArgumentNullException(nameof(configureApp));
}

var startupAssemblyName = configureApp.GetMethodInfo().DeclaringType.GetTypeInfo().Assembly.GetName().Name;

return hostBuilder.UseSetting(WebHostDefaults.ApplicationKey, startupAssemblyName)
.ConfigureServices(services =>
{
services.AddSingleton<IStartup>(new DelegateStartup(configureApp));
});
}


/// <summary>
/// Specify the startup type to be used by the web host.
/// </summary>
Expand All @@ -76,7 +76,7 @@ public static IWebHostBuilder Configure(this IWebHostBuilder hostBuilder, Action
public static IWebHostBuilder UseStartup(this IWebHostBuilder hostBuilder, Type startupType)
{
var startupAssemblyName = startupType.GetTypeInfo().Assembly.GetName().Name;

return hostBuilder.UseSetting(WebHostDefaults.ApplicationKey, startupAssemblyName)
.ConfigureServices(services =>
{
Expand All @@ -86,15 +86,15 @@ public static IWebHostBuilder UseStartup(this IWebHostBuilder hostBuilder, Type
}
else
{
services.AddSingleton(typeof(IStartup), sp =>
services.AddSingleton(typeof(IStartup), sp =>
{
var hostingEnvironment = sp.GetRequiredService<IHostingEnvironment>();
return new ConventionBasedStartup(StartupLoader.LoadMethods(sp, startupType, hostingEnvironment.EnvironmentName));
});
}
});
}

/// <summary>
/// Specify the startup type to be used by the web host.
/// </summary>
Expand All @@ -119,28 +119,12 @@ public static IWebHostBuilder UseStartup(this IWebHostBuilder hostBuilder, strin
throw new ArgumentNullException(nameof(startupAssemblyName));
}


return hostBuilder
.UseSetting(WebHostDefaults.ApplicationKey, 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>
/// Specify the server to be used by the web host.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ public void ReadsParametersCorrectly()
var parameters = new Dictionary<string, string>()
{
{ "webroot", "wwwroot"},
{ "server", "Microsoft.AspNetCore.Server.Kestrel"},
{ "applicationName", "MyProjectReference"},
{ "startupAssembly", "MyProjectReference" },
{ "environment", "Development"},
Expand All @@ -27,7 +26,6 @@ public void ReadsParametersCorrectly()
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);
Expand Down
9 changes: 3 additions & 6 deletions test/Microsoft.AspNetCore.Hosting.Tests/WebHostTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,12 @@ public void CanStartWithOldServerConfig()
{
var vals = new Dictionary<string, string>
{
{ "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<IHostingEnvironment>());
}
Expand All @@ -87,13 +86,12 @@ public void CanStartWithServerConfig()
{
var vals = new Dictionary<string, string>
{
{ "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<IHostingEnvironment>());
}
Expand All @@ -103,13 +101,12 @@ public void CanDefaultAddressesIfNotConfigured()
{
var vals = new Dictionary<string, string>
{
{ "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<IHostingEnvironment>());
Assert.Equal("http://localhost:5000", host.ServerFeatures.Get<IServerAddressesFeature>().Addresses.First());
Expand Down

0 comments on commit 626cb55

Please sign in to comment.