Add project files.
This commit is contained in:
		
							
								
								
									
										40
									
								
								Core.Blueprint.Mongo/Provider/MongoProvider.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										40
									
								
								Core.Blueprint.Mongo/Provider/MongoProvider.cs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,40 @@ | ||||
| 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; | ||||
|             } | ||||
|         } | ||||
|     } | ||||
| } | ||||
		Reference in New Issue
	
	Block a user
	 Sergio Matias Urquin
					Sergio Matias Urquin