nicojs / typed-inject

Type safe dependency injection for TypeScript
Apache License 2.0
431 stars 23 forks source link

Feature request: give access to the root injector #64

Open ukstv opened 12 months ago

ukstv commented 12 months ago

It would be nice to have access to the root injector via injector.root to later call dispose() on it.

Now I have to maintain two references to achieve disposability i.e. root.dispose():

  1. Root injector: const root = createInjector()
  2. Fully populated injector: const injector = root.provideClass('foo', Foo).provideClass('blah', Blah)

It would be cool if I could maintain just a single reference to later do this:

const injector = createInjector().provideClass('foo', Foo).provideClass('blah', Blah)
injector.root.dispose()