-
Notifications
You must be signed in to change notification settings - Fork 168
Update documentation for new polyglot environment variables (issue #5308) #5313
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
IEvangelist
merged 6 commits into
release-13
from
copilot/update-content-related-to-5308
Nov 11, 2025
Merged
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
5cf51a2
Initial plan
Copilot a4084e3
Update documentation with new polyglot environment variable format
Copilot 5394d23
Add clarification about resource names in environment variables
Copilot 0d5d097
Improve clarity of note about connection name parameter
Copilot a149d55
Merge branch 'release-13' into copilot/update-content-related-to-5308
IEvangelist 777e9b4
Update docs/fundamentals/app-host-overview.md
IEvangelist File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -217,9 +217,16 @@ | |
| | Method | Environment variable | | ||
| |--|--| | ||
| | `WithReference(cache)` | `ConnectionStrings__cache="localhost:62354"` | | ||
| | `WithReference(apiservice)` | `APISERVICE_HTTP="http://localhost:5455"` <br /> `APISERVICE_HTTPS="https://localhost:7356"` | | ||
| | `WithReference(apiservice)` | `APISERVICE_HTTP="http://localhost:5455"` <br /> `APISERVICE_HTTPS="https://localhost:7356"` <br /> `services__apiservice__http__0="http://localhost:5455"` <br /> `services__apiservice__https__0="https://localhost:7356"` | | ||
|
|
||
| Adding a reference to the "apiservice" project results in service discovery environment variables being added to the frontend. This is because typically, project-to-project communication occurs over HTTP/gRPC. For more information, see [Aspire service discovery](../service-discovery/overview.md). | ||
| Adding a reference to the "apiservice" project results in service discovery environment variables being added to the frontend. This is because typically, project-to-project communication occurs over HTTP/gRPC. | ||
|
Check failure on line 222 in docs/fundamentals/app-host-overview.md
|
||
|
|
||
| Aspire injects two types of environment variables for service references: | ||
|
|
||
| - **Simplified format** (e.g., `APISERVICE_HTTP`): Uses the pattern `{RESOURCENAME}_{ENDPOINTNAME}` in uppercase. This format is simpler and more suitable for non-.NET languages and polyglot scenarios. | ||
| - **.NET service discovery format** (e.g., `services__apiservice__http__0`): Uses the pattern `services__{servicename}__{endpointname}__{index}` in lowercase. This format is used by .NET's configuration-based service discovery. | ||
|
|
||
| For more information, see [Aspire service discovery](../service-discovery/overview.md). | ||
|
|
||
| To get specific endpoints from a <xref:Aspire.Hosting.ApplicationModel.ContainerResource> or an <xref:Aspire.Hosting.ApplicationModel.ExecutableResource>, use one of the following endpoint APIs: | ||
|
|
||
|
|
@@ -243,31 +250,68 @@ | |
|
|
||
| | Method | Environment variable | | ||
| |---------------------------|-------------------------------------------------------| | ||
| | `WithReference(endpoint)` | `MYAPP_ENDPOINT=https://localhost:9043` | | ||
| | `WithReference(endpoint)` | `MYAPP_ENDPOINT="https://localhost:9043"` <br /> `services__myapp__endpoint__0="https://localhost:9043"` | | ||
|
|
||
| The `port` parameter is the port that the container is listening on. For more information on container ports, see [Container ports](networking-overview.md#container-ports). For more information on service discovery, see [Aspire service discovery](../service-discovery/overview.md). | ||
|
|
||
| ### Service endpoint environment variable format | ||
|
|
||
| In the preceding section, the <xref:Aspire.Hosting.ResourceBuilderExtensions.WithReference*> method is used to express dependencies between resources. When service endpoints result in environment variables being injected into the dependent resource, the format might not be obvious. This section provides details on this format. | ||
| In the preceding section, the <xref:Aspire.Hosting.ResourceBuilderExtensions.WithReference*> method is used to express dependencies between resources. When service endpoints result in environment variables being injected into the dependent resource, the format might not be obvious. This section provides details on the available formats. | ||
|
|
||
| When one resource depends on another resource, the AppHost injects environment variables into the dependent resource. These environment variables configure the dependent resource to connect to the resource it depends on. Aspire provides two environment variable formats to support different scenarios: | ||
|
|
||
| When one resource depends on another resource, the AppHost injects environment variables into the dependent resource. These environment variables configure the dependent resource to connect to the resource it depends on. The format of the environment variables is specific to Aspire and expresses service endpoints in a way that is compatible with [Service Discovery](../service-discovery/overview.md) and polyglot scenarios. | ||
| #### Simplified format (polyglot-friendly) | ||
|
|
||
| Service endpoint environment variable names follow the pattern `{RESOURCENAME}_{ENDPOINTNAME}`, where both the resource name and endpoint name are uppercased. This format is language-agnostic and works well with non-.NET technologies. | ||
| The simplified format uses the pattern `{RESOURCENAME}_{ENDPOINTNAME}` in uppercase. This format is easier to use from non-.NET languages and is recommended for polyglot scenarios. | ||
|
|
||
| Consider the following environment variable examples: | ||
|
|
||
| ```Environment | ||
| APISERVICE_HTTP | ||
| APISERVICE_HTTPS | ||
| ``` | ||
|
|
||
| The preceding environment variable expresses the HTTP endpoint for the `apiservice` service. The value of the environment variable is the URL of the service endpoint. A named endpoint might be expressed as follows: | ||
| The preceding environment variables express HTTP and HTTPS endpoints for the `apiservice` service. A named endpoint might be expressed as follows: | ||
|
|
||
| ```Environment | ||
| APISERVICE_MYENDPOINT | ||
| ``` | ||
|
|
||
| In the preceding example, the `apiservice` service has a named endpoint called `myendpoint`. The value of the environment variable is the URL of the service endpoint. | ||
| In the preceding example, the `apiservice` service has a named endpoint called `myendpoint`. | ||
|
|
||
| > [!NOTE] | ||
| > The environment variable name is based on the resource name, not the optional connection name parameter. Even when using `WithReference(resource, "customname")` to specify a custom connection name, the generated environment variables still use the resource's name (e.g., `APISERVICE_HTTP`), not the custom name. | ||
| #### .NET service discovery format | ||
|
|
||
| The .NET service discovery format is used by .NET's configuration-based service discovery. Service endpoint environment variable names are prefixed with `services__` (double underscore), then the service name, the endpoint name, and finally the index. The index supports multiple endpoints for a single service, starting with `0` for the first endpoint and incrementing for each endpoint. | ||
|
|
||
| Consider the following environment variable examples: | ||
|
|
||
| ```Environment | ||
| services__apiservice__http__0 | ||
| services__apiservice__https__0 | ||
| ``` | ||
|
|
||
| The preceding environment variables express the first HTTP and HTTPS endpoints for the `apiservice` service. A named endpoint might be expressed as follows: | ||
|
|
||
| ```Environment | ||
| APISERVICE_MYENDPOINT | ||
| ``` | ||
|
|
||
| In the preceding example, the `apiservice` service has a named endpoint called `myendpoint`. | ||
|
|
||
| #### Using a specific endpoint with WithEnvironment | ||
|
|
||
| To specify a custom environment variable name for a specific endpoint, use the <xref:Aspire.Hosting.ResourceBuilderExtensions.WithEnvironment%2A> method combined with <xref:Aspire.Hosting.ResourceBuilderExtensions.GetEndpoint*>: | ||
|
|
||
| ```csharp | ||
| var projectA = builder.AddProject<Projects.ProjectA>("projecta"); | ||
| var projectB = builder.AddProject<Projects.ProjectB>("projectb") | ||
| .WithEnvironment("PROJECTA_URL", projectA.GetEndpoint("https")); | ||
| ``` | ||
|
|
||
| This generates a single environment variable `PROJECTA_URL` with the HTTPS endpoint URL of the `projecta` service. | ||
|
|
||
| ## Reference existing resources | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.