-
-
Notifications
You must be signed in to change notification settings - Fork 7.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feature(core): Add multi option for custom providers #1517
feature(core): Add multi option for custom providers #1517
Conversation
8943870
to
f1b3abc
Compare
5062a90
to
ac78d6e
Compare
Pull Request Test Coverage Report for Build 1484
💛 - Coveralls |
Done! Please review @kamilmysliwiec How does it work?I tried to mimic the behavior of Angular.
Mimic of the PRs behavior using the current public API to understand what is actually happening @Module({
providers: [
{
provide: 'TEST', // token gets changed in the background to `{ provide: 'TEST', useValue: 'test2', multi: true}`
useValue: 'test1',
multi: true,
},
{
provide: 'TEST', // token gets changed in the background to `{ provide: 'TEST', useValue: 'test1', multi: true}`
useValue: 'test1',
multi: true
}
{
// The multi provider
provide: 'TEST',
useFactory: (...args) => args,
// Inject the previous defined providers
inject: [{provide: 'TEST', useValue: 'test1', ... }, {provide: 'TEST', useValue: 'test2', ...}]
],
})
class TestModule { } |
0f920b7
to
9bb07f2
Compare
Waiting for this. I will migrate my backend to nestjs |
@thesayyn I am currently stuck because the current PR does not take the export of providers in consideration, which is definitely mandatory. I am currently trying to find a solution for this, but it is not easy, also because Angular behaves differently and therefore I can not proceed with my current Angular-inspired PR :/ |
Let me think a while I may can find a solution |
Is there any progress? |
let inject: any[] = null; | ||
const multiProviderToken = provider.provide; | ||
|
||
token = provider; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is my first time looking at nestjs source, so mind my ignorance. I am a little confused what is happening here where the token is set to provider
just moments after being set to provider.provide
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You’re right that is not needed. I had to do a lot of tinkering back then and seems like a unneeded statement is still present .
Nonetheless, this PR is currently on ice because I do not find time to look further into this at the moment. The current PR behaves similarly as in Angular. The problem is; Angular Injectables are global, whereas in Nest they are module specific (only public by exporting it). This makes it quite hard to implement in Nest but we hopefully get there!
Closed in favor of #2460. I think I got it working, but it slightly different (Multi Providers will be handled as globals). I gotta need to take a break, it is 35 degrees here, my brain is boiling and I have no idea why my code even works (?!?). Will follow up tomorrow :-) |
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
PR Checklist
Please check if your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
What is the current behavior?
No
multi
provider optionIssue Number: #770
What is the new behavior?
Support the
multi
option for providersDoes this PR introduce a breaking change?
Other information
I am looking forward to implementing a
APP_INITIALIZER
token for NestJS which could help with #1438