Thursday, February 15, 2018

What is Dependency Injection

Dependency injection is basically providing the objects that an object needs (its dependencies) instead of having it construct them itself. It's a very useful technique for testing, since it allows dependencies to be mocked or stubbed out.

In plain C language, it is the choice between passing a resource as an argument to a function (Dependency Injection) or let the function create the resource.

The benefit of DI is simpler testing since you can always pass a dummy resource while testing the function.


send_packet(byte data, socket s )

v/s

send_packet(byte data)
{
    socket s  = new socket();
    ....
}