Blog

A Properly Pleasing Primer Tutorial for WPF Prism - Part 1: Introduction

A Properly Pleasing Primer Tutorial for WPF Prism - Part 1:  Introduction

The usage of design patterns is situational. Their purpose is to reduce the overall complexity of an application or to replace unfamiliar complexity with manageable equivalents. For a sufficiently simple application, however, using patterns is often overkill. Even more so if the design pattern itself isn’t familiar to the developers that will be maintaining the code. The paradoxical upshot is usage of the pattern can actually increase the complexity if the application is simple.

For example, let’s say you’ve written a GUI that consists of a single button whose purpose when clicked is to produce a bell sound providing conditioned stimulus to make the user drool. (On the internet no one knows you’re a dog, after all.) The whole application can and should be handled completely by a single View. Usage of a pattern such as Model-View-Controller, Model-View-Presenter, or Model-View-ViewModel would be a sloppy mess, much like the aforementioned user’s screen, keyboard and mouse.

But rarely are applications that simple. Most will benefit from at least some pattern use, and as complexity grows, the advantages of patterns greatly exceed the overhead of implementing them. For applications using Windows Presentation Foundation (WPF), Silverlight, Windows 10 UWP, or Xamarin Forms as their user interface framework, this is where Prism can help.

What is Prism?

Prism, a project originally developed by Microsoft patterns and practices and now under the stewardship of the .NET Foundation, is a collection of resources implementing common design patterns and architectural support for loosely-coupled modular applications. It saves you the time, energy and complexity it would take to implement these resources yourself. To quote Prism’s own documentation:

Prism provides guidance designed to help you more easily design and build rich, flexible, and easy-to-maintain Windows Presentation Foundation (WPF) desktop applications. Using design patterns such as Model-View-ViewModel (MVVM), Composite View, and Event Aggregator that embody important architectural design principles helps you create a modular application—using loosely coupled components that can evolve independently. These types of applications are known as composite applications….It is expected that the application will evolve significantly over its lifetime in response to new requirements and business opportunities. In short, these applications are "built to last" and "built for change." Applications that do not demand these characteristics may not benefit from using Prism.

“Prism” was the early codename for the Composite Application Library (CAL) which was later renamed to Composite Application Guidance for WPF and Silverlight. No doubt realizing that they were headed towards a progression of increasingly long, complex and awkward to verbalize naming conventions, Microsoft took a step back and redubbed it “Prism.” Prism provides many different functionalities, including modular programming support, event aggregation, shared services, logging, command processing (including built-in implementation of the ICommand interface), deploying to multiple frameworks, support for both Model-View-Presenter (MVP) and Model-View-ViewModel (MVVM) presentation patterns (including built-in implementation of INotifyPropertyChanged) and dependency injection (DI) and inversion of control (IoC). For DI/IoC, Prism includes built-in support for both MEF and Unity, but can be configured to use other DI containers if desired. And since each asset is largely independent from the other assets, an application developer is free to use as many or as few of them as they want, depending on the needs of the application. While this blog series will touch on most of the functionality Prism provides, it will concern itself primarily with combining Prism with WPF, MVVM and Unity for UI framework, presentation model and dependency injection, respectively.

Where is Prism?

The Prism libraries and their source code are available on GitHub. The libraries are also available through NuGet. As of this blog post, the current version is 6.2.0.

Documentation can be found also at GitHub or through MSDN. The documentation is well written, thorough and organized and also includes some sample projects. However, it’s also fairly long and detailed, so this blog series will try to provide you with enough of an overview to get you started working with Prism without having to read the entire documentation start to finish. As a result, there are a considerable number of documented features that I won't be addressing in this series.

How Do I Use Prism?

In all honesty, considering all the functionality Prism provides, a full answer to that question exceeds what one can be reasonably expected to accomplish in a blog series. However, if you want a good foundation from which you can start programming with Prism and/or better absorb the documentation already out there, this series has that in spades. It will walk you through a step-by-step creation of a fairly simple WPF application that uses MVVM and Unity and touches upon a significant portion of the more commonly used functionality Prism provides. Each part of the blog will build on the previous part, and source code will be available, along with solution and project files. (Visual Studio 2015; .NET Framework SDK 4.6.2)

Note that this series assumes the reader has at least a passing familiarity with C#, WPF, and the MVVM design pattern.

So without further ado, we continue on to  Part 2:  The Shell and Bootstrapper

A Properly Pleasing Prism Primer - The Parts:

Part 1:  An Introduction
Part 2:  The Shell and Bootstrapper
Part 3:  Modules

Learn more about DMC's .NET application development services.

Comments

There are currently no comments, be the first to post one.

Post a comment

Name (required)

Email (required)

CAPTCHA image
Enter the code shown above:

Related Blog Posts