Domanda

Can a UserControl's ViewModel constructor be set up to fire with the view's DataContext AND another dependency injection?

I would like to be able to get the UserControl's datacontext (set in it's parent's veiw) and a database service into a ViewModel.

Can't figure this out:

public MyUserControlViewModel( theDataContext, InvoiceService)
{

} 

This works:

public MyUserControlViewModel( theDataContext)
{

} 

This works:

 public MyUserControlViewModel( InvoiceService)
 {

 }
È stato utile?

Soluzione

Yes, Catel supports of all this. In the case that you have above, all should work. For example:

public MyViewModel(Model model, IService1 service1, IService2 service2) { }

Note that in order to inject a model, it must be set as data context. All services except for the model must be registered in the ServiceLocator.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top