Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Oct 22, 2025

Overview

This PR removes all usages of the deprecated IDistributedApplicationLifecycleHook interface and replaces them with modern event-based patterns, as required by dotnet/aspire#11266.

Changes

Deno & Bun: Installer Resource Pattern

Previously, Deno and Bun used lifecycle hooks to install packages before application startup. This PR migrates them to use the installer resource pattern (consistent with NodeJS npm/yarn/pnpm):

Before:

resource.ApplicationBuilder.Services.TryAddLifecycleHook<DenoPackageInstallerLifecycleHook>();

After:

var installer = new DenoInstallerResource(installerName, workingDirectory);
var installerBuilder = builder.AddResource(installer)
    .WithArgs("install")
    .WithParentRelationship(resource.Resource)
    .ExcludeFromManifest();
resource.WaitForCompletion(installerBuilder);

Files Changed:

  • Added: DenoInstallerResource.cs, BunInstallerResource.cs
  • Removed: DenoPackageInstallerLifecycleHook.cs, DenoPackageInstaller.cs, BunPackageInstallerLifecycleHook.cs
  • Updated: DenoAppHostingExtensions.cs, BunAppExtensions.cs

Dapr: IDistributedApplicationEventingSubscriber Pattern

Dapr's lifecycle hook has been converted to use the IDistributedApplicationEventingSubscriber pattern for idempotent registration:

Before:

builder.Services.TryAddLifecycleHook<DaprDistributedApplicationLifecycleHook>();

After:

builder.Services.TryAddEventingSubscriber<DaprDistributedApplicationLifecycleHook>();

// In the subscriber class:
public Task SubscribeAsync(IDistributedApplicationEventing eventing, DistributedApplicationExecutionContext executionContext, CancellationToken cancellationToken)
{
    eventing.Subscribe<BeforeStartEvent>(OnBeforeStartAsync);
    return Task.CompletedTask;
}

Files Changed:

  • Updated: IDistributedApplicationBuilderExtensions.cs, DaprDistributedApplicationLifecycleHook.cs

Pattern Benefits:

  • Idempotent registration via TryAddEventingSubscriber (similar to old TryAddLifecycleHook)
  • Cleaner separation of concerns with subscriber pattern
  • Consistent with other Aspire infrastructure components (e.g., Azure AppService)

Tests

Updated tests to use standard public APIs instead of internal lifecycle hook methods:

  • Replaced ExecuteBeforeStartHooksAsync() with app.StartAsync()
  • Added tests to verify installer resources are created correctly
  • Removed UnsafeAccessor reflection code

Benefits

  1. No deprecated APIs - Eliminates all usages of IDistributedApplicationLifecycleHook
  2. Consistency - Deno and Bun now follow the same pattern as NodeJS integrations
  3. Better visibility - Package installers now appear as resources in the Aspire dashboard
  4. Improved testability - Tests use standard public APIs
  5. Idempotent registration - Dapr uses IDistributedApplicationEventingSubscriber for proper lifecycle management
  6. Future-proof - Aligned with current .NET Aspire architecture

Migration Notes

No breaking changes for users:

  • WithDenoPackageInstallation() and WithBunPackageInstallation() work exactly as before
  • AddDapr() continues to work with the same API
  • The only visible change is that installer resources now appear in the Aspire dashboard

Fixes #890

Original prompt

This section details on the original issue you should resolve

<issue_title>Ensure life cycle hooks interface isn't used anymore</issue_title>
<issue_description>See dotnet/aspire#11266 - IDistributedApplicationLifecycleHook has been deprecated, so we need to ensure it's no longer used.</issue_description>

<agent_instructions>Compiling the solution will show the errors around the obsolete type and gives an indication on what to fix.</agent_instructions>

Comments on the Issue (you are @copilot in this section)

Fixes #890


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI self-assigned this Oct 22, 2025
Copilot AI changed the title [WIP] Remove deprecated IDistributedApplicationLifecycleHook usage Remove deprecated IDistributedApplicationLifecycleHook interface Oct 22, 2025
Copilot AI requested a review from aaronpowell October 22, 2025 05:20
Copilot finished work on behalf of aaronpowell October 22, 2025 05:20
@davidfowl
Copy link
Contributor

You want to replace these with IDistributedApplicationEventingSubscriber is there a branch for 13? Is it main?

@aaronpowell
Copy link
Member

You want to replace these with IDistributedApplicationEventingSubscriber is there a branch for 13? Is it main?

don't we want to replace them with the On<Event> methods?

@davidfowl
Copy link
Contributor

davidfowl commented Oct 22, 2025

IDistributedApplicationEventingSubscriber is a way to get both idempotency during registration (TryAddLifecycleHook) and it relies on subscribing to events via the On<X> methods.

Copy link
Contributor Author

Copilot AI commented Oct 23, 2025

@copilot according to @davidfowl we should be using IDistributedApplicationEventingSubscriber instead. Here is the type definition: https://github.com/dotnet/aspire/blob/05ef4762f6748e9a8ff3d30857ab...

Updated Dapr to use IDistributedApplicationEventingSubscriber following the pattern from the Azure AppService example. The subscriber is now registered with TryAddEventingSubscriber for idempotency, and the SubscribeAsync method subscribes to BeforeStartEvent.

Commit: 69ebc86

Copilot finished work on behalf of aaronpowell October 23, 2025 00:34
@aaronpowell
Copy link
Member

@davidfowl how's that looking?

@aaronpowell aaronpowell marked this pull request as ready for review October 23, 2025 02:44
@aaronpowell aaronpowell requested a review from martinjt as a code owner October 23, 2025 03:26
// Only install packages during development, not in publish mode
if (!resource.ApplicationBuilder.ExecutionContext.IsPublishMode)
{
var installerName = $"{resource.Resource.Name}-bun-install";
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

But this is moving away from the event model for doing this to the same model used for npm/pnpm/etc. installing.

if (!resource.ApplicationBuilder.ExecutionContext.IsPublishMode)
{
var installerName = $"{resource.Resource.Name}-deno-install";
var installer = new DenoInstallerResource(installerName, resource.Resource.WorkingDirectory);
Copy link
Contributor

Choose a reason for hiding this comment

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

Same comment as above.

@davidfowl
Copy link
Contributor

Yep!

@aaronpowell aaronpowell merged commit 06d5985 into aspire-13 Oct 24, 2025
103 of 104 checks passed
@aaronpowell aaronpowell deleted the copilot/remove-deprecated-lifecycle-hook branch October 24, 2025 00:53
aaronpowell added a commit that referenced this pull request Nov 6, 2025
* baseline branch for the next major release

* Updating nightly

* Remove deprecated IDistributedApplicationLifecycleHook interface (#915)

* Initial plan

* Replace IDistributedApplicationLifecycleHook with event-based patterns

Co-authored-by: aaronpowell <[email protected]>

* Add tests for installer resources and update Dapr tests

Co-authored-by: aaronpowell <[email protected]>

* Refactor Dapr to use IDistributedApplicationEventingSubscriber

Co-authored-by: aaronpowell <[email protected]>

* Fixing build issue

* Updating the endpoint port

* Disabling some tests so we can move forward in other parts of the Aspire 13 update

---------

Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Co-authored-by: aaronpowell <[email protected]>
Co-authored-by: Aaron Powell <[email protected]>

* Adjusting the version of keycloak

* Updating aspire nightly

* New nightly

* Remove npm functionality moved to Aspire 13 (#928)

* Initial plan

* Remove AddViteApp and npm-specific functionality (moved to Aspire 13)

Co-authored-by: aaronpowell <[email protected]>

* Update comments and tests to reflect npm removal

Co-authored-by: aaronpowell <[email protected]>

* Update MONOREPO.md to remove npm references

Co-authored-by: aaronpowell <[email protected]>

* Adding missing types

* Bad copilot code

* Fixing missing namespace

* Handling port forwarding

* removing more stuff that has been migrated to aspire core

* Reworking how package installing is handled

* daily update

* Adding back the annotation that is no longer moving to core

* Forgot to install packages

* adding a bunch more annotations to provide enough metadata

* Removing old demo apps

* Disabling python tests

* Removing a testing change

* Updating to the latest nightly and dealing with type name changes

* Removing type that was can repurpose from aspire core

* breaking the tests down so they are easier to read

* Removing legacy docs

* Fixing failing tests

---------

Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Co-authored-by: aaronpowell <[email protected]>
Co-authored-by: Aaron Powell <[email protected]>

* Fixing failing test

* Remove deprecated EventStore integrations (#946)

* Initial plan

* Remove EventStore integrations and all associated files

Co-authored-by: aaronpowell <[email protected]>

* Remove EventStore project references from solution file

Co-authored-by: aaronpowell <[email protected]>

---------

Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Co-authored-by: aaronpowell <[email protected]>
Co-authored-by: Aaron Powell <[email protected]>
Co-authored-by: Fredi Machado <[email protected]>

* Creating a new agent for generating hosting integrations

* Creating a new agent for generating client integrations

* Expanded the hosting agent a bit

* Removing the legacy approach to checking resource health and updated the last usages of it

* Bumping go and removing pnpm setup

* maybe we need an explicit health check

* Using the new JavaScriptAppResource so we can leverage the new methods on inspector

Getting rid of some custom code but making it so we run from local by default

* Disabling tests on Windows due to modelcontextprotocol/inspector#893

---------

Co-authored-by: Copilot <[email protected]>
Co-authored-by: aaronpowell <[email protected]>
Co-authored-by: Fredi Machado <[email protected]>
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