Why don't languages integrate Dependency Injection in their core (at the lowest level : compilation maybe) since dependencies are the root of all evil in Complexity Theory? This would avoid to use Frameworks.
I'm rather targeting compiled languages.
My question is similar to duck typing that has been introduced recently with dynamics in .NET. Why not something similar in the future for DI?
Disadvantages of Dependency Injection: Dependency injection creates clients that demand configuration details to be supplied by construction code. This can be difficult when obvious defaults are available. Dependency injection can make code difficult to trace (read) because it separates behaviour from construction.
ASP.NET Core supports the dependency injection (DI) software design pattern, which is a technique for achieving Inversion of Control (IoC) between classes and their dependencies. For more information specific to dependency injection within MVC controllers, see Dependency injection into controllers in ASP.NET Core.
We can use dependency injection. To recap, our Car is currently responsible for the creation of its Driver. But what we actually want is to have the Driver dependency injected into the Car. The Car does not care where the Driver comes from, as long as it gets a working one. We want to use what we are given, rather than what we create. Fig 5.
The task of instantiating objects is done by the container according to the configurations specified by the developer. There are two types of Spring Dependency Injection. They are: Setter Dependency Injection (SDI): This is the simpler of the two DI methods. In this, the DI will be injected with the help of setter and/or getter methods.
Preferred option when properties on the bean are more and immutable objects (eg: financial processes) are important for application. We have used three classes and an interface as beans to exemplify the concepts of CDI and SDI. They are Vehicle, ToyotaEngine, Tyres classes and IEngine interface respectively.
Because languages are design/design-pattern neutral.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With