wordfor

dependency injection

noun

Software design

  1. Passing a component the things it depends on, rather than having it create them itself, so they can be swapped. new OrderService(paymentGateway) instead of new OrderService() that builds its own StripeClient.

In plain words

  • hard to test because it creates its own database connection
  • swap the real service for a fake one in tests
  • pass the dependencies in

See also test double (mock, stub, fake) tight coupling pure function

Find similar words