Inversion of control and Dependency injection in Typescript

Samuele Resca
4 min readJul 23, 2017

The following article is about inversion of control(IoC) and dependency injection(DI) in Typescript. The main aims of that techniques is to provide loose coupling between modules and classes.

IoC and DI are part of the SOLID topics, SOLID principles using Typescript can gives you more notions about SOLID combined with the Typescript world.

I have already written about Dependency injection: Dependency Injection overview. The article contains some general informations about Dependency injection base concepts.

I also suggest another cool explanation of Dependency injection: How to explain dependency injection to a 5-year-old? .

Reasons for use Inversion of control and Dependency Injection

Here are some reasons for use Inversion of control and Dependency injection:

  • Decoupling: dependency injection makes your modules less coupled resulting in a more maintainable codebase;
  • Easier unit testing: instead of using hardcoded dependencies you can pass them into the module you would like to use;
  • Faster development: with dependency injection, after the interfaces are defined it is easy to work without any merge conflicts;

--

--