Search code examples
mvvminversion-of-control

MVVM Dependency injection service usage


If i have two services, lets say IPrinterService and ILoggerService, should I inject ILoggerService into my implementation of IPrinterService and log exceptions from my implementation, or should i inject both services into my ViewModel and if IPrinterService throws exception then log this using injected ILoggerService?


Solution

  • My opinion is that you should do whatever will create the least number of dependencies in your code. This usually (but not always) means injecting the logger service into the printer service.