Skip to content

Commit 1299d8e

Browse files
authored
Fix DistributedApplicationFactory.OnBuilderCreating example (#2702)
1 parent c1b427a commit 1299d8e

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

docs/testing/manage-app-host.md

+5-3
Original file line numberDiff line numberDiff line change
@@ -175,15 +175,17 @@ The constructor requires the type of the app host project reference as a paramet
175175

176176
The `DistributionApplicationFactory` class provides several lifecycle methods that can be overridden to provide custom behavior throughout the preparation and creation of the app host. The available methods are `OnBuilderCreating`, `OnBuilderCreated`, `OnBuilding`, and `OnBuilt`.
177177

178-
For example, we can use the `OnBuilderCreating` method to set environment variables, such as the subscription and resource group information for Azure, before the app host is created and any dependent Azure resources are provisioned, resulting in our tests using the correct Azure environment.
178+
For example, we can use the `OnBuilderCreating` method to set configuration, such as the subscription and resource group information for Azure, before the app host is created and any dependent Azure resources are provisioned, resulting in our tests using the correct Azure environment.
179179

180180
```csharp
181181
public class TestingAspireAppHost : DistributedApplicationFactory(typeof(Projects.AspireApp_AppHost))
182182
{
183183
protected override void OnBuilderCreating(DistributedApplicationOptions applicationOptions, HostApplicationBuilderSettings hostOptions)
184184
{
185-
builder.EnvironmentVariables["AZURE_SUBSCRIPTION_ID"] = "00000000-0000-0000-0000-000000000000";
186-
builder.EnvironmentVariables["AZURE_RESOURCE_GROUP"] = "my-resource-group";
185+
hostOptions.Configuration ??= new();
186+
hostOptions.Configuration["environment"] = "Development";
187+
hostOptions.Configuration["AZURE_SUBSCRIPTION_ID"] = "00000000-0000-0000-0000-000000000000";
188+
hostOptions.Configuration["AZURE_RESOURCE_GROUP"] = "my-resource-group";
187189
}
188190
}
189191
```

0 commit comments

Comments
 (0)