Add project files.
This commit is contained in:
		
							
								
								
									
										66
									
								
								Core.Blueprint.Mongo/Context/MongoContext.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										66
									
								
								Core.Blueprint.Mongo/Context/MongoContext.cs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,66 @@ | ||||
| using Microsoft.Extensions.Configuration; | ||||
|  | ||||
| namespace Core.Blueprint.Mongo | ||||
| { | ||||
|     /// <summary> | ||||
|     /// The <see cref="MongoContext"/> class represents the MongoDB context that contains the connection information,  | ||||
|     /// including the connection string, database name, and audience. | ||||
|     /// It implements the <see cref="IMongoContext"/> interface to provide methods for accessing these values. | ||||
|     /// </summary> | ||||
|     public sealed class MongoContext : IMongoContext | ||||
|     { | ||||
|         /// <summary> | ||||
|         /// Gets or sets the connection string used to connect to the MongoDB instance. | ||||
|         /// </summary> | ||||
|         public string ConnectionString { get; set; } = string.Empty; | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Gets or sets the name of the MongoDB database. | ||||
|         /// </summary> | ||||
|         public string Databasename { get; set; } = string.Empty; | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Gets or sets the audience (resource identifier) used for MongoDB authentication. | ||||
|         /// </summary> | ||||
|         public string Audience { get; set; } = string.Empty; | ||||
|  | ||||
|         private readonly IConfiguration configuration; | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Initializes a new instance of the <see cref="MongoContext"/> class using the provided <see cref="IConfiguration"/>. | ||||
|         /// The configuration is used to retrieve MongoDB connection settings. | ||||
|         /// </summary> | ||||
|         /// <param name="configuration">The configuration used to retrieve the MongoDB connection settings.</param> | ||||
|         public MongoContext(IConfiguration configuration) | ||||
|         { | ||||
|             this.configuration = configuration; | ||||
|         } | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Retrieves the MongoDB connection string from the configuration. | ||||
|         /// </summary> | ||||
|         /// <returns>The MongoDB connection string, or an empty string if not found.</returns> | ||||
|         public string GetConnectionString() | ||||
|         { | ||||
|             return configuration.GetConnectionString("MongoDb:ConnectionString")?.ToString() ?? string.Empty; | ||||
|         } | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Retrieves the MongoDB database name from the configuration. | ||||
|         /// </summary> | ||||
|         /// <returns>The MongoDB database name, or an empty string if not found.</returns> | ||||
|         public string GetDatabasename() | ||||
|         { | ||||
|             return configuration.GetSection("MongoDb:DatabaseName").Value ?? string.Empty; | ||||
|         } | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Retrieves the MongoDB audience (resource identifier) from the configuration. | ||||
|         /// </summary> | ||||
|         /// <returns>The MongoDB audience, or an empty string if not found.</returns> | ||||
|         public string GetAudience() | ||||
|         { | ||||
|             return configuration.GetSection("MongoDb:Audience").Value ?? string.Empty; | ||||
|         } | ||||
|     } | ||||
| } | ||||
							
								
								
									
										25
									
								
								Core.Blueprint.Mongo/Context/MongoDbSettings.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										25
									
								
								Core.Blueprint.Mongo/Context/MongoDbSettings.cs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,25 @@ | ||||
| namespace Core.Blueprint.Mongo | ||||
| { | ||||
|     /// <summary> | ||||
|     /// Represents the MongoDB configuration settings, including the connection string,  | ||||
|     /// database name, and audience, used for connecting and authenticating to a MongoDB instance. | ||||
|     /// Implements the <see cref="IMongoDbSettings"/> interface to provide a strongly typed configuration. | ||||
|     /// </summary> | ||||
|     public class MongoDbSettings : IMongoDbSettings | ||||
|     { | ||||
|         /// <summary> | ||||
|         /// Gets or sets the connection string used to connect to the MongoDB instance. | ||||
|         /// </summary> | ||||
|         public string ConnectionString { get; set; } = string.Empty; | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Gets or sets the name of the MongoDB database to connect to. | ||||
|         /// </summary> | ||||
|         public string Databasename { get; set; } = string.Empty; | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Gets or sets the audience (resource identifier) used for MongoDB authentication. | ||||
|         /// </summary> | ||||
|         public string Audience { get; set; } = string.Empty; | ||||
|     } | ||||
| } | ||||
		Reference in New Issue
	
	Block a user
	 Sergio Matias Urquin
					Sergio Matias Urquin