Core.BluePrint.Packages/Core.Blueprint.Mongo/Provider/MongoProvider.cs
Sergio Matias Urquin 83fc1878c4 Add project files.
2025-04-29 18:42:29 -06:00

40 lines
1.6 KiB
C#

using MongoDB.Driver;
namespace Core.Blueprint.Mongo
{
/// <summary>
/// Provides the MongoDB provider and database connection using the specified configuration settings.
/// This class manages the connection to MongoDB and ensures that the correct credentials are used for authentication.
/// </summary>
public class MongoProvider
{
private readonly IMongoDatabase _database;
/// <summary>
/// Initializes a new instance of the <see cref="MongoProvider"/> class.
/// This constructor sets up the MongoDB provider using the connection string, audience, and other settings provided.
/// It also configures authentication using OpenID Connect (OIDC) credentials.
/// </summary>
/// <param name="mongoDbSettings">The MongoDB settings required for connecting to the database.</param>
public MongoProvider(IMongoDatabase database)
{
_database = database ?? throw new ArgumentNullException(nameof(database));
}
/// <summary>
/// Gets the initialized MongoDB database. If the database is not initialized, an exception is thrown.
/// </summary>
/// <exception cref="InvalidOperationException">Thrown when the database connection is not initialized.</exception>
protected IMongoDatabase Database
{
get
{
if (_database == null)
{
throw new InvalidOperationException("MongoDB connection is not initialized.");
}
return _database;
}
}
}
}