Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(dispose): dispose child injectors #29

Merged
merged 2 commits into from Aug 12, 2020
Merged

Commits on Aug 12, 2020

  1. feat(dispose): dispose child injectors

    This changes the way `dispose` works. Instead of an `Injector` disposing it's own provided dependencies and then call `dispose` on the parent, it will dipose it's child `Injector`'s (that were created using `provideXXX`) and then it's own dependencies. The parent `Injector` will _no longer_ be disposed.
    
    This allows you to dispose from the rootInjector down:
    
    ```ts
    class Foo {
      dispose() {
        console.log('Foo disposed');
      }
    }
    const rootInjector = createInjector();
    const fooProvider = rootInjector.provideClass('foo', Foo);
    fooProvider.resolve('foo');
    await rootInjector.dispose(); // => "Foo disposed"
    rootInjector.provideClass('bar', Bar); // Error: Injector already disposed
    ```
    
    Because now an `Injector` has to keep track of it's child injectors, the `rootInjector` would no longer be stateless. That's why it is removed all together. Developers are expected to create their own rootInjector using `createInjector()`.
    
    BREAKING CHANGE: `rootInjector` is removed in favor of `createInjector`.
    
    This:
    
    ```
    import { rootInjector } from 'typed-inject';
    ```
    
    Becomes:
    
    ```
    import { createInjector } from 'typed-inject';
    const rootInjector = createInjector();
    ```
    
    Injector's created from `createInjector` are no longer stateless. They
    keep track of their child injectors.
    
    BREAKING CHANGE: `dispose` no longer disposes parent injector, disposes
    the child injectors instead. See readme for more details.
    nicojs committed Aug 12, 2020
    Configuration menu
    Copy the full SHA
    0ba6454 View commit details
    Browse the repository at this point in the history
  2. remove only

    nicojs committed Aug 12, 2020
    Configuration menu
    Copy the full SHA
    27ca2b4 View commit details
    Browse the repository at this point in the history