tsyringe icon indicating copy to clipboard operation
tsyringe copied to clipboard

Auto register container to itself for dyanmic inject

Open Austaras opened this issue 4 years ago • 2 comments

In angular we could

private injector: Injector

so that we can get depenency dynamically at any time instead of when construted, this is specifically useful for inject multi instance like http interceptor. I guess it's already possible for tsyringe to do so, only thing needed is a standard token and some modify to container factory

Austaras avatar May 06 '21 11:05 Austaras

You can already do this, I guess, by assigning the container to a private member as you have suggested. But perhaps I'm not fully understanding the full context here - could you provide a fuller example of how you would like this to work?

MeltingMosaic avatar May 06 '21 17:05 MeltingMosaic

Yes I could assign it to a member, however for complex requirment like hierarchy inject I'd like to get child container instead of root container. Of course I could pass it manually -- but I think it's better to automate this process

@inject
class A {
   constructor(private container: Container) {}
   
   run() {
     this.container.resolveAll()
   }
}

Austaras avatar May 07 '21 07:05 Austaras