Skip to content

Refactor database explorer resource builders to not prefix their names the name of the first resource they are added to. #8237

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
May 13, 2025

Conversation

paulomorgado
Copy link
Contributor

Description

Refactor database explorer resource builders to not prefix their names the name of the first resource they are added to.

Kept the behavior where, when a containerName is passed, that's the one that is used.

Fixes #2060

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?

…s the name of the first resource they are added to.
@github-actions github-actions bot added the area-app-model Issues pertaining to the APIs in Aspire.Hosting, e.g. DistributedApplication label Mar 21, 2025
@dotnet-policy-service dotnet-policy-service bot added the community-contribution Indicates that the PR has been added by a community member label Mar 21, 2025
@davidfowl davidfowl requested review from eerhardt and mitchdenny and removed request for eerhardt March 31, 2025 09:00
@davidfowl
Copy link
Member

@paulomorgado You might need to follow the pattern here

private static string CreateDefaultStorageName(this IDistributedApplicationBuilder builder)
{
var applicationHash = builder.Configuration["AppHost:Sha256"]![..5].ToLowerInvariant();
return $"{DefaultAzureFunctionsHostStorageName}{applicationHash}";
}

This is to avoid conflicts with differnet apphosts.

@paulomorgado
Copy link
Contributor Author

@paulomorgado You might need to follow the pattern here

private static string CreateDefaultStorageName(this IDistributedApplicationBuilder builder)
{
var applicationHash = builder.Configuration["AppHost:Sha256"]![..5].ToLowerInvariant();
return $"{DefaultAzureFunctionsHostStorageName}{applicationHash}";
}

This is to avoid conflicts with differnet apphosts.

I'm sorry @davidfowl, but I don't get what you mean. I only changed the resource name, which is internal only to each instance of app host.

@davidfowl
Copy link
Member

You're right. I guess there's no volume associated here.

@eerhardt eerhardt requested a review from sebastienros April 2, 2025 15:40
@sebastienros
Copy link
Member

when a containerName is passed, that's the one that is used.

Isn't it the current behavior? And if none is passed then a unique name is created by using the initiating resource.

Now with you PR two resources will have the same name if containerName is not set, meaning you have to set it if you have at least two. That might be ok but that's an insidious breaking change.

@paulomorgado
Copy link
Contributor Author

@sebastienros,

Isn't it the current behavior? And if none is passed then a unique name is created by using the initiating resource.

No. If none is passed, the name is dependent on the name of the first resource adding this dependency.

Now with you PR two resources will have the same name if containerName is not set, meaning you have to set it if you have at least two. That might be ok but that's an insidious breaking change.

There will only be 1 and only 1 resource of these. there's no way of duplicating the names that was not possible before.

@paulomorgado
Copy link
Contributor Author

@davidfowl, @sebastienros,

Is there anything missing here?

@sebastienros
Copy link
Member

I will take another look, assigning to 9.3 so I don't forget

@sebastienros sebastienros added this to the 9.3 milestone Apr 16, 2025
@sebastienros sebastienros self-assigned this Apr 16, 2025
@sebastienros
Copy link
Member

I reverted the changes for Milvus and MongoDB because they won't handle multiple calls (two resources are then declared with the same name). You can test it too, I did, and if you look at the other implementations (PgWeb, PhpMyAdmin, ...) where you did the change, you can see that the second call of the method return the existing container if there is one, so these work fine. These will also handle resources coming from other builders, meaning that if you create multiple dbs, a single explorer will render all these dbs.

@sebastienros sebastienros merged commit 2ed738c into dotnet:main May 13, 2025
176 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Jun 13, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-app-model Issues pertaining to the APIs in Aspire.Hosting, e.g. DistributedApplication 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.

Make PgAdmin, RedisCommander, and incoming MyPhpAdmin opt in per resource.
4 participants