In my domain, I have several โprocessorโ classes that occupy the bulk of the business logic. Using StructureMap with default conventions, I insert repositories into these classes for my various IOs (databases, file systems, etc.). For instance:
public interface IHelloWorldProcessor { string HelloWorld(); } public class HelloWorldProcessor : IHelloWorldProcessor { private IDBRepository _dbRepository; public HelloWorldProcessor(IDBRepository dbRepository) { _dbRepository = dbrepository; } public string HelloWorld(){ return _dbRepository.GetHelloWorld(); } }
Now there are some repositories that I would like to get for all processors, so I made the base class as follows:
public class BaseProcessor { protected ICommonRepository _commonRepository; public BaseProcessor(ICommonRepository commonRepository) { _commonRepository = commonRepository; } }
But when my other processors inherit from it, I get a compiler error on each of them, saying that there is no constructor for BaseProcessor that accepts null arguments.
Is there a way to do what I'm trying to do here? That is, to have common dependencies introduced into the base class that my other classes can use without having to inject into each of them?
David source share