Okay first make a project in Blend..
Next add all of the references to the Composite Application Library.. If you need to download it you can do so right here..
The assemblies you need to reference are..
- Microsoft.Practices.Composite.dll
- Microsoft.Practices.Composite.Presentation.dll
- Microsoft.Practices.Composite.UnityExtensions.dll
- Microsoft.Practices.ObjectBuilder2.dll
- Microsoft.Practices.ServiceLocation.dll
- Microsoft.Practices.Unity.dll
The Composite Application Library ships as source code, which means you must compile it to get the Composite Application Library assemblies (Microsoft.Practices.Composite.dll, Microsoft.Practices.Composite.Presentation. dll, and Microsoft.Practices.Composite.UnityExtensions.dll). Since Blend has no multi-project support at the moment you will have to do this part in visual studio..
Next..We have to look at the structure of the project. It’s helpful to know about containers..
“Applications built using the Composite Application Library are composites that potentially consist of many loosely coupled components that need a way to interact and communicate with one another to deliver the required business functionality.
To tie together these various modules, applications built using the Composite Application Library rely on a dependency injection container. The container offers a collection of services. A service is an object that provides functionality to other components in a loosely coupled way through an interface and is often a singleton. The container creates instances of components that have service dependencies. During the component's creation, the container injects any dependencies that the component has requested into it. If those dependencies have not yet been created, the container creates and injects them first.”
We spoke about View Injection in our last message..
Next we setup our main window. for a composite application it’s normally named shell.xaml
It usually looks something like this from Blend’s Editor
<Window x:Class="HelloWorld.Shell"
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="Hello World" Height="300" Width="300">
<ItemsControl Name="MainRegion" cal:RegionManager.RegionName="MainRegion"/>
</Window>
What does this do? Well it’s a normal Xaml Window with an ItemsControl and a defined Region called MainRegion. The “cal:RegionManager.RegionName="MainRegion” portion registers this region with the region manager.
Each region registered can add modules (or VIEWS)
Next let’s look as the shell.cs file and see what we have to do to instantiate a region. Remember that if you instantiate something in XAML you don’t need to do it in code.
namespace WpfComposite.Shell
{
/// <summary>
/// Interaction logic for Window1.xaml
/// </summary>
public partial class Shell : Window
{
public Shell()
{
InitializeComponent();
}
}
}
Wow! Okay nothing here, so how does the region manager get called to startup things?? Through the bootstrapper of course.. So let’s add a class called bootstrapper.cs
Make sure the references are set in it’s code
You will probably have more than what we have below, but these are required..