ViewModel and initial parameters

Topics: Prism v2 - Silverlight 3
Mar 23, 2010 at 2:19 PM

What is the best practice for setting initial parameters in a viewmodel?



Mar 24, 2010 at 11:11 PM

Hi Rob,

The usual way to inject dependencies into the ViewModel, assuming it is created through the Unity container (so it goes through the Builder’s pipeline), is using Constructor Injection. You can find many examples of this in the Quickstarts and Reference Implementation that come with Prism.

Another possible scenario could be that the ViewModel is instantiated through its default constructor as it is declared in XAML (an assigned to the view’s DataContext). If this is the case, you probably will need to use the Service Locator to get the different dependencies of your ViewModel. This thread provides some more information about that.

If by “setting initial parameters” you meant something different please provide some more information about what you are trying to achieve so we can provide a more detailed answer.

Please let me know if this helps.

Damian Schenkelman