From c9a4ee8b719ffb01eb44705d68efd158eb80c221 Mon Sep 17 00:00:00 2001 From: Alfred Myers Date: Mon, 27 Aug 2018 14:33:05 -0300 Subject: [PATCH] Change List to Action (#1480) --- .../WebHostBuilder.cs | 30 ++++--------------- 1 file changed, 6 insertions(+), 24 deletions(-) diff --git a/src/Microsoft.AspNetCore.Hosting/WebHostBuilder.cs b/src/Microsoft.AspNetCore.Hosting/WebHostBuilder.cs index 423b898cec..9ebc1e5a8b 100644 --- a/src/Microsoft.AspNetCore.Hosting/WebHostBuilder.cs +++ b/src/Microsoft.AspNetCore.Hosting/WebHostBuilder.cs @@ -25,13 +25,13 @@ namespace Microsoft.AspNetCore.Hosting public class WebHostBuilder : IWebHostBuilder { private readonly HostingEnvironment _hostingEnvironment; - private readonly List> _configureServicesDelegates; + private Action _configureServices; private IConfiguration _config; private WebHostOptions _options; private WebHostBuilderContext _context; private bool _webHostBuilt; - private List> _configureAppConfigurationBuilderDelegates; + private Action _configureAppConfigurationBuilder; /// /// Initializes a new instance of the class. @@ -39,8 +39,6 @@ namespace Microsoft.AspNetCore.Hosting public WebHostBuilder() { _hostingEnvironment = new HostingEnvironment(); - _configureServicesDelegates = new List>(); - _configureAppConfigurationBuilderDelegates = new List>(); _config = new ConfigurationBuilder() .AddEnvironmentVariables(prefix: "ASPNETCORE_") @@ -111,12 +109,7 @@ namespace Microsoft.AspNetCore.Hosting /// The . public IWebHostBuilder ConfigureServices(Action configureServices) { - if (configureServices == null) - { - throw new ArgumentNullException(nameof(configureServices)); - } - - _configureServicesDelegates.Add(configureServices); + _configureServices += configureServices; return this; } @@ -131,12 +124,7 @@ namespace Microsoft.AspNetCore.Hosting /// public IWebHostBuilder ConfigureAppConfiguration(Action configureDelegate) { - if (configureDelegate == null) - { - throw new ArgumentNullException(nameof(configureDelegate)); - } - - _configureAppConfigurationBuilderDelegates.Add(configureDelegate); + _configureAppConfigurationBuilder += configureDelegate; return this; } @@ -272,10 +260,7 @@ namespace Microsoft.AspNetCore.Hosting .SetBasePath(_hostingEnvironment.ContentRootPath) .AddConfiguration(_config); - foreach (var configureAppConfiguration in _configureAppConfigurationBuilderDelegates) - { - configureAppConfiguration(_context, builder); - } + _configureAppConfigurationBuilder?.Invoke(_context, builder); var configuration = builder.Build(); services.AddSingleton(configuration); @@ -329,10 +314,7 @@ namespace Microsoft.AspNetCore.Hosting } } - foreach (var configureServices in _configureServicesDelegates) - { - configureServices(_context, services); - } + _configureServices?.Invoke(_context, services); return services; }