Appendix C: Prism Library
The Prism Library, formally named the Composite Application Library in earlier releases, helps architects and developers create applications for Windows Presentation Foundation (WPF), Silverlight, and Windows Phone 7. The Prism Library can support those wanting to build a number of application styles with WPF or Silverlight, but it is was primarily constructed for applications composed of discrete, functionally complete pieces that work together to create a single, integrated user interface (UI), often referred to as a composite application. The Prism Library accelerates the development of applications using proven design patterns.
The Prism Library is primarily designed to help architects and developers create applications that need to accomplish the following:
- Build clients composed of independent, yet cooperating, modules or pieces.
- Separate the concerns of module builders from the concerns of the shell developer; by doing this, business units can concentrate on developing domain-specific modules instead of the WPF or Silverlight architecture.
- Separate the concerns of presentation, presentation logic, and application model through support for presentation model patterns such as Model-View-ViewModel (MVVM).
- Use an architectural infrastructure to produce a consistent and high quality integrated application.
- Build applications that target both WPF and Silverlight.
When building your application with the Prism Library, you may use the Unity Extensions for the Prism Library and the Unity Application Block (Unity) or the Managed Extensibility Framework (MEF) Extensions for the Prism Library and MEF. These are built on the .NET Framework 4.0, for WPF, or the .NET Framework for Silverlight 4, as shown in the following illustration.
The Prism Library addresses common requirements for building both composite and non-composite applications on the WPF and Silverlight platforms. As a whole, the Prism Library accelerates development by providing the services and components to address these needs.
The Prism Library ships both as signed binaries to allow you to take advantage of Prism immediately without the need to compile and as source in case you want to make modifications or just see how it works.
Registering with Visual Studio 2010
Because the Prism library is delivered as a self-extracting executable file, the library assemblies do not automatically register with the Visual Studio 2010 Add References dialog box. If you want to register the assemblies with the Add References dialog box, you can run the RegisterPrismBinaries.bat file located where Prism was unpackaged, as shown here.
If you want to unregister these, specify /u, as shown here.
Organization of the Prism Library
The Prism Library can either be used in a WPF, Silverlight, or a Windows Phone 7 application. There are Prism binaries for Desktop, Silverlight, and Windows Phone under the Bin folder where Prism is installed. The binaries in the Desktop folder target WPF.
The Prism Library targeted for desktop applications consists of four assemblies:
- Microsoft.Practices.Prism. This assembly contains interfaces and components to help build composite applications. These components include the EventAggregator, ModuleManager, ModuleCatalog, and Bootstrapper. Additionally, this assembly contains components that relate to the presentation layer of the desktop application. These include CompositeCommand, DelegateCommand, CompositePresentationEvent, RegionManager, and NotificationObject.
- Microsoft.Practices.Prism.Interactivity. This assembly contains behaviors and actions for interactions with the UI based on Microsoft Expression Blend Behaviors (available in the Blend SDK), largely in support of the MVVM pattern. This includes InteractionRequest, InteractionRequestTrigger, Confirmation, and Notification.
- Microsoft.Practices.Prism.UnityExtensions. This assembly provides components to use the Unity Application Block (Unity) with the Prism Library. These components include UnityBootstrapper and UnityServiceLocatorAdapter.
- Microsoft.Practices.Prism.MefExtensions. This assembly provides components to use Managed Extensibility Framework (MEF) with the Prism Library. These components include MefBootstrapper and MefServiceLocatorAdapter.
The Prism Library targeted for Silverlight applications consists of four assemblies. The following describes additional functionality in each component specific to Silverlight:
- Microsoft.Practices.Prism. For Silverlight, this assembly includes classes that handle remote module loading, such as the FileDownloader and XapModuleTypeLoader. It also accounts for some behavioral differences in controls for regions with additional adapters and behaviors, such as TabControlRegionAdapter and TabControlRegionSyncBehavior.
- Microsoft.Practices.Prism.Interactivity. The Silverlight version contains TriggerActions to respond to InteractionRequests, such as ConfirmationChildWindow, NotificationChildWindow, and PopupChildWindowAction.
- Microsoft.Practices.Prism.UnityExtensions. This assembly provides components to use Unity for Silverlight with the Prism Library. These components include UnityBootstrapper and UnitServiceLocatorAdapter.
- Microsoft.Practices.Prism.MefExtensions. This assembly provides components to use MEF with the Prism Library. These components include MefBootstrapper and MefServiceLocatorAdapter.
The Prism Library targeted for Windows Phone 7 applications consists of a functional subset from the Prism Library and additional phone-specific features. The Phone Library consists of two assemblies:
- Microsoft.Practices.Prism. For the phone, this contains the components for commanding, including DelegateCommand; components to support view models, including NotificationObject and DataTemplateSelector; and components to support event aggregation, including EventAggregator and CompositePresentationEvent.
- Microsoft.Practices.Prism.Interactivity. For the phone, this assembly also includes phone-specific behaviors, including ApplicationBarButtonCommand, ApplicationBarButtonNavigation, UpdatePasswordBindingOnPropertyChanged, MessageBoxRequestTrigger, and ToastRequestTrigger.
The Prism Library Source
The source for the Prism Library can be found in the PrismLibrary folder where Prism is installed. The versions for the Desktop, Silverlight, and Windows Phone appear in their own folders. The source code in the Desktop folder targets WPF.
There is a Visual Studio 2010 project for each of the assemblies listed earlier, in addition to projects for test assemblies. Because each platform has very similar functionality, these projects work from a shared code-base. The primary source for the code base is under the desktop folders. The Silverlight and phone projects have links to source files under the Desktop folder. Platform-specific source files are under the platform-specific branches. For example, the TabControlRegionAdapter is only available in the Silverlight version of the Prism Library source.
|The Prism Library project and project folder names do not match their compiled assembly names for maximum path length reasons. The convention is that the project names have "Microsoft.Practices" removed from them.|
Modifying the Library
If you want to modify the Prism Library, you can replace the signed binaries (in the Bin folder) with your own version of the binaries. To accomplish this, use the UpdatePrismLibraries.bat file. This will compile the Prism Library projects and copy the output to the appropriate place under the Bin folder, as shown here.
Be default, this will only build the Desktop and Silverlight projects and copy their outputs. If you want to also build and copy the phone project, add the IncludePhone option, as shown here.
|When running these, they will overwrite the signed binaries delivered originally with the Prism Library. If you accidentally overwrite these, you can recover them only by re-extracting Prism from the self-extracting executable file.|
Running the Tests
If you modify the Prism Library and want to verify that existing functionality is not broken, execute the unit tests for the projects. To run all the desktop unit tests in the solution file PrismLibrary.sln, on the Test menu, point to Run, and then click All Tests in Solution.
Executing all the Silverlight tests is a bit more difficult. Each Silverlight test project is an individual Silverlight application and, as such, must be run independently.
To run a Silverlight test
- Right-click the desired test project in Solution Explorer, and then click Set as Startup Project.
- On the Debug menu, point to Start Without Debugging.
Prism's community site is http://www.codeplex.com/Prism.
For more information about Unity, see the following:
- "Unity Application Block" on MSDN:
- Unity community site on CodePlex:
For more information about MEF, see the following:
- "Managed Extensibility Framework Overview" on MSDN:
- MEF community site on CodePlex:
For more information about service locator, see the Common Service Locator on CodePlex:
For more information about using Prism on Windows Phone 7, see the Windows Phone 7 Developer Guide community site on CodePlex:
Last built: August 28, 2012