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

Commit 62e5349

Browse files
committed
Make webHostBuilder.UseStartup(startupAssemblyName) work
1 parent 568c8b6 commit 62e5349

File tree

3 files changed

+45
-6
lines changed

3 files changed

+45
-6
lines changed

src/Microsoft.AspNet.Hosting/Properties/AssemblyInfo.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,7 @@
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

44
using System.Reflection;
5+
using System.Runtime.CompilerServices;
56

6-
[assembly: AssemblyMetadata("Serviceable", "True")]
7+
[assembly: AssemblyMetadata("Serviceable", "True")]
8+
[assembly: InternalsVisibleTo("Microsoft.AspNet.Hosting.Tests")]

src/Microsoft.AspNet.Hosting/WebHostBuilder.cs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,10 @@ public class WebHostBuilder
4242
private string _serverFactoryLocation;
4343
private IServerFactory _serverFactory;
4444

45-
public WebHostBuilder([NotNull] IServiceProvider services)
46-
: this(services, config: new ConfigurationBuilder().Build()) { }
45+
public WebHostBuilder([NotNull] IServiceProvider services)
46+
: this(services, config: new ConfigurationBuilder().Build())
47+
{
48+
}
4749

4850
public WebHostBuilder([NotNull] IServiceProvider services, [NotNull] IConfiguration config)
4951
{
@@ -109,7 +111,7 @@ public IHostingEngine Build()
109111
// Only one of these should be set, but they are used in priority
110112
engine.Startup = _startup;
111113
engine.StartupType = _startupType;
112-
engine.StartupAssemblyName = _config.Get(ApplicationKey) ?? _config.Get(OldApplicationKey) ?? appEnvironment.ApplicationName;
114+
engine.StartupAssemblyName = _startupAssemblyName ?? _config.Get(ApplicationKey) ?? _config.Get(OldApplicationKey) ?? appEnvironment.ApplicationName;
113115

114116
return engine;
115117
}
@@ -177,7 +179,8 @@ public WebHostBuilder UseStartup([NotNull] Action<IApplicationBuilder> configure
177179
public WebHostBuilder UseStartup([NotNull] Action<IApplicationBuilder> configureApp, Action<IServiceCollection> configureServices)
178180
{
179181
_startup = new StartupMethods(configureApp,
180-
services => {
182+
services =>
183+
{
181184
if (configureServices != null)
182185
{
183186
configureServices(services);
@@ -187,4 +190,4 @@ public WebHostBuilder UseStartup([NotNull] Action<IApplicationBuilder> configure
187190
return this;
188191
}
189192
}
190-
}
193+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// Copyright (c) .NET Foundation. All rights reserved.
2+
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3+
4+
using Microsoft.AspNet.Hosting.Internal;
5+
using Microsoft.Framework.Runtime.Infrastructure;
6+
using Xunit;
7+
8+
namespace Microsoft.AspNet.Hosting
9+
{
10+
public class WebHostBuilderTests
11+
{
12+
[Fact]
13+
public void Build_uses_application_for_startup_assembly_by_default()
14+
{
15+
var builder = CreateWebHostBuilder();
16+
17+
var engine = (HostingEngine)builder.Build();
18+
19+
Assert.Equal("Microsoft.AspNet.Hosting.Tests", engine.StartupAssemblyName);
20+
}
21+
22+
[Fact]
23+
public void Build_honors_UseStartup_with_string()
24+
{
25+
var builder = CreateWebHostBuilder();
26+
27+
var engine = (HostingEngine)builder.UseStartup("MyStartupAssembly").Build();
28+
29+
Assert.Equal("MyStartupAssembly", engine.StartupAssemblyName);
30+
}
31+
32+
private WebHostBuilder CreateWebHostBuilder() => new WebHostBuilder(CallContextServiceLocator.Locator.ServiceProvider);
33+
}
34+
}

0 commit comments

Comments
 (0)