# RavenDBBuilderExtensions Methods

- Package: [CommunityToolkit.Aspire.Hosting.RavenDB](/reference/api/csharp/communitytoolkit.aspire.hosting.ravendb.md)
- Type: [RavenDBBuilderExtensions](/reference/api/csharp/communitytoolkit.aspire.hosting.ravendb/ravendbbuilderextensions.md)
- Kind: `Methods`
- Members: `8`

Provides extension methods for adding RavenDB resources to an `Hosting.IDistributedApplicationBuilder`.

## AddDatabase(IResourceBuilder<RavenDBServerResource>, string, string?, bool)

- Name: `AddDatabase(IResourceBuilder<RavenDBServerResource>, string, string?, bool)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<RavenDBDatabaseResource>`
- Source: [GitHub](https://github.com/CommunityToolkit/Aspire/blob/d9dc6fc02412d7398c5722840513d99965a6e98f/src/CommunityToolkit.Aspire.Hosting.RavenDB/RavenDBBuilderExtensions.cs#L230-L286)

Adds a database resource to an existing RavenDB server resource.

```csharp
public static class RavenDBBuilderExtensions
{
    public static IResourceBuilder<RavenDBDatabaseResource> AddDatabase(
        this IResourceBuilder<RavenDBServerResource> builder,
        string name,
        string? databaseName = null,
        bool ensureCreated = false)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IResourceBuilder<RavenDBServerResource>`)
  The resource builder for the RavenDB server.
- `name` (`string`)
  The name of the database resource.
- `databaseName` (`string?`) `optional`
  The name of the database to create/add. Defaults to the same name as the resource if not provided.
- `ensureCreated` (`bool`) `optional`
  Indicates whether the database should be created on startup if it does not already exist.

## Returns

`IResourceBuilder<RavenDBDatabaseResource>` -- A resource builder for the newly added RavenDB database resource.

## Exceptions

- `DistributedApplicationException` -- Thrown when the connection string cannot be retrieved during configuration.
- `InvalidOperationException` -- Thrown when the connection string is unavailable.

## ATS metadata

### ATS export

- Available to Polyglot AppHosts through the Aspire Type System.

## AddRavenDB(IDistributedApplicationBuilder, string)

- Name: `AddRavenDB(IDistributedApplicationBuilder, string)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<RavenDBServerResource>`
- Source: [GitHub](https://github.com/CommunityToolkit/Aspire/blob/d9dc6fc02412d7398c5722840513d99965a6e98f/src/CommunityToolkit.Aspire.Hosting.RavenDB/RavenDBBuilderExtensions.cs#L39-L41)

Adds a RavenDB server resource to the application model. A container is used for local development. This overload simplifies the configuration by creating an unsecured RavenDB server resource with default settings.

```csharp
public static class RavenDBBuilderExtensions
{
    public static IResourceBuilder<RavenDBServerResource> AddRavenDB(
        this IDistributedApplicationBuilder builder,
        string name)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IDistributedApplicationBuilder`)
  The `Hosting.IDistributedApplicationBuilder` to which the resource is added.
- `name` (`string`)
  The name of the RavenDB server resource.

## Returns

`IResourceBuilder<RavenDBServerResource>` -- A resource builder for the newly added RavenDB server resource.

## Exceptions

- `ArgumentNullException` -- Thrown if `builder` is null.

## Remarks

Note: When using this method, a valid RavenDB license must be provided as an environment variable before calling the `IDistributedApplicationBuilder.Build` and `DistributedApplication.Run` methods. You can set the license by calling:

```csharp
builder.WithEnvironment("RAVEN_License", "{your license}");
```

## ATS metadata

### ATS export

- Available to Polyglot AppHosts through the Aspire Type System.

## AddRavenDB(IDistributedApplicationBuilder, string, RavenDBServerSettings)

- Name: `AddRavenDB(IDistributedApplicationBuilder, string, RavenDBServerSettings)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<RavenDBServerResource>`
- Source: [GitHub](https://github.com/CommunityToolkit/Aspire/blob/d9dc6fc02412d7398c5722840513d99965a6e98f/src/CommunityToolkit.Aspire.Hosting.RavenDB/RavenDBBuilderExtensions.cs#L62-L74)

Adds a RavenDB server resource to the application model. A container is used for local development. This version of the package defaults to the tag of the container image. This overload simplifies configuration by accepting a [RavenDBServerSettings](/reference/api/csharp/communitytoolkit.aspire.hosting.ravendb/ravendbserversettings.md) object to specify server settings.

```csharp
public static class RavenDBBuilderExtensions
{
    public static IResourceBuilder<RavenDBServerResource> AddRavenDB(
        this IDistributedApplicationBuilder builder,
        string name,
        RavenDBServerSettings serverSettings)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IDistributedApplicationBuilder`)
  The `Hosting.IDistributedApplicationBuilder`
- `name` (`string`)
  The name of the RavenDB server resource.
- `serverSettings` ([RavenDBServerSettings](/reference/api/csharp/communitytoolkit.aspire.hosting.ravendb/ravendbserversettings.md))
  An object of type [RavenDBServerSettings](/reference/api/csharp/communitytoolkit.aspire.hosting.ravendb/ravendbserversettings.md) containing configuration details for the RavenDB server, such as whether the server should use HTTPS, RavenDB license and other relevant settings.

## Returns

`IResourceBuilder<RavenDBServerResource>` -- A resource builder for the newly added RavenDB server resource.

## Exceptions

- `DistributedApplicationException` -- Thrown when the connection string cannot be retrieved during configuration.
- `InvalidOperationException` -- Thrown when the connection string is unavailable.

## Remarks

This overload is not available in polyglot app hosts.

## ATS metadata

### Ignored by ATS

- Excluded from automatic Polyglot export.

## AddRavenDB(IDistributedApplicationBuilder, string, bool, Dictionary<string, object>, int?)

- Name: `AddRavenDB(IDistributedApplicationBuilder, string, bool, Dictionary<string, object>, int?)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<RavenDBServerResource>`
- Source: [GitHub](https://github.com/CommunityToolkit/Aspire/blob/d9dc6fc02412d7398c5722840513d99965a6e98f/src/CommunityToolkit.Aspire.Hosting.RavenDB/RavenDBBuilderExtensions.cs#L97-L102)

Adds a RavenDB server resource to the application model. A container is used for local development. This version of the package defaults to the tag of the container image.

```csharp
public static class RavenDBBuilderExtensions
{
    public static IResourceBuilder<RavenDBServerResource> AddRavenDB(
        this IDistributedApplicationBuilder builder,
        string name,
        bool secured,
        Dictionary<string, object> environmentVariables,
        int? port = null)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IDistributedApplicationBuilder`)
  The `Hosting.IDistributedApplicationBuilder`
- `name` (`string`)
  The name of the RavenDB server resource.
- `secured` (`bool`)
  Indicates whether the server connection should be secured (HTTPS). Defaults to false.
- `environmentVariables` (`Dictionary<string, object>`)
  The environment variables to configure the RavenDB server.
- `port` (`int?`) `optional`
  Optional port for the server. If not provided, defaults to the container's internal port (8080).

## Returns

`IResourceBuilder<RavenDBServerResource>` -- A resource builder for the newly added RavenDB server resource.

## Exceptions

- `DistributedApplicationException` -- Thrown when the connection string cannot be retrieved during configuration.
- `InvalidOperationException` -- Thrown when the connection string is unavailable.

## Remarks

This overload is not available in polyglot app hosts.

## ATS metadata

### Ignored by ATS

- Excluded from automatic Polyglot export.

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

- Name: `WithDataBindMount(IResourceBuilder<RavenDBServerResource>, string, bool)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<RavenDBServerResource>`
- Source: [GitHub](https://github.com/CommunityToolkit/Aspire/blob/d9dc6fc02412d7398c5722840513d99965a6e98f/src/CommunityToolkit.Aspire.Hosting.RavenDB/RavenDBBuilderExtensions.cs#L299-L302)

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

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

## Parameters

- `builder` (`IResourceBuilder<RavenDBServerResource>`)
  The resource builder for the RavenDB server.
- `source` (`string`)
  The source directory on the host to mount into the container.
- `isReadOnly` (`bool`) `optional`
  Indicates whether the bind mount should be read-only. Defaults to false.

## Returns

`IResourceBuilder<RavenDBServerResource>` -- The `ApplicationModel.IResourceBuilder`1` for the RavenDB server resource.

## ATS metadata

### ATS export

- Available to Polyglot AppHosts through the Aspire Type System.

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

- Name: `WithDataVolume(IResourceBuilder<RavenDBServerResource>, string?, bool)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<RavenDBServerResource>`
- Source: [GitHub](https://github.com/CommunityToolkit/Aspire/blob/d9dc6fc02412d7398c5722840513d99965a6e98f/src/CommunityToolkit.Aspire.Hosting.RavenDB/RavenDBBuilderExtensions.cs#L315-L317)

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

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

## Parameters

- `builder` (`IResourceBuilder<RavenDBServerResource>`)
  The resource builder for the RavenDB server.
- `name` (`string?`) `optional`
  Optional name for the volume. Defaults to a generated name if not provided.
- `isReadOnly` (`bool`) `optional`
  Indicates whether the volume should be read-only. Defaults to false.

## Returns

`IResourceBuilder<RavenDBServerResource>` -- The `ApplicationModel.IResourceBuilder`1` for the RavenDB server resource.

## ATS metadata

### ATS export

- Available to Polyglot AppHosts through the Aspire Type System.

## WithLogBindMount(IResourceBuilder<RavenDBServerResource>, string, bool)

- Name: `WithLogBindMount(IResourceBuilder<RavenDBServerResource>, string, bool)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<RavenDBServerResource>`
- Source: [GitHub](https://github.com/CommunityToolkit/Aspire/blob/d9dc6fc02412d7398c5722840513d99965a6e98f/src/CommunityToolkit.Aspire.Hosting.RavenDB/RavenDBBuilderExtensions.cs#L333-L336)

Adds a bind mount for the logs folder to a RavenDB container resource.

```csharp
public static class RavenDBBuilderExtensions
{
    public static IResourceBuilder<RavenDBServerResource> WithLogBindMount(
        this IResourceBuilder<RavenDBServerResource> builder,
        string source,
        bool isReadOnly = false)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IResourceBuilder<RavenDBServerResource>`)
  The resource builder for the RavenDB server.
- `source` (`string`)
  The source directory on the host to mount into the container.
- `isReadOnly` (`bool`) `optional`
  Indicates whether the bind mount should be read-only. Defaults to false.

## Returns

`IResourceBuilder<RavenDBServerResource>` -- The `ApplicationModel.IResourceBuilder`1` for the RavenDB server resource.

## ATS metadata

### ATS export

- Available to Polyglot AppHosts through the Aspire Type System.

## WithLogVolume(IResourceBuilder<RavenDBServerResource>, string?, bool)

- Name: `WithLogVolume(IResourceBuilder<RavenDBServerResource>, string?, bool)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<RavenDBServerResource>`
- Source: [GitHub](https://github.com/CommunityToolkit/Aspire/blob/d9dc6fc02412d7398c5722840513d99965a6e98f/src/CommunityToolkit.Aspire.Hosting.RavenDB/RavenDBBuilderExtensions.cs#L354-L356)

Adds a named volume for the logs folder to a RavenDB container resource.

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

## Parameters

- `builder` (`IResourceBuilder<RavenDBServerResource>`)
  The resource builder for the RavenDB server.
- `name` (`string?`) `optional`
  Optional name for the volume. Defaults to a generated name if not provided.
- `isReadOnly` (`bool`) `optional`
  Indicates whether the volume should be read-only. Defaults to false.

## Returns

`IResourceBuilder<RavenDBServerResource>` -- The `ApplicationModel.IResourceBuilder`1` for the RavenDB server resource.

## ATS metadata

### ATS export

- Available to Polyglot AppHosts through the Aspire Type System.
