26.32. Class MongoCollectionProvider<TData, TModelMapping>

Namespace: ArmoniK.Core.Adapters.MongoDB.Common
Assembly: ArmoniK.Core.Adapters.MongoDB.dll

Provides a MongoDB collection for data operations, implementing initialization and async initialization.

[PublicAPI]
public class MongoCollectionProvider<TData, TModelMapping> : IInitializable, IHealthCheckProvider, IAsyncInitialization<IMongoCollection<TData>> where TModelMapping : IMongoDataModelMapping<TData>, new()

26.32.1. Type Parameters

TData

The type of data stored in the MongoDB collection.

TModelMapping

The type of the model mapping that defines the MongoDB collection mapping.

26.32.2. Inheritance

objectMongoCollectionProvider<TData, TModelMapping>

26.32.3. Implements

IInitializable, IHealthCheckProvider, IAsyncInitialization<IMongoCollection<TData>>

26.32.4. Inherited Members

object.Equals(object?), object.Equals(object?, object?), object.GetHashCode(), object.GetType(), object.MemberwiseClone(), object.ReferenceEquals(object?, object?), object.ToString()

26.32.5. Remarks

This class is responsible for providing access to a MongoDB collection and ensuring it is properly initialized.

26.32.6. Constructors

26.32.6.1. MongoCollectionProvider(MongoDB, InitDatabase, SessionProvider, IMongoDatabase, ILogger<IMongoCollection<TData>>, CancellationToken)

Initializes a new instance of the class.

public MongoCollectionProvider(MongoDB options, InitDatabase initDatabase, SessionProvider sessionProvider, IMongoDatabase mongoDatabase, ILogger<IMongoCollection<TData>> logger, CancellationToken cancellationToken = default)

26.32.6.1.1. Parameters

options MongoDB

The MongoDB options used for configuration, including data retention settings.

initDatabase InitDatabase

The init data used to populate the database.

sessionProvider SessionProvider

The session provider used to manage MongoDB sessions.

mongoDatabase IMongoDatabase

The MongoDB database instance to which the collection belongs.

logger ILogger<IMongoCollection<TData>>

The logger instance used for logging purposes.

cancellationToken CancellationToken

A cancellation token to observe while waiting for the initialization to complete (optional).

26.32.6.1.2. Exceptions

ArgumentOutOfRangeException

Thrown when the data retention option is not defined (i.e., set to zero).

26.32.7. Properties

26.32.7.1. Initialization

The result of the asynchronous initialization of this instance.

public Task<IMongoCollection<TData>> Initialization { get; }

26.32.7.1.1. Property Value

Task<IMongoCollection<TData>>

26.32.8. Methods

26.32.8.1. Check(HealthCheckTag)

Checks the status of a class for the given health check type.

public Task<HealthCheckResult> Check(HealthCheckTag tag)

26.32.8.1.1. Parameters

tag HealthCheckTag

Health check for which the class has to answer.

26.32.8.1.2. Returns

Task<HealthCheckResult>

The result of the check containing the status of the class for the health check type.

26.32.8.2. Get()

Retrieves the MongoDB collection for data operations.

public IMongoCollection<TData> Get()

26.32.8.2.1. Returns

IMongoCollection<TData>

The MongoDB collection of type .

26.32.8.2.2. Exceptions

InvalidOperationException

Thrown when the MongoDB collection has not been initialized. Ensure that the method has been called before accessing the collection.

26.32.8.3. Init(CancellationToken)

Executes an initialization process for the class

public Task Init(CancellationToken cancellationToken)

26.32.8.3.1. Parameters

cancellationToken CancellationToken

Token used to cancel the execution of the method

26.32.8.3.2. Returns

Task

Task representing the asynchronous execution of the method