Consolidate WithEnvironment polyglot exports using AspireUnionAttribute#15333
Consolidate WithEnvironment polyglot exports using AspireUnionAttribute#15333joperezr merged 10 commits intorelease/13.2from
Conversation
|
🚀 Dogfood this PR with:
curl -fsSL https://raw.githubusercontent.com/dotnet/aspire/main/eng/scripts/get-aspire-cli-pr.sh | bash -s -- 15333Or
iex "& { $(irm https://raw.githubusercontent.com/dotnet/aspire/main/eng/scripts/get-aspire-cli-pr.ps1) } 15333" |
8f77857 to
2ea73e3
Compare
Merge the separate withEnvironment (string) and withEnvironmentExpression
(ReferenceExpression) polyglot exports into a single withEnvironment export
using [AspireUnion] to accept string | ReferenceExpression | EndpointReference.
This gives TypeScript AppHost users a single, clean API:
await api.withEnvironment('KEY', 'value');
await api.withEnvironment('KEY', refExpr`redis://${endpoint}`);
await api.withEnvironment('KEY', endpoint);
Instead of requiring separate method names for each value type.
Also adds EndpointReference support which was previously unexported,
and handles object target type in AtsMarshaller.ConvertPrimitive for
correct union parameter deserialization.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…, and IValueProvider fallback - Add IResourceBuilder<ParameterResource> and IResourceBuilder<IResourceWithConnectionString> to the AspireUnion - Add IValueProvider+IManifestExpressionProvider runtime fallback for extensibility (e.g. BicepOutputReference) - Remove withEnvironmentEndpoint separate export (covered by union) - Remove sync withEnvironmentCallback export, rename async to withEnvironmentCallback - Update codegen snapshots Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
8916f49 to
389967d
Compare
|
The transient CI rerun workflow requested reruns for the following jobs after analyzing the failed attempt.
|
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR updates Aspire’s polyglot (ATS) surface for setting environment variables by consolidating multiple exported capabilities into a single withEnvironment overload that accepts a union-typed value, and updates the ATS marshalling logic and generated SDK snapshots accordingly.
Changes:
- Replaces per-type
withEnvironment*exports (e.g.,withEnvironmentExpression,withEnvironmentCallbackAsync) with a unified exportedwithEnvironmentunion overload plus a single exported async callback capability. - Updates ATS marshalling to better handle
object(union) primitive conversion. - Refreshes multi-language codegen snapshots and updates the TypeScript validation playground to use the new API.
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| src/Aspire.Hosting/ResourceBuilderExtensions.cs | Introduces exported union withEnvironment overload; adjusts callback export; removes some prior exports. |
| src/Aspire.Hosting.RemoteHost/Ats/AtsMarshaller.cs | Adds object-target primitive inference for union parameters. |
| tests/Aspire.Hosting.CodeGeneration.TypeScript.Tests/Snapshots/TwoPassScanningGeneratedAspire.verified.ts | Snapshot updates reflecting consolidated withEnvironment and callback export changes. |
| tests/Aspire.Hosting.CodeGeneration.TypeScript.Tests/Snapshots/HostingContainerResourceCapabilities.verified.txt | Removes capabilities that are no longer exported (withEnvironmentCallbackAsync, withEnvironmentExpression). |
| tests/Aspire.Hosting.CodeGeneration.Rust.Tests/Snapshots/TwoPassScanningGeneratedAspire.verified.rs | Snapshot updates aligning Rust bindings with consolidated with_environment. |
| tests/Aspire.Hosting.CodeGeneration.Python.Tests/Snapshots/TwoPassScanningGeneratedAspire.verified.py | Snapshot updates aligning Python bindings with consolidated with_environment. |
| tests/Aspire.Hosting.CodeGeneration.Java.Tests/Snapshots/TwoPassScanningGeneratedAspire.verified.java | Snapshot updates aligning Java bindings with consolidated withEnvironment. |
| tests/Aspire.Hosting.CodeGeneration.Go.Tests/Snapshots/TwoPassScanningGeneratedAspire.verified.go | Snapshot updates aligning Go bindings with consolidated WithEnvironment. |
| playground/polyglot/TypeScript/Aspire.Hosting/ValidationAppHost/apphost.ts | Updates sample usage to call the unified withEnvironment overload. |
| playground/polyglot/TypeScript/Aspire.Hosting.SqlServer/aspire.config.json | Adds config for the TypeScript SqlServer polyglot playground. |
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
🎬 CLI E2E Test Recordings — 52 recordings uploaded (commit View recordings
📹 Recordings uploaded automatically from CI run #23256120144 |
| { | ||
| return d; | ||
| } | ||
| return value.ToJsonString(); |
There was a problem hiding this comment.
hmm not sure I follow here. Should this be throw new ArgumentException() or something like that?
…te (#15333) * Consolidate WithEnvironment exports using AspireUnionAttribute Merge the separate withEnvironment (string) and withEnvironmentExpression (ReferenceExpression) polyglot exports into a single withEnvironment export using [AspireUnion] to accept string | ReferenceExpression | EndpointReference. This gives TypeScript AppHost users a single, clean API: await api.withEnvironment('KEY', 'value'); await api.withEnvironment('KEY', refExpr`redis://${endpoint}`); await api.withEnvironment('KEY', endpoint); Instead of requiring separate method names for each value type. Also adds EndpointReference support which was previously unexported, and handles object target type in AtsMarshaller.ConvertPrimitive for correct union parameter deserialization. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Expand WithEnvironment union with ParameterResource, ConnectionString, and IValueProvider fallback - Add IResourceBuilder<ParameterResource> and IResourceBuilder<IResourceWithConnectionString> to the AspireUnion - Add IValueProvider+IManifestExpressionProvider runtime fallback for extensibility (e.g. BicepOutputReference) - Remove withEnvironmentEndpoint separate export (covered by union) - Remove sync withEnvironmentCallback export, rename async to withEnvironmentCallback - Update codegen snapshots Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Update TypeScript apphost environment usage Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Refresh polyglot codegen snapshots Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Add ReferenceExpression apphost coverage Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Fix TypeScript polyglot validation apphost Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Potential fix for pull request finding Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> * Potential fix for pull request finding Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> * Make WithEnvironment union overload internal Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Address WithEnvironment review feedback Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Co-authored-by: David Fowler <davidfowl@gmail.com> Co-authored-by: Sebastien Ros <sebastienros@gmail.com> Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

Summary
Consolidates the separate
withEnvironmentandwithEnvironmentExpressionpolyglot exports into a singlewithEnvironmentexport using[AspireUnion], giving TypeScript AppHost users a cleaner API.Before (TypeScript)
After (TypeScript)
Changes
src/Aspire.Hosting/ResourceBuilderExtensions.cs[AspireExport]from the individualWithEnvironment(name, string)andWithEnvironment(name, ReferenceExpression)overloads[AspireUnion(typeof(string), typeof(ReferenceExpression), typeof(EndpointReference))]on the value parameterEndpointReferencewhich was previously not exported to polyglot hostssrc/Aspire.Hosting.RemoteHost/Ats/AtsMarshaller.csobjecttarget type handling inConvertPrimitive— when the target type isobject(union parameter), infers the correct .NET type from the JSON value structure (string → string, bool → bool, etc.)Snapshot updates
HostingContainerResourceCapabilities.verified.txt—withEnvironmentExpressioncapability removed (folded intowithEnvironment)TwoPassScanningGeneratedAspire.verified.ts— generated TypeScript now showsvalue: string | ReferenceExpression | EndpointReferenceunion typeTesting
Aspire.Hostingbuilds clean (0 warnings)Aspire.Hosting.RemoteHostbuilds clean