# ParameterResourceBuilderExtensions Methods

- Package: [Aspire.Hosting](/reference/api/csharp/aspire.hosting.md)
- Type: [ParameterResourceBuilderExtensions](/reference/api/csharp/aspire.hosting/parameterresourcebuilderextensions.md)
- Kind: `Methods`
- Members: `13`

Provides extension methods for adding parameter resources to an application.

## AddConnectionString(IDistributedApplicationBuilder, string, string?)

- Name: `AddConnectionString(IDistributedApplicationBuilder, string, string?)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<IResourceWithConnectionString>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/bd20f904cde09ecb9c9ae5116a6f13614bf2d7c2/src/Aspire.Hosting/ParameterResourceBuilderExtensions.cs#L286-L295)

Adds a parameter to the distributed application but wrapped in a resource with a connection string for use with [ResourceBuilderExtensions.WithReference(IResourceBuilder<TDestination>, IResourceBuilder<IResourceWithConnectionString>, string?, bool)](/reference/api/csharp/aspire.hosting/resourcebuilderextensions/methods.md#withreference-iresourcebuilder-tdestination-iresourcebuilder-iresourcewithconnectionstring-string-bool)

```csharp
public static class ParameterResourceBuilderExtensions
{
    public static IResourceBuilder<IResourceWithConnectionString> AddConnectionString(
        this IDistributedApplicationBuilder builder,
        string name,
        string? environmentVariableName = null)
    {
        // ...
    }
}
```

## Parameters

- `builder` ([IDistributedApplicationBuilder](/reference/api/csharp/aspire.hosting/idistributedapplicationbuilder.md))
  Distributed application builder
- `name` (`string`)
  Name of parameter resource. The value of the connection string is read from the "ConnectionStrings:{resourcename}" configuration section, for example in appsettings.json or user secrets
- `environmentVariableName` (`string?`) `optional`
  Environment variable name to set when WithReference is used.

## Returns

`IResourceBuilder<IResourceWithConnectionString>` -- Resource builder for the parameter.

## Exceptions

- [DistributedApplicationException](/reference/api/csharp/aspire.hosting/distributedapplicationexception.md)

## ATS metadata

### Ignored by ATS

- Reason: Polyglot app hosts use the internal addConnectionString dispatcher export.

## AddParameter(IDistributedApplicationBuilder, string, bool)

- Name: `AddParameter(IDistributedApplicationBuilder, string, bool)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<ParameterResource>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/bd20f904cde09ecb9c9ae5116a6f13614bf2d7c2/src/Aspire.Hosting/ParameterResourceBuilderExtensions.cs#L29-L37)

Adds a parameter resource to the application.

```csharp
public static class ParameterResourceBuilderExtensions
{
    public static IResourceBuilder<ParameterResource> AddParameter(
        this IDistributedApplicationBuilder builder,
        string name,
        bool secret = false)
    {
        // ...
    }
}
```

## Parameters

- `builder` ([IDistributedApplicationBuilder](/reference/api/csharp/aspire.hosting/idistributedapplicationbuilder.md))
  Distributed application builder
- `name` (`string`)
  Name of parameter resource
- `secret` (`bool`) `optional`
  Optional flag indicating whether the parameter should be regarded as secret.

## Returns

`IResourceBuilder<ParameterResource>` -- Resource builder for the parameter.

## Exceptions

- [DistributedApplicationException](/reference/api/csharp/aspire.hosting/distributedapplicationexception.md)

## ATS metadata

### Ignored by ATS

- Reason: Polyglot app hosts use the internal addParameter dispatcher export.

## AddParameter(IDistributedApplicationBuilder, string, string, bool, bool)

- Name: `AddParameter(IDistributedApplicationBuilder, string, string, bool, bool)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<ParameterResource>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/bd20f904cde09ecb9c9ae5116a6f13614bf2d7c2/src/Aspire.Hosting/ParameterResourceBuilderExtensions.cs#L73-L77)

Adds a parameter resource to the application with a given value.

```csharp
public static class ParameterResourceBuilderExtensions
{
    public static IResourceBuilder<ParameterResource> AddParameter(
        this IDistributedApplicationBuilder builder,
        string name,
        string value,
        bool publishValueAsDefault = false,
        bool secret = false)
    {
        // ...
    }
}
```

## Parameters

- `builder` ([IDistributedApplicationBuilder](/reference/api/csharp/aspire.hosting/idistributedapplicationbuilder.md))
  Distributed application builder
- `name` (`string`)
  Name of parameter resource
- `value` (`string`)
  A string value to use for the parameter
- `publishValueAsDefault` (`bool`) `optional`
  Indicates whether the value should be published to the manifest. This is not meant for sensitive data.
- `secret` (`bool`) `optional`
  Optional 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.

## ATS metadata

### Ignored by ATS

- Reason: Polyglot app hosts use the internal addParameter dispatcher export.

## AddParameter(IDistributedApplicationBuilder, string, Func<string>, bool, bool)

- Name: `AddParameter(IDistributedApplicationBuilder, string, Func<string>, bool, bool)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<ParameterResource>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/bd20f904cde09ecb9c9ae5116a6f13614bf2d7c2/src/Aspire.Hosting/ParameterResourceBuilderExtensions.cs#L98-L118)

Adds a parameter resource to the application with a value coming from a callback function.

```csharp
public static class ParameterResourceBuilderExtensions
{
    public static IResourceBuilder<ParameterResource> AddParameter(
        this IDistributedApplicationBuilder builder,
        string name,
        Func<string> valueGetter,
        bool publishValueAsDefault = false,
        bool secret = false)
    {
        // ...
    }
}
```

## Parameters

- `builder` ([IDistributedApplicationBuilder](/reference/api/csharp/aspire.hosting/idistributedapplicationbuilder.md))
  Distributed application builder
- `name` (`string`)
  Name of parameter resource
- `valueGetter` (`Func<string>`)
  A callback function that returns the value of the parameter
- `publishValueAsDefault` (`bool`) `optional`
  Indicates whether the value should be published to the manifest. This is not meant for sensitive data.
- `secret` (`bool`) `optional`
  Optional 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 app hosts. Use the overload with a string value instead.

## ATS metadata

### Ignored by ATS

- Reason: Raw Func<string> delegate -- not ATS-compatible.

## AddParameter(IDistributedApplicationBuilder, string, ParameterDefault, bool, bool)

- Name: `AddParameter(IDistributedApplicationBuilder, string, ParameterDefault, bool, bool)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<ParameterResource>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/bd20f904cde09ecb9c9ae5116a6f13614bf2d7c2/src/Aspire.Hosting/ParameterResourceBuilderExtensions.cs#L164-L178)

Adds a parameter resource to the application, with a value coming from a [ParameterDefault](/reference/api/csharp/aspire.hosting/parameterdefault.md) if not supplied from configuration.

```csharp
public static class ParameterResourceBuilderExtensions
{
    public static IResourceBuilder<ParameterResource> AddParameter(
        this IDistributedApplicationBuilder builder,
        string name,
        ParameterDefault value,
        bool secret = false,
        bool persist = false)
    {
        // ...
    }
}
```

## Parameters

- `builder` ([IDistributedApplicationBuilder](/reference/api/csharp/aspire.hosting/idistributedapplicationbuilder.md))
  Distributed application builder
- `name` (`string`)
  Name of parameter resource
- `value` ([ParameterDefault](/reference/api/csharp/aspire.hosting/parameterdefault.md))
  A [ParameterDefault](/reference/api/csharp/aspire.hosting/parameterdefault.md) that is used to provide the parameter value if a value is not present in configuration
- `secret` (`bool`) `optional`
  Optional flag indicating whether the parameter should be regarded as secret.
- `persist` (`bool`) `optional`
  Persist the value to the app host 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](/reference/api/csharp/aspire.hosting/distributedapplicationexecutioncontext/properties.md#isrunmode) is `true`

## Returns

`IResourceBuilder<ParameterResource>` -- Resource builder for the parameter.

## Remarks

This method is not available in polyglot app hosts. Use the overload with a string value instead.

## ATS metadata

### Ignored by ATS

- Reason: ParameterDefault is not an ATS-exported type.

## AddParameterFromConfiguration(IDistributedApplicationBuilder, string, string, bool)

- Name: `AddParameterFromConfiguration(IDistributedApplicationBuilder, string, string, bool)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<ParameterResource>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/bd20f904cde09ecb9c9ae5116a6f13614bf2d7c2/src/Aspire.Hosting/ParameterResourceBuilderExtensions.cs#L132-L143)

Adds a parameter resource to the application, with a value coming from configuration.

```csharp
public static class ParameterResourceBuilderExtensions
{
    public static IResourceBuilder<ParameterResource> AddParameterFromConfiguration(
        this IDistributedApplicationBuilder builder,
        string name,
        string configurationKey,
        bool secret = false)
    {
        // ...
    }
}
```

## Parameters

- `builder` ([IDistributedApplicationBuilder](/reference/api/csharp/aspire.hosting/idistributedapplicationbuilder.md))
  Distributed application builder
- `name` (`string`)
  Name of parameter resource
- `configurationKey` (`string`)
  Configuration key used to get the value of the parameter
- `secret` (`bool`) `optional`
  Optional flag indicating whether the parameter should be regarded as secret.

## Returns

`IResourceBuilder<ParameterResource>` -- Resource builder for the parameter.

## ATS metadata

### ATS export

- Available to Polyglot AppHosts through the Aspire Type System.

## ConfigureConnectionStringManifestPublisher(IResourceBuilder<IResourceWithConnectionString>)

- Name: `ConfigureConnectionStringManifestPublisher(IResourceBuilder<IResourceWithConnectionString>)`
- Modifiers: `static`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/bd20f904cde09ecb9c9ae5116a6f13614bf2d7c2/src/Aspire.Hosting/ParameterResourceBuilderExtensions.cs#L338-L345)

Configures the manifest writer for this resource to be a parameter resource.

```csharp
public static class ParameterResourceBuilderExtensions
{
    public static void ConfigureConnectionStringManifestPublisher(
        IResourceBuilder<IResourceWithConnectionString> builder)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IResourceBuilder<IResourceWithConnectionString>`)
  The `ApplicationModel.IResourceBuilder`1`.

## CreateDefaultPasswordParameter(IDistributedApplicationBuilder, string, bool, bool, bool, bool, int, int, int, int)

- Name: `CreateDefaultPasswordParameter(IDistributedApplicationBuilder, string, bool, bool, bool, bool, int, int, int, int)`
- Modifiers: `static`
- Returns: [ParameterResource](/reference/api/csharp/aspire.hosting/parameterresource.md)
- Source: [GitHub](https://github.com/microsoft/aspire/blob/bd20f904cde09ecb9c9ae5116a6f13614bf2d7c2/src/Aspire.Hosting/ParameterResourceBuilderExtensions.cs#L370-L386)

Creates a default password parameter that generates a random password.

```csharp
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

- `builder` ([IDistributedApplicationBuilder](/reference/api/csharp/aspire.hosting/idistributedapplicationbuilder.md))
  Distributed application builder
- `name` (`string`)
  Name of parameter resource
- `lower` (`bool`) `optional`
  `true` if lowercase alphabet characters should be included; otherwise, `false`.
- `upper` (`bool`) `optional`
  `true` if uppercase alphabet characters should be included; otherwise, `false`.
- `numeric` (`bool`) `optional`
  `true` if numeric characters should be included; otherwise, `false`.
- `special` (`bool`) `optional`
  `true` if special characters should be included; otherwise, `false`.
- `minLower` (`int`) `optional`
  The minimum number of lowercase characters in the result.
- `minUpper` (`int`) `optional`
  The minimum number of uppercase characters in the result.
- `minNumeric` (`int`) `optional`
  The minimum number of numeric characters in the result.
- `minSpecial` (`int`) `optional`
  The minimum number of special characters in the result.

## Returns

[ParameterResource](/reference/api/csharp/aspire.hosting/parameterresource.md) -- The created [ParameterResource](/reference/api/csharp/aspire.hosting/parameterresource.md).

## Remarks

To ensure the generated password has enough entropy, see the remarks in [GenerateParameterDefault](/reference/api/csharp/aspire.hosting/generateparameterdefault.md). The value will be saved to the app host project's user secrets store when [DistributedApplicationExecutionContext.IsRunMode](/reference/api/csharp/aspire.hosting/distributedapplicationexecutioncontext/properties.md#isrunmode) is `true`.

## CreateGeneratedParameter(IDistributedApplicationBuilder, string, bool, GenerateParameterDefault)

- Name: `CreateGeneratedParameter(IDistributedApplicationBuilder, string, bool, GenerateParameterDefault)`
- Modifiers: `static`
- Returns: [ParameterResource](/reference/api/csharp/aspire.hosting/parameterresource.md)
- Source: [GitHub](https://github.com/microsoft/aspire/blob/bd20f904cde09ecb9c9ae5116a6f13614bf2d7c2/src/Aspire.Hosting/ParameterResourceBuilderExtensions.cs#L403-L416)

Creates a new [ParameterResource](/reference/api/csharp/aspire.hosting/parameterresource.md) that has a generated value using the `parameterDefault`.

```csharp
public static class ParameterResourceBuilderExtensions
{
    public static ParameterResource CreateGeneratedParameter(
        IDistributedApplicationBuilder builder,
        string name,
        bool secret,
        GenerateParameterDefault parameterDefault)
    {
        // ...
    }
}
```

## Parameters

- `builder` ([IDistributedApplicationBuilder](/reference/api/csharp/aspire.hosting/idistributedapplicationbuilder.md))
  Distributed application builder
- `name` (`string`)
  Name of parameter resource
- `secret` (`bool`)
  Flag indicating whether the parameter should be regarded as secret.
- `parameterDefault` ([GenerateParameterDefault](/reference/api/csharp/aspire.hosting/generateparameterdefault.md))
  The [GenerateParameterDefault](/reference/api/csharp/aspire.hosting/generateparameterdefault.md) that describes how the parameter's value should be generated.

## Returns

[ParameterResource](/reference/api/csharp/aspire.hosting/parameterresource.md) -- The created [ParameterResource](/reference/api/csharp/aspire.hosting/parameterresource.md).

## Remarks

The value will be saved to the app host project's user secrets store when [DistributedApplicationExecutionContext.IsRunMode](/reference/api/csharp/aspire.hosting/distributedapplicationexecutioncontext/properties.md#isrunmode) is `true`.

## CreateParameter(IDistributedApplicationBuilder, string, bool)

- Name: `CreateParameter(IDistributedApplicationBuilder, string, bool)`
- Modifiers: `static`
- Returns: [ParameterResource](/reference/api/csharp/aspire.hosting/parameterresource.md)
- Source: [GitHub](https://github.com/microsoft/aspire/blob/bd20f904cde09ecb9c9ae5116a6f13614bf2d7c2/src/Aspire.Hosting/ParameterResourceBuilderExtensions.cs#L431-L436)

Creates a new [ParameterResource](/reference/api/csharp/aspire.hosting/parameterresource.md).

```csharp
public static class ParameterResourceBuilderExtensions
{
    public static ParameterResource CreateParameter(
        IDistributedApplicationBuilder builder,
        string name,
        bool secret)
    {
        // ...
    }
}
```

## Parameters

- `builder` ([IDistributedApplicationBuilder](/reference/api/csharp/aspire.hosting/idistributedapplicationbuilder.md))
  Distributed application builder
- `name` (`string`)
  Name of parameter resource
- `secret` (`bool`)
  Flag indicating whether the parameter should be regarded as secret.

## Returns

[ParameterResource](/reference/api/csharp/aspire.hosting/parameterresource.md) -- The created [ParameterResource](/reference/api/csharp/aspire.hosting/parameterresource.md).

## Remarks

The value will be saved to the app host project's user secrets store when [DistributedApplicationExecutionContext.IsRunMode](/reference/api/csharp/aspire.hosting/distributedapplicationexecutioncontext/properties.md#isrunmode) is `true`.

## PublishAsConnectionString(IResourceBuilder<T>)

- Name: `PublishAsConnectionString(IResourceBuilder<T>)`
- Modifiers: `extension`
- Returns: [IResourceBuilder<T>](/reference/api/csharp/aspire.hosting/iresourcebuilder-1.md)
- Source: [GitHub](https://github.com/microsoft/aspire/blob/bd20f904cde09ecb9c9ae5116a6f13614bf2d7c2/src/Aspire.Hosting/ParameterResourceBuilderExtensions.cs#L326-L329)

Changes the resource to be published as a connection string reference in the manifest.

```csharp
public static class ParameterResourceBuilderExtensions
{
    public static IResourceBuilder<T> PublishAsConnectionString<T>(
        this IResourceBuilder<T> builder)
    {
        // ...
    }
}
```

## Parameters

- `builder` ([IResourceBuilder<T>](/reference/api/csharp/aspire.hosting/iresourcebuilder-1.md))
  The resource builder.

## Returns

[IResourceBuilder<T>](/reference/api/csharp/aspire.hosting/iresourcebuilder-1.md) -- The configured `ApplicationModel.IResourceBuilder`1`.

## ATS metadata

### ATS export

- Available to Polyglot AppHosts through the Aspire Type System.

## WithCustomInput(IResourceBuilder<ParameterResource>, Func<ParameterResource, InteractionInput>)

> **Experimental:** ASPIREINTERACTION001 - [Learn more](/diagnostics/aspireinteraction001/)

- Name: `WithCustomInput(IResourceBuilder<ParameterResource>, Func<ParameterResource, InteractionInput>)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<ParameterResource>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/bd20f904cde09ecb9c9ae5116a6f13614bf2d7c2/src/Aspire.Hosting/ParameterResourceBuilderExtensions.cs#L238-L243)

Sets a custom input generator function for the parameter resource.

```csharp
public static class ParameterResourceBuilderExtensions
{
    public static IResourceBuilder<ParameterResource> WithCustomInput(
        this IResourceBuilder<ParameterResource> builder,
        Func<ParameterResource, InteractionInput> createInput)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IResourceBuilder<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.:

```csharp
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 app hosts.

## ATS metadata

### Ignored by ATS

- Reason: Complex Func delegate with InteractionInput -- not ATS-compatible.

## WithDescription(IResourceBuilder<ParameterResource>, string, bool)

- Name: `WithDescription(IResourceBuilder<ParameterResource>, string, bool)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<ParameterResource>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/bd20f904cde09ecb9c9ae5116a6f13614bf2d7c2/src/Aspire.Hosting/ParameterResourceBuilderExtensions.cs#L204-L210)

Sets the description of the parameter resource.

```csharp
public static class ParameterResourceBuilderExtensions
{
    public static IResourceBuilder<ParameterResource> WithDescription(
        this IResourceBuilder<ParameterResource> builder,
        string description,
        bool enableMarkdown = false)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IResourceBuilder<ParameterResource>`)
  Resource builder for the parameter.
- `description` (`string`)
  The parameter description.
- `enableMarkdown` (`bool`) `optional`
  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.

## ATS metadata

### ATS export

- Available to Polyglot AppHosts through the Aspire Type System.
