Support for optional parameters in Aspire
- Dominant language
- C#
- Stars
- 6.3k
- Forks
- 991
- Avg merge
- 2d 15h
- Merged PRs (30d)
- 196
Description
Aspire currently does not support optional parameters, which can limit flexibility when integrating or extending Aspire components. Adding support for optional parameters would allow developers to provide more concise and expressive code, improve interoperability, and reduce boilerplate.
**Scenario Example:**
In @dotnet/eShop/pull/858, configuration for either OpenAI or Azure OpenAI relies on parameters. For Azure OpenAI, the Endpoint is required, while the Key is optional. For OpenAI, only the Key is required because the Endpoint is already known. However, when both parameters are defined, users are repeatedly prompted to fill in "optional" parameters, even if they aren't needed for the selected configuration.
**Proposed Solution:**
- Review key APIs and configuration points in Aspire for places where optional parameters would provide value.
- Update method signatures to include optional parameters using default values, ensuring API stability and backward compatibility.
- Allow parameters to be left blank when not required by the scenario, preventing unnecessary reprompting.
- Add tests to verify behavior when optional parameters are omitted or specified.
**Benefits:**
- Increased flexibility and ease-of-use for consumers of Aspire APIs.
- Reduced need for multiple overloads or verbose configuration.
- Alignment with modern C# coding practices.
**Risks and Considerations:**
- Ensure backward compatibility for existing consumers.
- Document all changes thoroughly in API docs and changelogs.
Please discuss specific scenarios or APIs where this enhancement is most needed, or provide examples from your usage.
Contributor guide
Assessment
This issue has not been assessed yet.