Building Windows Store Business Apps with Prism

This course covers how to leverage the Prism for Windows Runtime guidance from Microsoft patterns and practices to build maintainable and testable Windows Store business applications using the Model-View-ViewModel pattern.
Course info
Rating
(108)
Level
Intermediate
Updated
May 17, 2013
Duration
5h 54m
Table of contents
Course Overview
Prism for Windows Runtime Overview
Getting Started Building WinRT Apps with Prism
Commands and Dependencies
Navigation and Application Lifecycle State Management
PubSubEvents and EventAggregator
Validation
Calling Web APIs
Leveraging WinRT Platform Features
Description
Course info
Rating
(108)
Level
Intermediate
Updated
May 17, 2013
Duration
5h 54m
Description

When building client business applications for WinRT and the Windows Store in XAML you need to design your application for maintainability and testability. To achieve this, you need to design your application following principles of separation of concerns and loose coupling, which usually means employing the Model-View-ViewModel (MVVM) pattern in XAML. In addition, you have to learn how to leverage the new features of the Windows Runtime (WinRT) platform to ensure a great user experience, but have the code that drives that experience in the right places in your application following the MVVM pattern. In this course you will learn how to do that by learning how to leverage the Microsoft patterns and practices guidance "Prism for Windows Runtime" directly from a member of the Prism team. You will learn how to separate your Pages into Views and ViewModels following the MVVM pattern and integrate nicely with the WinRT navigation system and application lifecycle of suspend/terminate/resume. You'll learn how to manage dependencies and communicate between loosely coupled components in your application. You will see how to validate user input, both on the client side and through service calls to a back end, as well as how to display those errors to the user. You learn how to call Web API services and how to do simple authentication and authorization with those services. Finally you will learn how to leverage Windows Runtime platform features including Search charm, Settings charm flyout panels, and Live Tiles.

About the author
About the author

Brian Noyes is CTO and Architect at Solliance, an expert technology solutions development company. Brian is a Microsoft Regional Director and MVP, and specializes in rich client technologies including XAML and HTML 5, as well as building the services that back them with WCF and ASP.NET Web API.

More from the author
Securing Angular Apps with OpenID and OAuth2
Intermediate
2h 30m
27 Jul 2018
WPF Productivity Playbook
Intermediate
2h 57m
22 Aug 2016
More courses by Brian Noyes
Section Introduction Transcripts
Section Introduction Transcripts

Prism for Windows Runtime Overview
In this first module I'm going to introduce you to the general concept surrounding Prism for Windows Runtime guidance. I'll talk about some of the surrounding business context to building applications for WinRT and some of the considerations that business apps have as opposed to non-business apps. I'll talk about the Prism for Windows Runtime guidance itself, the architectural goals, and what it contains, and I'll contrast Prism for Windows Runtime with a previous set of guidance called Prism 4. First up, we'll talk about business apps in general and what the categories of business apps are that Prism was really designed to address. We'll also talk about some of the terminology surrounding WinRT and Windows Store apps to make sure you're very clear on what the target platform is for Prism and how it relates to some of the terminology you may hear around developing apps for the Windows Store. Next, I'll get into the Prism for Windows Runtime guidance itself. And we'll talk about the architectural goals, what it's designed to address. And more importantly, what's contained in the box, if you will, that you get and can reuse, and use for reference from Prism for Windows Runtime. I'll go into a demo of the AdventureWorks Shopper RI. RI here, stands for Reference Implementation, which really means a big end-to-end sample application that show you how to employ all of the concepts and code that Prism includes for building business apps on WinRT. I'll get you familiar with both the solution structure of the code itself, and then I'll give you and end-to-end walk through of the functionality of the application so that you can use that as a reference as I go through the rest of the materials of the course to go back to the AdventureWorks Shopper, and find where the individual pieces of functionality reside. Finally, I'll finish off this module by contrasting Prism for Windows Runtime versus Prism 4, a previous set of guidance which targeted WPF and Silverlight. I'll talk about the similarities and differences of those, and where the shared heritage is between them.

Getting Started Building WinRT Apps with Prism
In this module I'm going to show you how to get started from scratch building your own applications using the Prism reusable libraries. We'll talk about the MVVM pattern in general with WinRT and how they mesh together. And then we'll build out a demo from scratch using the Prism reusable libraries to get some basic MVVM functionality. Then we'll look at one of the pieces of infrastructure supporting MVVM in Prism, is the View Model Locator class and how to use it. So, first I'm going to dive into MVVM and WinRT. I'll do a quick review of the core concepts of MVVM. And we'll talk about how it overlaps with WinRT development and some of the things you get out-of-the-box when building a WinRT application. Then we're going to build out an application from scratch. I'll tell you the steps involved ahead of time. And then we'll do it through a demo mostly showing you how to get started building out an app with Prism. Then we'll show you once you get into the MVVM pattern, you need to hookup views and view models all over the place, and a good way to go about doing that in a centralized fashion is a ViewModel Locator, which is part of the reusable code in Prism that makes it very easy to get your Views and ViewModels hooked up together.

Commands and Dependencies
In this module I'm going to introduce you to using commands to hook up communications between Views and ViewModels, so that the interactive logic that results from that can be put down in your ViewModels. We'll be using the DelegateCommand class from Prism to do that. We'll also talk about managing dependencies in your ViewModels. Dependencies are objects that your ViewModel uses to get its work done and managing those dependences is all about how do you go about constructing and getting those object references into your ViewModels in a way that can still be testable. First we're going to talk about the command pattern in general. How it relates to the MVVM pattern and where it came from and what it looks like in the WinRT APIs. Then we'll talk about the Prism DelegateCommand, which is the implementation of the ICommand interface to the platform that's built to be a reusable component that you can expose as properties from your ViewModel and easily bind to from your Views, and hook up the handling logic down inside of your ViewModels. After we've talked about commands we'll talk about dependencies. We'll talk about what a dependency is, how it gets into your ViewModels, some of the kinds of dependencies the ViewModels have, and how to do manual injection of those dependencies. And then we'll finish off the module by talking about IOC and DI containers. IOC stands for Inversion of Control and DI stands for Dependency Injection. To design patterns that go hand in hand and containers are the things that implement these patters to automate the construction and dependency hookup in your applications.

Navigation and Application Lifecycle State Management
In this module I'm going to get you more familiar with navigation in WinRT and how Prism assists you in controlling navigation and being aware of it in your ViewModels. I'm also going to dive into application lifecycle state management, which is a big fancy term for basically the transient data that runs around in your application and how it relates to your apps starting up and shutting down in various ways. You'll see that you need to proactively manage your state because of the normal lifecycle of a Windows Store application. First I'm going to go into navigation in WinRT and make sure you're familiar with the styles of navigation that are standard in a Windows Store application as well as the key objects in the WinRT platform that you use to cause navigation to occur. Then I'm going to switch over and talk about how Prism supports you in navigation and specifically how you can command navigation and control it from your ViewModels which we've actually already seen in some of the previous demos. I've shown the basics of calling the Navigate method to cause navigation to occur. But we'll go a little bit deeper there and show you what some of the options are. Then we'll talk about how your ViewModels can participate in navigation and be aware when there corresponding view is loaded up and they're being navigated to. As well as when their view is being unloaded to navigate to a different page and the ViewModel is being unloaded as well. This is important because you'll have to proactively manage the state that's managed by that ViewModel in the face of navigation. Then we'll talk a little bit about the WinRT application lifecycle and make sure you're very familiar with the different ways that your app can start up and shut down because they affect the way you manage your state in your application. Finally we'll see how Prism makes this a lot easier to manage, makes it very declarative and easy to save off transient state from your ViewModels as well as from your client-side services.

PubSubEvents and EventAggregator
In this module I'm going to get you familiar with the PubSubEvents of Prism which are centered around the event aggregator service. So first we'll talk about PubSubEvents in general and the scenarios where they make sense. The places in your application where you should think about communicating with PubSubEvents instead of explicit calls and dependencies. Next we'll talk about the basic hookup of PubSubEvents and demonstrate that. How you can use the event aggregator service, declare events, and then publish and subscribe those from different parts of your application. Next we'll take a little look at weak references, we'll describe what those really are. If you haven't been exposed to them, why they're important when it comes to events, and show how they can be used with the Prism PubSubEvents. So you don't have to worry about unsubscribing or leaking memory if you forget to. Next we'll look at the thread dispatching capabilities of the Prism PubSubEvents in the form of a demo. And you'll see how you can use that to control what thread you're subscriber gets notified on. Finally we'll look at the filtering capabilities of PubSubEvents which allows you to put a filter criteria to prevent your handler method from being called if the filter criteria is not met.

Validation
In this module I'm going to get you familiar with the Validation features that Prism offers for data input scenarios. As I've mentioned before, the WinRT platform doesn't have any direct support for displaying Validation. So in Prism we implemented a mechanism that makes it very easy to hook up Validation scenarios in your data entry forms with presentation that looked similar to what WPF and Silverlight had natively and underlying Validation mechanisms that are similar as well. First I'm going to talk about the Validation mechanisms in WPF and Silverlight for review purposes. Just as a point of contrast, because it's what we base the Prism mechanisms that we put together on. Then I'll talk about what's lacking in WinRT and what you need to do to supplement it if you want to put a Validation mechanism on top of the WinRT platform. And then we'll get into the specific support that Prism gives you for doing Validation. And we'll see how you can declare rules, attach them to your model or view model objects, have those rules evaluated whenever property changes occur, and how to display them. And even how to implement custom Validation rules that go beyond the ones built in to the. NET platform.

Leveraging WinRT Platform Features
In this final module, I'm going to give you a quick, guided tour of some of the WinRT platform features and how those are leveraged in the AdventureWorks Shopper application of Prism. You'll see how Prism has wrapped some of those up in abstractions and interfaces to make them more MVVM-friendly and more testable. First we'll talk about the Search Charm or contract. Again, charm and contract are somewhat interchangeable terms in WinRT and we've already seen this demonstrated in the AdventureWorks Shopper, but we'll see how it plays out here in terms of the code. Then, we'll look at the Settings Charm, the ability to put your own custom settings in the settings file panel that's part of the operating system, but have the functionality embedded in your application. Then we'll look at Flyout panels, which are an ability to have your own custom UI that comes out from the side of the screen similar to the settings panel. These can be the actual dialogues that result from clicking on different settings links in the settings panel or they could be things that are part of your application where you want a similar experience. And last, we'll look at Live Tiles, both the primary Live Tile of the application and the secondary tiles that AdventureWorks Shopper supports, which is like a deep link to a particular page in your application that you can put on the Start screen.