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”
- Create a new WPF Application
- Reference the following assemblies (The PRISM stuff)
- Microsoft.Practices.Composite
- Microsoft.Practices.Composite.UnityExtensions
- Microsoft.Practices.Composite.Wpf
- Remove the StartupUri from the App.xaml
- Remove Window1 and add a new Window called Shell (You could also have renamed the Window1 to Shell)
- 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