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.
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();
}
}
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.
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"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With