Login screen prior to Shell

Topics: Prism v4 - WPF 4
May 18, 2015 at 1:58 PM
I am fairly new to Prism, however, if the bootstrapper takes care of the IOC container and launches the shell, where do I initialise a login screen and how would that link in? It would need unity to resolve the data service etc.
May 18, 2015 at 4:45 PM
It depends on whether you want the user to see the shell in the background with the login as a pop up over it, or you want only the login dialog and never show the main window if they don't successfully log in. For the former, you can just trigger showing the dialog from the Loaded event of the main window/shell. If the latter, you can wire it into the Boostrapper CreateShell method. The trick for the latter is knowing that you have to set the Application.Current.MainWindow since that drives the lifetime of the application and WPF automatically sets it to the first window you show, which will be your login dialog window.
May 19, 2015 at 4:38 PM
Thanks for the reply Brian,

I am pretty sure I want it prior to the main shell showing, it is a shame because I will have to resolve the dependency on the service layer myself as the unity container does all the resolving in the bootstrapper. Is this normal practice, seems such a struggle coming from a winforms background :-)

Would you put it here

Some code - If success then proceed
         Bootstrapper bootstrapper = new Bootstrapper();
May 19, 2015 at 5:16 PM
Not sure I understand your concern.

It is very normal to register some shell level services in the Bootstrapper. Typically that is done by overriding ConfigureContainer, and after the call to the base method, add your calls to Container.Register there to register services. Then in the CreateShell override, you would construct the View, Resolve the ViewModel through the container so that it does the dependency injection for you, and then set the View's data context to the ViewModel to complete the MVVM wire up. Then wire up a completion handler for the login dialog (possibly an event raised by the ViewModel indicating successful completion of login, and in that handler construct the shell main window, show it, and set it as the Application.Current.MainWindow.

Hope that helps.
May 20, 2015 at 8:54 AM
You have been really helpful so far, currently I have the following - the configure container will resolve and DI and I am using ViewModelLocator to hook everything up, I am just not sure about how and where to launch the login in form and add a new handler prior to InitialiseShell

public class Bootstrapper : UnityBootstrapper
    public Bootstrapper()
        ViewModelLocationProvider.SetDefaultViewTypeToViewModelTypeResolver((viewType) =>
            var viewName = viewType.FullName;
            var viewAssemblyName = viewType.GetTypeInfo().Assembly.FullName;
            var viewModelName = String.Format(CultureInfo.InvariantCulture, "{0}ViewModel, {1}", viewName, viewAssemblyName);
            return Type.GetType(viewModelName);

    protected override void ConfigureContainer()

        //Container.RegisterType<IMyObject, MyObject>();

        ViewModelLocationProvider.SetDefaultViewModelFactory((type) =>
            return Container.Resolve(type);


    protected override DependencyObject CreateShell()
        return Container.Resolve<Shell>();
    protected override void InitializeShell()

        Application.Current.MainWindow = (Window)Shell;

    protected override void ConfigureModuleCatalog()

        ModuleCatalog moduleCatalog = (ModuleCatalog)this.ModuleCatalog;
May 20, 2015 at 7:02 PM
You can put it in InitializeShell - create and show your login dialog from there, and don't do the two lines of code that set the main window and show it until after the login dialog is successfully completed.
May 21, 2015 at 9:20 AM
Thanks for your help Brian