The client side application is made out of three assemblies:
- The Shell (PrismWalkthrough.Shell)
- The Modules ( PrismWalkthrough.Modules)
- The Infrastructure (PrismWalkthrough.Infrastructure)
The foundation of the application is “The Shell”. The Shell is the top-level window of an application based on the Prism Composite Application Library. This window is a place to host different user interface (UI) components that exposes a way for itself to be dynamically populated by others, and it may also contain common UI elements, such as menus and toolbars. The Shell window sets the overall appearance of the application.
In our application it’s the shell that is responsible to load the Modules. A module represents a set of related concerns. It can include components such as views, business logic, and pieces of infrastructure, such as services for logging or authenticating users. Modules are independent of one another but can communicate with each other in a loosely coupled fashion. In this walkthrough our application will contain only one module: the CoreModule nevertheless the modular architecture enable us to easily extend the application adding new modules later on.
The Infrastructure Assembly is a shared library referenced by both the shell project and the module projects, and holds shared types such as constants, event types, entity definitions and interfaces.
Create the Solution
- Create the Shell project (PrismWalkthrough.Shell) application with Visual Studio-> File, Project, WPF Application.
- Add the Modules project and Infrastructure project –> File, Add New Project, Classlibrary
- The three projects should reference the Composite Application Library assemblies, add the following reference:
(These assemblies can be found in the october 2009 Guidance of Prism - you will need to compile the sample application)
- Add a reference to the Modules and Shell projects referencing the Infrastructure assembly.
- Add a refrence to the Shell project referencing the Modules assembly.
- Add a refrence to the Modules and infrastructure that reference to the WindowsBase & PresentationCore and PresentationFramework –> Reference, Add, .Net tab.
Your solution should look like this:
Initialize the application
To enable modularity and dependency injection in our application we need to make some changes to the standard WPF application we just created. First we setup a bootstrapper. The bootstrapper is responsible for the initialization of the application, this is realized by overriding the CreateShell method.
- Add a new class on the root of the application containing the shell (PrismWalkthrough.Shell), name it Bootstrapper
- The Bootstrapper should inherit from Microsoft.Practices.Composite.UnityExtensions.UnityBootstrapper class and override the CreateShell method. You need to instantiate the Shell through the Unity conatiner and call his Show method
1: public class Bootstrapper : UnityBootstrapper
3: protected override System.Windows.DependencyObject CreateShell()
5: Shell shell = this.Container.Resolve<Shell>();
To be able to run the bootstrapper at least one module should be registered in our application.
- Add a class to the PrismWalkthrough.Module and name it CoreModule.cs
- This class should implement the IModule interface:
1: namespace PrismWalkthrough.Modules
3: public class CoreModule : IModule
5: public void Initialize()
Through the bootstrapper you must configure which Modules are available in our Shell. You need to register at least one module in your bootstrapper.
- Override the InitializeModules in the bootstrapper:
1: protected override void InitializeModules()
3: IModule coreModule = this.Container.Resolve<CoreModule>();
The WPF Application class needs to execute the bootstrapper by calling his Run method.
- First you should delete the StartupUri in the App.Xaml file.
- Override the OnStartup method in the App.cs file:
1: protected override void OnStartup(StartupEventArgs e)
4: Bootstrapper bootstrapper = new Bootstrapper();
Now you should be able to run you application, you should see a white screen.