Container Hierarchy

Jul 14, 2008 at 2:50 PM
I'm using CAB for over a year and got used to the container hierarchy concept using WorkItems with Sub-WorkItems. This is very helpful if you have i.e. to create multiple instances of the same view working with their own local services of the same type. Using separate WorkItems comes here very handy because you can create the service instance and the view in the same WorkItem. The view uses the local service from its WorkItem and can still use the global services of the RootWorkItem.  Does Prism also support a container hierarchy using Unity by default? Or do we have to implement this support by ourselfs?

Jul 21, 2008 at 11:35 AM
Edited Jul 21, 2008 at 11:36 AM
Hi tschaena,

It is possible to create child container in prism, this is a default feature of Unity and allows the same scheme to be implemented as provided in CAB.
One possible scenario would be something like this:

public class MyModule: IModule
  private IUnityContainer _container;

  public MyModule(IUnityContainer parentContainer)
    _container = parentContainer.CreateChildContainer();

  protected UnityContainer Container
    get { return _container; }

  public void Initialize()

Jul 22, 2008 at 7:40 PM
Hi WMeints,

Sure, Unity does support a container hierarchy. But since Composite WPF does not seem to support multiple containers with special classes, I'm forced to write my own kind of "WorkItemController" for Unity (Let's call it UnityContainerController ;-)). Anyway, this problem seems solvable...

Jul 23, 2008 at 2:10 PM
I'm considering to implement a module base class an workitem base class for CompositeWPFContrib, I will keep you posted on the progress.
Jul 23, 2008 at 3:39 PM
Hi Tschaena & WMeints,

You can implement the equivalent the equivalent of the WorkItemController in your Composite WPF App.  Simply implement a plain old C# class and add in to your container.  If using the Unity Container and you want only one instance within the container, just register your type with a ContainerControlledLifetimeManager.  See the OrdersController in the StockTraderRI.Modules.Position project for an example.  You can accomplish all the equivalent functionality as provided by the WorkItemController in this manner.

Registering your controller...

_container.RegisterType<IOrdersController, OrdersController>(new ContainerControlledLifetimeManager());

Injecting dependecies needed by your controller...

class OrdersController : IOrdersController
{ ...
public OrdersController(IRegionManager regionManager, IUnityContainer container,
                                     StockTraderRICommandProxy commandProxy, IAccountPositionService accountPositionService)

{ ...}

Using the controller...

public class PositionSummaryPresentationModel : IPositionSummaryPresentationModel, INotifyPropertyChanged
{ ...

public PositionSummaryPresentationModel(..., IOrdersController ordersController...) { ...}

Hope this helps.  Jim

Jul 24, 2008 at 7:36 PM
Hi Jim,

Thanks for the reference to the StockTrader example. Yep, I will do it in such a way.