I have been recently looking for better ways to architect my Node applications. I generally performed all business logic and DB queries within my individual Express Routes, but I have now settled upon a three-tier architecture consisting of a Data Acess Layer, a Service Layer, and a Controller Layer.Paramount to this architecture is establishing Inversion of Control through Dependency Injection. Being able to pass mocked dependencies into the constructor of Services and Repositories is a breeze compared to Manual Mocks with Jest.Another user on Reddit recommended the Awilix Dependency Injection Container, and I've found that it works beautifully for my purposes. If anyone is interested in a similar architecture with DI, you might like Awilix, available here. The author of Awilix also has a series of articles on how to use it, which can be found here.
Submitted July 01, 2019 at 08:26PM by JamieCorkhill
No comments:
Post a Comment