I am currently learning Catel+Orchestra using MahApps Metro. I am doing the Authentication example from the Catel.Examples project using the MetroUI. My problem is when i create a new MainWindow in my MahAppsService
public FrameworkElement GetMainView()
{
return new MainWindow();
}
The constructor of the MainWindowViewModel is never called
public MainWindowViewModel(UIVisualizerService uiVisualizarService, IAuthenticationProvider authenticationProvider)
{
_uiVisualizerService = uiVisualizarService;
_authenticationProvider = authenticationProvider;
RoleCollection = new ObservableCollection<string>(new[] { "Read-Only", "Administrator" });
ShowView = new Command(OnShowViewExecute, OnShowViewCanExecute, "ShowView");
}
I have narrowed it down to the 2 dependencies of the constructor. If i remove the UIVisualizerService and IAuthenticacionProvider dependencies the constructor is properly called but the ModelView needs those two services later on.
I am lost at what can i do to get this working.
I solved the problem by adding a explicit injection of the viewmodel into the mainwindow constructor.
Declaring the field for the AuthenticationProvider interface to the MahAppsService class.
Also adding the dependency of the AuthenticationProvider interface to the constructor.
And the last step is creating an instance of the viewmodel in the GetMainView in the MahAppsService class.
Please note that this might not be the best way to do it but it gets the work done. If someone has better way feel free to share it.