Skip to content

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Oct 16, 2025

Summary

Adds a new Inspect operation mode to the Aspire AppHost that enables introspection of the application model without activating DCP (Distributed Control Plane) or Publishers. This mode is useful for scenarios where you need to analyze the application structure, dependencies, and configuration without the overhead and side effects of actually running or publishing the application.

Usage

The Inspect mode can be activated via command-line argument:

dotnet run --operation inspect

Or programmatically:

var builder = DistributedApplication.CreateBuilder(["--operation", "inspect"]);
// Add resources...
var app = builder.Build();

// The execution context exposes the mode
if (app.Services.GetRequiredService<DistributedApplicationExecutionContext>().IsInspectMode)
{
    // Introspect application model, resources, configuration, etc.
}

await app.StartAsync();
// No DCP, Publishers, Dashboard, or Health Checks are activated
await app.StopAsync();

Behavior

What Inspect Mode Does:

  • ✅ Builds the application model (resources, dependencies, configuration)
  • ✅ Initializes the service container (DI resolution works)
  • ✅ Supports the eventing system (targeted event subscriptions work)

What Inspect Mode Does NOT Do:

  • ❌ Does NOT start DCP (Distributed Control Plane)
  • ❌ Does NOT start orchestration services
  • ❌ Does NOT activate publishers
  • ❌ Does NOT run health checks
  • ❌ Does NOT start the dashboard
  • ❌ Does NOT execute lifecycle hooks

Changes

  1. DistributedApplicationOperation enum: Added Inspect value
  2. DistributedApplicationExecutionContext: Added IsInspectMode property for convenient mode checking
  3. DistributedApplicationBuilder: Updated to parse "inspect" from --operation argument and disable health checks in Inspect mode
  4. OrchestratorHostService: Fixed IsSupported check to use IsRunMode instead of !IsPublishMode to ensure DCP doesn't run in Inspect mode
  5. Test coverage: Added 4 comprehensive tests validating parsing, service registration, and behavior

Comparison with Other Modes

Feature Run Publish Inspect
Application Model
Service Container
Eventing
DCP/Orchestrator
Publishers
Dashboard
Health Checks
Lifecycle Hooks

Design Notes

The implementation leverages existing conditional logic patterns where most services were already conditionally registered based on IsRunMode. The only service that needed a fix was OrchestratorHostService, which was using !IsPublishMode and would have incorrectly activated DCP in Inspect mode. The code in DistributedApplication.cs already had comments anticipating this mode, showing it was part of the original design intent.

This is a minimal, backward-compatible change with no breaking changes to existing APIs. All code compiles successfully and follows the repository's established patterns and style guidelines.

Original prompt

Add a new operation mode called Inspect (inert mode) to Aspire apphost alongside existing Publish and Run modes.

Requirements:

  • Update the DistributedApplicationOperation enum to include Inspect.
  • Update DistributedApplicationExecutionContext and DistributedApplicationExecutionContextOptions to support and expose Inspect.
  • Update mode parsing in DistributedApplicationBuilder to recognize and allow "inspect" as a valid mode.
  • Ensure that in Inspect mode, DCP and Publishers are NOT activated or registered. This includes all code paths where DCP containers, hosts, or publisher registration/activation is performed (e.g., in DistributedApplicationBuilder and any event subscriptions or hosted services related to DCP/Publishers).
  • Update or add tests verifying Inspect mode:
    • It is parsed and set correctly from arguments/configuration.
    • No DCP or Publisher activity occurs in Inspect mode.

This mode should be discoverable via command-line args (e.g., --operation inspect).

This pull request was created as a result of the following prompt from Copilot chat.

Add a new operation mode called Inspect (inert mode) to Aspire apphost alongside existing Publish and Run modes.

Requirements:

  • Update the DistributedApplicationOperation enum to include Inspect.
  • Update DistributedApplicationExecutionContext and DistributedApplicationExecutionContextOptions to support and expose Inspect.
  • Update mode parsing in DistributedApplicationBuilder to recognize and allow "inspect" as a valid mode.
  • Ensure that in Inspect mode, DCP and Publishers are NOT activated or registered. This includes all code paths where DCP containers, hosts, or publisher registration/activation is performed (e.g., in DistributedApplicationBuilder and any event subscriptions or hosted services related to DCP/Publishers).
  • Update or add tests verifying Inspect mode:
    • It is parsed and set correctly from arguments/configuration.
    • No DCP or Publisher activity occurs in Inspect mode.

This mode should be discoverable via command-line args (e.g., --operation inspect).


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

@davidfowl
Copy link
Member

If we add a new mode, then we need deploymode.

Copy link
Contributor

github-actions bot commented Oct 16, 2025

🚀 Dogfood this PR with:

⚠️ WARNING: Do not do this without first carefully reviewing the code of this PR to satisfy yourself it is safe.

curl -fsSL https://raw.githubusercontent.com/dotnet/aspire/main/eng/scripts/get-aspire-cli-pr.sh | bash -s -- 12072

Or

  • Run remotely in PowerShell:
iex "& { $(irm https://raw.githubusercontent.com/dotnet/aspire/main/eng/scripts/get-aspire-cli-pr.ps1) } 12072"

@Copilot Copilot AI changed the title [WIP] Add Inspect operation mode to Aspire apphost Add Inspect operation mode for introspection without activating DCP or Publishers Oct 16, 2025
@Copilot Copilot AI requested a review from mitchdenny October 16, 2025 01:17
Copilot finished work on behalf of mitchdenny October 16, 2025 01:17
@mitchdenny
Copy link
Member

@davidfowl I was mostly just demonstrating agent tasks to someone. But I do think we will need something like this if we want to fully support aspire update for single-file app hosts.

With a single file app host you can't currently reference a C# project using something like #:project, so we need to use path based references. The problem with that is that we need to be able to figure out which project resources actually end up in the application model so that we can get aspire update to go and search for those projects and update their references.

I'm sure we'll find other users for this inert mode as well. TBH I think in the future all modes will start of in an inert state and it'll be an API call that triggers an event that causes a cascade of activity.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants