Generally speaking, my dependencies are abstracted to interfaces, but I will use only one specific implementation during use without testing. For example, I had to write FooService :
public class FooService : IFooService { private readonly IBarDependency _barDependency; public FooService(IBarDependency barDependency) { this._barDependency = barDependency; } public FooService() : this (new BarDependency()) {
Now purists tend to suffocate in horror because I created a specific class in a parameterless constructor. I in the past shrugged because I know that the only time I will not use a particular class is when I test units of measure and mocking dependencies.
While it connects the FooService class to the FooService class, it is not a hard link; these classes and interfaces also exist in the same assembly, so it doesn't seem to me that I'm losing a lot of space here or drawing myself into a corner. I can still easily test the FooService class without getting unmanaged code, just using a constructor that allows me to pass in mocking interfaces.
So the question is: what is really at stake? What am I losing with a template worth adding an IoC container?
c # dependency-injection interface
Jeremy holovacs
source share