I've been using AutoFac for some time now to take care of the dependency injection we're using in a web project. All is well, but I now want to demonstrate DI outside of an AutoFac context for reasons irrelevant to this question.
In doing so, I'm having to read up on 'manual' methods of achieving this pattern. All of the examples in tutorials work (obviously), but the issue of tightly coupled objects still exist.
Take this for example: http://www.devx.com/dotnet/Article/34066/0/page/2
The constructor of the dependent class takes an interface:
public class BusinessFacade {
private IBusinessLogic businessLogic;
public BusinessFacade(IBusinessLogic businessLogic) {
this.businessLogic = businessLogic;
}
}
But then the instantiation of BusinessFacade
still requires a concrete implementation to be passed, which means an implementation needs to be instantiated:
IBusinessLogic productBL = new ProductBL();
BusinessFacade businessFacade = new BusinessFacade(productBL);
Question
Now I know, somewhere at some point, something (whether it is a container or manually written code) will have to decide on the implementation to choose, but how can I come to terms with the benefit of moving such decision outside of the dependent class? Of course the BusinessFacade class is no longer tightly coupled, but we're still very explicit about which implementation we choose - so what's been gained here? Is it purely for the fact we can mock out the dependencies?