tsyringe icon indicating copy to clipboard operation
tsyringe copied to clipboard

Inject into named destructured bag?

Open devshorts opened this issue 5 years ago • 0 comments

Is there any way to easily inject into a constructor that does something like this

export class Foo {
  constructor({
   foo,
   bar,
   baz
 }: { foo: Foo, bar: Bar, baz: Baz}) {}
}

This is a pretty common pattern in existing codebases to be able to leverage named properties and then desugar them in the constructor to bind to local fields. But it seems wreak havoc on migrating to a DI container since you now need to wrap all these custom classes in factory providers in the container kernel.

Really just asking if anyone has experience on good patterns to leverage here. Thanks!

devshorts avatar Jul 16 '20 22:07 devshorts