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

Make webHostBuilder.UseStartup(startupAssemblyName) work #284

Merged
merged 1 commit into from
May 29, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/Microsoft.AspNet.Hosting/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
13 changes: 8 additions & 5 deletions src/Microsoft.AspNet.Hosting/WebHostBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,10 @@ public class WebHostBuilder
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)
{
Expand Down Expand Up @@ -109,7 +111,7 @@ public IHostingEngine Build()
// 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;
}
Expand Down Expand Up @@ -177,7 +179,8 @@ public WebHostBuilder UseStartup([NotNull] Action<IApplicationBuilder> configure
public WebHostBuilder UseStartup([NotNull] Action<IApplicationBuilder> configureApp, Action<IServiceCollection> configureServices)
{
_startup = new StartupMethods(configureApp,
services => {
services =>
{
if (configureServices != null)
{
configureServices(services);
Expand All @@ -187,4 +190,4 @@ public WebHostBuilder UseStartup([NotNull] Action<IApplicationBuilder> configure
return this;
}
}
}
}
34 changes: 34 additions & 0 deletions test/Microsoft.AspNet.Hosting.Tests/WebHostBuilderTests.cs
Original file line number Diff line number Diff line change
@@ -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);
}
}