次の方法で共有


AspireMongoDBDriverExtensions.AddMongoDBClient Method

Definition

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

public static void AddMongoDBClient (this Microsoft.Extensions.Hosting.IHostApplicationBuilder builder, string connectionName, Action<Aspire.MongoDB.Driver.MongoDBSettings>? configureSettings = default, Action<MongoDB.Driver.MongoClientSettings>? configureClientSettings = default);
static member AddMongoDBClient : Microsoft.Extensions.Hosting.IHostApplicationBuilder * string * Action<Aspire.MongoDB.Driver.MongoDBSettings> * Action<MongoDB.Driver.MongoClientSettings> -> unit
<Extension()>
Public Sub AddMongoDBClient (builder As IHostApplicationBuilder, connectionName 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.

connectionName
String

A name used 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 when mandatory ConnectionString is not provided.

Remarks

Reads the configuration from "Aspire:MongoDB:Driver" section.

Applies to