Design Patterns · Junior · Question 47 of 75
What is Dependency Injection in its simplest form?
- ✓Correct answer: Passing dependencies into a function or class from outside instead of creating them inside
- 2Automatically installing missing npm packages on startup
- 3Importing all of the project's modules in a single
index.jsfile
Explanation
createOrderService({ api, logger }) instead of import api inside: it's easy to substitute mocks in tests, and the implementation can be replaced. In React, DI is often done via Context or props.