Skip to content

Commit

Permalink
Expose the IWebHostBuilder itself for additional flexibility
Browse files Browse the repository at this point in the history
  • Loading branch information
shaynevanasperen committed Nov 8, 2020
1 parent 3928a48 commit a6118b1
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions Fun.AspNetCore.Mvc.Testing/ExtensibleWebApplicationFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public sealed class ExtensibleWebApplicationFactory<TEntryPoint> : WebApplicatio
{
Action<WebHostBuilderContext, IConfigurationBuilder>? _afterConfigureAppConfiguration;
Action<IServiceCollection>? _afterConfigureServices;
Action<IWebHostBuilder>? _afterConfigureWebHost;

/// <summary>
/// Configures an additional action to be performed after the application configuration has been configured.
Expand All @@ -32,6 +33,12 @@ public void AfterConfigureAppConfiguration(Action<WebHostBuilderContext, IConfig
/// <param name="configure">The action to perform.</param>
public void AfterConfigureServices(Action<IServiceCollection> configure) => _afterConfigureServices += configure;

/// <summary>
/// Configures an additional action to be performed after the web host has been configured.
/// </summary>
/// <param name="configure">The action to perform.</param>
public void AfterConfigureWebHost(Action<IWebHostBuilder> configure) => _afterConfigureWebHost += configure;

/// <summary>
/// Creates a new instance of <see cref="WebApplication"/> representing the running web application.
/// </summary>
Expand All @@ -52,6 +59,8 @@ protected override void ConfigureWebHost(IWebHostBuilder builder)

builder.ConfigureAppConfiguration((context, config) => _afterConfigureAppConfiguration?.Invoke(context, config));
builder.ConfigureTestServices(services => _afterConfigureServices?.Invoke(services));

_afterConfigureWebHost?.Invoke(builder);
}
}
}

0 comments on commit a6118b1

Please sign in to comment.