Of course there is always property injections for optional dependencies and most of the IoC frameworks supports this (I mostly use Castle Windsor). So you have best of both worlds, dependency injection AND not having another mandatory dependency declared in your constructor. You can also use Null Object Pattern for the logger so you don’t have to wire the logger if not necessary (e.g. in some test scenarios)
↧