docs: moved some explanations from readme to comments
This commit is contained in:
@@ -411,7 +411,7 @@ Examples:
|
||||
- [user-created.domain-event.ts](src/modules/user/domain/events/user-created.domain-event.ts) - simple object that holds data related to published event.
|
||||
- [create-wallet-when-user-is-created.domain-event-handler.ts](src/modules/wallet/application/event-handlers/create-wallet-when-user-is-created.domain-event-handler.ts) - this is an example of Domain Event Handler that executes some actions when a domain event is raised (in this case, when user is created it also creates a wallet for that user).
|
||||
- [typeorm.repository.base.ts](src/libs/ddd/infrastructure/database/base-classes/typeorm.repository.base.ts) - repository publishes all domain events for execution when it persists changes to an aggregate.
|
||||
- [typeorm-unit-of-work.ts](src/libs/ddd/infrastructure/database/base-classes/typeorm-unit-of-work.ts) - this ensures that all changes are saved in a single database transaction. Keep in mind that this is a naive implementation of a Unit of Work as it only wraps execution into a transaction. Proper Unit of Work implementation requires storing all changes in memory first. [Mikro-orm](https://www.npmjs.com/package/mikro-orm) is a nice ORM for nodejs that can be used instead of [typeorm](https://www.npmjs.com/package/typeorm) to have a proper Unit of Work pattern. Read more about [mikro-orm unit of work](https://mikro-orm.io/docs/unit-of-work/).
|
||||
- [typeorm-unit-of-work.ts](src/libs/ddd/infrastructure/database/base-classes/typeorm-unit-of-work.ts) - this ensures that all changes are saved in a single database transaction.
|
||||
- [unit-of-work.ts](src/infrastructure/database/unit-of-work/unit-of-work.ts) - here you create factories for specific Domain Repositories that are used in a transaction.
|
||||
- [create-user.service.ts](src/modules/user/commands/create-user/create-user.service.ts) - here we get a user repository from a `UnitOfWork` and execute a transaction.
|
||||
|
||||
|
||||
@@ -4,6 +4,18 @@ import { IsolationLevel } from 'typeorm/driver/types/IsolationLevel';
|
||||
import { Logger } from 'src/libs/ddd/domain/ports/logger.port';
|
||||
import { Result } from '@src/libs/ddd/domain/utils/result.util';
|
||||
|
||||
/**
|
||||
* Keep in mind that this is a naive implementation
|
||||
* of a Unit of Work as it only wraps execution into
|
||||
* a transaction. Proper Unit of Work implementation
|
||||
* requires storing all changes in memory first and
|
||||
* then execute a transaction as a singe database call.
|
||||
* Mikro-orm (https://www.npmjs.com/package/mikro-orm)
|
||||
* is a nice ORM for nodejs that can be used instead
|
||||
* of typeorm to have a proper Unit of Work pattern.
|
||||
* Read more about mikro-orm unit of work:
|
||||
* https://mikro-orm.io/docs/unit-of-work/.
|
||||
*/
|
||||
export class TypeormUnitOfWork implements UnitOfWorkPort {
|
||||
constructor(private readonly logger: Logger) {}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user