obsidian icon indicating copy to clipboard operation
obsidian copied to clipboard

Singleton providers leak non-singleton dependencies

Open guyca opened this issue 3 years ago • 0 comments

In the following example, useCase is retained throwout the lifespan of all PushedScreenGraphinstances, while presenter is meant to be retained only for the lifespan of the PushedScreen component this graph instance is bound to.

@Graph()
class PushedScreenGraph {
  @Provides()
  presenter(): PushedScreenPresenter {
    return new PushedScreenPresenter();
  }

  @Provides() @Singleton()
  someUseCase(presenter: PushedScreenPresenter): SomeUseCase {
    return new SomeUseCase(presenter);
  }
}

guyca avatar Jan 05 '22 08:01 guyca