-
Notifications
You must be signed in to change notification settings - Fork 659
Open
Open
Copy link
Labels
area-app-modelIssues pertaining to the APIs in Aspire.Hosting, e.g. DistributedApplicationIssues pertaining to the APIs in Aspire.Hosting, e.g. DistributedApplication
Description
Currently, Aspire supports events for resource initialization, start, readiness, connection string availability, and endpoint allocation. However, there is no event that is triggered when a specific resource stops.
Adding an event that fires when a resource stops would enable users to build integrations that can register and unregister resources appropriately as they start, stop, or restart. This would improve lifecycle management and allow for more robust cleanup and teardown operations for resources.
Proposal:
- Add a new event (e.g.,
ResourceStoppedEvent
) to the set of available events inEventingExtensions.cs
. - Provide an extension method (e.g.,
OnResourceStopped
) similar to the existing ones for subscribing to this new event. - Ensure that this event is fired when a resource stops, and that appropriate data is provided to the event handler.
- Model the new event on the existing
BeforeResourceStartedEvent
class, following its structure and conventions.
Example implementation:
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using Aspire.Hosting.Eventing;
namespace Aspire.Hosting.ApplicationModel;
/// <summary>
/// This event is raised by orchestrators after a resource has stopped.
/// </summary>
/// <param name="resource">The resource that has stopped.</param>
/// <param name="services">The <see cref="IServiceProvider"/> for the app host.</param>
/// <remarks>
/// This event allows for cleanup or unregistration logic when a resource is stopped by an orchestrator.
/// </remarks>
public class ResourceStoppedEvent(IResource resource, IServiceProvider services) : IDistributedApplicationResourceEvent
{
/// <inheritdoc />
public IResource Resource { get; } = resource;
/// <summary>
/// The <see cref="IServiceProvider"/> for the app host.
/// </summary>
public IServiceProvider Services { get; } = services;
}
Relevant file(s):
- src/Aspire.Hosting/EventingExtensions.cs
- src/Aspire.Hosting/ApplicationModel/BeforeResourceStartedEvent.cs
This enhancement would allow users to cleanly register and unregister integrations when resources start, stop, or restart, improving the developer experience and integration capabilities.
Metadata
Metadata
Assignees
Labels
area-app-modelIssues pertaining to the APIs in Aspire.Hosting, e.g. DistributedApplicationIssues pertaining to the APIs in Aspire.Hosting, e.g. DistributedApplication