# 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: `4`

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/67afcca30f02c18687f9c5219313710af9706630/src/CommunityToolkit.Aspire.Hosting.DbGate/DbGateBuilderExtensions.cs#L68-L87)

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.

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

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

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

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

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

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

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

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

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.
