Iām developing a WPF application with the help MVVM Light Toolkit 4.1.24. Here is my ViewModel Locator class.
public class ViewModelLocator
{
/// <summary>
/// Initializes a new instance of the ViewModelLocator class.
/// </summary>
public ViewModelLocator()
{
ServiceLocator.SetLocatorProvider(() => SimpleIoc.Default);
if (ViewModelBase.IsInDesignModeStatic)
{
// Create design time view services and models
SimpleIoc.Default.Register<IService1, DesignDataService>();
}
else
{
// Create run time view services and models
SimpleIoc.Default.Register<IService1, Service1Client>();
}
SimpleIoc.Default.Register<MainViewModel>();
}
public MainViewModel Main
{
get
{
return ServiceLocator.Current.GetInstance<MainViewModel>();
}
}
public static void Cleanup()
{
// TODO Clear the ViewModels
ServiceLocator.Current.GetInstance<MainViewModel>().Cleanup();
}
}
Where
IService1 - is a WCF service interface
DesignDataService ā Implementation of IService1 for design purpose
Service1Client ā WCF proxy class that implement IService1
I have two questions:
1) While run the App, I got an error like this "Cannot register: Multiple constructors found in Service1Client but none marked with PreferredConstructor.". For that I have added "[PreferredConstructorAttribute]" attribute to the Service1Client default constructor and the application run as expected. I know it's not a good method for two reasons
- it will result a dependency to SimpleIoc
- Whenever I update service reference I have to manually add this attribute to the default constructor.
So is there any better method?
2) I want to pass the endpoint address to Service1Client manually. How can I do that?
Thanks in advance...