Make webHostBuilder.UseStartup(startupAssemblyName) work

This commit is contained in:
Brice Lambson 2015-05-28 14:29:17 -07:00 committed by Brice Lambson
parent 568c8b6bc4
commit 62e5349773
3 changed files with 45 additions and 6 deletions

View File

@ -2,5 +2,7 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Reflection;
using System.Runtime.CompilerServices;
[assembly: AssemblyMetadata("Serviceable", "True")]
[assembly: AssemblyMetadata("Serviceable", "True")]
[assembly: InternalsVisibleTo("Microsoft.AspNet.Hosting.Tests")]

View File

@ -42,8 +42,10 @@ namespace Microsoft.AspNet.Hosting
private string _serverFactoryLocation;
private IServerFactory _serverFactory;
public WebHostBuilder([NotNull] IServiceProvider services)
: this(services, config: new ConfigurationBuilder().Build()) { }
public WebHostBuilder([NotNull] IServiceProvider services)
: this(services, config: new ConfigurationBuilder().Build())
{
}
public WebHostBuilder([NotNull] IServiceProvider services, [NotNull] IConfiguration config)
{
@ -109,7 +111,7 @@ namespace Microsoft.AspNet.Hosting
// Only one of these should be set, but they are used in priority
engine.Startup = _startup;
engine.StartupType = _startupType;
engine.StartupAssemblyName = _config.Get(ApplicationKey) ?? _config.Get(OldApplicationKey) ?? appEnvironment.ApplicationName;
engine.StartupAssemblyName = _startupAssemblyName ?? _config.Get(ApplicationKey) ?? _config.Get(OldApplicationKey) ?? appEnvironment.ApplicationName;
return engine;
}
@ -177,7 +179,8 @@ namespace Microsoft.AspNet.Hosting
public WebHostBuilder UseStartup([NotNull] Action<IApplicationBuilder> configureApp, Action<IServiceCollection> configureServices)
{
_startup = new StartupMethods(configureApp,
services => {
services =>
{
if (configureServices != null)
{
configureServices(services);
@ -187,4 +190,4 @@ namespace Microsoft.AspNet.Hosting
return this;
}
}
}
}

View File

@ -0,0 +1,34 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using Microsoft.AspNet.Hosting.Internal;
using Microsoft.Framework.Runtime.Infrastructure;
using Xunit;
namespace Microsoft.AspNet.Hosting
{
public class WebHostBuilderTests
{
[Fact]
public void Build_uses_application_for_startup_assembly_by_default()
{
var builder = CreateWebHostBuilder();
var engine = (HostingEngine)builder.Build();
Assert.Equal("Microsoft.AspNet.Hosting.Tests", engine.StartupAssemblyName);
}
[Fact]
public void Build_honors_UseStartup_with_string()
{
var builder = CreateWebHostBuilder();
var engine = (HostingEngine)builder.UseStartup("MyStartupAssembly").Build();
Assert.Equal("MyStartupAssembly", engine.StartupAssemblyName);
}
private WebHostBuilder CreateWebHostBuilder() => new WebHostBuilder(CallContextServiceLocator.Locator.ServiceProvider);
}
}