26

Since the Bootstrapper Class is obsolete with Prism 7 I would like to change my C# WPF App using the PrismApplication Class.

Does anybody know how to refactor a Prism 6 App using the Bootstrapper : UnityBootstrapper to the new PrismApplication?

I´m asking because the documentation regarding those pre-releases is pretty limited and I am not the best in understanding what I need to do from just looking at the Prism source code.

TomTomB
  • 419
  • 1
  • 4
  • 13

3 Answers3

20

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();
    }
}
Haukinger
  • 10,420
  • 2
  • 15
  • 28
  • 1
    Okay, but the `ConfigureModuleCatalog()`doesnt seem to be there / is no longer overwriteable. How should I register my modules now? – TomTomB Dec 20 '17 at 16:52
  • See line 203 here: https://github.com/PrismLibrary/Prism/blob/master/Source/Wpf/Prism.Wpf/PrismApplicationBase.cs: `protected virtual void ConfigureModuleCatalog(IModuleCatalog moduleCatalog) { }` – Haukinger Dec 20 '17 at 20:42
  • *Remember to update `App.xaml` to change the type of your application...* what do you mean by this? What would need to be changed? – R. Richards Dec 21 '17 at 00:12
  • The app's base type is defined there, and by default it's `System.Windows.Application`. Here, we want it to be `Prism.Unity.PrismApplication`... – Haukinger Dec 21 '17 at 06:35
  • Well, you´ve opend my eyes. I´ve had a classic _copy & paste_ error. I copied the `ConfigureModuleCatalog` from the old `Bootstrapper` class without noticing the new `PrismApplication ConfigureModuleCatalog` needs to have a parameter of `IModuleCatalog` passed in. – TomTomB Dec 21 '17 at 13:33
  • 1
    My issue was that I didn't update the tag from to – Andrejs Gasilovs Apr 01 '20 at 14:40
10

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.

Steztric
  • 2,832
  • 2
  • 24
  • 43
  • Can you expand on why the app needs to be public? Normally, one tries to keep the surface of one's assemblies as small as possible... – Haukinger Jul 03 '20 at 20:09
2

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"

3xGuy
  • 2,235
  • 2
  • 29
  • 51