0

I`ve a question about DI and MVVM architecture. Our project has got a lot of services and these services are registered inside the OnStartup method available on App.xaml.cs file. I've also register all the VMs available in our project but now, I don't know if the best solution is to inject the IServiceProvider interface and then get the specific service or inject directly the specific service.

  • @Max That does not answer the question in any way. This question is NOT about ServiceLocator – Sir Rufo Aug 08 '23 at 11:04
  • This is opinion based. Some like to use `IServiceProvider` others do not. It is up to you what you want. I personally inject the specific service (interfaces) and there are very rare conditions where I inject the `IServiceProvider` – Sir Rufo Aug 08 '23 at 11:08
  • @SirRufo thanks for your opinion. This question comes to my mind because I have a ViewModel with a lot of services injected. Maybe this sound like a violation of the first principle of SOLID principles or maybe not (this model is the entry point for out project and contains all command bind to the view). So, I'll try the approach based on specific service injection – Riccardo Zamuner Aug 08 '23 at 11:44
  • The main problem here is testing and maintaining. Maybe injecting a [Mediator](https://www.nuget.org/packages/MediatR) can solve that – Sir Rufo Aug 08 '23 at 11:58

0 Answers0