microsoft / tsyringe

Lightweight dependency injection container for JavaScript/TypeScript
MIT License
5.18k stars 172 forks source link

Register collection of providers #198

Open abratko opened 2 years ago

abratko commented 2 years ago

I have collection of config params. I want register it in container to inject into my services as init settings.

Some of params depends of request context on ssr. In this case I create child container and register them in child container.

I have to write many code to do these actions, beacouse container.register method does not take collection of providers, although @registry does this action.

It will be cool if i can create container and child container with initial collection of providers. For example

createContainer([
  { token: '%param_1%, useValue: 'value_1' },
  { token: '%param_2%, useValue: 'value_2' }
])
.createChildContainer([
  { token: '%param_1%, useValue: 'new_value_1' },
  { token: '%param_3%, useValue: 'value_3' }
])