Skip to content
Docs Try Aspire

AspireMongoDBDriverExtensions Methods

Class Methods 2 members
Extension methods for connecting MongoDB database with MongoDB.Driver client.
AddKeyedMongoDBClient(IHostApplicationBuilder, string, Action<MongoDBSettings>, Action<MongoClientSettings>) Section titled AddKeyedMongoDBClient(IHostApplicationBuilder, string, Action<MongoDBSettings>, Action<MongoClientSettings>) extension
Registers Driver.IMongoClient and Driver.IMongoDatabase instances for connecting MongoDB database with MongoDB.Driver client.
public static class AspireMongoDBDriverExtensions
{
public static void AddKeyedMongoDBClient(
this IHostApplicationBuilder builder,
string name,
Action<MongoDBSettings>? configureSettings = null,
Action<MongoClientSettings>? configureClientSettings = null)
{
// ...
}
}
builder IHostApplicationBuilder The Hosting.IHostApplicationBuilder to read config from and add services to.
name string The name of the component, which is used as the ServiceDescriptor.ServiceKey of the service and also to retrieve the connection string from the ConnectionStrings configuration section.
configureSettings Action<MongoDBSettings> optional An optional delegate that can be used for customizing options. It's invoked after the settings are read from the configuration.
configureClientSettings Action<MongoClientSettings> optional An optional delegate that can be used for customizing MongoClientSettings.
ArgumentNullException Thrown if mandatory builder is null.
InvalidOperationException Thrown when mandatory MongoDBSettings.ConnectionString is not provided.
Reads the configuration from "Aspire:MongoDB:Driver:{name}" section.
AddMongoDBClient(IHostApplicationBuilder, string, Action<MongoDBSettings>, Action<MongoClientSettings>) Section titled AddMongoDBClient(IHostApplicationBuilder, string, Action<MongoDBSettings>, Action<MongoClientSettings>) extension
Registers Driver.IMongoClient and Driver.IMongoDatabase instances for connecting MongoDB database with MongoDB.Driver client.
public static class AspireMongoDBDriverExtensions
{
public static void AddMongoDBClient(
this IHostApplicationBuilder builder,
string connectionName,
Action<MongoDBSettings>? configureSettings = null,
Action<MongoClientSettings>? configureClientSettings = null)
{
// ...
}
}
builder IHostApplicationBuilder The Hosting.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> optional An optional delegate that can be used for customizing options. It's invoked after the settings are read from the configuration.
configureClientSettings Action<MongoClientSettings> optional An optional delegate that can be used for customizing MongoClientSettings.
InvalidOperationException Thrown when mandatory MongoDBSettings.ConnectionString is not provided.
Reads the configuration from "Aspire:MongoDB:Driver" section.