40 lines
		
	
	
		
			1.6 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
			
		
		
	
	
			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;
 | |
|             }
 | |
|         }
 | |
|     }
 | |
| } | 
