I am working with Caliburn.Micro v2.0.1 on a Windows 8.1 Unversal (WinRT) project.
I followed the Caliburn.Micro Working with WinRT example.
My code looks as follows:
App.xaml.cs
protected override void OnLaunched(LaunchActivatedEventArgs args)
{
Initialize();
DisplayRootViewFor<LoginViewModel>();
}
protected override void PrepareViewFirst(Frame rootFrame)
{
_container.RegisterNavigationService(rootFrame);
}
LoginViewModel.cs
public LoginViewModel(INavigationService navigationService, ...)
{
...
}
The issue
The OnLaunched
is called first.
Initialize()
Configures the WinRT container.
- The
DisplayRootViewFor<LoginViewModel>
invokes an instance of theLoginViewModel
and results in a Null exception because NavigationService has not yet been registered byPrepareViewFirst(Frame)
PrepareViewFirst(Frame)
is not yet called, having a dependency on theRootFrame
that should be configured byOnLaunched
Thus LoginViewModel
is dependent on RegisterNavigationService
and RegisterNavigationService
is dependent on DisplayRootViewFor<LoginViewModel>()
which is dependent on LoginViewModel
Is there any way to overcome this circular reference issue?