Skip to content

Is there an "Invalidate" functionality for DI ? #2030

Answered by Romakita
alexdonh asked this question in Q&A
Discussion options

You must be logged in to vote

In this case, don’t use ˋInject` decorator. Use injectorService directly to rebuild the service.

@Service()
export class Service1 {

  @Inject()
  protected injector: InjectorService;
  protected something: Something;
 
   $onInit() {
     this.something = this.injector.invoke(Something);
   }
  doThis() {
    if (new) {
       this.something = this.injector.invoke(Something, undefined, { rebuild: true });
    }
  }
}

Note: this example use internal DI Api and I won’t give warranty to maintain this in future. Use this at your own risk ;)

see you
Romain

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@alexdonh
Comment options

@Romakita
Comment options

Answer selected by alexdonh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants