Dependency inversion is a complicated topic. This repo explores the most common, simple issue as it relates to software development.
yarn
yarn build
In src/noDI
.
yarn start:noDI
This is our starting point. Just a couple of classes with dependencies created in the constructors.
In src/mutatorDI
.
yarn start:mutatorDI
DI enabled only by calling setters.
In src/constructorDI
.
yarn start:constructorDI
DI enabled by passing parameters to constructors.
In src/simpleDI
.
yarn start:simpleDI
This moves the dependency setup to another module to encapsulate the inversion of control logic. This technique is often referred to as a "container", though that term most often applies to larger DI frameworks.
In src/InversifyDI
.
yarn start:InversifyDI
Demonstrates a naïve use of Inversify for dependency injection. This appears to be one of the more popular frameworks, but hasn't seen much recent activity.