This commit is contained in:
parent
23b4ecd8d3
commit
4c84dab879
|
|
@ -19,8 +19,11 @@ namespace Microsoft.AspNetCore.Hosting.WebHostBuilderFactory
|
|||
return FactoryResolutionResult<TWebhost, TWebhostBuilder>.NoEntryPoint();
|
||||
}
|
||||
|
||||
var factory = programType?.GetTypeInfo().GetDeclaredMethod(CreateWebHostBuilder);
|
||||
if (factory == null)
|
||||
var factory = programType.GetTypeInfo().GetDeclaredMethod(CreateWebHostBuilder);
|
||||
if (factory == null ||
|
||||
!typeof(TWebhostBuilder).IsAssignableFrom(factory.ReturnType) ||
|
||||
factory.GetParameters().Length != 1 ||
|
||||
!typeof(string []).Equals(factory.GetParameters()[0].ParameterType))
|
||||
{
|
||||
return FactoryResolutionResult<TWebhost, TWebhostBuilder>.NoCreateWebHostBuilder(programType);
|
||||
}
|
||||
|
|
@ -39,8 +42,11 @@ namespace Microsoft.AspNetCore.Hosting.WebHostBuilderFactory
|
|||
return findResult;
|
||||
case FactoryResolutionResultKind.Success:
|
||||
case FactoryResolutionResultKind.NoCreateWebHostBuilder:
|
||||
var buildWebHostMethod = findResult.ProgramType.GetTypeInfo().GetDeclaredMethod("BuildWebHost");
|
||||
if (buildWebHostMethod == null)
|
||||
var buildWebHostMethod = findResult.ProgramType.GetTypeInfo().GetDeclaredMethod(BuildWebHost);
|
||||
if (buildWebHostMethod == null ||
|
||||
!typeof(TWebhost).IsAssignableFrom(buildWebHostMethod.ReturnType) ||
|
||||
buildWebHostMethod.GetParameters().Length != 1 ||
|
||||
!typeof(string[]).Equals(buildWebHostMethod.GetParameters()[0].ParameterType))
|
||||
{
|
||||
if (findResult.ResultKind == FactoryResolutionResultKind.Success)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -12,6 +12,8 @@
|
|||
<ProjectReference Include="..\..\src\Microsoft.AspNetCore.Hosting.Abstractions\Microsoft.AspNetCore.Hosting.Abstractions.csproj" />
|
||||
<ProjectReference Include="..\TestAssets\BuildWebHostPatternTestSite\BuildWebHostPatternTestSite.csproj" />
|
||||
<ProjectReference Include="..\TestAssets\IStartupInjectionAssemblyName\IStartupInjectionAssemblyName.csproj" />
|
||||
<ProjectReference Include="..\TestAssets\CreateWebHostBuilderInvalidSignature\CreateWebHostBuilderInvalidSignature.csproj" />
|
||||
<ProjectReference Include="..\TestAssets\BuildWebHostInvalidSignature\BuildWebHostInvalidSignature.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ namespace Microsoft.AspNetCore.Hosting.WebHostBuilderFactory.Tests
|
|||
public void CanFindWebHostBuilder_CreateWebHostBuilderPattern()
|
||||
{
|
||||
// Arrange & Act
|
||||
var resolverResult = WebHostFactoryResolver.ResolveWebHostBuilderFactory<IWebHost,IWebHostBuilder>(typeof(IStartupInjectionAssemblyName.Startup).Assembly);
|
||||
var resolverResult = WebHostFactoryResolver.ResolveWebHostBuilderFactory<IWebHost, IWebHostBuilder>(typeof(IStartupInjectionAssemblyName.Startup).Assembly);
|
||||
|
||||
// Assert
|
||||
Assert.Equal(FactoryResolutionResultKind.Success, resolverResult.ResultKind);
|
||||
|
|
@ -45,6 +45,30 @@ namespace Microsoft.AspNetCore.Hosting.WebHostBuilderFactory.Tests
|
|||
Assert.Null(resolverResult.WebHostFactory);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void CanNotFindWebHostBuilder_CreateWebHostBuilderIncorrectSignature()
|
||||
{
|
||||
// Arrange & Act
|
||||
var resolverResult = WebHostFactoryResolver.ResolveWebHostBuilderFactory<IWebHost, IWebHostBuilder>(typeof(CreateWebHostBuilderInvalidSignature.Startup).Assembly);
|
||||
|
||||
// Assert
|
||||
Assert.Equal(FactoryResolutionResultKind.NoCreateWebHostBuilder, resolverResult.ResultKind);
|
||||
Assert.Null(resolverResult.WebHostBuilderFactory);
|
||||
Assert.Null(resolverResult.WebHostFactory);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void CanNotFindWebHost_BuildWebHostIncorrectSignature()
|
||||
{
|
||||
// Arrange & Act
|
||||
var resolverResult = WebHostFactoryResolver.ResolveWebHostFactory<IWebHost, IWebHostBuilder>(typeof(BuildWebHostInvalidSignature.Startup).Assembly);
|
||||
|
||||
// Assert
|
||||
Assert.Equal(FactoryResolutionResultKind.NoBuildWebHost, resolverResult.ResultKind);
|
||||
Assert.Null(resolverResult.WebHostBuilderFactory);
|
||||
Assert.Null(resolverResult.WebHostFactory);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void CanFindWebHost_BuildWebHostPattern()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -0,0 +1,17 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFrameworks>$(StandardTestAssetTfms)</TargetFrameworks>
|
||||
<OutputType>Exe</OutputType>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\..\src\Microsoft.AspNetCore.Hosting\Microsoft.AspNetCore.Hosting.csproj" />
|
||||
<ProjectReference Include="..\..\..\src\Microsoft.AspNetCore.TestHost\Microsoft.AspNetCore.TestHost.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="$(MicrosoftExtensionsDependencyInjectionPackageVersion)" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
// 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.AspNetCore.Hosting;
|
||||
|
||||
namespace BuildWebHostInvalidSignature
|
||||
{
|
||||
class Program
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
}
|
||||
|
||||
public static IWebHost BuildWebHost() => null;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
// 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.AspNetCore.Builder;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
namespace BuildWebHostInvalidSignature
|
||||
{
|
||||
public class Startup
|
||||
{
|
||||
public void ConfigureServices(IServiceCollection services)
|
||||
{
|
||||
}
|
||||
|
||||
public void Configure(IApplicationBuilder builder)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFrameworks>$(StandardTestAssetTfms)</TargetFrameworks>
|
||||
<OutputType>Exe</OutputType>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\..\src\Microsoft.AspNetCore.Hosting\Microsoft.AspNetCore.Hosting.csproj" />
|
||||
<ProjectReference Include="..\..\..\src\Microsoft.AspNetCore.TestHost\Microsoft.AspNetCore.TestHost.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="$(MicrosoftExtensionsDependencyInjectionPackageVersion)" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
// 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.AspNetCore.Hosting;
|
||||
|
||||
namespace CreateWebHostBuilderInvalidSignature
|
||||
{
|
||||
class Program
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
}
|
||||
|
||||
public static IWebHostBuilder CreateWebHostBuilder() => null;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
// 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.AspNetCore.Builder;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
namespace CreateWebHostBuilderInvalidSignature
|
||||
{
|
||||
public class Startup
|
||||
{
|
||||
public void ConfigureServices(IServiceCollection services)
|
||||
{
|
||||
}
|
||||
|
||||
public void Configure(IApplicationBuilder builder)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue