Introduction to Microsoft Prism Tomaš Maconko
Aug 08, 2015
Introduction to Microsoft Prism
Tomaš Maconko
Issue
• We need a HUGE WPF desktop application
• Application must be module-based (plugin-based)
• Modules are developed by different teams in different countries
• Team work is not synchronized
• Application must be tested periodically
Solution
• Easy, but totally not acceptable – decline the project
• Hard, but hardly acceptable – write your own module management infrastructure
• Medium and acceptable – use an already implemented framework for modular applications
Microsoft Prism
• Used in applications consisting of multiple modules
• Contains module management infrastructure
• Provides navigation between views, even if navigation is performed between views from different modules
• Allows application to evolve and enables easy-maintenance
• Currently used in WinRT, WPF, Silverlight and Windows Phone apps
Reusability
• Allows components and services to be developed, tested and integrated into one or more applications
• Reuse of unit-tested components that can be easily discovered and integrated at run time through dependency injection
• Modules can encapsulate application-level capabilities that may be reused across applications
Extensibility
• Allows components to be more easily integrated or replaced with alternative implementations at run time
• Provides the ability to decompose an application into modules that can be independently updated and deployed
• Many of the components in the Prism Library itself can also be extended or replaced
Flexibility
• Allows to extend the application with new capabilities, that can be easily developed and integrated
• Allows WPF applications to be developed using common services and components, allowing the application to be deployed and consumed in the most appropriate way
Team Development
• Allows separate teams to develop and even deploy different parts of the application independently
• Minimizes the cross-team dependencies and allows teams to focus on:• Different functional areas: UI design, business logic implementation,
and infrastructure code development
• Different business-level functional areas: profile, sales, inventory, or logistics
Quality
• Allows common services and components to be fully tested and made available to the development teams
• Allows development teams to focus on their application requirements instead of implementing and testing infrastructure code
Where to use it?
Module management infrastructure
• Load modules immediately or on demand depending on configuration
• There can be no direct/static references between projects
• Modules can be configured through C# code or in configuration file
• Can register each module separately or read all modules from directory
Configuration is simple
Module initialization sequence
1. When application starts BaDemo.Common is initialized as it is static reference.
2. Next BaDemo.Main is loaded, because is should be initialized immediately after startup.
3. A. If the user requested BaDemo.Orders, then both BaDemo.Orders and BaDemo.Items would be initialized, as BaDemo.Orders depends on BaDemo.Items.
4. If the user requested BaDemo.Items, then it is initialized without BaDemo.Orders.
BaDemo
BaDemo.Main
BaDemo.Items
BaDemo.Common
BaDemo.Orders
1. On application start
2. On application start 3a. On requested
4. On requested
3b. On BaDemo.Orders module requested
Other features
• Model-View-ViewModel pattern utilities
• Navigation handling
• Dependency Injection support
• Event aggregation
Model-View-ViewModel
• INotifyPropertyChanged implementation
• ICommand implementation
Navigation handling
• IRegionManager • INavigationAware
Dependency injection support
• Registration • Usage
• Registration can be done in Bootstrapper class or in each module
• Each container provides its own dependency management mechanism:• MEF uses attributes to specify the
exported and imported dependencies• Unity container requires registration
of types and can automatically resolve instances
• And so on...
Event aggregation
Conclusions
• Prism seems to be usable and proper framework for in modular application development
• It contains many tools for easy module management, navigation between modules
• It provides additional tools for MVVM, DI, Event Aggregation and other patterns
• It’s Open Source
Sources
• Prism CodePlex: http://compositewpf.codeplex.com/SourceControl/latest
• MSDN Prism Guide: https://msdn.microsoft.com/en-us/library/ff648465.aspx
• Demo in GitHub: https://github.com/tmaconko/BaDemo
Keep #EnjoyITContact me, if you have questions:
• www.ba.lt