Typemock and Injection Dependency Injection still using interfaces?

I see some good design benefits in DI, not just a good test design. Therefore, although I have Typemock and I can unit test without the IOC, I still prefer the DI constructor. I think this is a great way to quickly discover class dependencies.

Now I'm wondering if interfaces should be used as a type parameter in the constructor. They are very easy to create with Resharper, but it is still the type that I really don't need.

A quick example of what I mean

public interface IService { void Method(); } public class Service : IService { public void Method() { } } public class ClassThatUsesDI { public ClassThatUsesDI(IService service) **or** (Service service) { } } 

What are your thoughts?

+4
source share
1 answer

With interfaces, you can replace the actual type used at runtime based on configuration. You can do this with classes as well, if you inherit them, but still easier with just interfaces.

My advice is to stay with the interfaces.

And honestly, I write my services differently. First I update the interfaces, because the "world" I'm in now is more limited, and makes me think more about what I really can do in the interface, and then I update the specific types.

+2
source

All Articles