typedi icon indicating copy to clipboard operation
typedi copied to clipboard

feat: configure dependency lookup in parent container

Open tonyxiao opened this issue 7 years ago • 4 comments

Is it possible to configure typedi to lookup dependencies in the parent container rather than having to do explicit container.set for all the named services?

tonyxiao avatar Oct 17 '18 15:10 tonyxiao

Our team would also find this useful. child = container.child() or the like.

epferrari avatar Nov 29 '18 17:11 epferrari

Can you please provide a minimal example of your desired behavior? Including what would you like to happen and what happens currently.

NoNameProvided avatar Aug 02 '20 11:08 NoNameProvided

What i think he meant is this:

What happens currently:

Container.set('foo', 'bar');
Container.get('foo') === 'bar'; // true
Container.of('random').get('foo') === 'bar'; // ServiceNotFoundError

What would like to happen:

Container.set('foo', 'bar');
Container.get('foo') === 'bar'; // true
Container.of('random').get('foo') === 'bar'; // true

evertonht avatar Aug 13 '20 20:08 evertonht

I have the same use case. I have some service that can be registered into the global namespace (Container.set), but I also have a container that depends on the request taht contains a DB service. I'm using it in conjunction with type-graphql (https://typegraphql.com/docs/dependency-injection.html#scoped-containers) and I can tell it only about one container. Of course I configure it to use the scoped container. How can I access what I define in the global scope? Is this an anti-pattern? Is there any other way to achieve this or should I declare everything in the scoped container?

ramiel avatar Feb 09 '21 10:02 ramiel