Skip to content

Commit 85c8e11

Browse files
committed
feat: add ConfigureAppHost hook to AspireFixture
Add a protected virtual ConfigureAppHost method that allows users to configure DistributedApplicationOptions and HostApplicationBuilderSettings before the Aspire builder is created. Closes #5199
1 parent 7cfd395 commit 85c8e11

1 file changed

Lines changed: 12 additions & 1 deletion

File tree

TUnit.Aspire/AspireFixture.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using Aspire.Hosting.ApplicationModel;
66
using Aspire.Hosting.Testing;
77
using Microsoft.Extensions.DependencyInjection;
8+
using Microsoft.Extensions.Hosting;
89
using TUnit.Core;
910
using TUnit.Core.Interfaces;
1011

@@ -123,6 +124,16 @@ protected virtual void LogProgress(string message)
123124
/// </remarks>
124125
protected virtual string[] Args => [];
125126

127+
/// <summary>
128+
/// Override to configure the <see cref="DistributedApplicationOptions"/> and
129+
/// <see cref="Microsoft.Extensions.Hosting.HostApplicationBuilderSettings"/> passed to
130+
/// <see cref="DistributedApplicationTestingBuilder.CreateAsync{TEntryPoint}(string[], Action{DistributedApplicationOptions, Microsoft.Extensions.Hosting.HostApplicationBuilderSettings}, CancellationToken)"/>.
131+
/// This callback is invoked during builder creation, before <see cref="ConfigureBuilder"/>.
132+
/// </summary>
133+
/// <param name="options">The distributed application options.</param>
134+
/// <param name="settings">The host application builder settings.</param>
135+
protected virtual void ConfigureAppHost(DistributedApplicationOptions options, HostApplicationBuilderSettings settings) { }
136+
126137
/// <summary>
127138
/// Override to customize the builder before building the application.
128139
/// </summary>
@@ -201,7 +212,7 @@ public virtual async Task InitializeAsync()
201212
var sw = Stopwatch.StartNew();
202213

203214
LogProgress($"Creating distributed application builder for {typeof(TAppHost).Name}...");
204-
var builder = await DistributedApplicationTestingBuilder.CreateAsync<TAppHost>(Args);
215+
var builder = await DistributedApplicationTestingBuilder.CreateAsync<TAppHost>(Args, ConfigureAppHost);
205216
ConfigureBuilder(builder);
206217
LogProgress($"Builder created in {sw.Elapsed.TotalSeconds:0.0}s");
207218

0 commit comments

Comments
 (0)