How to implement the new PrismApplication to replace the Bootstrapper class

Okay, So call me dumb or whatever but I had the same issue with the same error:

App.RegisterTypes(IContainerRegistery): no suitable method found to override

My issue was that I went and copied and pasted the App.xaml from Here and the cs from Here and didnt change the name space in the App.xaml from x:Class="Regions.App" to x:Class="WpfApp.App"


I started with sample 1 of the Prism samples on GitHub and immediately I get a warning that using a UnityBootstrapper is deprecated. So I sought to upgrade it to the current mechanism.

First step is to replace the base class of your application from Application to PrismApplication in App.xaml. It should now look like this;

<unity:PrismApplication x:Class="BootstrapperShell.App"
                        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                        xmlns:local="clr-namespace:BootstrapperShell" 
                        xmlns:unity="http://prismlibrary.com/">
    <Application.Resources>

    </Application.Resources>
</unity:PrismApplication>

Then in App.xaml.cs, remove the reference to Application and implement the abstract methods of PrismApplication. Copy across the contents of InitializeShell in Bootstrapper.cs into the CreateShell() method. The final result should look like this;

/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App
{
    protected override Window CreateShell()
    {
        return Container.Resolve<MainWindow>();
    }

    protected override void RegisterTypes(IContainerRegistry containerRegistry)
    {
    }
}

I also added some markup to MainWindow.xaml in order to ensure that it was resolving correctly;

<Window x:Class="BootstrapperShell.Views.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="Shell" Height="350" Width="525">
    <Grid>
        <TextBlock HorizontalAlignment="Center"
                   VerticalAlignment="Center"
                   FontSize="24">Hello</TextBlock>
    </Grid>
</Window>

Everything should work as it did before.


It depends on what your bootstrapper does, but Prism.Unity.PrismApplication has similar methods to override, so you should be able to copy the code over from the bootstrapper. Probably you only need RegisterTypes and CreateShell. Remember to update App.xaml to change the type of your application...

App.xaml should be something like this:

<prism:PrismApplication x:Class="WpfApp1.App"
                        x:ClassModifier="internal" 
                        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                        xmlns:prism="http://prismlibrary.com/"/>

and for completeness' sake, App.xaml.cs:

internal partial class App
{
    protected override void RegisterTypes(IContainerRegistry containerRegistry)
    {
        throw new NotImplementedException();
    }

    protected override Window CreateShell()
    {
        throw new NotImplementedException();
    }
}

Tags:

Prism