ParameterResourceBuilderExtensions Methods
ClassMethods13 members
Provides extension methods for adding parameter resources to an application.
AddConnectionString(IDistributedApplicationBuilder, string, string?) Section titled AddConnectionString(IDistributedApplicationBuilder, string, string?)extensionIResourceBuilder<IResourceWithConnectionString> Adds a parameter to the distributed application but wrapped in a resource with a connection string for use with
ResourceBuilderExtensions.WithReference public static class ParameterResourceBuilderExtensions{ public static IResourceBuilder<IResourceWithConnectionString> AddConnectionString( this IDistributedApplicationBuilder builder, string name, string? environmentVariableName = null) { // ... }}Parameters
builderInamestringName of parameter resource. The value of the connection string is read from the "ConnectionStrings:{resourcename}" configuration section, for example in appsettings.json or user secretsenvironmentVariableName string?optionalEnvironment variable name to set when WithReference is used.Returns
IResourceBuilder<IResourceWithConnectionString> Resource builder for the parameter.Exceptions
AddParameter(IDistributedApplicationBuilder, string, bool) Section titled AddParameter(IDistributedApplicationBuilder, string, bool)extensionIResourceBuilder<ParameterResource> Adds a parameter resource to the application.
public static class ParameterResourceBuilderExtensions{ public static IResourceBuilder<ParameterResource> AddParameter( this IDistributedApplicationBuilder builder, string name, bool secret = false) { // ... }}Parameters
builderInamestringName of parameter resourcesecretbooloptionalOptional flag indicating whether the parameter should be regarded as secret.Returns
IResourceBuilder<ParameterResource> Resource builder for the parameter.Exceptions
AddParameter(IDistributedApplicationBuilder, string, string, bool, bool) Section titled AddParameter(IDistributedApplicationBuilder, string, string, bool, bool)extensionIResourceBuilder<ParameterResource> Adds a parameter resource to the application with a given value.
public static class ParameterResourceBuilderExtensions{ public static IResourceBuilder<ParameterResource> AddParameter( this IDistributedApplicationBuilder builder, string name, string value, bool publishValueAsDefault = false, bool secret = false) { // ... }}Parameters
builderInamestringName of parameter resourcevaluestringA string value to use for the parameterpublishValueAsDefault booloptionalIndicates whether the value should be published to the manifest. This is not meant for sensitive data.secretbooloptionalOptional flag indicating whether the parameter should be regarded as secret.Returns
IResourceBuilder<ParameterResource> Resource builder for the parameter.Remarks
publishValueAsDefault and secret are mutually exclusive.
AddParameter(IDistributedApplicationBuilder, string, Func<string>, bool, bool) Section titled AddParameter(IDistributedApplicationBuilder, string, Func<string>, bool, bool)extensionIResourceBuilder<ParameterResource> Adds a parameter resource to the application with a value coming from a callback function.
public static class ParameterResourceBuilderExtensions{ public static IResourceBuilder<ParameterResource> AddParameter( this IDistributedApplicationBuilder builder, string name, Func<string> valueGetter, bool publishValueAsDefault = false, bool secret = false) { // ... }}Parameters
builderInamestringName of parameter resourcevalueGetter Func<string> A callback function that returns the value of the parameterpublishValueAsDefault booloptionalIndicates whether the value should be published to the manifest. This is not meant for sensitive data.secretbooloptionalOptional flag indicating whether the parameter should be regarded as secret.Returns
IResourceBuilder<ParameterResource> Resource builder for the parameter.Remarks
publishValueAsDefault and secret are mutually exclusive.
This method is not available in polyglot AppHosts. Use the overload with a string value instead.
AddParameter(IDistributedApplicationBuilder, string, ParameterDefault, bool, bool) Section titled AddParameter(IDistributedApplicationBuilder, string, ParameterDefault, bool, bool)extensionIResourceBuilder<ParameterResource> Adds a parameter resource to the application, with a value coming from a
ParameterDefault if not supplied from configuration. public static class ParameterResourceBuilderExtensions{ public static IResourceBuilder<ParameterResource> AddParameter( this IDistributedApplicationBuilder builder, string name, ParameterDefault value, bool secret = false, bool persist = false) { // ... }}Parameters
builderInamestringName of parameter resourcevalueParameterParameterDefault that is used to provide the parameter value if a value is not present in configurationsecretbooloptionalOptional flag indicating whether the parameter should be regarded as secret.persistbooloptionalPersist the value to the AppHost project's user secrets store. This is typically done when the value is generated, so that it stays stable across runs. This is only relevant when DistributedApplicationExecutionContext.IsRunMode is trueReturns
IResourceBuilder<ParameterResource> Resource builder for the parameter.Remarks
This method is not available in polyglot AppHosts. Use the overload with a string value instead.
AddParameterFromConfiguration(IDistributedApplicationBuilder, string, string, bool) Section titled AddParameterFromConfiguration(IDistributedApplicationBuilder, string, string, bool)extensionIResourceBuilder<ParameterResource> Adds a parameter resource to the application, with a value coming from configuration.
public static class ParameterResourceBuilderExtensions{ public static IResourceBuilder<ParameterResource> AddParameterFromConfiguration( this IDistributedApplicationBuilder builder, string name, string configurationKey, bool secret = false) { // ... }}Parameters
builderInamestringName of parameter resourceconfigurationKey stringConfiguration key used to get the value of the parametersecretbooloptionalOptional flag indicating whether the parameter should be regarded as secret.Returns
IResourceBuilder<ParameterResource> Resource builder for the parameter.ConfigureConnectionStringManifestPublisher(IResourceBuilder<IResourceWithConnectionString>) Section titled ConfigureConnectionStringManifestPublisher(IResourceBuilder<IResourceWithConnectionString>)static Configures the manifest writer for this resource to be a parameter resource.
public static class ParameterResourceBuilderExtensions{ public static void ConfigureConnectionStringManifestPublisher( IResourceBuilder<IResourceWithConnectionString> builder) { // ... }}Parameters
builderIResourceBuilder<IResourceWithConnectionString> The ApplicationModel.IResourceBuilder`1 .CreateDefaultPasswordParameter(IDistributedApplicationBuilder, string, bool, bool, bool, bool, int, int, int, int) Section titled CreateDefaultPasswordParameter(IDistributedApplicationBuilder, string, bool, bool, bool, bool, int, int, int, int)staticParameter Creates a default password parameter that generates a random password.
public static class ParameterResourceBuilderExtensions{ public static ParameterResource CreateDefaultPasswordParameter( IDistributedApplicationBuilder builder, string name, bool lower = true, bool upper = true, bool numeric = true, bool special = true, int minLower = 0, int minUpper = 0, int minNumeric = 0, int minSpecial = 0) { // ... }}Parameters
builderInamestringName of parameter resourcelowerbooloptionaltrue if lowercase alphabet characters should be included; otherwise, false.upperbooloptionaltrue if uppercase alphabet characters should be included; otherwise, false.numericbooloptionaltrue if numeric characters should be included; otherwise, false.specialbooloptionaltrue if special characters should be included; otherwise, false.minLower intoptionalThe minimum number of lowercase characters in the result.minUpper intoptionalThe minimum number of uppercase characters in the result.minNumeric intoptionalThe minimum number of numeric characters in the result.minSpecial intoptionalThe minimum number of special characters in the result.Returns
ParameterResource The created ParameterResource .Remarks
To ensure the generated password has enough entropy, see the remarks in
GenerateParameterDefault . The value will be saved to the AppHost project's user secrets store when DistributedApplicationExecutionContext.IsRunMode is true. CreateGeneratedParameter(IDistributedApplicationBuilder, string, bool, GenerateParameterDefault) Section titled CreateGeneratedParameter(IDistributedApplicationBuilder, string, bool, GenerateParameterDefault)staticParameter Creates a new
ParameterResource that has a generated value using the parameterDefault . public static class ParameterResourceBuilderExtensions{ public static ParameterResource CreateGeneratedParameter( IDistributedApplicationBuilder builder, string name, bool secret, GenerateParameterDefault parameterDefault) { // ... }}Parameters
builderInamestringName of parameter resourcesecretboolFlag indicating whether the parameter should be regarded as secret.parameterDefault GenerateGenerateParameterDefault that describes how the parameter's value should be generated.Returns
ParameterResource The created ParameterResource .Remarks
The value will be saved to the AppHost project's user secrets store when
DistributedApplicationExecutionContext.IsRunMode is true. CreateParameter(IDistributedApplicationBuilder, string, bool) Section titled CreateParameter(IDistributedApplicationBuilder, string, bool)staticParameter Creates a new
ParameterResource . public static class ParameterResourceBuilderExtensions{ public static ParameterResource CreateParameter( IDistributedApplicationBuilder builder, string name, bool secret) { // ... }}Parameters
builderInamestringName of parameter resourcesecretboolFlag indicating whether the parameter should be regarded as secret.Returns
ParameterResource The created ParameterResource .Remarks
The value will be saved to the AppHost project's user secrets store when
DistributedApplicationExecutionContext.IsRunMode is true. PublishAsConnectionString(IResourceBuilder<T>) Section titled PublishAsConnectionString(IResourceBuilder<T>)extensionI Changes the resource to be published as a connection string reference in the manifest.
public static class ParameterResourceBuilderExtensions{ public static IResourceBuilder<T> PublishAsConnectionString<T>( this IResourceBuilder<T> builder) { // ... }}Parameters
builderIReturns
IResourceBuilder<T> The configured ApplicationModel.IResourceBuilder`1 .Remarks
This API only changes the manifest representation; it does not change the resource model used by other publishers.
WithCustomInput(IResourceBuilder<ParameterResource>, Func<ParameterResource, InteractionInput>) Section titled WithCustomInput(IResourceBuilder<ParameterResource>, Func<ParameterResource, InteractionInput>)extensionIResourceBuilder<ParameterResource> Sets a custom input generator function for the parameter resource.
public static class ParameterResourceBuilderExtensions{ public static IResourceBuilder<ParameterResource> WithCustomInput( this IResourceBuilder<ParameterResource> builder, Func<ParameterResource, InteractionInput> createInput) { // ... }}Parameters
builderIResourceBuilder<ParameterResource> Resource builder for the parameter.createInput Func<ParameterResource, InteractionInput> Function to customize the input for the parameter.Returns
IResourceBuilder<ParameterResource> Resource builder for the parameter.Remarks
Use this method to customize how the input field for this parameter is rendered when its value is requested, e.g.:
builder.AddParameter("external-service-url") .WithCustomInput(parameter => new() { InputType = parameter.Secret ? InputType.SecretText : InputType.Text, Value = "https://example.com", Label = parameter.Name, Placeholder = $"Enter value for {parameter.Name}", Description = parameter.Description });This method is not available in polyglot AppHosts.
WithDescription(IResourceBuilder<ParameterResource>, string, bool) Section titled WithDescription(IResourceBuilder<ParameterResource>, string, bool)extensionIResourceBuilder<ParameterResource> Sets the description of the parameter resource.
public static class ParameterResourceBuilderExtensions{ public static IResourceBuilder<ParameterResource> WithDescription( this IResourceBuilder<ParameterResource> builder, string description, bool enableMarkdown = false) { // ... }}Parameters
builderIResourceBuilder<ParameterResource> Resource builder for the parameter.descriptionstringThe parameter description.enableMarkdown booloptional A value indicating whether the description should be rendered as Markdown. true allows the description to contain Markdown elements such as links, text decoration and lists. Returns
IResourceBuilder<ParameterResource> Resource builder for the parameter.