DEV Community


Discussion on: Implementing SOLID and the onion architecture in Node.js with TypeScript and InversifyJS

smile_by21 profile image

Why do you need the EntityDataMapper? why not use the domain entity directly? I am curious about how did this work with typeorm and how did your DalEntities synced with the database ?

remojansen profile image
Remo H. Jansen Author

We use the data mapper because we don't want to "pollute" our entire application with data-access concerns. The TypeORM entities are data-access concerns because they are a 1-to-1 map to the database tables and contain database-related metadata added via decorators. We use the domain entities instead in the entire system but the data access layer (DAL) cannot use domain entities to persist them (via TypeORM). So the data mapper job is to translate in and out of the DAL from domain-entity-to-orm-entity (in) and from orm-entity-to-domain-entity (out).

Forem Open with the Forem app