Make it easier to use the Dashboard with `DistributedApplicationTestingBuilder`
- Dominant language
- C#
- Stars
- 6.3k
- Forks
- 991
- Avg merge
- 2d 15h
- Merged PRs (30d)
- 196
Description
### Is there an existing issue for this?
- [x] I have searched the existing issues
### Is your feature request related to a problem? Please describe the problem.
To make it easier to debug tests locally, it can often be useful to enable the dashboard on test runs. Whilst this is possible it is a bit of a pain - the dashboard's use & configuration are evaluated during the constructor of `DistributedApplicationBuilder`, and cannot be modified after the builder, so you have to make your decision up front, and fudge any configuration you need into arguments
```cs
string[] args = [
#if DEBUG
"--ASPNETCORE_URLS=https://localhost:17036",
"--ASPIRE_ALLOW_UNSECURED_TRANSPORT=true",
"--ASPIRE_DASHBOARD_OTLP_ENDPOINT_URL=http://localhost:21259",
#endif
];
var appHost = await DistributedApplicationTestingBuilder.CreateAsync(args, (options, _) =>
{
#if DEBUG
options.DisableDashboard = false;
#endif
}, cts.Token);
```
### Describe the solution you'd like
It would be nice if enabling the dashboard was as simple as calling `testingBuilder.WithDashboard()` - something along the lines of the following)
```cs
// And/Or accept a Uri rather than just a port
public static T WithDashboard(this T builder, int port)
where T : IDistributedApplicationTestingBuilder
{
builder.Services.Configure(x =>
{
x.DisableDashboard = false;
});
builder.Configuration["ASPNETCORE_URLS"] = $"https://localhost:{port}";
//TODO: try and set a dynbamic port for OTLP endpoint, rather than forcing one to be set:
//builder.Configuration["ASPIRE_DASHBOARD_OTLP_ENDPOINT_URL"] = "https://localhost:0";
return builder;
}
```
This would require some refactoring of `DistributedApplicationBuilder.ctor(DistributedApplicationOptions options)` to delay uses of `DistributedApplicationOptions` until `.Build()`. Or at least delaying use of `DisableDashboard`.
### Additional context
_No response_
Contributor guide
Assessment
This issue has not been assessed yet.