ViewModelLocator类不太理解
ViewModelLocator 是连接view 和viewmodel用的。我疑惑的系统所有的viewmodel都要在这个类注册一遍吗?比如我500个viewmodel ,那我就写500行注册的代码?(如:SimpleIoc.Default.Register<TestViewModel>();)
这样写一次行加载完,这样写的性能会不会不好,内存会不会增加很多?
public class ViewModelLocator
{
static ViewModelLocator()
{
ServiceLocator.SetLocatorProvider(() => SimpleIoc.Default);
if (ViewModelBase.IsInDesignModeStatic)
{
SimpleIoc.Default.Register<IDataService, Design.DesignDataService>();
}
else
{
SimpleIoc.Default.Register<IDataService, DataService>();
}
SimpleIoc.Default.Register<MainViewModel>();
SimpleIoc.Default.Register<TestViewModel>();
}
/// <summary>
/// Gets the Main property.
/// </summary>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance",
"CA1822:MarkMembersAsStatic",
Justification = "This non-static member is needed for data binding purposes.")]
public MainViewModel Main
{
get
{
return ServiceLocator.Current.GetInstance<MainViewModel>();
}
}
public TestViewModel Test
{
get
{
return ServiceLocator.Current.GetInstance<TestViewModel>();
}
}
/// <summary>
/// Cleans up all the resources.
/// </summary>
public static void Cleanup()
{
}
}