You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Add optional parameters and programmatic value setting - #18108
Parameters currently do not have a complete first-class model for two related scenarios: optional parameters that can intentionally have no value, and programmatic parameter values that can be set by AppHost code instead of only through configuration, prompts, or generated defaults. This change adds both pieces so run, publish, dashboard, C# AppHost, and TypeScript AppHost flows share the same parameter value contract.
Users can now mark parameter resources optional with WithOptional() / WithRequired(...), allowing unset optional parameters to resolve to null without prompting or blocking publish. Users can also inspect and set parameter values programmatically with TryGetCurrentValue(...) and SetValueAsync(...); observed parameter updates synchronize dashboard state, resolve missing-value prompts, and preserve required-parameter validation when a required parameter is cleared.
The implementation centralizes value state on ParameterResource and refactors ParameterProcessor to consume that public/resource-level contract instead of manipulating internal completion state directly. ATS and TypeScript generation expose the value-management APIs, including nullable value metadata for setValueAsync and tryGetCurrentValue.
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR adds first-class support for optional parameter resources and programmatic parameter value management in Aspire. It introduces a Required property on ParameterResource (defaulting to true), fluent builder extensions (WithOptional(), WithRequired()), and a suite of value-management methods (TrySetValue, TrySetException, SetValueAsync, SetExceptionAsync, TryGetCurrentValue). The ParameterProcessor is refactored to use an observer pattern via ValueChanged events instead of directly manipulating internal TaskCompletionSource state, enabling dashboard state synchronization when values are set programmatically. ATS code generation is updated to propagate nullability metadata for parameters and return types.
Changes:
New ParameterResource public API for optional parameters and programmatic value management, with an internal event-based observer pattern consumed by ParameterProcessor for dashboard state synchronization.
ParameterProcessor refactored to use thread-safe collections with locks, observer-based state updates, and a new SetValueAsync method for non-interactive value setting.
ATS capability scanner updated to detect and propagate C# nullability annotations for method parameters and return types, reflected in TypeScript codegen snapshots.
Refactored to observer pattern: ObserveParameterValueChanges, thread-safe unresolved parameters, SetValueAsync for non-interactive value setting, SetValueCoreAsync
Make Aspire parameters first-class for both optionality and runtime value
management, and surface the new capabilities to polyglot hosts.
Optional parameters:
- WithOptional() marks a parameter resource as optional so a missing value
no longer prompts or fails resolution; WithRequired() restores the default
required behavior. Custom-input parameters honor the Required flag.
Programmatic value management:
- ParameterResource.SetValueAsync / TryGetCurrentValue let code set and read a
parameter's value at runtime.
- ParameterProcessor.SetValueAsync is the persistence-aware path: with
saveToUserSecrets it writes the value back to user secrets, and setting a
value notifies observers so the dashboard reflects the change live.
Polyglot exposure:
- The new methods are exported via ATS ([AspireExport]) so TypeScript, Java,
Python, Go, and Rust app hosts get them. The generated bindings are additive
only - no changes to the existing generated surface. Reference-type
nullability is intentionally not propagated into the model, preserving the
established convention (for example getConnectionString() stays non-null).
Publish vs run:
- ManifestPublishingContext handles optional parameters when publishing.
Includes unit tests for AddParameter optionality, ParameterProcessor value
management and notification, execution configuration gathering, and the ATS
scanner capability for the new parameter methods.
Related: #17710
Co-authored-by: Copilot <[email protected]>
Preserve resource-level setters and optional null values alongside main's secret redaction, dashboard value metadata, and dismissed-prompt handling. Record secret assignments before releasing value waiters and keep prompt completion from canceling persistence. Regenerate Java and TypeScript SDK snapshots and adapt backchannel tests to nullable parameter values.
Validation: 209 hosting/backchannel tests and 12 code-generation checks passed.
Co-authored-by: Copilot App <[email protected]>
Copilot-Session: c63c476d-a728-4c18-9ad1-1f283254aa4a
Changing Required only invalidates a cached lazy lookup; it does not reconcile an already-completed WaitForValueTcs. For example, after a required parameter is cleared with SetValueAsync(null), WithOptional() leaves the completion source faulted, so GetValueAsync() still throws and initialization still prompts even though the parameter is now optional. Reconcile a completed missing-value state when requiredness changes (and notify observers so dashboard/prompt state follows the new contract).
This public method rejects both a null parameterResource and a null/empty value, but its XML documentation omits those exception contracts. Add <exception> entries so IntelliSense documents the validation callers must satisfy.
Added two new sections to fundamentals/external-parameters.mdx: "Optional parameters" (documents WithOptional()/WithRequired(bool) on ParameterResource, including the manifest-publish restriction) and "Set and inspect parameter values programmatically" (documents TryGetCurrentValue/SetValueAsync, with C# and TypeScript examples). Triggered signals: pr_body_has_user_facing_section (PR body's "User-facing usage" section with C#/TypeScript WithOptional/TryGetCurrentValue/SetValueAsync examples was used as the primary source), pr_body_has_cli_flag_mention (build/test command mentions, not user-facing CLI surface — no CLI docs change needed), polyglot_code_generator_changed (ATS/polyglot SDK export changes for withOptional/withRequired/setValueAsync/tryGetCurrentValue; covered via the TypeScript example mirroring the C# API, consistent with the page's existing bilingual pattern — no separate polyglot reference page exists for this). Review-comment context (manifest schema limitation thrown as DistributedApplicationException, and SetValueAsync not persisting to user secrets by default) was folded into the new prose as an Aside.
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
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.
Description
Parameters currently do not have a complete first-class model for two related scenarios: optional parameters that can intentionally have no value, and programmatic parameter values that can be set by AppHost code instead of only through configuration, prompts, or generated defaults. This change adds both pieces so run, publish, dashboard, C# AppHost, and TypeScript AppHost flows share the same parameter value contract.
Users can now mark parameter resources optional with
WithOptional()/WithRequired(...), allowing unset optional parameters to resolve tonullwithout prompting or blocking publish. Users can also inspect and set parameter values programmatically withTryGetCurrentValue(...)andSetValueAsync(...); observed parameter updates synchronize dashboard state, resolve missing-value prompts, and preserve required-parameter validation when a required parameter is cleared.The implementation centralizes value state on
ParameterResourceand refactorsParameterProcessorto consume that public/resource-level contract instead of manipulating internal completion state directly. ATS and TypeScript generation expose the value-management APIs, including nullable value metadata forsetValueAsyncandtryGetCurrentValue.User-facing usage
C# AppHost:
TypeScript AppHost:
The TypeScript validation AppHost exercises inspection, assignment, clearing, and required toggling against the generated SDK./
Validation
./build.sh --build /p:SkipNativeBuild=true /p:RepositoryCommit=$(git rev-parse HEAD)dotnet test --project tests/Aspire.Hosting.Tests/Aspire.Hosting.Tests.csproj --no-launch-profile -- --filter-class "*.AddParameterTests" --filter-class "*.ParameterProcessorTests" --filter-not-trait "quarantined=true" --filter-not-trait "outerloop=true"git diff --checkFixes #17710
Checklist
<remarks />and<code />elements on your triple slash comments?