Allow filtering endpoints from the default reference set#15558
Allow filtering endpoints from the default reference set#15558danegsta wants to merge 2 commits intomicrosoft:mainfrom
Conversation
|
🚀 Dogfood this PR with:
curl -fsSL https://raw.githubusercontent.com/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.sh | bash -s -- 15558Or
iex "& { $(irm https://raw.githubusercontent.com/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.ps1) } 15558" |
There was a problem hiding this comment.
Pull request overview
This PR updates Aspire.Hosting’s default WithReference(resource) behavior to allow endpoint authors to exclude specific endpoints (e.g., management/health) from the default reference set, while still permitting explicit references to those endpoints when needed.
Changes:
- Adds
EndpointAnnotation.IsDefaultReferenceEndpoint(defaulttrue) and plumbs it intoWithReferenceenvironment-variable injection logic. - Exposes
EndpointReference.IsDefaultReferenceEndpointto reflect the underlying annotation setting. - Excludes selected management/health endpoints (Keycloak management, Azure emulator health endpoints) from default references and adds unit tests covering the new behavior.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| tests/Aspire.Hosting.Tests/WithReferenceTests.cs | Adds coverage for default-vs-explicit endpoint reference behavior and default property value. |
| src/Aspire.Hosting/ResourceBuilderExtensions.cs | Updates endpoint injection filtering and documents the new default reference semantics. |
| src/Aspire.Hosting/ApplicationModel/EndpointReference.cs | Adds IsDefaultReferenceEndpoint to reflect endpoint default-reference inclusion. |
| src/Aspire.Hosting/ApplicationModel/EndpointAnnotation.cs | Introduces IsDefaultReferenceEndpoint (default true) with XML documentation. |
| src/Aspire.Hosting.Keycloak/KeycloakResourceBuilderExtensions.cs | Marks Keycloak management endpoint as non-default for WithReference(resource). |
| src/Aspire.Hosting.Azure.ServiceBus/AzureServiceBusExtensions.cs | Marks ServiceBus emulator health endpoint as non-default for WithReference(resource). |
| src/Aspire.Hosting.Azure.EventHubs/AzureEventHubsExtensions.cs | Marks EventHubs emulator health endpoint as non-default for WithReference(resource). |
| src/Aspire.Hosting.Azure.CosmosDB/AzureCosmosDBExtensions.cs | Marks CosmosDB emulator health endpoint as non-default for WithReference(resource). |
|
What is the breaking change? |
|
IsDefaultReferenceEndpoint = ExcludeReferenceEndpoint? @eerhardt ? We can punt this to API review.
Old code could be using that env variable (directly or indirectly). |
+1. Default value to false is more idomatic in .NET land. |
|
Thanks for very quickly addressing the issue. |
Description
We were including additional endpoints (such as the Keycloak management dashboard endpoint) as part of the service discovery endpoints for a resource when referenced via
WithReference(resource). This is problematic because the management endpoint is not intended to be referenced by a Keycloak client, it's dashboard for users to access.This PR adds an additional property that can be set on an EndpointAnnotation to exclude it from the set of endpoints covered by a default EndpointReferenceAnnotation. These non-default endpoints can still be referenced via an explicit
WithReference(resource.GetEndpoint("name"))call.Endpoints will be included in the default set unless explicitly opted out.
To exclude an endpoint from the default set:
The following resource endpoints are now excluded from the default set:
Fixes #15547
Checklist
<remarks />and<code />elements on your triple slash comments?aspire.devissue: