Partager via


AspireMongoDBDriverExtensions.AddKeyedMongoDBClient Method

Definition

Registers MongoDB.Driver.IMongoClient and MongoDB.Driver.IMongoDatabase instances for connecting MongoDB database with MongoDB.Driver client.

public static void AddKeyedMongoDBClient (this Microsoft.Extensions.Hosting.IHostApplicationBuilder builder, string name, Action<Aspire.MongoDB.Driver.MongoDBSettings>? configureSettings = default, Action<MongoDB.Driver.MongoClientSettings>? configureClientSettings = default);
static member AddKeyedMongoDBClient : Microsoft.Extensions.Hosting.IHostApplicationBuilder * string * Action<Aspire.MongoDB.Driver.MongoDBSettings> * Action<MongoDB.Driver.MongoClientSettings> -> unit
<Extension()>
Public Sub AddKeyedMongoDBClient (builder As IHostApplicationBuilder, name As String, Optional configureSettings As Action(Of MongoDBSettings) = Nothing, Optional configureClientSettings As Action(Of MongoClientSettings) = Nothing)

Parameters

builder
IHostApplicationBuilder

The IHostApplicationBuilder to read config from and add services to.

name
String

The name of the component, which is used as the ServiceKey of the service and also to retrieve the connection string from the ConnectionStrings configuration section.

configureSettings
Action<MongoDBSettings>

An optional delegate that can be used for customizing options. It's invoked after the settings are read from the configuration.

configureClientSettings
Action<MongoDB.Driver.MongoClientSettings>

An optional delegate that can be used for customizing MongoClientSettings.

Exceptions

Thrown if mandatory builder is null.

Thrown when mandatory ConnectionString is not provided.

Remarks

Reads the configuration from "Aspire:MongoDB:Driver:{name}" section.

Applies to