-
Notifications
You must be signed in to change notification settings - Fork 457
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 API to support configuring parameter default values #5410
Comments
@davidebbo can you look at this one? |
This has some overlap with #4429. e.g. the first overload there is the same as the first from Suggestion 1 here. But the rest is distinct. How do we rationalize this? We sort of want the union of both proposals? See also my comment there, as the same questions apply here. In particular, the 'Do not add multiple overloads with optional parameters' is going to hit us. Suggestion 2 probably avoids it. Other question: why have distinct overloads for |
The feature that saves generated values to the user secrets store relies on |
@DamianEdwards and to be clear, everything you're discussing here is a fallback value, right? i.e. if the setting is found in app settings, we use that as normal. Otherwise, we use this, instead of not having a value at all. That seems like a very simple change, and I'll take a crack at it. I like Solution 1 better. And I think the 'Do not add multiple overloads with optional parameters' warning it gives is bogus in this case, since all the overloads are well differentiated by param types. |
The manifest implications are interesting. My take is:
|
#5529) * Add AddParameter overloads that take a constant and a ParameterDefault Fixes #5410 * Persist the default value if it needs it * Add test that checks that UserSecretsParameterDefault is only used when it should be * Tweak previous test * Change behavior so that value provided in code is always used * Rename tests to match new behavior * Add a persist param to AddParameter * Fix comment Co-authored-by: Eric Erhardt <eric.erhardt@microsoft.com> --------- Co-authored-by: Eric Erhardt <eric.erhardt@microsoft.com>
Background and Motivation
Adding parameters to the application model via
builder.AddParameter("name")
is straightforward enough, but sometimes it's desirable to create parameters that have a default value generated via theGenerateParameterDefault
type, or use a hard-coded default value string, or customParameterDefault
implementation. This is difficult to do today asParameterResource
default behaviors are largely controlled by the body of thebuilder.AddParameter()
method itself and that method accepts no overloads for controlling parameter default values.There should be API that makes it simple to set a parameter's default value in the same way that the implicit password parameters for many resources are.
Related:
Proposed API
Suggestion 1: Overloads of
AddParameter
that acceptstring,
GenerateParameterDefault
, andParameterDefault
.The second overload above (the one that accepts
GenerateParameterDefault
would create theParameterResource
internally using theCreateGeneratedParameter
method which ensures the generated value is stored in user secrets automatically.Suggestion 2: Extension method to
IResourceBuilder<ParameterResource>
that allows setting the parameter default valueAn alternative approach is to add new extension methods that enable setting the default value after the parameter is created and added to the application model with
AddParameter
:The second overload above (the one that accepts
GenerateParameterDefault
would wrap it in an instance of theUserSecretsParameterDefault
internal class which ensures the generated value is stored in user secrets automatically.Note that this approach would likely require some reworking of how
AddParameter
is currently implemented as it currently defaults the parameter resource initial state to an error if a value isn't found in configuration.Usage Examples
Suggestion 2:
AddParameter
overloadsSuggestion 2:
WithDefault
The text was updated successfully, but these errors were encountered: