Skip to content

Commit 0fec1c7

Browse files
CopilotIEvangelist
andauthored
Update environment variable format to polyglot-friendly pattern (#5320)
* Initial plan * Update environment variable format to polyglot-friendly pattern Co-authored-by: IEvangelist <7679720+IEvangelist@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: IEvangelist <7679720+IEvangelist@users.noreply.github.com>
1 parent eed887a commit 0fec1c7

File tree

9 files changed

+20
-20
lines changed

9 files changed

+20
-20
lines changed

docs/deployment/azd/aca-deployment-azd-in-depth.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -370,9 +370,9 @@ properties:
370370
value: "true"
371371
- name: OTEL_DOTNET_EXPERIMENTAL_OTLP_EMIT_EXCEPTION_LOG_ATTRIBUTES
372372
value: "true"
373-
- name: services__apiservice__0
373+
- name: APISERVICE_HTTP
374374
value: http://apiservice.internal.{{ .Env.AZURE_CONTAINER_APPS_ENVIRONMENT_DEFAULT_DOMAIN }}
375-
- name: services__apiservice__1
375+
- name: APISERVICE_HTTPS
376376
value: https://apiservice.internal.{{ .Env.AZURE_CONTAINER_APPS_ENVIRONMENT_DEFAULT_DOMAIN }}
377377
tags:
378378
azd-service-name: webfrontend

docs/deployment/manifest-format.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,8 @@ Publishing the manifest from the default starter template for Aspire produces th
110110
"OTEL_DOTNET_EXPERIMENTAL_OTLP_EMIT_EXCEPTION_LOG_ATTRIBUTES": "true",
111111
"OTEL_DOTNET_EXPERIMENTAL_OTLP_EMIT_EVENT_LOG_ATTRIBUTES": "true",
112112
"ConnectionStrings__cache": "{cache.connectionString}",
113-
"services__apiservice__0": "{apiservice.bindings.http.url}",
114-
"services__apiservice__1": "{apiservice.bindings.https.url}"
113+
"APISERVICE_HTTP": "{apiservice.bindings.http.url}",
114+
"APISERVICE_HTTPS": "{apiservice.bindings.https.url}"
115115
},
116116
"bindings": {
117117
"http": {
@@ -142,8 +142,8 @@ This dependency is known because the environment variables for the _webfrontend_
142142
"env": {
143143
// ... other environment variables omitted for clarity
144144
"ConnectionStrings__cache": "{cache.connectionString}",
145-
"services__apiservice__0": "{apiservice.bindings.http.url}",
146-
"services__apiservice__1": "{apiservice.bindings.https.url}"
145+
"APISERVICE_HTTP": "{apiservice.bindings.http.url}",
146+
"APISERVICE_HTTPS": "{apiservice.bindings.https.url}"
147147
},
148148
```
149149

docs/extensibility/dev-tunnels-integration.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ The preceding code:
101101
When another resource references a dev tunnel, environment variables are injected using the [Aspire service discovery](../service-discovery/overview.md) configuration format. Use the `WithReference` overloads that accept the `IResourceBuilder<DevTunnelResource>` parameter to reference a dev tunnel. This injects environment variables like:
102102

103103
```env
104-
services__web__https__0=https://myweb-1234.westeurope.devtunnels.ms/
104+
WEB_HTTPS=https://myweb-1234.westeurope.devtunnels.ms/
105105
```
106106

107107
This lets downstream resources use the tunneled address exactly like any other Aspire service discovery entry.

docs/fundamentals/app-host-overview.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ Project-to-project references are handled differently than resources that have w
176176
| Method | Environment variable |
177177
|--|--|
178178
| `WithReference(cache)` | `ConnectionStrings__cache="localhost:62354"` |
179-
| `WithReference(apiservice)` | `services__apiservice__http__0="http://localhost:5455"` <br /> `services__apiservice__https__0="https://localhost:7356"` |
179+
| `WithReference(apiservice)` | `APISERVICE_HTTP="http://localhost:5455"` <br /> `APISERVICE_HTTPS="https://localhost:7356"` |
180180

181181
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).
182182

@@ -202,28 +202,28 @@ var apiservice = builder.AddProject<Projects.AspireApp_ApiService>("apiservice")
202202

203203
| Method | Environment variable |
204204
|---------------------------|-------------------------------------------------------|
205-
| `WithReference(endpoint)` | `services__myapp__endpoint__0=https://localhost:9043` |
205+
| `WithReference(endpoint)` | `MYAPP_ENDPOINT=https://localhost:9043` |
206206

207207
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).
208208

209209
### Service endpoint environment variable format
210210

211211
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.
212212

213-
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).
213+
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.
214214

215-
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.
215+
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.
216216

217217
Consider the following environment variable examples:
218218

219219
```Environment
220-
services__apiservice__http__0
220+
APISERVICE_HTTP
221221
```
222222

223-
The preceding environment variable expresses the first 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:
223+
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:
224224

225225
```Environment
226-
services__apiservice__myendpoint__0
226+
APISERVICE_MYENDPOINT
227227
```
228228

229229
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.

docs/fundamentals/orchestrate-resources.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ var frontend = builder.AddProject<Projects.Frontend>("frontend")
285285
.WithReference(api);
286286
```
287287

288-
This configuration injects an environment variable like `services__api__https__0=https://api.example.com/` into the frontend project, enabling service discovery through the standard .NET service discovery mechanisms.
288+
This configuration injects an environment variable like `API_HTTPS=https://api.example.com/` into the frontend project, enabling service discovery through the standard .NET service discovery mechanisms.
289289

290290
### External service lifecycle
291291

docs/get-started/build-aspire-apps-with-nodejs.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ There are several key modifications from the original Angular template. The firs
147147

148148
:::code language="javascript" source="~/aspire-samples/samples/AspireWithJavaScript/AspireJavaScript.Angular/proxy.conf.js":::
149149

150-
The Aspire AppHost sets the `services__weatherapi__http__0` environment variable, which is used to resolve the "weatherapi" service endpoint. The preceding configuration proxies HTTP requests that start with `/api` to the target URL specified in the environment variable.
150+
The Aspire AppHost sets the `WEATHERAPI_HTTPS` and `WEATHERAPI_HTTP` environment variables, which are used to resolve the "weatherapi" service endpoints. The preceding configuration proxies HTTP requests that start with `/api` to the target URL specified in the environment variable.
151151

152152
Then include the proxy file to in the _angular.json_ file.
153153
Update the `serve` target to include the `proxyConfig` option, referencing to the created _proxy.conf.js_ file.
@@ -217,7 +217,7 @@ As the `TheWelcome` integration is `mounted`, it calls the `/api/weatherforecast
217217

218218
:::code language="typescript" source="~/aspire-samples/samples/AspireWithJavaScript/AspireJavaScript.Vue/vite.config.ts":::
219219

220-
Additionally, the Vite config specifies the `server.proxy` property to forward requests to the "weatherapi" service. This is achieved by using the `services__weatherapi__http__0` environment variable, which is set by the Aspire AppHost.
220+
Additionally, the Vite config specifies the `server.proxy` property to forward requests to the "weatherapi" service. This is achieved by using the `WEATHERAPI_HTTPS` and `WEATHERAPI_HTTP` environment variables, which are set by the Aspire AppHost.
221221

222222
The final update from the template is made to the _TheWelcome.vue_ file. This file calls the `/api/WeatherForecast` endpoint to retrieve the weather forecast data, and displays the data in a table. It includes [CSS, HTML, and TypeScript updates](https://github.com/dotnet/aspire-samples/blob/ef6868b0999c6eea3d42a10f2b20433c5ea93720/samples/AspireWithJavaScript/AspireJavaScript.Vue/src/components/TheWelcome.vue).
223223

docs/testing/snippets/testing/mstest/AspireApp.Tests/EnvVarTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public async Task WebResourceEnvVarsResolveToApiService()
2121
// Assert
2222
CollectionAssert.Contains(envVars,
2323
new KeyValuePair<string, string>(
24-
key: "services__apiservice__https__0",
24+
key: "APISERVICE_HTTPS",
2525
value: "{apiservice.bindings.https.url}"));
2626
}
2727
}

docs/testing/snippets/testing/nunit/AspireApp.Tests/EnvVarTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public async Task WebResourceEnvVarsResolveToApiService()
2020
// Assert
2121
Assert.That(envVars, Does.Contain(
2222
new KeyValuePair<string, string>(
23-
key: "services__apiservice__https__0",
23+
key: "APISERVICE_HTTPS",
2424
value: "{apiservice.bindings.https.url}")));
2525
}
2626
}

docs/testing/snippets/testing/xunit/AspireApp.Tests/EnvVarTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public async Task WebResourceEnvVarsResolveToApiService()
2222
{
2323
var (key, value) = kvp;
2424

25-
return key is "services__apiservice__https__0"
25+
return key is "APISERVICE_HTTPS"
2626
&& value is "{apiservice.bindings.https.url}";
2727
});
2828
}

0 commit comments

Comments
 (0)