Tuesday, April 29, 2008

Prism: Composite WPF Guidance

UPDATE: Minor changes thanks to some feedback from Glenn.

This is a post I am long overdue in making (yes, Glenn, I am finally getting to it!). For the last 4 months, I've been working about a week a month in between consulting and training gigs for Microsoft patterns and practices, helping to develop and architect Prism, which is the codename for a Composite WPF guidance package we have been working on. I can't take too much credit considering I have only been dedicating 1/4 time or so to the project, the bulk of the work has been done by the p&p Prism team. Plus, Adam Calderon from Interknowlogy recently joined them as another outside WPF expert, and is filling the void nicely since I didn't have enough time to give them.

What is a Composite UI Application?

Basically Prism is looking to address most of the same concerns that led to the development of the Composite UI Application Block (CAB) and the Smart Client Software Factory (SCSF). Specifically, if you have a large, complicated smart client application, particularly one developed by multiple (possibly distributed) teams, you can't afford to build it all into one big monolithic mass of UI code in a single or small number of top level windows and their code behind. You will need to modularize the application and compose the UI that the user sees out of smaller, more granular and well factored parts that are as decoupled as possible from one another, but come together to make the end result without an overly complex integration effort.

To a small degree, you can pull this off by simply decomposing your UI into user controls to partition the functionality across a number of these mini-screens that compose the UI. But even with that approach you typically end up with a complicated mess of interdependencies and communication paths between the individual parts.

To do it right, you need to apply a number of patterns for composing your top level UI out of individual modules and views, each of which is decoupled from each other and composable themselves. This is what we are setting out to make easier with Prism. CAB and SCSF actually did a very good job of this for Windows Forms, and can be used for WPF as well. However, CAB and SCSF had a number of negatives to them and also don't fully leverage the capabilities of WPF. As a result, we started with a clean slate with Prism and are not simply porting CAB. We are trying to leverage concepts and patterns that worked well in CAB, while strictly avoiding those that were overly cumbersome. We are also not reusing any code, with the goal of not being tainted by any of that past work and led down the "it was good enough" mentality that plagues many porting efforts.

What is it?

So what is Prism, or at least, what will it be when it ships? Prism is a guidance deliverable, which is a  combination of written guidance documentation, sample code, and the beginnings of what could become a "framework" some day. If you have been exposed to other p&p offerings such as Enterprise Library or Smart Client Software Factory, you will find it easier to understand what we will be shipping. Most of the effort so far has been focused on developing a "Reference Implementation" or RI, which is a sample application that represents a real world application that is more than a simple demo, but less than a huge sample like Dinner Now. Specifically, it is sample application that demonstrates the core concepts and coding patterns of the project, and that allows those to be teased out while trying to build something semi-real. While building that and refining the patterns, we also factor out as much reusable stuff as possible into a set of class libraries that could be considered the beginnings of a framework for building composite WPF applications.

By the time we ship, Prism will also contain documentation that includes overview information of goals and challenges, design patterns, how-to topics, documentation on the RI, and documentation on the reusable parts (the framework), as well as QuickStarts. The QuickStarts are smaller sample apps that demonstrate just one aspect of what Prism offers, often a pattern or piece of code that we recognize as a common need for composite apps, but not one that we can really incorporate into the RI without making it seem like a confusing mishmash of unrelated stuff. These too will be covered in the documentation. The frameworky pieces are designed so that they are usable in isolation - you don't have to adopt all of Prism to use part of it (one of the big downsides of CAB).

The key thing here is to provide stuff that makes building well designed composite WPF applications as easy as possible. However, I do have to caution you: building composite decoupled complex applications is... well, complex. We can help make it easier, but we can't make it easy. You are still going to have to do the work of figuring what the right levels of decomposition and decoupling are for your app and your dev team, and then learn how to apply the patterns that we are fleshing out and demonstrating for you. This will not be a push a button, read your mind, and pop out a fully implemented application tool. It will be more like a do-it-yourself guide for building these kinds of applications.

What is in Prism today?

p&p runs a very agile shop. We develop with a Test-Driven Development (yes, even test first to the degree possible) approach, short iterations (2-3 weeks), and ship frequently (current goals and performance are to release a code drop with each iteration). As a result, our code drops on each iteration are publicly available through the Prism Codeplex side. We welcome anyone who wants to start playing with or using the early bits to do so and give us feedback on what you like or don't like.

So far, Prism is mainly the RI, which is a stock trading application scenario. It is not very fully functioned, and has to only deal with dummy data for legal reasons yadda yadda. But it does incorporate a number of the features we have been working on.

The things in the RI so far include:

  • UI Patterns - we have Model-View-Presenter (MVP), Presentation Model (aka Model-View-ViewModel MVVM or just View Model), and a couple kinds of controllers in the RI and QuickStarts so far.
  • Modular decomposition - we are factoring out different pieces of functionality into different modules to represent the way a distributed team or multiple teams would likely decompose the work and allocate responsibility to different teams for different parts of the UI. The modular approach allows them to work more in isolation, minimizing dependencies and the need for shared source code access and check out (reducing source control contention). We are not yet doing dynamic modular loading like CAB does, but that is definitely in the backlog (to-do list).
  • Views - The UI composition is all based around the definition of views, which are granular piece of the overall "screen" that you are putting together. We have examples of simple views, which can be defined as a custom control, user control, or even just a data template, as well as composite views, which have child views and possibly regions contained within them.
  • Regions - this is the term we have settled on for something that is similar to what CAB called a Workspace. It is basically a container or location in the UI that modules can inject their views. For a decoupled composite app, you absolutely need these at a shell level so that the shell (top level window) does not have to have intimate (or any) knowledge of the contents that are provided by the modules. They can also be important down inside a composite view that is contributed by a module, so we are working on support at that level as well.
  • Commands - for decoupled composite UIs, the built-in routed commands of WPF are insufficient because they are inextricably tied to the visual tree of your application. As a result, you get stuck in focus hell if you try to use them when your command handling logic lives anywhere other than at the root of your visual tree. To provide a more decoupled approach that will work across views and modules, we have implemented a commanding approach that is based on the ICommand interface of WPF, but with a different implementation.
  • Dependency Injection (DI) - Also known as Inversion of Control (IoC), this becomes critically important for both breaking dependency chains when unit testing, and in the context of Prism, for allowing objects to be resolved without having object references passed explicitly all over the place, which breaks down the decoupling that you strive for in a composite app. Prism supports using multiple different DI containers. We are primarily using Unity, which is a new DI container developed by p&p, but you can also use Castle Winsor, StructureMap, Spring.net, or possible others.
  • Services - Services in Prism are not SOA web services, but rather decoupled chunks of functionality that can be used across multiple models. We are using services for getting data into our presentation models (with dummy data), as well as for some of the common functionality such as region management, commands, and eventually event brokering.
  • Custom Controls - to present some of our data in the way that we wanted, we needed some custom controls. Luckily we were able to steal a set of them from another Microsoft product team. They are not fully featured or production ready, but they are a starting point you can look at if you need to develop similar controls.

There is probably a few other key things in there that I am not thinking of off the top of my head, but hey, this post is getting long enough as it is.

Wrap up

So if you are in or moving into the WPF space, and if you are building large, enterprise scale apps with large or distributed teams, I'd encourage you to check out Prism and stay tuned for when we eventually release. I think you will find it will help accelerate your WPF development.





Tuesday, April 29, 2008 2:31:16 PM (GMT Standard Time, UTC+00:00)
Comments [3]  | 


  Monday, April 28, 2008

VS Live! San Francisco Slides and Demos

A little late to the game, but I have been struggling with some blog configuration issues that were preventing me from posting, and have finally found time to tackle those.

I gave two talks at VS Live! San Francisco.

Here are the slides and demos:

Exploit WPF Graphics without Wounding the Eyes   Slides    Demos

Build Composite UI Applications with CAB and SCSF    Slides    Demos

 

To create the database for the music data demos, you have two choices.

1) Follow the instructions in this post to create your own music library database based on your own collection:
http://briannoyes.net/2008/02/13/BuildYourOwnMusicDatabaseForDemosAndSamples.aspx

2) Download a database backup (29MB) from here: http://www.softinsight.com/downloads/MusicLibrary.bak and restore it.



Speaking

Monday, April 28, 2008 11:01:40 AM (GMT Standard Time, UTC+00:00)
Comments [1]  | 


  Friday, April 25, 2008

DevConnections Orlando Slides and Demos

I spoke this week at DevConnections in Orlando. As always a great time and a good show. For those that attended my talks, thanks for the great participation and questions! For those that didn't, you really need to work harder on convincing your boss to send you to a DevConnections conference. The line up of speakers is amazing and the venue is always great.

 

The three talks I gave were on building custom activities in WF, WPF Tools, and Service Oriented workflows.

 

You can grab the slides and demos from the links below.

 

Custom WF Activities:   Slides    Demos

WPF Tools:    Slides

SO Workflows:   Slides     Demos

Enjoy!



.NET | Speaking

Thursday, April 24, 2008 11:10:20 PM (GMT Standard Time, UTC+00:00)
Comments [0]  | 


  Friday, February 22, 2008

Upcoming Talks at VSLive! San Francisco

I'll  be speaking at VSLive! San Francisco this year after quite a few years since doing a VSLive! conference. I'm looking forward to it.

The two talks I'll be giving are:

Exploit WPF Graphics without Wounding the Eyes

Build Composite UI Applications with CAB and SCSF

If you haven’t already registered for VSLive San Francisco, you can receive a $695 discount on the Gold Passport if you register using priority code SPNOY. More at www.vslive.com/sf

Hope to see you there!



Speaking

Friday, February 22, 2008 11:06:03 PM (GMT Standard Time, UTC+00:00)
Comments [0]  | 


  Thursday, February 14, 2008

.NET Rocks! - WPF Update

I did another .NET Rocks! interview with Carl and Richard last week and it has gone live. You can find it here. We discussed a lot of tangential aspects of WPF including adoption rates, UI patterns, the WPF Composite (codename Prism) work I am doing with Microsoft patterns and practices, and a lot more.

Check it out if you have an hour to kill away from the keyboard.



Speaking

Thursday, February 14, 2008 4:32:39 PM (GMT Standard Time, UTC+00:00)
Comments [0]  | 


  Wednesday, February 13, 2008

Build your own music database for demos and samples

I have a music database I have been using for years for demos because lets face it, music data is a lot more engaging than tired old Northwind. The database I was using had been hacked together with some crude code that read MP3 metadata tags through some Windows APIs and a web service client that pulled down album art from Amazon. However it was write once/run once sort of code and I never got around to cleaning it up so others could generate their own database and not be stuck with the few albums I had data for in mine.

My buddy Tim recently used that database for a demo VSTO app he wrote and is demoing this week at the Office System Developer Conference, and he prodded me to update that utility code, so I finally got off my butt and did so (sorry it wasn't in time for your session buddy!). One decision I made was to not try to resurrect the code for using the Amazon Web Service directly. The problem with doing so is twofold. One problem is that unless you find an exact match on Artist and Album, it is hard to pull down the right album cover in an automated fashion without getting garbage. And unless the metadata is already up to date on your MP3 or WMV files, or you have been extremely disciplined with a folder convention matching the artist and album name, you are hosed for trying to do that matching. The other hitch is that to use the Amazon Web Service, you have to go register as a dev with them, get some IDs, and then make sure that you don't make more than one call per second to their web service.

I decided a better approach was to leverage embedded album covers in the MP3/WMV file metadata. That of course requires that your music files have those. So how do you get them there? You do what it says here and here. MediaMonkey is a great little app for updating the metadata of your music files, and it will pull down the album cover for you - one at a time. So it did take me a few hours one day that I was extremely brain dead and lazy and not feeling like doing anything remotely challenging to go through my hundreds of albums and get their album covers updated into the file. But that benefits you for Zune, iPod, Windows Media Player, and any other decent software that plays those files, so I have already found it well worth doing.

Once your music files have the album art in them, updating my utility became more of a one-stop shop. I just needed a library that would pull those tags out of the metadata for me. I found a nice one in CSID3Lib (http://sourceforge.net/projects/csid3lib). This made it a snap to load an MP3 file and suck the metadata out of it. Then a little LINQ to SQL sprinkled on and I have a decent little database generating tool.

You can find the source code for the database builder here. I also have a little WPF data app that demonstrates using the database here. There is a SQL script in the MusicDBBuilder project that you will need to run to create the database, but there is a command line switch that will do that for you. If you choose this, you will need to run once with the -c and master as the database connection string, then run again without the -c and the connection string to the new database, which will be named MusicLibrary based on the SQL script.

The project is currently configured in the debug command line parameters so that if you just run it in the debugger, it will create the database for you (or blow it away if it already existed and was not up to date).

You will need to go into the project properties and change the file path command line parameter to the root folder of wherever your music files live and change the connection strinig to the new database after the first run that creates the DB. It will recursively probe for music files, but will only read MP3 files in the current version. There is also a command line switch to turn off recursion and you can remove the -c if you just want it to add what it finds to the database instead of starting from scratch.





Wednesday, February 13, 2008 5:35:14 AM (GMT Standard Time, UTC+00:00)
Comments [2]  | 


  Thursday, February 07, 2008

Data Binding in WPF - .NET Rocks! TV

I recorded a DNR TV episode back in December that took a little while to hit the site, but is up now. This episode walks through the data binding features of WPF and shows how to set up basic data binding, converters, work with data contexts and more.

http://www.dnrtv.com/default.aspx?showNum=101



Speaking

Thursday, February 07, 2008 9:22:47 PM (GMT Standard Time, UTC+00:00)
Comments [0]  | 


  Tuesday, February 05, 2008

Dino Esposito Joins IDesign!

We are very excited to announce that the legendary Dino Esposito has joined us as a member of IDesign. Dino is well known throughout the .NET community for his wonderful books, articles, and conference talks. He will be teaching a number of classes through IDesign as well as doing consulting with us. Later this year he will be launching a new .NET Design Patterns class as well.

We are honored to have Dino among our ranks!





Tuesday, February 05, 2008 1:58:35 PM (GMT Standard Time, UTC+00:00)
Comments [0]  | 





















Sign In
Copyright © 2006-2007 Brian Noyes. All rights reserved.
designed by NUKEATION STUDIOS