Skip to content
This repository was archived by the owner on Dec 19, 2018. It is now read-only.
Closed
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
18 changes: 17 additions & 1 deletion src/Microsoft.AspNetCore.Hosting/WebHostBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public class WebHostBuilder : IWebHostBuilder
private WebHostBuilderContext _context;
private bool _webHostBuilt;
private List<Action<WebHostBuilderContext, IConfigurationBuilder>> _configureAppConfigurationBuilderDelegates;
private Func<IServiceCollection> _serviceCollectionDelegate;

/// <summary>
/// Initializes a new instance of the <see cref="WebHostBuilder"/> class.
Expand Down Expand Up @@ -87,6 +88,12 @@ public IWebHostBuilder UseSetting(string key, string value)
return this;
}

public IWebHostBuilder UseExternalServiceCollection(Func<IServiceCollection> serviceCollectionDelegate)
{
_serviceCollectionDelegate = serviceCollectionDelegate;
return this;
}

/// <summary>
/// Adds a delegate for configuring additional services for the host or web application. This may be called
/// multiple times.
Expand Down Expand Up @@ -237,7 +244,16 @@ private IServiceCollection BuildCommonServices(out AggregateException hostingSta
_hostingEnvironment.Initialize(contentRootPath, _options);
_context.HostingEnvironment = _hostingEnvironment;

var services = new ServiceCollection();
IServiceCollection services;
if (_serviceCollectionDelegate == null)
{
services = new ServiceCollection();
}
else
{
services = _serviceCollectionDelegate();
}

services.AddSingleton(_options);
services.AddSingleton<IHostingEnvironment>(_hostingEnvironment);
services.AddSingleton<Extensions.Hosting.IHostingEnvironment>(_hostingEnvironment);
Expand Down