Skip to content

Conversation

danegsta
Copy link
Member

@danegsta danegsta commented Sep 5, 2025

Description

Deprecates IDistributedApplicationLifecycleHook and the LifecycleHookServiceCollectionExtensions extension methods and adds a new IDistributedApplicationEventingSubscriber and EventingSubscriberServiceCollectionExtensions methods to allow services to use the equivalent IDistributedApplicationEventing events (including BeforeStartEvent).

This change is necessary to complete the removal of the old AfterEndpointsAllocated event and callback in a future release which will allow us to properly support new features that require asynchronous discovery of allocated endpoints (such as proxyless persistent containers with random port allocation). These obsolete types will be removed in a future release, but the replacement has been designed to be relatively painless.

Checklist

  • Is this feature complete?
    • Yes. Ready to ship.
    • No. Follow-up changes expected.
  • Are you including unit tests for the changes and scenario tests if relevant?
    • Yes
    • No
  • Did you add public API?
    • Yes
      • If yes, did you have an API Review for it?
        • Yes
        • No
      • Did you add <remarks /> and <code /> elements on your triple slash comments?
        • Yes
        • No
    • No
  • Does the change make any security assumptions or guarantees?
    • Yes
      • If yes, have you done a threat model and had a security review?
        • Yes
        • No
    • No
  • Does the change require an update in our Aspire docs?

Copy link
Contributor

github-actions bot commented Sep 5, 2025

🚀 Dogfood this PR with:

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

Or

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

@github-actions github-actions bot added the area-app-model Issues pertaining to the APIs in Aspire.Hosting, e.g. DistributedApplication label Sep 5, 2025
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR deprecates the IDistributedApplicationLifecycleHook interface and its extension methods, replacing them with a new event-driven approach using IDistributedApplicationEventingSubscriber. This change is necessary to properly support asynchronous endpoint discovery for new features like proxyless persistent containers with random port allocation.

  • Marks the existing lifecycle hook interface and extension methods as obsolete
  • Introduces new IDistributedApplicationEventingSubscriber interface and corresponding extension methods
  • Migrates all internal usage from lifecycle hooks to the new eventing system

Reviewed Changes

Copilot reviewed 34 out of 34 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/Aspire.Hosting/Lifecycle/IDistributedApplicationLifecycleHook.cs Marked interface as obsolete
src/Aspire.Hosting/Lifecycle/LifecycleHookServiceCollectionExtensions.cs Marked extension methods as obsolete
src/Aspire.Hosting/Lifecycle/IDistributedApplicationEventingSubscriber.cs New eventing subscriber interface
src/Aspire.Hosting/Lifecycle/EventingSubscriberServiceCollectionExtensions.cs New extension methods for eventing subscribers
src/Aspire.Hosting/Dashboard/DashboardEventHandlers.cs Migrated from lifecycle hook to eventing subscriber pattern
src/Aspire.Hosting/Devcontainers/DevcontainerPortForwardingLifecycleHook.cs Migrated to eventing subscriber while keeping class name
src/Aspire.Hosting/DistributedApplication.cs Updated to initialize eventing subscribers before publishing events
Multiple Azure infrastructure files Migrated Azure provisioning and infrastructure classes to use eventing
Multiple test files Added pragma warnings to suppress obsolete API usage in tests
Multiple playground files Updated example projects to use new eventing pattern

@davidfowl
Copy link
Member

I think we need to stage this. The eventing has a bunch of issues that prevent it from being a full replacement at the moment:

/// <param name="executionContext">The <see cref="DistributedApplicationExecutionContext"/> instance for the run.</param>
/// <param name="cancellationToken">Cancellation token from the service collection</param>
/// <returns>A task indicating event registration is complete</returns>
Task SubscribeAsync(IDistributedApplicationEventing eventing, DistributedApplicationExecutionContext executionContext, CancellationToken cancellationToken);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the expected pattern for conditional subscription to do the check within SubscribeAsync? I assume so, but this will be a bit different from how we currently do conditional subscription. Maybe we can add a test to validate/document this?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That was the pattern that seemed to make the most sense. With the callback based model there wasn't a way to selectively subscribe to a given hook so we did the checks in the actual callback, but with events it seemed better to only subscribe to the event if we actually wanted to receive it.

@danegsta
Copy link
Member Author

danegsta commented Sep 8, 2025

I think we need to stage this. The eventing has a bunch of issues that prevent it from being a full replacement at the moment:

Ah, I hadn't seen those issues, but ended up adding a new IDistributedApplicationEventingSubscriber interface to work around the same issues that were described in them (ensuring we can subscribe to events such as BeforeStartEvent early enough and ensuring we only subscribe once).

@danegsta danegsta requested a review from radical as a code owner September 8, 2025 18:27
@sebastienros sebastienros changed the title Obsolete the IDistirbutedApplicationLifecycleHook interface and extension methods and add a new eventing based replacement Obsolete the IDistributedApplicationLifecycleHook interface and extension methods and add a new eventing based replacement Sep 15, 2025
@davidfowl davidfowl added the breaking-change Issue or PR that represents a breaking API or functional change over a prerelease. label Sep 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-app-model Issues pertaining to the APIs in Aspire.Hosting, e.g. DistributedApplication breaking-change Issue or PR that represents a breaking API or functional change over a prerelease.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants