Skip to content

Conversation

@afscrome
Copy link
Contributor

@afscrome afscrome commented Jan 2, 2026

Description

  • Add IServiceProvider Services to IDistributedApplicationResourceEvent. All existing implementations already had this property, so it doesn't really change anything, but provided a default interface method to maintain backwards compatibility.
  • Add an ILogger property to IDistributedApplicationResourceEvent, with a default implementation using IDistributedApplicationEvent.Services to get the resource logger
  • Update xml docs of existing Service properties to inherit from the parent interface

Fixes #7531.

Checklist

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

Fixes dotnet#7531.

- Add `IServiceProvider Services` to `IDistributedApplicationResourceEvent`.  All existing implementations already had this property, so it doesn't really change anything, but provided a default interface method to maintain backwards compatibility.
- Add an ILogger property to `IDistributedApplicationResourceEvent`, with a default implementation using  `IDistributedApplicationEvent.Services` to get the resource logger
- Update xml docs of Service properties to inherit from the parent interface
Copilot AI review requested due to automatic review settings January 2, 2026 17:41
@github-actions
Copy link
Contributor

github-actions bot commented Jan 2, 2026

🚀 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 -- 13732

Or

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

@dotnet-policy-service dotnet-policy-service bot added the community-contribution Indicates that the PR has been added by a community member label Jan 2, 2026
/// <summary>
/// The <see cref="IServiceProvider"/> instance.
/// </summary>
IServiceProvider Services => throw new NotImplementedException();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the one part I'm a bit unsure about. It's really nice about how this lets Logger just light up.

But if you just go an implement the interface, the IDE won't add it automatically for you, and you could easily miss that you need to implement the Services property.

Copy link
Contributor

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 adds a convenient Logger property to IDistributedApplicationResourceEvent to simplify resource event logging. Previously, developers had to manually obtain the resource logger using evt.Services.GetRequiredService<ResourceLoggerService>().GetLogger(evt.Resource), which required knowledge of internal service APIs.

Key Changes:

  • Added Services property to the IDistributedApplicationResourceEvent interface with a default implementation that throws NotImplementedException (for backwards compatibility)
  • Added Logger property to the interface that uses the Services property to automatically resolve and return the resource-specific logger
  • Updated all concrete event class implementations to use <inheritdoc /> for their Services property documentation, inheriting from the parent interface

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/Aspire.Hosting/Eventing/IDistributedApplicationEvent.cs Adds Services and Logger properties to IDistributedApplicationResourceEvent interface with default implementations
src/Aspire.Hosting/ApplicationModel/ResourceStoppedEvent.cs Updates XML docs to use <inheritdoc /> for Services property
src/Aspire.Hosting/ApplicationModel/ResourceReadyEvent.cs Updates XML docs to use <inheritdoc /> for Services property
src/Aspire.Hosting/ApplicationModel/ResourceEndpointsAllocatedEvent.cs Updates XML docs to use <inheritdoc /> for Services property
src/Aspire.Hosting/ApplicationModel/ConnectionStringAvailableEvent.cs Updates XML docs to use <inheritdoc /> for Services property
src/Aspire.Hosting/ApplicationModel/BeforeResourceStartedEvent.cs Updates XML docs to use <inheritdoc /> for Services property
src/Aspire.Hosting.DevTunnels/DevTunnelResourceBuilderExtensions.cs Removes unused DevTunnelResourceStartedEvent private class that implemented the interface

Comment on lines +27 to +29
/// <summary>
/// The <see cref="IServiceProvider"/> instance.
/// </summary>
Copy link

Copilot AI Jan 2, 2026

Choose a reason for hiding this comment

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

The XML documentation for the Services property should provide more descriptive content beyond just the type. According to the Aspire documentation guidelines, properties should not simply restate the member name. Consider adding a description that explains its purpose, such as "Gets the service provider for the application host that can be used to resolve additional services."

Copilot generated this review using guidance from repository custom instructions.
Comment on lines +32 to +35
/// <summary>
/// An instance of <see cref="ILogger"/> that can be used to log messages for the resource.
/// </summary>
ILogger Logger => Services.GetRequiredService<ResourceLoggerService>().GetLogger(Resource);
Copy link

Copilot AI Jan 2, 2026

Choose a reason for hiding this comment

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

According to Aspire documentation guidelines, the Logger property should include a <remarks> section explaining when and how to use this property. Consider adding remarks to clarify that this logger is specifically scoped to the associated resource and will write to that resource's log stream, which is visible in the Aspire dashboard.

Copilot generated this review using guidance from repository custom instructions.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

community-contribution Indicates that the PR has been added by a community member

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Include ILogger on all IDistributedApplicationResourceEvent

1 participant