Skip to main content

Dependency Injection and IoC

Dependency Injection

How objects obtain dependent objects

The class being injected has no responsibillity in instantiating the object being injected Key Theme: Avoid Tight Coupling

Types of Dependency Injection:

  • By class properties - not reccommended
  • By Setter
  • By Constructor - most perfered way

Inversion of Control

A technique to allow dependencies to be injected at runtime

IoC vs DI

  • DI is the composition of your classes
  • IoC is the runtime enviornment of your code