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) { // ... }}Parameters
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.Exceptions
ArgumentNullExceptionThrown if mandatory builder is null.InvalidOperationExceptionThrown when mandatory MongoDBSettings.ConnectionString is not provided.Remarks
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) { // ... }}Parameters
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.Exceptions
InvalidOperationExceptionThrown when mandatory MongoDBSettings.ConnectionString is not provided.Remarks
Reads the configuration from "Aspire:MongoDB:Driver" section.