container-ioc
container-ioc copied to clipboard
[bug] can't inject values that evaluate to false
Hello,
If I want to register a value of 0/null/false/empty string, it won't get resolved and it will fail.
Ex:
container.register({ token: 'foo', useValue: 0 });
container.resolve('foo') fails
The problem seems to be in container.ts : registerOne(provider).
if (provider.useValue) {
registryData.instance = provider.useValue;
}
I would suggest replacing it with
if (provider.useValue !== void 0) {
registryData.instance = provider.useValue;
}
or
if ('useValue' in provider) {
registryData.instance = provider.useValue;
}
to support undefined values.
Also, maybe check if a provider is valid (has only one of useClass/useValue/useFactory set on something different than undefined).
Thanks
Hey! Thanks for submitting your bug report! Never thought such use case would come up. I'm gonna fix that today.
Glad to be helpful :)