Article Reference on How to Implement Repository Pattern in NestJS
One of the SOLID Principles, the Dependency Inversion principle, says: “Entities must depend on abstractions, not on concretions. It states that the high-level module must not depend on the low-level module, but they should depend on abstractions.” — SOLID: The First 5 Principles of Object Oriented Design by Samuel Oloruntoba in Digital Ocean.
My team has backend services built on Node.js and the NestJS framework. Previously, they were dependent on the repository implementation. The database connections, models, and functionalities are written in each service module. As we expected, the code became bloating as the project grew and thus became unmaintainable.
To implement the Dependency Inversion Principle in our service, I tried to find relevant articles and find out if someone has been working on the same thing. If I went back to when I was working on backend services written using C# and built on top of .NET, It was easy to find the example since Microsoft wrote it on their documentation. However, it was harder to find an example for NestJS.
It turns out Royi Benita has written a great article about this topic. He started his article with a definition, followed by why the principle should be applied, and explained by the use case example. He also provided the link to his github repo to find out the full code.
If you are interested, check his article below.