CAL Cookbook
CAL provides a host of application support facilities, some of which I think should have been natively supported in the .Net Framework (but we won’t go there now). CAL includes; a UI composition facility through its RegionsManager; dependency injection support using the Unity container; a locator service; module loading and instancing control; an implementation for WPF Commanding (ICommand); a logging service; and a publisher/subscriber service. That’s a lotta stuff! So in order to be able to understand each facility we’ll break them out and cover each one individually.
CAL App
I’m assuming that you’ve already downloaded the library, if not you’ll find it here.
<Window x:Class="CALCookbook.AppShell"
xmlns:cal="http://www.codeplex.com/CompositeWPF"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="CAL Application" Height="300" Width="300">
<ItemsControl Name="MainRegion" cal:RegionManager.RegionName="MainRegion" />
</Window>
In App.xaml remove the default startup Uri from app.xaml, we’ll be manually instantiating the startup window. You might as well go ahead and add references to the CAL library, wherever you have located the library DLLs.
Create a new class, call it ‘Bootstrapper’ and derive it from UnityBootstrapper. And you probably want to add namespace references for CAL UnityExtensions and Modularity. In the new class provide an override for the ‘CreateShell’ and ‘GetModuleCatalog’ methods. In the CreateShell methods return an instance of the main window, AppShell. And in the GetModuleCatalog method, return an instance of ModuleCatalog. We’ll discuss this when we get to talking about modules.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Practices.Composite.Modularity;
using Microsoft.Practices.Composite.UnityExtensions;
using System.Windows;
namespace CALCookbook
{
class Bootstrapper : UnityBootstrapper
{
protected override DependencyObject CreateShell()
{
AppShell shell = new AppShell();
shell.Show();
return shell;
}
protected override IModuleCatalog GetModuleCatalog()
{
ModuleCatalog catalog = new ConfigurationModuleCatalog();
return catalog;
}
}
}
public partial class App : Application
{
protected override void OnStartup(StartupEventArgs e)
{
base.OnStartup(e);
Bootstrapper bootstrapper = new Bootstrapper();
bootstrapper.Run();
}
}
That’s it. Compile and run the application.

Not very exciting, right? Well it will be once we add some modules. And that’s what we’ll do next.
RSS feed for comments on this post. TrackBack URI