# IResourceWithConnectionString Methods

- Package: [Aspire.Hosting](/reference/api/csharp/aspire.hosting.md)
- Type: [IResourceWithConnectionString](/reference/api/csharp/aspire.hosting/iresourcewithconnectionstring.md)
- Kind: `Methods`
- Members: `2`

Represents a resource that has a connection string associated with it.

## GetConnectionProperties

- Name: `GetConnectionProperties`
- Modifiers: `virtual`
- Returns: `IEnumerable<KeyValuePair<string, ReferenceExpression>>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/bd20f904cde09ecb9c9ae5116a6f13614bf2d7c2/src/Aspire.Hosting/ApplicationModel/IResourceWithConnectionString.cs#L44)

Retrieves a collection of connection property name and value pairs associated with the current context.

```csharp
public interface IResourceWithConnectionString
{
    public virtual IEnumerable<KeyValuePair<string, ReferenceExpression>> GetConnectionProperties()
    {
        // ...
    }
}
```

## Returns

`IEnumerable<KeyValuePair<string, ReferenceExpression>>` -- An enumerable collection of key/value pairs, where each key is the name of a connection property and each value is its corresponding [ReferenceExpression](/reference/api/csharp/aspire.hosting/referenceexpression.md). The collection is empty if there are no connection properties.

## GetConnectionStringAsync(CancellationToken)

- Name: `GetConnectionStringAsync(CancellationToken)`
- Modifiers: `virtual`
- Returns: `ValueTask<string?>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/bd20f904cde09ecb9c9ae5116a6f13614bf2d7c2/src/Aspire.Hosting/ApplicationModel/IResourceWithConnectionString.cs#L17)

Gets the connection string associated with the resource.

```csharp
public interface IResourceWithConnectionString
{
    public virtual ValueTask<string?> GetConnectionStringAsync(
        CancellationToken cancellationToken = default(CancellationToken))
    {
        // ...
    }
}
```

## Parameters

- `cancellationToken` (`CancellationToken`) `optional`
  A `Threading.CancellationToken` to observe while waiting for the task to complete.

## Returns

`ValueTask<string?>` -- The connection string associated with the resource, when one is available.
