Skip to content
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

Add AddParameter overloads that take a constant and a ParameterDefault #5529

Merged
merged 8 commits into from
Sep 6, 2024

Conversation

davidebbo
Copy link
Contributor

@davidebbo davidebbo commented Sep 3, 2024

Description

See #5410 for details.

Fixes #5410

Checklist

  • Is this feature complete?
    • Yes. Ready to ship.
    • No. Follow-up changes expected.
  • Are you including unit tests for the changes and scenario tests if relevant?
    • Yes
    • No
  • Did you add public API?
    • Yes
      • If yes, did you have an API Review for it?
        • Yes
        • No
      • Did you add <remarks /> and <code /> elements on your triple slash comments?
        • Yes
        • No, may not be necessary here.
    • No
  • Does the change make any security assumptions or guarantees?
    • Yes
      • If yes, have you done a threat model and had a security review?
        • Yes
        • No
    • No
  • Does the change require an update in our Aspire docs?
    • Yes
      • Link to aspire-docs issue: None opened yet.
    • No
Microsoft Reviewers: Open in CodeFlow

@dotnet-issue-labeler dotnet-issue-labeler bot added the area-app-model Issues pertaining to the APIs in Aspire.Hosting, e.g. DistributedApplication label Sep 3, 2024
@dotnet-policy-service dotnet-policy-service bot added the community-contribution Indicates that the PR has been added by a community member label Sep 3, 2024
Copy link
Member

@eerhardt eerhardt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This LGTM. Thanks for the contribution, @davidebbo!

@DamianEdwards @davidfowl @mitchdenny - any other thoughts?

// An alternate implementation is to use some ConstantParameterDefault implementation that always returns the default value.
// However, doing this causes a "default": {} to be written to the manifest, which is not valid.
// And note that we ignore parameterDefault in the callback, because it can never be non-null, and we want our own default.
return builder.AddParameter(name, parameterDefault => builder.Configuration[$"Parameters:{name}"] ?? defaultValue, secret: secret);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm struggling with this one. Why is defaultValue a fallback instead of an override?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's the "default value". I.e. "if no one else supplied a value - use this one".

We would call it string value, if we wanted to always win.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fallback value?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds like a continuation of your earlier conversation: #4429 (comment). And frankly, I'm a bit confused about the comment there that says that "code wins". To me, "config wins", and the code is a fall back, which is what my code is doing.

Copy link
Member

@eerhardt eerhardt Sep 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In C#, when you have "optional arguments", the value that is used if you don't supply a value to the argument is called a "default value":

https://learn.microsoft.com/en-us/dotnet/csharp/programming-guide/classes-and-structs/named-and-optional-arguments#optional-arguments

Each optional parameter has a default value as part of its definition. If no argument is sent for that parameter, the default value is used.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In C#, when you have "optional arguments", the value that is used if you don't supply a value to the argument is called a "default value"

Right, though this is quite different from our situation here, where the value can come from two completely different systems (config vs code). Here, I could see fallbackValue as a reasonable name, though I don't think defaultValue is so bad either.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Started Discord thread to make it easier to discuss: https://discord.com/channels/732297728826277939/1281287950491193436

Co-authored-by: Eric Erhardt <eric.erhardt@microsoft.com>
@davidfowl davidfowl merged commit d2d14cf into dotnet:main Sep 6, 2024
11 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Oct 7, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-app-model Issues pertaining to the APIs in Aspire.Hosting, e.g. DistributedApplication community-contribution Indicates that the PR has been added by a community member
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add API to support configuring parameter default values
3 participants