Design Patterns · Junior · Question 47 of 75

What is Dependency Injection in its simplest form?

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.

Further reading

Problem with a question

Design Patterns · Junior · question 47

Test yourself

Take the Design Patterns · Junior quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz