Skip to content
DocsTry Aspire
DocsTry

AspireMongoDBDriverExtensions Methods

ClassMethods2 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)
{
// ...
}
}
builderIHostApplicationBuilderThe Hosting.IHostApplicationBuilder to read config from and add services to.
namestringThe 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.
configureSettingsAction<MongoDBSettings>optionalAn optional delegate that can be used for customizing options. It's invoked after the settings are read from the configuration.
configureClientSettingsAction<MongoClientSettings>optionalAn optional delegate that can be used for customizing MongoClientSettings.
ArgumentNullExceptionThrown if mandatory builder is null.
InvalidOperationExceptionThrown 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)
{
// ...
}
}
builderIHostApplicationBuilderThe Hosting.IHostApplicationBuilder to read config from and add services to.
connectionNamestringA name used to retrieve the connection string from the ConnectionStrings configuration section.
configureSettingsAction<MongoDBSettings>optionalAn optional delegate that can be used for customizing options. It's invoked after the settings are read from the configuration.
configureClientSettingsAction<MongoClientSettings>optionalAn optional delegate that can be used for customizing MongoClientSettings.
InvalidOperationExceptionThrown when mandatory MongoDBSettings.ConnectionString is not provided.
Reads the configuration from "Aspire:MongoDB:Driver" section.