Composite Application Guidance for WPF (Prism V1) Book released

October 31st, 2008 by dpoza

I’m proud to announce that the Composite Application Guidance for WPF was released in Book format and it is published by Microsoft Press.

We introduced the book this week at Microsoft PDC and it was a great success. Every copy was sold out on Tuesday with lots of people wanting more.

Overview
The Composite Application Guidance for WPF is a set of guidance designed to help you manage the complexities you face when building enterprise-level Windows Presentation Foundation (WPF) client applications. This guidance helps you design and build flexible composite WPF client applications using loosely coupled, independently evolvable pieces that work together and are integrated into the overall application. This type of application is known as a composite application. This guide spans a wide range of topics from the conceptual drivers to the architecture of the Composite Application Library. The guidance is intended to appeal to a broad technical audience to help you understand proven practices for creating composite applicatiions and evaluate the Composite Application Library.

Who should read this guide:

  • Application Architects
  • Developers
  • IT consultants
  • System Integrators

What this guide covers:

  • Key challenges in building composite applications and guidance on the solutions to solve these challenges.
  • Software design patterns applied in the Composite Application Library
  • Candidate composite architecture that you can use to create your own baseline architecture
  • Stock Trader Reference Implementation, which demonstrates an implementation of the baseline architecture
  • Technical implementation details of the Composite Application Library
  • How to design a UI for applications using the Composite Application Library
  • Pointers to the Hands-On Lab, QuickStarts, and How-to topics on MSDN

I hope that you find this useful. As always we are open to hear feedback from you.

Diego

Posted in Composite Application Guidance for WPF, Composite Applications, Silverlight, WPF | 1 Comment »

Composite Application Library (Prism) for CAB developers guidance released

August 22nd, 2008 by dpoza

Today we published the Composite Application Library for Composite UI Application Block developers guidance at Codeplex.
You can find the PDF in the CAL Getting Started page under the  section “Interested in Migrating from the Composite Application Block (CAB)?”.

This guidance will help those CAB developers that want to migrate their applications to the Composite Application Library and those who want to give it a try.

The guidance states the main reasons to migrate to the Composite Application Library for WPF and compares both libraries. This will help you to better understand how the concepts in CAB map to CAL.

The guidance includes code comparison, figures and comments. For example, the following figure compares the equivalent elements between the WPFQuickstart solution shipped with the Composite UI Application Block in the Smart Client Software Factory and the WPFQuickstart solution rewritten to use the Composite Application Library.

image

It also includes an interesting appendix which shows how to emulate WorkItems in CAL, using controllers with scoped containers.

We are looking forward to have feedback from your side on this guide in order to improve it before publishing it on MSDN.

I hope it helps,

Diego

Posted in .NET Framework 3.5, Composite Application Guidance for WPF, Composite Applications, WPF | No Comments »

Getting Started with the Composite Application Guidance for WPF

August 13th, 2008 by dpoza
 

Continuing with my previous post. Now I will be describing some of the Composite Application Library (Prism) concepts in more detail.
The following sections will describe how to create an application using the library and some of its key features.

How to create a new application that uses the Composite Application Library

To create an application that uses the Composite Application Library, you just have to create a new WPF Application project.

image

After that create a folder where you will put the Composite Application Library assemblies and add references to them.

You will use the recently created project as a Shell project. Typically, in a composite application, the Shell project provides an UI extensibility point where the views that compose the application will be shown.

You can see the XAML markup of a basic Shell window, containing an empty control defined as the main region, in the following snippet.

image

Bootstrapper

In an application that uses the Composite Application Library, you use a bootstrapper class to initialize the application. Having a bootstrapper gives you more control of how the Composite Application Library components are wired up to your application.

Typically, the bootstrapper initializes the container used for dependency injection, registers infrastructure services and region adapters, creates and shows the shell window, and loads modules.

The Composite Application Library comes with a default abstract UnityBootstrapper class that handles this initialization using the Unity container. Typically, you use this base class to create a derived bootstrapper class for your application.

The Composite Application Library allows you to choose the Dependency Injection container that your application will use because it is unaware of the container. The library brings out-of-the-box support for the Unity container; however, one of the architectural principles of the Composite Application guidance is Extensibility, therefore the container, as other library pieces, can be easily replaced.

If you are using a container other than Unity, you should write your own container-specific bootstrapper.

The bootstrapper’s CreateShell method must be overridden because it is declared as an abstract method in the base class.

You can see the typical implementation of the CreateShell Method in the following snippet:

image

Working with Modules

A module is a logical unit in your application and represents a set of related concerns. Modules created with Composite Application Library are defined in such a way that they can be discovered and loaded by the application at run time. Modules do not reference each other but they communicate with each other in a loosely coupled way.

A module initializer class should implements the IModule interface. This interface contains a single Initialize method that is called during the module’s initialization process.

In the Initialize method of your module initializer class, you implement logic to initialize the module. For example, you can register views and services or add views to regions.

Module loading is the process of loading modules into the application and initializing them. Modules are listed by the module enumerator service. The module enumerator creates a collection of metadata about those modules that can be consumed by the module loader service. After that, the module loader service loads the modules, instantiates the module initializer classes of each module, and invokes the Initialize method on them.

Types of Module Loading

You can load modules in several ways provided by the library, but you can also provide your own custom implementation.

The following are types of module loading supported out-of-the-box by the Composite Application Library:

  • Static module loading. When you statically load a module, the shell contains a reference to the module’s assembly. Static module loading provides less decoupling of the shell with modules than dynamic module loading. However, in cases where decoupling modules from the shell is not a requirement, loading modules statically can reduce code complexity, simplify the application deployment, improve startup performance, and simplify debugging compared to dynamic loading.
  • Dynamic module loading. When you dynamically load a module, the shell does not contain a reference to the module’s assembly; instead, modules are dynamically discovered at run time when the application starts. By doing this, the shell is decoupled from the modules. This implies that you can add, update, or remove modules from your application without recompiling the Shell project. There are two dynamic module loading provided by the library:
    • Directory lookup: This approach allows you to configure the modules using attributes in code and does not require a configuration file.
    • Configuration: This approach allows you to specify the modules in the application configuration file and does not require you to use attributes in code.

The following table shows the bootstrapper’s GetModuleEnumerator method configured to use each type of module loading.

Static Module Loading

image

Dynamic Module Loading - Directory Lookup

image

Dynamic Module Loading - Configuration

image

When modules are configured to be loaded using the ConfigurationModuleEnumerator, you have to add the corresponding section to the app.config file and configure that section.

image

Views and Regions

A region is a mechanism that developers can use to expose to the application’s WPF container control as components that encapsulate a particular visual way of displaying views (typically, views are user controls). Regions can be accessed in a decoupled way by their name and support adding or removing views dynamically at run time.

Because the library is designed to be extensible, it does not enforce you to use a specific view pattern. Therefore, you can use the pattern that suits your application better. See the “Separated Presentation” section in the library documentation for more information.

The following controls are supported out-of-the.box to be exposed as regions:

·         ContentControl and derived controls

·         ItemsControl and derived controls

·         Controls derived from Selector

Region Manager

The region manager service is responsible for maintaining a collection of regions and creating new regions for controls. Typically, you interact directly with this service to locate regions in a decoupled way through their name and add views to those regions. By default, the UnityBootstrapper base class registers an instance of this service in the application container. This means that you can obtain a reference to the region manager service in the application by using dependency injection.

Commands

Commands handle UI actions in a decoupled way. The Composite Application Library provides two command types.

Delegate Commands

The DelegateCommand allows you to delegate the commanding logic instead of requiring a handler in the code behind. It uses a delegate as the method of invoking a target handling method.

Additionally, because it accepts delegates, it removes the need for creating a new command type that implements ICommand for every instance where you need commanding. Also, it does not rely on control focus or the element tree as the RoutedCommand does, which can reduce headaches in composite applications, where pieces of the UI are pushed from different modules.

In the case of the Order module from the Commanding QuickStart had a Save Order command that was bound to a Button control in the UI. This is a simplified version of the code:

image

And from the view in XAML:

image

Composite Commands

The CompositeCommand is a command that has multiple child commands.

In the Commanding QuickStart, the Order module is using a CompositeCommand command to implement the Save All Orders functionality from the toolbar, where all the individual Save Order commands are called at a single button click.

Event Aggregator

The Event Aggregator service enables loosely coupled communications between components in your application. This service implements the publish/subscribe pattern, where the publishers do not send their messages to specific receivers, instead they publish to the service and subscribers receive only messages that are of their interest.

The real work of connecting publishers and subscribers is done by the CompositeWpfEvent class. This class maintains the list of subscribers and handles event dispatching to the subscribers.

The CompositeWpfEvent class is a generic class that requires the payload type to be defined as the generic type. This helps enforce, at compile time, that publishers and subscribers provide the correct methods for successful event connection.

Subscribing to an Event

Subscribers can enlist with an event using one of the CompositeWpfEvent available Subscribe method overloads. There are a number of options for subscribing to CompositeWpfEvents. The following code shows an example of event subscription.

image

Publishing an Event

Publishers raise an event by retrieving the event from the EventAggregator and simply calling the Publish method. As it can be seen in the following snippet.

image

Summary

This post is a pretty long one, but hopefully helps you realize the advantages of composite applications when developing enterprise-level applications between different teams. It is intended to provide a reasonably broad look at the Composite Application Library and all its features, and to show how easy it is to start developing applications with it.

While many of the concepts were redesigned from the Composite UI Application Block (CAB), the Patterns & Practices team has done an excellent job by incorporating customer and user’s feedback in the development of the library, thus, creating a simpler, more lightweight, less invasive and extensible library.

Therefore if you want to create a composite application taking advantage of WPF capabilities or upgrade an existing WPF application to a composite application, you definitely should take a look at the Composite Application Library.

If you want to learn more about the Composite Application Guidance, I strongly recommend giving the documentation a try, because it is very exhaustive and easy to read.

I hope you find it useful,

Diego

Posted in .NET Framework 3.5, Composite Application Guidance for WPF, Composite Applications, Visual Studio 2008, WPF | No Comments »

Composite Application Guidance for WPF Released

July 5th, 2008 by dpoza

I am proud to announce that we release the Composite Application Guidance for WPF both on Codeplex and on MSDN.

For the past months I have been working with the Patterns & Practices team in the development of the Composite Application Guidance for WPF. I took part of the documentation team, we worked hard to provide an excellent documentation and as a result we had really good feedback from users on the included documents.

Overview. What is the Composite Application Guidance for WPF?

The Composite Application Guidance for WPF is a set of Guidance designed to help you build enterprise-level applications composed of multiple independent and loosely-coupled pieces of software that work together to compose a single application.

Package Contents

The Guidance includes the following elements:

  • The Composite Application Library and Unity binaries
  • The StockTrader Reference Implementation
  • 4 QuickStarts: UIComposition QS, EventAggregation QS, Modularity QS and Commanding QS
  • Composite Application Guidance Hands-On Lab
  • API Documentation
  • Composite Application Guidance Documentation

Documentation

The following diagram shows what is included in the Composite Application Guidance Documentation:

image

I strongly recommend you to check the documentation because its very exhaustive and easy to read. I think it is an excellent starting point to learn the basics if you are new to composite applications and patterns usage, as well as if you are a CAB (Composite Application Block) developer.

Technorati Profile 

Posted in Composite Application Guidance for WPF, Composite Applications, Software, Visual Studio 2008, WPF | 1 Comment »