IoC pattern, i.e. not DI

Dependency injection is some form of inversion of control.

  • Can anyone point out some other form of Inversion of Control that is not dependency injection?
  • Is there any java framework that is an IoC container but not a DI container?
  • Which part of spring is IoC but not DI?
+3


source to share


1 answer


Inversion of Control is the ability to allow the framework to run your own code. As Martin Fowler says here :

Inversion of control is a common phenomenon that you encounter when expanding the scope. Indeed, this is often regarded as a defining characteristic of the framework.

So this is an example of inversion of control:

public class HomePage : Page
{
    protected override void OnPageLoad(object sender, EventArgs e) {
        // here your custom code
    }
}

      

Here we have some custom class that "by some convention" creates the framework (ASP.NET Web Forms in this case) and runs our own code. The way it is done here is inheriting and overriding the base class virtual methods that the framework provides.

So this is another example of inversion of control:



public class HomeController : Controller
{
    public ActionResult Save(HomeSaveModel model) {
        // here your custom code
    }
}

      

Here we have our own custom controller, where again the framework will call our code some convention. Here we are still using the base class specified by the structure, but now the structure will call our action Save

using reflection.

The inversion of control is to connect to the framework. Note that there is no dependency injection in the examples above, which is always the case (and there is no place of service).

Is there any java framework that is an IoC container but not a DI container?

The name "IoC container" is misleading because these tools are meant to help you wire dependency graphs in your application and not help you wire your code to the infrastructure. IoC is a property of a framework; if it doesn't do IoC, it's not a framework: it's a library. Therefore "IoC containers" are libraries, not frameworks, and they usually have nothing to do with the frameworks we use (for example, web frameworks like ASP.NET).

So, in that sense, there is no such thing as an "IoC container" since that is something they cannot do; a-priory. In this context, your question stops changing :-) but still answer it: no, "IoC containers" are always "DI containers", but never "IoC containers".

+3


source







All Articles