I have decided to use prism with xamarin . found some articles to start with prism . I have installed 3 xamarin packages
1)Prism.Core
2)Prism.Forms
3)Prism.Unity.Forms
and inherits App from PrismApplication like This
public partial class App : PrismApplication {}
I don't want to use ViewModelLocator.AutowireViewModel="True" to bind view with Naming Conventions
I found this code to bind view with viewmodel without following naming convention
protected override void ConfigureViewModelLocator()
{
base.ConfigureViewModelLocator();
BindViewModelToView<LoginRegisterViewModel, MainPage>();
}
public void BindViewModelToView<TViewModel, TView>()
{
ViewModelLocationProvider.Register(typeof(TView).ToString(), () => Container.Resolve<TViewModel>());
}
Here is my ViewModel
public class LoginRegisterViewModel : BindableBase
{
#region Private variables
private readonly IPageDialogService _diglogService;
private readonly INavigationService _navigationService;
#endregion
#region Constructor
public LoginRegisterViewModel(IPageDialogService diglogService, INavigationService navigationService)
{
_diglogService = diglogService;
_navigationService = navigationService;
}
#endregion
}
When start a App it shows error
Unhandled Exception:
Microsoft.Practices.Unity.ResolutionFailedException: Resolution of the dependency failed, type = "DSMobile.ViewModels.LoginRegisterViewModel", name = "(none)".
Exception occurred while: while resolving.
Exception is: InvalidOperationException - The current type, Prism.Navigation.INavigationService, is an interface and cannot be constructed. Are you missing a type mapping?
At the time of the exception, the container was:
Resolving DSMobile.ViewModels.LoginRegisterViewModel,(none)
Resolving parameter "navigationService" of constructor DSMobile.ViewModels.LoginRegisterViewModel(Prism.Services.IPageDialogService diglogService, Prism.Navigation.INavigationService navigationService)
Resolving Prism.Navigation.INavigationService,(none)
Dependency Injection not working . while not using naming conventions . It works fine when using naming convention binding
Please help . how can i bind views with viewmodel without naming conventions . suggestion are most welcome
Thanks in advance