Detect duplicate startups in HostingStartupAssemblies (#1183)
This commit is contained in:
parent
c24c717eee
commit
500668619f
|
|
@ -5,6 +5,7 @@ using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System.Runtime.ExceptionServices;
|
using System.Runtime.ExceptionServices;
|
||||||
using Microsoft.AspNetCore.Hosting.Builder;
|
using Microsoft.AspNetCore.Hosting.Builder;
|
||||||
|
|
@ -195,7 +196,7 @@ namespace Microsoft.AspNetCore.Hosting
|
||||||
var exceptions = new List<Exception>();
|
var exceptions = new List<Exception>();
|
||||||
|
|
||||||
// Execute the hosting startup assemblies
|
// Execute the hosting startup assemblies
|
||||||
foreach (var assemblyName in _options.HostingStartupAssemblies)
|
foreach (var assemblyName in _options.HostingStartupAssemblies.Distinct(StringComparer.OrdinalIgnoreCase))
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ using Microsoft.AspNetCore.Hosting.Internal;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.Hosting.Tests
|
namespace Microsoft.AspNetCore.Hosting.Tests
|
||||||
{
|
{
|
||||||
public class ConfigureBuilderTests
|
public class ConfigureBuilderTests
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -234,6 +234,36 @@ namespace Microsoft.AspNetCore.Hosting
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task MultipleStartupAssembliesSpecifiedOnlyAddAssemblyOnce()
|
||||||
|
{
|
||||||
|
var provider = new TestLoggerProvider();
|
||||||
|
var assemblyName = "RandomName";
|
||||||
|
var data = new Dictionary<string, string>
|
||||||
|
{
|
||||||
|
{ WebHostDefaults.ApplicationKey, assemblyName },
|
||||||
|
{ WebHostDefaults.HostingStartupAssembliesKey, assemblyName }
|
||||||
|
};
|
||||||
|
var config = new ConfigurationBuilder().AddInMemoryCollection(data).Build();
|
||||||
|
|
||||||
|
var builder = CreateWebHostBuilder()
|
||||||
|
.UseConfiguration(config)
|
||||||
|
.ConfigureLogging((_, factory) =>
|
||||||
|
{
|
||||||
|
factory.AddProvider(provider);
|
||||||
|
})
|
||||||
|
.UseServer(new TestServer());
|
||||||
|
|
||||||
|
// Verify that there was only one exception throw rather than two.
|
||||||
|
using (var host = (WebHost)builder.Build())
|
||||||
|
{
|
||||||
|
await host.StartAsync();
|
||||||
|
var context = provider.Sink.Writes.Where(s => s.EventId.Id == LoggerEventIds.HostingStartupAssemblyException);
|
||||||
|
Assert.NotNull(context);
|
||||||
|
Assert.Single(context);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void HostingContextContainsAppConfigurationDuringConfigureLogging()
|
public void HostingContextContainsAppConfigurationDuringConfigureLogging()
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue