Search code examples
c#interfacedependency-injectionloose-coupling

Is it ok to have interface as parameter for loose coupling


Most of the examples for dependency injection I have seen, the dependencies are injected in constructor. In my situation, I cannot inject the dependency through constructor nor any DI tool. So, I have an interface as parameter to the method. I would like to know if it is a bad approach and what disadvantages it has over constructor injection.


Solution

  • There is nothing wrong with a method-level dependency (i.e. something that is only a dependency for a single method), and there is nothing wrong with passing that dependency as an interface.