Another post on Converting the Composite Web Application Block to Unity

Topics: Web Client Software Factory, User Forum
Apr 10, 2008 at 12:58 AM
Edited Apr 10, 2008 at 12:58 AM
I posted part three of the series on my blog today, Converting the Composite Web Application Block to Unity - Clean Up ICompositionContainer.

Based on feedback, I have also posted the source code at CWAB and Unity.

Enjoy,
Michael Puleio - patterns & practices
Webhttp://msdn.microsoft.com/practices/
Bloghttp://blogs.msdn.com/mpuleio/
Apr 12, 2008 at 12:38 AM


MichaelPuleio wrote:
I posted part three of the series on my blog today, Converting the Composite Web Application Block to Unity - Clean Up ICompositionContainer.


Hi Michael,

Understanding that I realize that I'm in over my head on this (my DI knowledge is minimal) along with the knowledge that I am committed to learning Unity and this seems to be a perfect vehicle to do so... I was curious if you have the time (and patience) to help me as I follow your lead with the Smart Client Software Factory?

I was going to wait until I completed my SCSF Contrib project but I figured you are doing this in bite-size chunks and I figured I could take a break as I work through each of your series.

My lack of DI and containers experience has me at a loss coming out of the gate because it is not real clear to what the separation of responsibility is for the container and therefore what the final interface needs to be, however I figured I'd try to keep it as close as possible to yours - and work through it.

Before I move on to series two I need to get my interface completed. With the differences is it practical to attempt to utilize your ICompositionContainer interface to Wrap the WorkItem around? Or should I be moving towards an interface that supports the ManagedObjectCollection containers (using Interfaces versus class reference)?

If you could point me in the general direction I need to go to construct me interface I'd appreciate it :)

using System;
using System.Diagnostics;
using System.ComponentModel;
 
using Microsoft.Practices.ObjectBuilder;
using Microsoft.Practices.CompositeUI.Collections;
using Microsoft.Practices.CompositeUI.Commands;
using Microsoft.Practices.CompositeUI.Utility;
using Microsoft.Practices.CompositeUI.SmartParts;
using Microsoft.Practices.CompositeUI.EventBroker;
 
namespace Microsoft.Practices.CompositeUI
{
    interface IWorkItemContainer
    {
        WorkItem Parent { get; set; }
 
        WorkItem RootWorkItem { get; }
        Builder builder { get; }            //<=== was private
        IReadWriteLocator locator { get; }  //<=== was private
        ServiceCollection Services { get; }
        event EventHandler<DataEventArgs<object>> ObjectAdded;      //<=== was internal
        event EventHandler<DataEventArgs<object>> ObjectRemoved;    //<=== was internal
 
        ManagedObjectCollection<Command> Commands { get; }
        ManagedObjectCollection<EventTopic> EventTopics { get; }
        ManagedObjectCollection<object> Items { get; }
        ManagedObjectCollection<object> SmartParts { get; }
        ManagedObjectCollection<WorkItem> WorkItems { get; }
        ManagedObjectCollection<IWorkspace> Workspaces { get; }
        UIExtensionSiteCollection UIExtensionSites { get; }
 
        void Buildup();                                 //<=== was internal
        void InitializeRootWorkItem(Builder builder);   //<=== was internal
 
        [InjectionMethod]
        void InitializeContainer();                     //<=== added
 
        //------------------------------------------------------------------
        //------------------------------------------------------------------
 
        WorkItemStatus Status { get; }
 
        TSmartPartInfo GetSmartPartInfo<TSmartPartInfo>(object smartPart) where TSmartPartInfo : ISmartPartInfo;
 
        TraceSource TraceSource { set; }
        string ID { get; set; }
        State State { get; }
 
        void OnBuiltUp(string id);
        void OnTearingDown();
        void Activate();
        void Deactivate();
        void DeleteState();
        void Dispose();
        void InitializeWorkItem();
        void Load();
        void RegisterSmartPartInfo(object smartPart, ISmartPartInfo info);
        void Run();
        void Save();
        void Terminate();
 
        event EventHandler Activated;
        event EventHandler Deactivated;
        event EventHandler Disposed;
        event EventHandler Initialized;
        event EventHandler RunStarted;
        event EventHandler Terminated;
        event EventHandler Terminating;
 
        event CancelEventHandler Activating;
        event CancelEventHandler Deactivating;
        event EventHandler<DataEventArgs<string>> IdChanged;
    }
}
Apr 12, 2008 at 6:17 AM
I have not looked at the guts of CAB in a looooong while. However, I would start by determining where the container is, see if it can easily be wrapped and extracted, and then compare the interface with that of Unity, and see what would need to be done. If I have a chance over the weekend (unlikely considering it is supposed to be sunny and 70 tomorrow -- Yea!), I will take a look at CAB and reply over on the SCSF forums.

Another option, go look at Prism and what they are doing. Consider Prism as close to CAB for WPF as you are going to ever see. Since Prism is using Unity, in a way that it can be swapped out with any other DI container, it would give you a starting point for an architecture that may work.

Enjoy,
Michael Puleio - patterns & practices
Webhttp://msdn.microsoft.com/practices/
Bloghttp://blogs.msdn.com/mpuleio/
Apr 12, 2008 at 2:32 PM
[Michael] I will take a look at CAB and reply over on the SCSF forums

Didn't mean to put something else on your plate :O please don't feel obligated to do so unless it's something that's got your interest (don't want to take away from your series). I need to do my homework and increase my knowledge so that I communicate with you at a level that will best leverage your time and experience.

[Michael] I would start by determining where the container is, see if it can easily be wrapped and extracted, and then compare the interface with that of Unity, and see what would need to be done.

Forest through the trees - your statement gave me a path to take. Where I feel comfortable with the ObjectBuilder I'll need to take a few days with Prism and Unity to understand its Interface so that I can perform the comparision; once I have it understood I can do an effective gap analysis to determine the required interface.

Once out of the forest... I'll revisit your first series and start with your ICompositionContainer so that I don't have to reduplicate the wheel; particularly since I'd rather complete a car that had wheels built on experience ;)
Apr 24, 2008 at 6:26 PM
The other day, I posted part 4 of the series on my blog at Converting the Composite Web Application Block to Unity - Ummmm...Oooops.
There is no code yet on this one. The ooops in the title means that I need to roll back and redo a few things. :-(
It should be an interesting read for those who are fuzzy on refactoring, making major architectural changes to a system, and those who want to see a technique for failing fast.

Enjoy,
Michael Puleio - patterns & practices
Bloghttp://blogs.msdn.com/mpuleio/
Apr 25, 2008 at 4:04 AM
Edited Apr 25, 2008 at 4:04 AM


MichaelPuleio wrote:
It should be an interesting read for those who are fuzzy on refactoring, making major architectural changes to a system, and those who want to see a technique for failing fast.


The cost of living on the bleeding edge - someone has to bleed... Those of us that leave our footprints in the sticky ooze you leave behind are very greatful to you (because it isn't ours ;) We appreciate you because we learn something from every battle you fight (win or lose). This battle taught me that VSS will be my best friend, unit test are critical to the process, test and check-in, check-in and test, test, check-in often :)

Side note... the SCSF Workitem has boo-coo Managed Object collections and from what I'm reading they, like services, will be going away as "Unity handles this sort of functionality" - I'll have to tread carefully..... I'm chomping at the bit to get started but figured I'd better get out from underneath of my SCContrib.CompositeUI.MDI project first so I can focus (hopefully by the end of the month, early May).

The Unity container I have in mind (to start with) will be used to unify my WCSF/SCSF shared projects (for my http://www.CodePlex.com/SDMS solution). My initial goal is to let WCSF/SCSF do what they do best (infrastructure) and let the Unity Container pick up business for both platforms starting at the <module>ModuleInitializer.cs and ModuleController.cs respectively.

No worries on us thinking "you dropped the series"; we know your doing this on your own time - and that you have a life - particularly on nice days :) I think I can speak for the community in saying that we appreciate anything you can provide, when you can provide it - at your convenience.

Thanks!
Bill
Apr 25, 2008 at 11:24 PM
The code for #4 is finally up. It took all of 15 minutes to redo. Find it on the CWAB and Unity page. The next article will actually add unity to the solution (I think). :-)

Enjoy,
Michael Puleio - patterns & practices
Bloghttp://blogs.msdn.com/mpuleio/