Hi i try to register my class into serviceLocator and reuse it my code is:
public ViewModelLocator()
{
ServiceLocator.SetLocatorProvider(() => SimpleIoc.Default);
SimpleIoc.Default.Register<IUnitOfWork, UnitOfWork>(true);
SimpleIoc.Default.Register<MainViewModel>(() =>
{
return new MainViewModel(UnitOfWorkItem);
});
SimpleIoc.Default.Register<LoginViewModel>(() =>
{
return new LoginViewModel(UnitOfWorkItem);
});
}
public UnitOfWork UnitOfWorkItem
{
get
{
return ServiceLocator.Current.GetInstance<UnitOfWork>();
}
}
public MainViewModel Main
{
get
{
return ServiceLocator.Current.GetInstance<MainViewModel>();
}
}
when i try to give UnitOfWorkItem into the function that instance MainViewModel throw a exception like:
Type not found in cache: Client.Business.UnitOfWork.
my stack trace is:
in GalaSoft.MvvmLight.Ioc.SimpleIoc.DoGetService(Type serviceType, String key, Boolean cache) in D:\GalaSoft\mydotnet\MVVMLight\source\GalaSoft.MvvmLight\GalaSoft.MvvmLight.Extras (PCL)\Ioc\SimpleIoc.cs:riga 537 in GalaSoft.MvvmLight.Ioc.SimpleIoc.GetInstanceTService in D:\GalaSoft\mydotnet\MVVMLight\source\GalaSoft.MvvmLight\GalaSoft.MvvmLight.Extras (PCL)\Ioc\SimpleIoc.cs:riga 912 in PrivateVideoChat.Client.ViewModel.ViewModelLocator.get_UnitOfWorkItem() in C:\Users\c.fasolin\Documents\Visual Studio 2013\Projects\PrivateVideoChat.Solution\PrivateVideoChat.Client\ViewModel\ViewModelLocator.cs:riga 63 in PrivateVideoChat.Client.ViewModel.ViewModelLocator.<.ctor>b__0_1() in C:\Users\c.fasolin\Documents\Visual Studio 2013\Projects\PrivateVideoChat.Solution\PrivateVideoChat.Client\ViewModel\ViewModelLocator.cs:riga 52
Where I am wrong thanks