Skip to content

Commit

Permalink
Only add dashboard services if the dashboard is enabled (#3489)
Browse files Browse the repository at this point in the history
* Only add dashboard services if the dashboard is enabled
  • Loading branch information
ReubenBond authored Apr 8, 2024
1 parent 3d82b0f commit a6f7540
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Aspire.Hosting/DistributedApplicationBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -140,14 +140,14 @@ public DistributedApplicationBuilder(DistributedApplicationOptions options)
_innerBuilder.Services.TryAddEnumerable(ServiceDescriptor.Singleton<IValidateOptions<TransportOptions>, TransportOptionsValidator>());
_innerBuilder.Services.AddSingleton<DashboardServiceHost>();
_innerBuilder.Services.AddHostedService(sp => sp.GetRequiredService<DashboardServiceHost>());
_innerBuilder.Services.AddSingleton<IDashboardEndpointProvider, HostDashboardEndpointProvider>();
_innerBuilder.Services.AddLifecycleHook<DashboardLifecycleHook>();
_innerBuilder.Services.TryAddEnumerable(ServiceDescriptor.Singleton<IConfigureOptions<DashboardOptions>, ConfigureDefaultDashboardOptions>());
_innerBuilder.Services.TryAddEnumerable(ServiceDescriptor.Singleton<IValidateOptions<DashboardOptions>, ValidateDashboardOptions>());
}

// DCP stuff
_innerBuilder.Services.AddSingleton<ApplicationExecutor>();
_innerBuilder.Services.AddSingleton<IDashboardEndpointProvider, HostDashboardEndpointProvider>();
_innerBuilder.Services.AddSingleton<IDcpDependencyCheckService, DcpDependencyCheck>();
_innerBuilder.Services.AddHostedService<DcpHostService>();
_innerBuilder.Services.TryAddEnumerable(ServiceDescriptor.Singleton<IConfigureOptions<DcpOptions>, ConfigureDefaultDcpOptions>());
Expand Down
14 changes: 14 additions & 0 deletions tests/Aspire.Hosting.Tests/Dashboard/DashboardResourceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,20 @@ public async Task DashboardIsNotAddedIfDisabled()
Assert.Empty(model.Resources);
}

[Fact]
public void ContainerIsValidWithDashboardIsDisabled()
{
// Set the host environment to "Development" so that the container validates services.
using var builder = TestDistributedApplicationBuilder.Create(new DistributedApplicationOptions
{
DisableDashboard = true,
Args = ["--environment", "Development"] }
);

// Container validation logic runs when the service provider is built.
using var app = builder.Build();
}

private sealed class MockDashboardEndpointProvider : IDashboardEndpointProvider
{
public Task<string> GetResourceServiceUriAsync(CancellationToken cancellationToken = default)
Expand Down

0 comments on commit a6f7540

Please sign in to comment.