I use Prism for a appliction and need a login dialog. For the login to be verified i need to initialize some of the application data that is loaded by Prism/MEF so i cant put it in App.xmal.cs
OnStartUp so i put the login dialog in the bootstrappers InitializeShell like this
protected override void InitializeShell()
{
Application.Current.ShutdownMode = ShutdownMode.OnExplicitShutdown;
//// Authenticate the current user and set the default principal
LoginDialog auth = new LoginDialog();
auth.WindowStartupLocation = WindowStartupLocation.CenterScreen;
bool? dialogResult = auth.ShowDialog();
// deal with the results
if (dialogResult.HasValue && dialogResult.Value)
{
base.InitializeShell();
Application.Current.ShutdownMode = ShutdownMode.OnMainWindowClose;
}
else
{
Application.Current.Shutdown(-1);
}
#if SILVERLIGHT
Application.Current.RootVisual = (Shell)this.Shell;
#else
Application.Current.MainWindow = (Shell)this.Shell;
Application.Current.MainWindow.Show();
#endif
}
I have a hard time assessing if there are any traps or drawback, anyone have a comment
Yes, I had exactly same dilemma. You have only one RootVisual and yet you have to force user to login. It’s a common scenario that’s not really addressed.
Here is what I did:
Code like you don’t have Login. Initialize shell and load first module. In my case first module contains security stuff.
When your “System” or whatever you call it module loaded – write code in
Initialize()to call your login procedure, in my case this isSecurityService.I used
RegionPopupManager(example in StockTrader RI project bundled with PRISM) to show modal popup interaction.When logged in – just hide popup and proceed loading other modules, populating regions, etc