Class MongoDbUnitOfWorkManager

Represents a Unit of Work Manager, which is responsible for managing the lifecycle of Unit of Work instances. The Unit of Work pattern is a design pattern used in domain-driven design to maintain consistency and integrity within a transactional boundary.

For more information on the Unit of Work pattern and domain-driven design, refer to Martin Fowler's articles:

Implements

Constructors

Methods

Constructors

Methods

  • Starts a new Unit of Work and returns a Promise that resolves to the created UnitOfWork instance.

    Parameters

    • Optionaloptions: TransactionOptions

    Returns Promise<MongoDbUnitOfWork>

    A Promise that resolves to a UnitOfWork instance representing the started Unit of Work.

    The Unit of Work pattern encapsulates a set of operations that should be treated as a single transaction. This method is responsible for creating and initializing a new UnitOfWork instance.

    const unitOfWork = await unitOfWorkManager.startUnitOfWork();
    // Perform operations within the Unit of Work
    await unitOfWork.commit();

    If an error occurs while starting the Unit of Work.