-
Hi there, With service discovery in aspire it's easy to give resources references to each other and register http clients that resolve to a particular app. Is there a way to leverage it in other places to get a url to a service, particularly between web apps? I'm thinking for example if I've got identity server and a web app using it: var identity = builder.AddProject<Projects.Identity>("identity").WithExternalHttpEndpoints();
var web = builder.AddProject<Projects.Identity>("web")
.WithExternalHttpEndpoints()
.WithReference(identity);
identity = identity.WithReference(web); Where I have to configure things like 'authority' and 'redirectUri' etc. (on both ends) , can I get these Uri's via aspire/service discovery? I can see it does add urls to configuration in the 'services' section, so I can pull things out via IConfiguration (don't know if there's a neater mechanism?). But, when deployed to Azure container apps, these config urls aren't to the custom binding that I've applied to the container app (just the generic/random Azure assigned ones, I've not put a wildcard binding at the cae level). Is there a way for it to know about these and fetch via some service discovery mechanism? |
Beta Was this translation helpful? Give feedback.
Replies: 5 comments
-
Did you ever find a solution for this @mip1983 ? I have the identical scenario and suspect many others would as well... seems like something that should be supported. |
Beta Was this translation helpful? Give feedback.
-
You can just read the format described here https://learn.microsoft.com/en-us/dotnet/aspire/fundamentals/app-host-overview?tabs=docker#service-endpoint-environment-variable-format |
Beta Was this translation helpful? Give feedback.
-
As David linked to, I'd noticed the aspire referenced projects appear in config, so I have a static helper class along the lines of: public static class ServiceUrlHelper
{
public static string GetAppUrl(IConfiguration config, string appName)
{
string? serviceDiscoveryUrl = configuration[$"services:{appName.ToLowerInvariant()}:https:0"];
return serviceDiscoveryUrl;
}
} e.g. var identityUrl = ServiceUrlHelper.GetAppUrl(config, ApplicationNames.Identity); (Looking at it now, would probably be better as an extension method to IConfiguration) Mine's a little more complex than this as I follow a predictable pattern to my app names/url's, so it'll resolve projects where the name ends with '-api' to the aspire config url as above, but for publicly accessible web apps it's always {appName}{-environment suffix if not prod}.{domain} so I'll resolve these by pattern. I use 'PublishAsAzureContainerApp' and 'ConfigureCustomDomain' to configure domains now, but it doesn't look like those domains get registered as endpoints in the config at the moment, just the 'containerapps.io' internal ones. |
Beta Was this translation helpful? Give feedback.
-
Ah, got it now. Thanks so much gentlemen! 🙏🙏 |
Beta Was this translation helpful? Give feedback.
-
For future travellers, here's a small method to extract the endpoint from the env variable. Extend with appropriate error handling for your production code.
|
Beta Was this translation helpful? Give feedback.
For future travellers, here's a small method to extract the endpoint from the env variable. Extend with appropriate error handling for your production code.