# DbGateBuilderExtensions Methods

- Package: [CommunityToolkit.Aspire.Hosting.DbGate](/reference/api/csharp/communitytoolkit.aspire.hosting.dbgate.md)
- Type: [DbGateBuilderExtensions](/reference/api/csharp/communitytoolkit.aspire.hosting.dbgate/dbgatebuilderextensions.md)
- Kind: `Methods`
- Members: `5`

Provides extension methods for DbGate resources to an `Hosting.IDistributedApplicationBuilder`.

## AddDbGate(IDistributedApplicationBuilder, string, int?)

- Name: `AddDbGate(IDistributedApplicationBuilder, string, int?)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<DbGateContainerResource>`
- Source: [GitHub](https://github.com/CommunityToolkit/Aspire/blob/d9dc6fc02412d7398c5722840513d99965a6e98f/src/CommunityToolkit.Aspire.Hosting.DbGate/DbGateBuilderExtensions.cs#L74-L93)

Adds a DbGate container resource to the application.

```csharp
public static class DbGateBuilderExtensions
{
    public static IResourceBuilder<DbGateContainerResource> AddDbGate(
        this IDistributedApplicationBuilder builder,
        string name = "dbgate",
        int? port = null)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IDistributedApplicationBuilder`)
  The resource builder.
- `name` (`string`) `optional`
  The name of the resource. This name will be used as the connection string name when referenced in a dependency. Optional; defaults to `dbgate`.
- `port` (`int?`) `optional`
  The host port to bind the underlying container to.

## Returns

`IResourceBuilder<DbGateContainerResource>` -- A reference to the `ApplicationModel.IResourceBuilder`1`.

## Remarks

Multiple [DbGateBuilderExtensions.AddDbGate(IDistributedApplicationBuilder, string, int?)](/reference/api/csharp/communitytoolkit.aspire.hosting.dbgate/dbgatebuilderextensions/methods.md#adddbgate-idistributedapplicationbuilder-string-int) calls will return the same resource builder instance.

## ATS metadata

### ATS export

- Available to Polyglot AppHosts through the Aspire Type System.

## SanitizeConnectionId(string)

- Name: `SanitizeConnectionId(string)`
- Modifiers: `static`
- Returns: `string`
- Source: [GitHub](https://github.com/CommunityToolkit/Aspire/blob/d9dc6fc02412d7398c5722840513d99965a6e98f/src/CommunityToolkit.Aspire.Hosting.DbGate/DbGateBuilderExtensions.cs#L115-L116)

Sanitizes a resource name to be used as a connection ID in DbGate environment variables.

```csharp
public static class DbGateBuilderExtensions
{
    public static string SanitizeConnectionId(
        string resourceName)
    {
        // ...
    }
}
```

## Parameters

- `resourceName` (`string`)
  The resource name to sanitize.

## Returns

`string` -- A sanitized connection ID safe for use in environment variable names.

## Remarks

This method performs basic sanitization by replacing hyphens with underscores, as hyphens are not valid in Linux environment variable names.

Note: Linux environment variable names have additional constraints (must contain only letters, numbers, and underscores, and cannot start with a number). This method does not validate or enforce these additional constraints. Resource names should follow standard naming conventions to ensure compatibility.

## WithDataBindMount(IResourceBuilder<DbGateContainerResource>, string, bool)

- Name: `WithDataBindMount(IResourceBuilder<DbGateContainerResource>, string, bool)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<DbGateContainerResource>`
- Source: [GitHub](https://github.com/CommunityToolkit/Aspire/blob/d9dc6fc02412d7398c5722840513d99965a6e98f/src/CommunityToolkit.Aspire.Hosting.DbGate/DbGateBuilderExtensions.cs#L55-L58)

Adds a bind mount for the data folder to a DbGate container resource.

```csharp
public static class DbGateBuilderExtensions
{
    public static IResourceBuilder<DbGateContainerResource> WithDataBindMount(
        this IResourceBuilder<DbGateContainerResource> builder,
        string source,
        bool isReadOnly = false)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IResourceBuilder<DbGateContainerResource>`)
  The resource builder.
- `source` (`string`)
  The source directory on the host to mount into the container.
- `isReadOnly` (`bool`) `optional`
  A flag that indicates if this is a read-only mount.

## Returns

`IResourceBuilder<DbGateContainerResource>` -- The `ApplicationModel.IResourceBuilder`1`.

## ATS metadata

### ATS export

- Available to Polyglot AppHosts through the Aspire Type System.

## WithDataVolume(IResourceBuilder<DbGateContainerResource>, string?, bool)

- Name: `WithDataVolume(IResourceBuilder<DbGateContainerResource>, string?, bool)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<DbGateContainerResource>`
- Source: [GitHub](https://github.com/CommunityToolkit/Aspire/blob/d9dc6fc02412d7398c5722840513d99965a6e98f/src/CommunityToolkit.Aspire.Hosting.DbGate/DbGateBuilderExtensions.cs#L40-L42)

Adds a named volume for the data folder to a DbGate container resource.

```csharp
public static class DbGateBuilderExtensions
{
    public static IResourceBuilder<DbGateContainerResource> WithDataVolume(
        this IResourceBuilder<DbGateContainerResource> builder,
        string? name = null,
        bool isReadOnly = false)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IResourceBuilder<DbGateContainerResource>`)
  The resource builder.
- `name` (`string?`) `optional`
  The name of the volume. Defaults to an auto-generated name based on the application and resource names.
- `isReadOnly` (`bool`) `optional`
  A flag that indicates if this is a read-only volume.

## Returns

`IResourceBuilder<DbGateContainerResource>` -- The `ApplicationModel.IResourceBuilder`1`.

## ATS metadata

### ATS export

- Available to Polyglot AppHosts through the Aspire Type System.

## WithHostPort(IResourceBuilder<DbGateContainerResource>, int?)

- Name: `WithHostPort(IResourceBuilder<DbGateContainerResource>, int?)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<DbGateContainerResource>`
- Source: [GitHub](https://github.com/CommunityToolkit/Aspire/blob/d9dc6fc02412d7398c5722840513d99965a6e98f/src/CommunityToolkit.Aspire.Hosting.DbGate/DbGateBuilderExtensions.cs#L22-L27)

Configures the host port that the DbGate resource is exposed on instead of using randomly assigned port.

```csharp
public static class DbGateBuilderExtensions
{
    public static IResourceBuilder<DbGateContainerResource> WithHostPort(
        this IResourceBuilder<DbGateContainerResource> builder,
        int? port)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IResourceBuilder<DbGateContainerResource>`)
  The resource builder for DbGate.
- `port` (`int?`)
  The port to bind on the host. If `null` is used random port will be assigned.

## Returns

`IResourceBuilder<DbGateContainerResource>` -- The resource builder for DbGate.

## ATS metadata

### ATS export

- Available to Polyglot AppHosts through the Aspire Type System.
