New StaticInjector APIs for DI in Angular 5


Since version 5.0.0, ReflectiveInjector has been deprecated in favour of StaticInjectorto not depend on reflection to get hold of dependencies. We don’t really have to worry about this if we aren’t dealing with creating injectors manually (because Angular does it for us). However, if we are, for whatever reason, relying on lower level injector APIs, here’s what’s different:

  • Creating injectors is done via Injector.create()
  • Dependencies tokens have to be listed explicitly using deps property

StaticInjector doesn’t really need to resolve tokens anymore as everything is supposed to be static and passed right to the configuration. That’s why there’s not resolveAndCreate(), but a create() method. Also, instead of importing ReflectiveInjector, we’re importing Injector.