Repository: https://github.com/TomDoesTech/js-des...
Dependency injection is a strategy where an object has its dependencies injected into it. The receiving object is called the client and the object that is injected is called the service.
In simpler terms, dependency injection is passing something that the client depends on, in as arguments, instead of either building the service itself, or getting it from the global scope.
Why use dependency injection?
Separation of concerns - Separates the construction and use a service
Reusability - Services created outside of the client can be used anywhere
Testing - A mocked service can easily be injected into the client during tests
Why not use dependency injection?
Can be more work
Can be just as simple to construct the service in the client
Might move the logic to build services somewhere that's harder to manage
0:00 Introduction
1:49 Simple example of dependency injection
4:38 Dependency injection in NestJS
🌎 Follow me here:
Discord: / discord
Twitter: / tomdoes_tech
Facebook: / tomdoestech
Instagram: / tomdoestech
TikTok: / tomdoes_tech
☕ Buy me a coffee: https://www.buymeacoffee.com/tomn