question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Provide multiple providers from the single provision

See original GitHub issue

Which @angular/* package(s) are relevant/releated to the feature request?

core

Description

Hi, I wonder whether is it possible to add an option to provide multiple providers by single provision; this way it is possible to make the app more customizable and inject providers on any level - through useFactory and dependency, for example. The important thing is that injectors create a tree, so other dependencies visibility matters at this point - that is why providing something further in the tree in a ‘lazy’ manner is feasible - now you should somehow fetch the lower injector and create the new one based on it, or make some nasty delegation.

Proposed solution

Let us assume that there is the token TOKEN_PROVIDER which should provide Provider[] - this way you could return different providers based on some condition, or just pass these ‘created’ before - like for Injector.create().

Alternatives considered

As mentioned in the description now there is a possibility to provide some dummy-delegate implementation and fill it later, but it still does not solve the problem in total, because it could be shared between different nodes in the injector tree.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:14
  • Comments:15 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
Azbesciakcommented, Feb 10, 2022

But the case is that the config need to be injected, or providers from ‘above’, not to mention about some injected factory which provides another providers.

there’s a sufficiently strong use case for this in Angular

What does it mean? AI think that if you provide a tree-based injector, and at the same time, there is a possibility to use multiple providers of the same type, this may be required for better flexibility - at least I missed it for the last 5 years, for the last 3 I made some workarounds, but now I am into the corner with not perfect solutions - it looks like it must be solved on the framework level.

I supose that most of your users use just DI as injecting type, maybe even 90% even do not use multi providers, so in fact this may be not the most keen feature. But please be aware of the rest of your users - they probably write their own proxy frameworks on this if they need something. Please, remember also about their needs.

1reaction
marcinmilewiczcommented, Feb 11, 2022

This is exactly what I’ve looked for recently.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Multi Providers in Angular | Articles by thoughtram
With multi providers, we can basically provide multiple dependencies for a single token. Let's see what that looks like.
Read more >
How to use multiple AWS providers in a Terraform project
Configuring Multiple AWS providers​​ We can't write two or more providers with the same name i.e. two AWS providers. If there's any such...
Read more >
Multiple providers in a single vagrant file? - Stack Overflow
Multiple config.vm.provision methods can be used to define multiple provisioners. These provisioners will be run in the order they're defined.
Read more >
The Pros and Cons of Single and Multiple IT Providers
Awarding all IT service provisions to a single provider means the provider has full accountability. The provider is responsible if a service fails,...
Read more >
Providers Within Modules - Configuration Language | Terraform
Providers can be passed down to descendent modules in two ways: either implicitly through inheritance, or explicitly via the providers argument within a...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found