Skip to content

Commit 6a44aca

Browse files
authored
React to WebHostBuilderFactory changes (#6460)
1 parent 09b5085 commit 6a44aca

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+527
-478
lines changed

build/artifacts.props

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,6 @@ This can be done once #4246 is complete, and done in conjunction with converting
9797
<PackageArtifact Include="Microsoft.AspNetCore.Server.IntegrationTesting.IIS" Category="noship" />
9898
<PackageArtifact Include="Microsoft.AspNetCore.Server.IntegrationTesting" Category="noship" />
9999

100-
<!-- This package is produced for use in aspnet/EntityFrameworkCore to ensure EF tools can load a service collection from and app using ASP.NET's Program/Startup patterns/ -->
101-
<PackageArtifact Include="Internal.WebHostBuilderFactory.Sources" Category="noship"/>
102-
103100
<!-- These packages are produced temporarily while we finish refactoring the way this repo builds. See https://github.com/aspnet/AspNetCore/issues/4246 -->
104101
<PackageArtifact Include="Microsoft.AspNetCore.Antiforgery" Category="noship" />
105102
<PackageArtifact Include="Microsoft.AspNetCore.Authentication.Abstractions" Category="noship" />

build/repo.props

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,6 @@
3434
<BuildJava>true</BuildJava>
3535
</PropertyGroup>
3636

37-
<ItemGroup>
38-
<SharedSourceDirectories Include="$(SharedSourcesFolder)Hosting.WebHostBuilderFactory\" />
39-
</ItemGroup>
40-
4137
<!-- These projects are always excluded, even when -projects is specified on command line. -->
4238
<ItemGroup>
4339
<!-- These projects use 'legacy' csproj, which is not supported by dotnet-msbuild. -->

eng/Dependencies.props

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ and are generated based on the last package release.
6565
<LatestPackageReference Include="Microsoft.Extensions.HashCodeCombiner.Sources" Version="$(MicrosoftExtensionsHashCodeCombinerSourcesPackageVersion)" />
6666
<LatestPackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="$(MicrosoftExtensionsHostingAbstractionsPackageVersion)" />
6767
<LatestPackageReference Include="Microsoft.Extensions.Hosting" Version="$(MicrosoftExtensionsHostingPackageVersion)" />
68+
<LatestPackageReference Include="Microsoft.Extensions.HostFactoryResolver.Sources" Version="$(MicrosoftExtensionsHostFactoryResolverSourcesPackageVersion)" />
6869
<LatestPackageReference Include="Microsoft.Extensions.Localization.Abstractions" Version="$(MicrosoftExtensionsLocalizationAbstractionsPackageVersion)" />
6970
<LatestPackageReference Include="Microsoft.Extensions.Localization" Version="$(MicrosoftExtensionsLocalizationPackageVersion)" />
7071
<LatestPackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="$(MicrosoftExtensionsLoggingAbstractionsPackageVersion)" />

src/Hosting/Hosting.sln

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.Hostin
2929
EndProject
3030
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "testassets", "testassets", "{31587D24-F6B5-4A47-A962-47CA7FEA79D0}"
3131
EndProject
32-
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BuildWebHostInvalidSignature", "test\testassets\BuildWebHostInvalidSignature\BuildWebHostInvalidSignature.csproj", "{BF146375-AA6C-43F3-BF0A-DCA551892DF8}"
33-
EndProject
3432
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.Hosting.FunctionalTests", "test\FunctionalTests\Microsoft.AspNetCore.Hosting.FunctionalTests.csproj", "{D6EC0A3E-384A-4EE9-8068-21E1848BBB11}"
3533
EndProject
36-
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.Hosting.WebHostBuilderFactory.Tests", "test\WebHostBuilderFactory.Tests\Microsoft.AspNetCore.Hosting.WebHostBuilderFactory.Tests.csproj", "{4AB4D911-7741-4F3E-982E-7945C6FC36C4}"
37-
EndProject
38-
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BuildWebHostPatternTestSite", "test\testassets\BuildWebHostPatternTestSite\BuildWebHostPatternTestSite.csproj", "{953E1E06-F39F-45E7-840D-FA8DE1E01740}"
39-
EndProject
40-
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CreateWebHostBuilderInvalidSignature", "test\testassets\CreateWebHostBuilderInvalidSignature\CreateWebHostBuilderInvalidSignature.csproj", "{BE562963-37E1-410F-8751-A3044458B861}"
41-
EndProject
4234
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "IStartupInjectionAssemblyName", "test\testassets\IStartupInjectionAssemblyName\IStartupInjectionAssemblyName.csproj", "{F032B4F6-2F03-4885-AB03-CA81038808A6}"
4335
EndProject
4436
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.Hosting.TestSites", "test\testassets\Microsoft.AspNetCore.Hosting.TestSites\Microsoft.AspNetCore.Hosting.TestSites.csproj", "{9CA19BE4-DC10-4690-9142-61BD007B6D80}"
@@ -95,26 +87,10 @@ Global
9587
{CCD5D010-7E06-4209-ADD5-3B010A41DCF1}.Debug|Any CPU.Build.0 = Debug|Any CPU
9688
{CCD5D010-7E06-4209-ADD5-3B010A41DCF1}.Release|Any CPU.ActiveCfg = Release|Any CPU
9789
{CCD5D010-7E06-4209-ADD5-3B010A41DCF1}.Release|Any CPU.Build.0 = Release|Any CPU
98-
{BF146375-AA6C-43F3-BF0A-DCA551892DF8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
99-
{BF146375-AA6C-43F3-BF0A-DCA551892DF8}.Debug|Any CPU.Build.0 = Debug|Any CPU
100-
{BF146375-AA6C-43F3-BF0A-DCA551892DF8}.Release|Any CPU.ActiveCfg = Release|Any CPU
101-
{BF146375-AA6C-43F3-BF0A-DCA551892DF8}.Release|Any CPU.Build.0 = Release|Any CPU
10290
{D6EC0A3E-384A-4EE9-8068-21E1848BBB11}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
10391
{D6EC0A3E-384A-4EE9-8068-21E1848BBB11}.Debug|Any CPU.Build.0 = Debug|Any CPU
10492
{D6EC0A3E-384A-4EE9-8068-21E1848BBB11}.Release|Any CPU.ActiveCfg = Release|Any CPU
10593
{D6EC0A3E-384A-4EE9-8068-21E1848BBB11}.Release|Any CPU.Build.0 = Release|Any CPU
106-
{4AB4D911-7741-4F3E-982E-7945C6FC36C4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
107-
{4AB4D911-7741-4F3E-982E-7945C6FC36C4}.Debug|Any CPU.Build.0 = Debug|Any CPU
108-
{4AB4D911-7741-4F3E-982E-7945C6FC36C4}.Release|Any CPU.ActiveCfg = Release|Any CPU
109-
{4AB4D911-7741-4F3E-982E-7945C6FC36C4}.Release|Any CPU.Build.0 = Release|Any CPU
110-
{953E1E06-F39F-45E7-840D-FA8DE1E01740}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
111-
{953E1E06-F39F-45E7-840D-FA8DE1E01740}.Debug|Any CPU.Build.0 = Debug|Any CPU
112-
{953E1E06-F39F-45E7-840D-FA8DE1E01740}.Release|Any CPU.ActiveCfg = Release|Any CPU
113-
{953E1E06-F39F-45E7-840D-FA8DE1E01740}.Release|Any CPU.Build.0 = Release|Any CPU
114-
{BE562963-37E1-410F-8751-A3044458B861}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
115-
{BE562963-37E1-410F-8751-A3044458B861}.Debug|Any CPU.Build.0 = Debug|Any CPU
116-
{BE562963-37E1-410F-8751-A3044458B861}.Release|Any CPU.ActiveCfg = Release|Any CPU
117-
{BE562963-37E1-410F-8751-A3044458B861}.Release|Any CPU.Build.0 = Release|Any CPU
11894
{F032B4F6-2F03-4885-AB03-CA81038808A6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
11995
{F032B4F6-2F03-4885-AB03-CA81038808A6}.Debug|Any CPU.Build.0 = Debug|Any CPU
12096
{F032B4F6-2F03-4885-AB03-CA81038808A6}.Release|Any CPU.ActiveCfg = Release|Any CPU
@@ -134,9 +110,6 @@ Global
134110
GlobalSection(NestedProjects) = preSolution
135111
{7351DDBC-71DF-4C40-A364-981710B80E29} = {3E9635DD-53A9-4098-B6F6-E5C3C8F7C600}
136112
{3C3F4D2D-6676-4A0B-895D-348E7DD4152E} = {3E9635DD-53A9-4098-B6F6-E5C3C8F7C600}
137-
{BF146375-AA6C-43F3-BF0A-DCA551892DF8} = {31587D24-F6B5-4A47-A962-47CA7FEA79D0}
138-
{953E1E06-F39F-45E7-840D-FA8DE1E01740} = {31587D24-F6B5-4A47-A962-47CA7FEA79D0}
139-
{BE562963-37E1-410F-8751-A3044458B861} = {31587D24-F6B5-4A47-A962-47CA7FEA79D0}
140113
{F032B4F6-2F03-4885-AB03-CA81038808A6} = {31587D24-F6B5-4A47-A962-47CA7FEA79D0}
141114
{9CA19BE4-DC10-4690-9142-61BD007B6D80} = {31587D24-F6B5-4A47-A962-47CA7FEA79D0}
142115
{570D1047-A109-4209-9258-9BA7C8BDC9AA} = {31587D24-F6B5-4A47-A962-47CA7FEA79D0}

src/Hosting/Hosting/src/GenericHost/GenericWebHostBuilder.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,9 +203,14 @@ public IWebHostBuilder UseDefaultServiceProvider(Action<WebHostBuilderContext, S
203203

204204
public IWebHostBuilder UseStartup(Type startupType)
205205
{
206+
// UseStartup can be called multiple times. Only run the last one.
207+
_builder.Properties["UseStartup.StartupType"] = startupType;
206208
_builder.ConfigureServices((context, services) =>
207209
{
208-
UseStartup(startupType, context, services);
210+
if (_builder.Properties.TryGetValue("UseStartup.StartupType", out var cachedType) && (Type)cachedType == startupType)
211+
{
212+
UseStartup(startupType, context, services);
213+
}
209214
});
210215

211216
return this;

src/Hosting/TestHost/src/Microsoft.AspNetCore.TestHost.csproj

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
1+
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
44
<Description>ASP.NET Core web server for writing and running tests.</Description>
@@ -9,12 +9,9 @@
99
<IsProductPackage>true</IsProductPackage>
1010
</PropertyGroup>
1111

12-
<ItemGroup>
13-
<Compile Include="$(SharedSourceRoot)Hosting.WebHostBuilderFactory\**\*.cs" />
14-
</ItemGroup>
15-
1612
<ItemGroup>
1713
<Reference Include="Microsoft.AspNetCore.Hosting" />
14+
<Reference Include="Microsoft.Extensions.HostFactoryResolver.Sources" PrivateAssets="All" />
1815
<Reference Include="System.IO.Pipelines" />
1916
</ItemGroup>
2017

src/Hosting/TestHost/src/TestServer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ public void Dispose()
146146
if (!_disposed)
147147
{
148148
_disposed = true;
149-
_hostInstance.Dispose();
149+
_hostInstance?.Dispose();
150150
}
151151
}
152152

src/Hosting/TestHost/src/WebHostBuilderExtensions.cs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) .NET Foundation. All rights reserved.
1+
// Copyright (c) .NET Foundation. All rights reserved.
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

44
using System;
@@ -33,9 +33,17 @@ public static IWebHostBuilder ConfigureTestServices(this IWebHostBuilder webHost
3333
throw new ArgumentNullException(nameof(servicesConfiguration));
3434
}
3535

36-
webHostBuilder.ConfigureServices(
37-
s => s.AddSingleton<IStartupConfigureServicesFilter>(
38-
new ConfigureTestServicesStartupConfigureServicesFilter(servicesConfiguration)));
36+
if (webHostBuilder.GetType().Name.Equals("GenericWebHostBuilder"))
37+
{
38+
// Generic host doesn't need to do anything special here since there's only one container.
39+
webHostBuilder.ConfigureServices(servicesConfiguration);
40+
}
41+
else
42+
{
43+
webHostBuilder.ConfigureServices(
44+
s => s.AddSingleton<IStartupConfigureServicesFilter>(
45+
new ConfigureTestServicesStartupConfigureServicesFilter(servicesConfiguration)));
46+
}
3947

4048
return webHostBuilder;
4149
}

src/Hosting/TestHost/src/WebHostBuilderFactory.cs

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,18 @@
1-
// Copyright (c) .NET Foundation. All rights reserved.
1+
// Copyright (c) .NET Foundation. All rights reserved.
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

44
using System.Reflection;
55
using Microsoft.AspNetCore.Hosting;
6-
using Microsoft.AspNetCore.Hosting.WebHostBuilderFactory;
6+
using Microsoft.Extensions.Hosting;
77

88
namespace Microsoft.AspNetCore.TestHost
99
{
1010
public static class WebHostBuilderFactory
1111
{
12-
public static IWebHostBuilder CreateFromAssemblyEntryPoint(Assembly assembly, string [] args)
12+
public static IWebHostBuilder CreateFromAssemblyEntryPoint(Assembly assembly, string[] args)
1313
{
14-
var result = WebHostFactoryResolver.ResolveWebHostBuilderFactory<IWebHost,IWebHostBuilder>(assembly);
15-
if (result.ResultKind != FactoryResolutionResultKind.Success)
16-
{
17-
return null;
18-
}
19-
20-
return result.WebHostBuilderFactory(args);
14+
var factory = HostFactoryResolver.ResolveWebHostBuilderFactory<IWebHostBuilder>(assembly);
15+
return factory?.Invoke(args);
2116
}
2217

2318
public static IWebHostBuilder CreateFromTypesAssemblyEntryPoint<T>(string[] args) =>

src/Hosting/test/WebHostBuilderFactory.Tests/Microsoft.AspNetCore.Hosting.WebHostBuilderFactory.Tests.csproj

Lines changed: 0 additions & 22 deletions
This file was deleted.

0 commit comments

Comments
 (0)