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
Is there an existing issue that is already proposing this?
I have searched the existing issues
Is your feature request related to a problem? Please describe it
When implementing clean / hexagonal architecture and the dependency inversion, you want to type an interface in your services constructor instead of the implementation class.
For exemple, if you need to persist data, you'll type a repository interface instead of the type orm / prisma orm or whatever you want to use. In order to keep the application or domain layers clean of infrastructure references, you don't want to use the Inject annotation to inject the dependency, but instead you use the module definition to inject the dependency in your services (using useFactory for exemple).
But it requires some boilerplate code, especially if you have a lot of modules / services.
Describe the solution you'd like
In frameworks like symfony, the type hinted dependency in the service is automatically resolved, even if you type an interface. The dependency injection component find the class that implement the interface and inject it.
And if multiple classes implement the same typed interface, you can specify which class you want to inject, so the the "autowire" feature is just a default if you have just one class implementing the typed interface, but it save a lot of time / boilerplate code.
This autowire feature could also be turned off, or even disabled by default, so that it doesn't change the default behavior of the DI.
Could this "autowire" feature be a good idea in Nest? If so, i can look into it (with some help) :)
This autowires could be disabled by default, so that it doesn't change the default behavior of the DI. And if you want to enabled it, the the bootstrap function of the main.ts file could be the place to do it.
What is the motivation / use case for changing the behavior?
Save boilerplate code for the DI / dependency inversion
The text was updated successfully, but these errors were encountered:
There is a community package for this already. It works by enforcing convention over configuration, which I don't think that will be good for NestJS because it won't be flexible enough
This has been discussed in the past and we decided to not implement it in the foreseeable future.
If you think your request could live outside Nest's scope, we'd encourage you to collaborate with the community on publishing it as an open source package.
Is there an existing issue that is already proposing this?
Is your feature request related to a problem? Please describe it
When implementing clean / hexagonal architecture and the dependency inversion, you want to type an interface in your services constructor instead of the implementation class.
For exemple, if you need to persist data, you'll type a repository interface instead of the type orm / prisma orm or whatever you want to use. In order to keep the application or domain layers clean of infrastructure references, you don't want to use the Inject annotation to inject the dependency, but instead you use the module definition to inject the dependency in your services (using useFactory for exemple).
But it requires some boilerplate code, especially if you have a lot of modules / services.
Describe the solution you'd like
In frameworks like symfony, the type hinted dependency in the service is automatically resolved, even if you type an interface. The dependency injection component find the class that implement the interface and inject it.
And if multiple classes implement the same typed interface, you can specify which class you want to inject, so the the "autowire" feature is just a default if you have just one class implementing the typed interface, but it save a lot of time / boilerplate code.
This autowire feature could also be turned off, or even disabled by default, so that it doesn't change the default behavior of the DI.
Could this "autowire" feature be a good idea in Nest? If so, i can look into it (with some help) :)
Teachability, documentation, adoption, migration strategy
This autowires could be disabled by default, so that it doesn't change the default behavior of the DI. And if you want to enabled it, the the bootstrap function of the main.ts file could be the place to do it.
What is the motivation / use case for changing the behavior?
Save boilerplate code for the DI / dependency inversion
The text was updated successfully, but these errors were encountered: