Learning PRISM – Getting Started… - Rudi Grobler

Learning PRISM – Getting Started…

Now that we have covered Unity and Modularity, we can start cutting into the meat of PRISM! 2 more fundamental concepts do need a little explaining… I will cover them as I get to them.

One of the big changes in PRISM is the way the application gets loaded and how it shows the main window. PRISM rely on a Bootstrapper (Or more specifically, the UnityBootstrapper) to create the Shell and ModuleEnumerator 

The shell is the main window. Lets build our “Hallo World”

  1. Create a new WPF Application
  2. Reference the following assemblies (The PRISM stuff)
    1. Microsoft.Practices.Composite
    2. Microsoft.Practices.Composite.UnityExtensions
    3. Microsoft.Practices.Composite.Wpf
  3. Remove the StartupUri from the App.xaml
  4. Remove Window1 and add a new Window called Shell (You could also have renamed the Window1 to Shell)
  5. Add a new class called Bootstrapper

By default, we will derive from the UnityBootstrapper. For now, all your bootstrapper will do is create our shell and allow for static enumeration of our modules. Here is my bootstrapper

public class Bootstrapper : UnityBootstrapper
{
    protected override System.Windows.DependencyObject CreateShell()
    {
        Shell shell = new Shell();
        shell.Show();
        return shell;
    }
    protected override Microsoft.Practices.Composite.Modularity.IModuleEnumerator GetModuleEnumerator()
    {
        return new StaticModuleEnumerator();
    }
}
The last step is to instantiate the bootstrapper… To do this, we override the OnStartup of App.
protected override void OnStartup(StartupEventArgs e)
{
    base.OnStartup(e);
    Bootstrapper bootstrapper = new Bootstrapper();
    bootstrapper.Run();
}

Now we have a very basic PRISM application… I highly recommend you do this by hand the first 2 or 3 times just to grasp why you have all these things… but if you are lazy (like me), use the Visual Studio Project Template available on Composite WPF Contrib

Read more here

Published Wednesday, October 08, 2008 2:51 PM by rudi

Comments

# Learning PRISM - Getting started

You've been kicked (a good thing) - Trackback from DotNetKicks.com

Wednesday, October 08, 2008 2:56 PM by DotNetKicks.com

# 2008 October 09 - Links for today « My (almost) Daily Links

Pingback from  2008 October 09 - Links for today « My (almost) Daily Links

Thursday, October 09, 2008 7:40 AM by 2008 October 09 - Links for today « My (almost) Daily Links

# Dew Drop - October 9, 2008 | Alvin Ashcraft's Morning Dew

Pingback from  Dew Drop - October 9, 2008 | Alvin Ashcraft's Morning Dew

Thursday, October 09, 2008 2:58 PM by Dew Drop - October 9, 2008 | Alvin Ashcraft's Morning Dew

# Dew Drop - October 9, 2008 | Alvin Ashcraft's Morning Dew

Pingback from  Dew Drop - October 9, 2008 | Alvin Ashcraft's Morning Dew

Sunday, October 12, 2008 11:02 PM by Dew Drop - October 9, 2008 | Alvin Ashcraft's Morning Dew