I using MVVM light library in my project. I trying to add an array to the constructor of the ViewModel.
For example... if the code below is
public MainViewModel(ToolWindowViewModel[] toolItems)
{
// to do
}
I would like to know a way that injects the array to the constructor of the MainViewModel with SimpleIoC class.
Is there a formulaic way to add an array with SimpleIoc class?
If it is, could someone tell me how to do? If it is not, what is the best way in this scenario?
Thanks for reading.
You could register a Func<MainViewModel>
in the ViewModelLocator
where you initialize the array:
public class ViewModelLocator
{
public ViewModelLocator()
{
ServiceLocator.SetLocatorProvider(() => SimpleIoc.Default);
SimpleIoc.Default.Register(new System.Func<MainViewModel>(() => new MainViewModel(new ToolWindowViewModel[0])));
}
public MainViewModel Main
{
get
{
return ServiceLocator.Current.GetInstance<MainViewModel>();
}
}
}