• Home
  • Documentation
Show / Hide Table of Contents
  • Introduction
  • Getting Started
    • Download and Setup Prism
    • NuGet Packages
    • Productivity Tools
  • Commands
    • Commanding
    • Composite Commands
  • Dependency Injection
    • Getting Started
    • Registering Types
    • Platform Specific Services
    • Exception Handling
    • ContainerLocator
    • Adding a Custom Container
    • Appendix
  • Event Aggregator
  • ViewModelLocator
  • Modules
  • WPF / Uno
    • Introduction
    • Getting Started
    • Converting From Prism 7.x
    • Converting From Prism 6.x
    • View Composition
    • Region Navigation
      • About Navigation in Prism
      • Basic Region Navigation
      • View/ViewModel Participation
      • Navigating to Existing Views
      • Passing Parameters
      • Confirming Navigation
      • Controlling View Lifetime
      • Navigation Journal
    • Interactivity
      • Event To Command
    • Dialog Service
    • Advanced
      • Region Adapters
    • Legacy (Prism 6)
      • Introduction
      • Initializing
      • Managing-Dependencies
      • Modules
      • Implementing-MVVM
      • Advanced-MVVM
      • Composing-the-UI
      • Navigation
      • Communication
      • Deploying
      • Appendix-A-Glossary
      • Appendix-B-Patterns
      • Appendix-C-Prism-Library
      • Appendix-D-Extending-Prism
      • Appendix-E-Click-Once
  • .NET MAUI
    • Getting Started
    • Migrating from Prism.Forms
    • PrismAppBuilder
    • Dependency Injection
    • AppModel
      • IPageLifecycleAware
    • Behaviors
      • Introduction
      • BehaviorBase<T>
      • EventToCommandBehavior
      • PageBehaviorFactory
    • Dialogs
      • Getting Started
      • IPageDialogService
      • IDialogService
    • Navigation
      • Introduction
      • Page Navigation
      • NavigationBuilder
      • Understanding the INavigationResult
      • NavigationExceptions
      • Global Navigation Observer
      • XAML Navigation
    • Regions
      • Introduction
  • Xamarin.Forms
    • Create Your First App
    • Behaviors
      • Working with Behaviors
      • EventToCommand Behavior
      • PageBehaviorFactory
    • Dialogs
      • Dialogs
      • Page Dialog Service
      • Dialog Service
      • Styling Dialogs
    • Navigation
      • Navigation Basics
      • Passing Parameters
      • Confirming Navigation
      • Deep Linking
      • Working w/ MasterDetailPages
      • Working w/ NavigationPages
      • Working w/ TabbedPages
      • XAML Navigation
    • Application Lifecycle
    • Page Lifecycle
    • Additional Platforms
      • GTK

Converting Your App From Prism 6.x

In version 6.x, using the Prism framework required an implementation of a bootstrapper class derived from one of the container bootstrapper classes provided by Prism. In the sample below is a minimum version of what that would look like.

class AppBootstrapper : UnityBootstrapper
{
    protected override DependencyObject CreateShell()
    {
        return Container.Resolve<MainWindow>():
    }

    protected override void InitializeShell()
    {
        Application.Current.MainWindow.Show();
    }
}

The bootstrapper class is used in the Application class and implemented as follows:

public partial class App : Application
{
    protected override void OnStartup(StartupEventArgs e)
    {
        base.OnStartup(e);

        var bootstrapper = new AppBootstrapper();
        bootstrapper.Run();
    }
}

Above is about the minimum viable implementation of a Prism 6.x implementation. If there is a need to upgrade the application to Prism 7.x, the implementation in the bootstrapper class needs to be moved into the Application class.

Updating the Application Class

First step is to update the application class. In most cases the App application class is derived from Application. In Prism 7.x the class will be instead derived from one of the Prism application class based on the container of choice. These examples are using the Unity container.

Update the Application XAML

Make sure that the correct namespace is added to the XAML.

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

In the above code snippet, the opening tag is changed. Also note the xmlns:prism namespace added on line 6.

Next update the App class code behind.

using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Threading.Tasks;
using System.Windows;
using Prism.Unity;

namespace WpfApp1
{
    public partial class App : PrismApplication
    {
    }
}

After updating the class, there will be a couple of abstract methods that need to be implemented in a similar fashion to Prism 6.x.

First implement CreateShell. This is the same as Prism 6.x and can be implemented as follows:

protected override Window CreateShell()
{
    var w = Container.Resolve<MainWindow>();
    return w;
}

Next RegisterTypes needs to be implemented. This is the same as the ConfigureContainer in the Bootstrapper class. If you don't have any services to register, this can be left empty.

protected override void RegisterTypes(IContainerRegistry containerRegistry)
{
    // pretend to register a service
    containerRegistry.Register<Services.ISampleService, Services.DbSampleService>();
    // register other needed services here
}

Other Bootstrapper Functionality

The bootstrapper in 6.3x contained other functions that could be overridden for the app. These should have equivalents in the PrismApplication class that can be overridden in Prism 7.x app. One common example would be the ConfigureModuleCatalog() function.

  • Edit on GitHub
  • Ask questions
  • Follow @PrismLib
  • Follow @BrianLagunas
  • Follow @DanJSiegel
Back to top Copyright 2015-2022 Prism