PRISM, or Composite Application Guidance/Library for WPF/Silverlight, is a library and a corresponding guidance document that helps you to build loosely coupled “composite” WPF and Silverlight applications.
The library itself “sits on top” of an Inversion of Control Container (Unity by default), and provides facilities for modularising your application, composing your UI from components, loosely coupling events and, in Silverlight’s case, only downloading parts of your application as and when they’re required.
Sounds great doesn’t it?
So, There Must Be Something Wrong With It.. Right?
Plenty has been written about PRISM, its benefits, and how to get started; but very little on why you wouldn’t use it on your next WPF/Silverlight project. I’ve put together some concerns, based both on criticisms I’ve read, and supposition on my part; and some commentary about whether I believe those concerns are well founded or not.
“I’m Only Doing a Small Project!”
Granted, PRISM is rather overkill for “toy” applications; but are you sure your application is always going to stay that small and simple? One of the big advantages of the modular nature of a PRISM app is being able to add and test new features with relative ease. I’m sure we’ve all started projects that started off as a simple little toy app, but have since grown organically into something rather more complex – possibly ending up with some pretty kludgey code at the end of it.
No; it’s not. Really. There’s nothing particularly complex in PRISM, either conceptually or in the code you have to write. Once you understand the structure of a PRISM project, you’ll probably find that your code is actually easier to follow, as it is separated into clearly defined parts.
If you want an easy to follow tutorial that takes you from File.. New, through to a working application, then take a look at the excellent screencasts from Blaine Wastell’s blog.
“It Takes Too Long To Use! There’s Too Much Overhead!”
If you’ve watched some of the initial screencasts about PRISM, or had a peak at some sample code, you might be thinking that the overhead of creating all these “extra” classes and projects is just too much. While it certainly is more work than just File.. New and throwing controls on a page; once your initial project structure and bootstrapper is setup, adding new modules is no more time consuming than adding a normal User Control.
Separating your view from it’s logic; whether it be with ViewModels, the Presentation Model, or any other pattern, is going to be slightly more work; but the testability and data binding benefits far outweigh any slight increase in typing!
“It Will Add Bloat to My Silverlight App!”
The PRISM binaries, including Unity, weigh in at around 270k; and squeeze down to approximately 100k when zipped. Not exactly tiny, but not exactly Bloaty McBloater. In fact, if you take advantage of PRISM’s ability to bundle parts of your Silverlight application into different XAP files, and only load them when needed, you may find your initial payload is actually smaller than it would be without PRISM.
“You Have To Use Unity! I Don’t Want That Dependency!”
I’ve seen this repeated several times, but it’s simply not true. Although PRISM “out of the box” uses Unity, and comes with a Unity Bootstrapper; you can plug in your own IoC container without too much trouble. At the time of writing I believe there are alternatives for Spring.Net, Castle Windsor and StructureMap already written for you.
“I Want Control Over *ALL* My Damn Code!”
Firstly, if you’re writing a .Net application then chances are you are calling at least one library that you didn’t write Secondly, PRISM is very “lightweight”. It’s a helping hand at your disposal, rather than a monolithic framework that takes over your whole application and forces you to work in a certain way. Thirdly, you can just pick and choose which parts of PRISM you want to use, it’s not an “all or nothing” proposition. Don’t like the view composition? Then don’t use it! And finally, it’s all open source, so if you don’t like the way something works – change it!
“It’s From MS – So It Sucks!”
Unfortunately if someone holds this view, then there’s probably nothing anyone can say to change their mind. While everything that comes out of Microsoft isn’t perfect, far from it, it most certainly doesn’t all suck
With PRISM, the exceedingly smart guys from the Patterns and Practices team have created an excellent set of tools and guidance to help solve some very common problems; without producing a heavy, complicated framework in the process (CAB anyone? )
“I Can’t Frikkin’ Find It!”
Ok, I admit it, you’ve got me on this one! Is it on MSDN? Is it on CodePlex? Both?! Is it called PRISM? The Composite Application Library (CAL)? Or maybe Composite Application Guidance for WPF and Silverlight (CAG)?
Now CAL obviously refers to the library, CAG to the guidance, and I believe PRISM is an umbrella term for the whole project, but the naming is certainly confusing, and searching for PRISM takes you to CodePlex then MSDN and back again, so it’s very easy to get confused! In fact, finding, downloading and building the library is actually MORE confusing than using the damn thing! There is actually a whole article on Sparking Client on How to Find, Download and Build Prism for Silverlight, which speaks volumes
I really don’t see what’s wrong with calling the whole thing PRISM and leaving it at that. If I say “.Net Framework”, then most developers would know what I mean. There’s certainly no need for me to call it the “Microsoft Framework for Building Managed Applications Targeting the Windows Platform (MFBMATWP)”
Tell Me More!
If you want to know more about PRISM, or if you want some walkthroughs and examples of how to use it, then here’s some links that should float your boat:
- The MSDN section covers the goals and architecture of PRISM, along with some hands on examples and labs.
- Shawn Wildermuth’s recent article from MSDN Magazine, entitled Composite Web Apps With Prism, contains a good intro to Prism, and a walkthrough on putting together a Composite Silverlight app.
- Blaine Wastell has plenty of PRISM resources on his blog, including links to the excellent “getting started” screencasts from Channel 9.
- Ward Bell did an excellent video introduction to PRISM at Tech-Ed and it’s available from IdeaBlade.
- Brian Noyes did some DNRTV episodes showing PRISM basics, and PRISM Events and Commands
- There’s some good introductory information on the Sparkling Client blog, including how to download and install it
- There are some interesting additions to PRISM on the contrib Codeplex site.
- Ward Bell has an interesting article on his blog, in a similar vein to this one, where he asks Are We Overselling Prism?
- There’s a list of 10 Things To Know About Silverlight Prism on the Sparkling Client blog.