Skip to content

Commit c9a4ee8

Browse files
alfredmyersTratcher
authored andcommitted
Change List<Action> to Action (#1480)
1 parent 637dea8 commit c9a4ee8

File tree

1 file changed

+6
-24
lines changed

1 file changed

+6
-24
lines changed

src/Microsoft.AspNetCore.Hosting/WebHostBuilder.cs

Lines changed: 6 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -25,22 +25,20 @@ namespace Microsoft.AspNetCore.Hosting
2525
public class WebHostBuilder : IWebHostBuilder
2626
{
2727
private readonly HostingEnvironment _hostingEnvironment;
28-
private readonly List<Action<WebHostBuilderContext, IServiceCollection>> _configureServicesDelegates;
28+
private Action<WebHostBuilderContext, IServiceCollection> _configureServices;
2929

3030
private IConfiguration _config;
3131
private WebHostOptions _options;
3232
private WebHostBuilderContext _context;
3333
private bool _webHostBuilt;
34-
private List<Action<WebHostBuilderContext, IConfigurationBuilder>> _configureAppConfigurationBuilderDelegates;
34+
private Action<WebHostBuilderContext, IConfigurationBuilder> _configureAppConfigurationBuilder;
3535

3636
/// <summary>
3737
/// Initializes a new instance of the <see cref="WebHostBuilder"/> class.
3838
/// </summary>
3939
public WebHostBuilder()
4040
{
4141
_hostingEnvironment = new HostingEnvironment();
42-
_configureServicesDelegates = new List<Action<WebHostBuilderContext, IServiceCollection>>();
43-
_configureAppConfigurationBuilderDelegates = new List<Action<WebHostBuilderContext, IConfigurationBuilder>>();
4442

4543
_config = new ConfigurationBuilder()
4644
.AddEnvironmentVariables(prefix: "ASPNETCORE_")
@@ -111,12 +109,7 @@ public IWebHostBuilder ConfigureServices(Action<IServiceCollection> configureSer
111109
/// <returns>The <see cref="IWebHostBuilder"/>.</returns>
112110
public IWebHostBuilder ConfigureServices(Action<WebHostBuilderContext, IServiceCollection> configureServices)
113111
{
114-
if (configureServices == null)
115-
{
116-
throw new ArgumentNullException(nameof(configureServices));
117-
}
118-
119-
_configureServicesDelegates.Add(configureServices);
112+
_configureServices += configureServices;
120113
return this;
121114
}
122115

@@ -131,12 +124,7 @@ public IWebHostBuilder ConfigureServices(Action<WebHostBuilderContext, IServiceC
131124
/// </remarks>
132125
public IWebHostBuilder ConfigureAppConfiguration(Action<WebHostBuilderContext, IConfigurationBuilder> configureDelegate)
133126
{
134-
if (configureDelegate == null)
135-
{
136-
throw new ArgumentNullException(nameof(configureDelegate));
137-
}
138-
139-
_configureAppConfigurationBuilderDelegates.Add(configureDelegate);
127+
_configureAppConfigurationBuilder += configureDelegate;
140128
return this;
141129
}
142130

@@ -272,10 +260,7 @@ private IServiceCollection BuildCommonServices(out AggregateException hostingSta
272260
.SetBasePath(_hostingEnvironment.ContentRootPath)
273261
.AddConfiguration(_config);
274262

275-
foreach (var configureAppConfiguration in _configureAppConfigurationBuilderDelegates)
276-
{
277-
configureAppConfiguration(_context, builder);
278-
}
263+
_configureAppConfigurationBuilder?.Invoke(_context, builder);
279264

280265
var configuration = builder.Build();
281266
services.AddSingleton<IConfiguration>(configuration);
@@ -329,10 +314,7 @@ private IServiceCollection BuildCommonServices(out AggregateException hostingSta
329314
}
330315
}
331316

332-
foreach (var configureServices in _configureServicesDelegates)
333-
{
334-
configureServices(_context, services);
335-
}
317+
_configureServices?.Invoke(_context, services);
336318

337319
return services;
338320
}

0 commit comments

Comments
 (0)