Skip to content

Is it possible to use aspire/service discovery to get a url by the service name (locally/production) #6620

Answered by mmacneil
mip1983 asked this question in Q&A
Discussion options

You must be logged in to vote

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.

public static class ServiceDiscoveryUtilities
{
    public static string? GetServiceEndpoint(string serviceName, string endpointName, int index = 0) =>
      Environment.GetEnvironmentVariable($"services__{serviceName}__{endpointName}__{index}");
}

Replies: 5 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by davidfowl
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants