You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[ ] Regression
[x] Bug report
[x] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.
Current behavior
@Injtectable Classes can't return their own instance, the instance will always be
a single instance of the prototype which is later get's values assigned to it from the new
instance created.
For example, if I have class XYZ {}, when Nest init's it will do this:
component.instance=Object.create(XYZ.prototype);
Laster when XYZ is needed and instantiated it will do this:
Now, I know I can use a factory provider to solve this, but it makes to solution cumbersome and requires extra steps. Proxies are powerful but not natively usable with nest.
I know it's a big deal and a core behaviour, this is why I suggest to add it as an opt-in feature.
The text was updated successfully, but these errors were encountered:
I'm submitting a...
Current behavior
@Injtectable
Classes can't return their own instance, the instance will always bea single instance of the prototype which is later get's values assigned to it from the new
instance created.
For example, if I have
class XYZ {}
, when Nest init's it will do this:Laster when XYZ is needed and instantiated it will do this:
See here:
https://github.com/nestjs/nest/blob/master/packages/core/injector/injector.ts#L63-L66
Expected behavior
Allow an opt-in option to use the returned value from the constructor (i.e. new XYZ()) directly.
What is the motivation / use case for changing the behavior?
Mainly, using
Proxy
classes and other sort of thing requiring the return of a different value.Here is an example of a
winston
wrapper:Notice the last part, the constructor...
Now, I know I can use a factory provider to solve this, but it makes to solution cumbersome and requires extra steps. Proxies are powerful but not natively usable with nest.
I know it's a big deal and a core behaviour, this is why I suggest to add it as an opt-in feature.
The text was updated successfully, but these errors were encountered: