Wednesday, July 2, 2008

Composite Application Guidance (CAG) for WPF is here!

Patterns and Practices just released the Composite Application Guidance (CAG) for WPF 2008.

You might know it by its codename, "Prism" ... a name I loved and will miss. What matters is that it exists. There is now a set of libraries and guidance for building WPF applications in a compositional manner.

Why does this matter? Because most of us have learned the hard way that we should "compose" our applications from parts and pieces. The question is not should we do so, but how to do so.

How do we build those parts independently and make them come together in what the user perceives as a single application? It's easy if the parts have nothing to do with each other. It's much harder if the parts must interact. We're going to need some architecture, some patterns, and some glue code to achieve that blissful state in which truly independent components, with no references to each other, somehow manage to collaborate seamlessly.

Patterns and Practices has been down this road before with the Composite UI Application Block (CAB) and its add-ons (Smart Client Software Factory, Web Client Software Factory, etc.). CAB was PnP's pioneering effort in this space. It achieved considerable success; there were many substantial applications built with CAB and my company wrote its own application integration layer on top of it called Cabana.

It also acquired substantial notoriety. Everyone agrees it had too many moving pieces that were hopelessly entangled and that it was devilishly difficult to learn.

So when the team took up the challenge of providing compositional guidance for WPF applications, they seized the opportunity to re-examine the CAB experience, harvest what worked, and improve upon its defects.

They reached out to the developer community, drawing upon those with CAB experience and upon those who had experience with rival approaches. And they listened. And they spiked what they heard and listened some more. They turned the spikes into production code and listened again. Iteration after iteration.

The Results

They have delivered an elegant product. On time. Far ahead of the December '08 date that I dreamed of in my unbridled optimism.

I think it hits the right notes. CAG is small enough to understand and rich enough to support serious application scenarios. The parts work well together. But you don't have to use them all and you can easily substitute your service for any of the shipped services.

The team likes to talk about how you can replace the Dependency Injection mechanism with your favorite: Unity, Castle, StructureMap, etc. I think it is as important that you can replace the EventAggregator or RegionManager or any other ingredient that didn't suit your needs. Not that I'm in a hurry to do so. I just want the comfort of knowing that I could.

This time PnP devoted serious effort and resources to guidance. You see it most prominently in the "Stock Trader Reference Implementation" (RI) that demonstrates (a) what we mean by a "compositional UI" and (b) how all of CAG collectively supports such an application. It is simple without being simple-minded. It's a toy for sure but it serves its pedagogical purpose well.

  Note: Please don't build on it! It is not an application framework. Its practices are not always the "best" or even necessarily good. It is a resource for you; a place to discover how you might solve a problem with two or more CAG components in combination.

I don't know for sure but it sure strikes me that CAB's RI, the "Bank Teller", was an afterthought. Not so with CAG's "Stock Trader". It was designed first, before CAG work began in earnest. It co-evolved with CAG. It is and was intended to be CAG's "acceptance test".

There are eight "Quick Starts" that explore CAG components individually and (mostly) in isolation. As with the RI, you wouldn't slavishly adopt Quick Start code. Indeed, you should probably fight with this code, hurl it against the wall, and shake your fist ... and after your satisfying tantrum subsides, you will realize that you understand how it works. Somewhere, someone on the PnP team will be smiling.

There are over 300 pages of CAG documentation. This is not of the "insert tab 'A' into slot 'B'" variety. The team tried to explain "why" as well as "how" and it shows.

Is CAG right for you?

How would I know? I haven't built anything with it yet. And I don't know anything about you. That won't stop me from telling you what to do.

I would use CAG if I was starting a new WPF project. I'm convinced it will pay dividends immediately. WPF applications, more than Windows Forms applications, resist compositional strategies. I'd want to work on manageability early. WPF itself is still a struggle to learn and when things go wrong, they go really wrong. I want confidence that if this little corner of the application catches fire, the rest of my house is well insulated and will keep standing.

There is no CAG for Windows Forms or Web Client. If I had an existing CAB investment, I'd stay with it. If you are starting a new Windows Forms project and have some time to kill, you might glom on to one of the efforts to port CAG to WinForms ... there is sure to be someone attempting it soon. I say this as a CAB guy too. I would be sorely tempted to develop in CAG rather than CAB if I was starting a new WinForms app and had enough lee-way to make some beginner mistakes. It's simply that much better than CAB, even in the medium term.

If you have a CAB app today, do not despair. Don't be distracted. Don't drop everything and re-implement in CAG. CAB is working for you. Sit this one out until there is more real world CAG experience.

If you're building your application in Silverlight ... you're getting ahead of yourself aren't you.  Expect to see a CAG for Silverlight. Someone is bound to port it. I just don't know who.

6 comments:

iennacca said...

Ah, I wish I read more posts like yours and Googled Acropolis and Prism in the same search box a lot sooner :). We're in the downwind phase of a huge conversion effort built around .NET and CAB, and I'm just now starting to check on the new releases (with an eye on WPF integration).
I downloaded and played around with Acropolis for a couple of days before realizing I had to go to Prism instead. Acropolis showed great promise, and I do hope to see more of what it promised in the near future. Until then, I'm doing my RI's for my current development work in Prism :D.
Thanks for your blog, quite enlightening :D.

Anonymous said...

We are working on composite application for Silverlight. My opinion is there is no need to port any desktop platform to Silverlight. In this case xap packages will have large size.

Anonymous said...

Hi !.
You may , perhaps very interested to know how one can collect a huge starting capital .
There is no need to invest much at first. You may start earning with as small sum of money as 20-100 dollars.

AimTrust is what you thought of all the time
The company represents an offshore structure with advanced asset management technologies in production and delivery of pipes for oil and gas.

It is based in Panama with structures everywhere: In USA, Canada, Cyprus.
Do you want to become a happy investor?
That`s your choice That`s what you desire!

I feel good, I started to take up income with the help of this company,
and I invite you to do the same. It`s all about how to choose a correct companion who uses your funds in a right way - that`s the AimTrust!.
I earn US$2,000 per day, and my first investment was 500 dollars only!
It`s easy to start , just click this link http://gysatylycu.mindnmagick.com/sojuku.html
and lucky you`re! Let`s take this option together to feel the smell of real money

Anonymous said...

Good day !.
You re, I guess , perhaps curious to know how one can manage to receive high yields .
There is no need to invest much at first. You may begin earning with as small sum of money as 20-100 dollars.

AimTrust is what you thought of all the time
The firm represents an offshore structure with advanced asset management technologies in production and delivery of pipes for oil and gas.

It is based in Panama with offices around the world.
Do you want to become really rich in short time?
That`s your chance That`s what you desire!

I feel good, I started to get income with the help of this company,
and I invite you to do the same. It`s all about how to select a correct partner utilizes your savings in a right way - that`s the AimTrust!.
I earn US$2,000 per day, and my first deposit was 1 grand only!
It`s easy to get involved , just click this link http://axytyfewyb.dreamstation.com/tisyrax.html
and go! Let`s take this option together to feel the smell of real money

Anonymous said...

Nice post and this mail helped me alot in my college assignement. Thank you on your information.

Anonymous said...

Good fill someone in on and this mail helped me alot in my college assignement. Thank you on your information.