Delay resolution until after application services are built (#1553)
- Resolve the logger from the right service provider to log duplicate hosting startup assemblies. - Don't create a 3rd IServiceProvider if we resolved the default implementation.
This commit is contained in:
parent
ef69aa833b
commit
f17142b2ec
|
|
@ -174,13 +174,6 @@ namespace Microsoft.AspNetCore.Hosting
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var logger = hostingServiceProvider.GetRequiredService<ILogger<WebHost>>();
|
|
||||||
// Warn about duplicate HostingStartupAssemblies
|
|
||||||
foreach (var assemblyName in _options.GetFinalHostingStartupAssemblies().GroupBy(a => a, StringComparer.OrdinalIgnoreCase).Where(g => g.Count() > 1))
|
|
||||||
{
|
|
||||||
logger.LogWarning($"The assembly {assemblyName} was specified multiple times. Hosting startup assemblies should only be specified once.");
|
|
||||||
}
|
|
||||||
|
|
||||||
AddApplicationServices(applicationServices, hostingServiceProvider);
|
AddApplicationServices(applicationServices, hostingServiceProvider);
|
||||||
|
|
||||||
var host = new WebHost(
|
var host = new WebHost(
|
||||||
|
|
@ -193,6 +186,14 @@ namespace Microsoft.AspNetCore.Hosting
|
||||||
{
|
{
|
||||||
host.Initialize();
|
host.Initialize();
|
||||||
|
|
||||||
|
var logger = host.Services.GetRequiredService<ILogger<WebHost>>();
|
||||||
|
|
||||||
|
// Warn about duplicate HostingStartupAssemblies
|
||||||
|
foreach (var assemblyName in _options.GetFinalHostingStartupAssemblies().GroupBy(a => a, StringComparer.OrdinalIgnoreCase).Where(g => g.Count() > 1))
|
||||||
|
{
|
||||||
|
logger.LogWarning($"The assembly {assemblyName} was specified multiple times. Hosting startup assemblies should only be specified once.");
|
||||||
|
}
|
||||||
|
|
||||||
return host;
|
return host;
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
|
|
@ -208,7 +209,7 @@ namespace Microsoft.AspNetCore.Hosting
|
||||||
var provider = collection.BuildServiceProvider();
|
var provider = collection.BuildServiceProvider();
|
||||||
var factory = provider.GetService<IServiceProviderFactory<IServiceCollection>>();
|
var factory = provider.GetService<IServiceProviderFactory<IServiceCollection>>();
|
||||||
|
|
||||||
if (factory != null)
|
if (factory != null && !(factory is DefaultServiceProviderFactory))
|
||||||
{
|
{
|
||||||
using (provider)
|
using (provider)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue