# RavenDBClientExtension Methods

- Package: [CommunityToolkit.Aspire.RavenDB.Client](/reference/api/csharp/communitytoolkit.aspire.ravendb.client.md)
- Type: [RavenDBClientExtension](/reference/api/csharp/communitytoolkit.aspire.ravendb.client/ravendbclientextension.md)
- Kind: `Methods`
- Members: `4`

Extension methods for connecting RavenDB database.

## AddKeyedRavenDBClient(IHostApplicationBuilder, object, string, Action<RavenDBClientSettings>)

- Name: `AddKeyedRavenDBClient(IHostApplicationBuilder, object, string, Action<RavenDBClientSettings>)`
- Modifiers: `extension`
- Source: [GitHub](https://github.com/CommunityToolkit/Aspire/blob/d9dc6fc02412d7398c5722840513d99965a6e98f/src/CommunityToolkit.Aspire.RavenDB.Client/RavenDBClientExtension.cs#L66-L69)

Registers `Documents.IDocumentStore` and the associated `Session.IDocumentSession` and `Session.IAsyncDocumentSession` instances for connecting to an existing or new RavenDB database with RavenDB.Client, identified by a unique service key.

```csharp
public static class RavenDBClientExtension
{
    public static void AddKeyedRavenDBClient(
        this IHostApplicationBuilder builder,
        object serviceKey,
        string connectionName,
        Action<RavenDBClientSettings>? configureSettings = null)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IHostApplicationBuilder`)
  The `Hosting.IHostApplicationBuilder` used to add services.
- `serviceKey` (`object`)
  A unique key that identifies this instance of the RavenDB client service.
- `connectionName` (`string`)
  The name used to retrieve the connection string from the "ConnectionStrings" configuration section.
- `configureSettings` (`Action<RavenDBClientSettings>`) `optional`
  An optional delegate that can be used for customizing options. It is invoked after the settings are read from the configuration.

## Remarks

Notes:

- Reads the configuration from "Aspire:RavenDB:Client" section.
- The `Documents.IDocumentStore` is registered as a singleton, meaning a single instance is shared throughout the application's lifetime, while `Session.IDocumentSession` and `Session.IAsyncDocumentSession` are registered per request to ensure short-lived session instances for each use.

## AddKeyedRavenDBClient(IHostApplicationBuilder, object, RavenDBClientSettings)

- Name: `AddKeyedRavenDBClient(IHostApplicationBuilder, object, RavenDBClientSettings)`
- Modifiers: `extension`
- Source: [GitHub](https://github.com/CommunityToolkit/Aspire/blob/d9dc6fc02412d7398c5722840513d99965a6e98f/src/CommunityToolkit.Aspire.RavenDB.Client/RavenDBClientExtension.cs#L112-L113)

Registers `Documents.IDocumentStore` and the associated `Session.IDocumentSession` and `Session.IAsyncDocumentSession` instances for connecting to an existing or new RavenDB database with RavenDB.Client, identified by a unique service key.

```csharp
public static class RavenDBClientExtension
{
    public static void AddKeyedRavenDBClient(
        this IHostApplicationBuilder builder,
        object serviceKey,
        RavenDBClientSettings settings)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IHostApplicationBuilder`)
  The `Hosting.IHostApplicationBuilder` used to add services.
- `serviceKey` (`object`)
  A unique key that identifies this instance of the RavenDB client service.
- `settings` ([RavenDBClientSettings](/reference/api/csharp/communitytoolkit.aspire.ravendb.client/ravendbclientsettings.md))
  The settings required to configure the `Documents.IDocumentStore`.

## Remarks

Notes:

- If [RavenDBClientSettings.DatabaseName](/reference/api/csharp/communitytoolkit.aspire.ravendb.client/ravendbclientsettings/properties.md#databasename) is not specified and [RavenDBClientSettings.CreateDatabase](/reference/api/csharp/communitytoolkit.aspire.ravendb.client/ravendbclientsettings/properties.md#createdatabase) is set to 'false', `Session.IDocumentSession` and `Session.IAsyncDocumentSession` will not be registered.
- The `Documents.IDocumentStore` is registered as a singleton, meaning a single instance is shared throughout the application's lifetime, while `Session.IDocumentSession` and `Session.IAsyncDocumentSession` are registered per request to ensure short-lived session instances for each use.

## AddRavenDBClient(IHostApplicationBuilder, string, Action<RavenDBClientSettings>)

- Name: `AddRavenDBClient(IHostApplicationBuilder, string, Action<RavenDBClientSettings>)`
- Modifiers: `extension`
- Source: [GitHub](https://github.com/CommunityToolkit/Aspire/blob/d9dc6fc02412d7398c5722840513d99965a6e98f/src/CommunityToolkit.Aspire.RavenDB.Client/RavenDBClientExtension.cs#L40-L43)

Registers `Documents.IDocumentStore` and the associated `Session.IDocumentSession` and `Session.IAsyncDocumentSession` instances for connecting to an existing or new RavenDB database with RavenDB.Client.

```csharp
public static class RavenDBClientExtension
{
    public static void AddRavenDBClient(
        this IHostApplicationBuilder builder,
        string connectionName,
        Action<RavenDBClientSettings>? configureSettings = null)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IHostApplicationBuilder`)
  The `Hosting.IHostApplicationBuilder` used to add services.
- `connectionName` (`string`)
  The name used to retrieve the connection string from the "ConnectionStrings" configuration section.
- `configureSettings` (`Action<RavenDBClientSettings>`) `optional`
  An optional delegate that can be used for customizing options. It is invoked after the settings are read from the configuration.

## Remarks

Notes:

- Reads the configuration from "Aspire:RavenDB:Client" section.
- The `Documents.IDocumentStore` is registered as a singleton, meaning a single instance is shared throughout the application's lifetime, while `Session.IDocumentSession` and `Session.IAsyncDocumentSession` are registered per request to ensure short-lived session instances for each use.

## AddRavenDBClient(IHostApplicationBuilder, RavenDBClientSettings)

- Name: `AddRavenDBClient(IHostApplicationBuilder, RavenDBClientSettings)`
- Modifiers: `extension`
- Source: [GitHub](https://github.com/CommunityToolkit/Aspire/blob/d9dc6fc02412d7398c5722840513d99965a6e98f/src/CommunityToolkit.Aspire.RavenDB.Client/RavenDBClientExtension.cs#L89-L90)

Registers `Documents.IDocumentStore` and the associated `Session.IDocumentSession` and `Session.IAsyncDocumentSession` instances for connecting to an existing or new RavenDB database with RavenDB.Client.

```csharp
public static class RavenDBClientExtension
{
    public static void AddRavenDBClient(
        this IHostApplicationBuilder builder,
        RavenDBClientSettings settings)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IHostApplicationBuilder`)
  The `Hosting.IHostApplicationBuilder` used to add services.
- `settings` ([RavenDBClientSettings](/reference/api/csharp/communitytoolkit.aspire.ravendb.client/ravendbclientsettings.md))
  The settings required to configure the `Documents.IDocumentStore`.

## Remarks

Notes:

- If [RavenDBClientSettings.DatabaseName](/reference/api/csharp/communitytoolkit.aspire.ravendb.client/ravendbclientsettings/properties.md#databasename) is not specified and [RavenDBClientSettings.CreateDatabase](/reference/api/csharp/communitytoolkit.aspire.ravendb.client/ravendbclientsettings/properties.md#createdatabase) is set to 'false', `Session.IDocumentSession` and `Session.IAsyncDocumentSession` will not be registered.
- The `Documents.IDocumentStore` is registered as a singleton, meaning a single instance is shared throughout the application's lifetime, while `Session.IDocumentSession` and `Session.IAsyncDocumentSession` are registered per request to ensure short-lived session instances for each use.
