Gavin Stevens's Blog

the ramblings of another developer....

  Home  |   Contact  |   Syndication    |   Login
  34 Posts | 0 Stories | 57 Comments | 212 Trackbacks

News

Archives

Post Categories

I started working on a new project a few weeks ago.  Were writing a new extensible Shell application with the Microsoft CompositeUI Application Block.  I haven't used this block before.  Looks like Microsoft rushed this thing out the door.  Alot of needed functionality is missing, maybe the goal was to just provide a simple base shell layer and allow developers to extend it to do whatever.  I guess thats how it works when they are trying to release a new pattern or practice. 

So it took me a few weeks to wrap my head around this thing. ObjectBuilder was a new concept for me.  Pretty cool stuff though it turns out, Dependency Injection is a nice way of sharing global objects and making sure everything is referecing the right things.  Here some sample Dependency Injection Code.

Say you create a new object, and you want it to have a reference a global Selection Service..  all you have to do is add this code to your class:

[SmartPart]

public partial class PropertyGridToolWindow : UserControl, ISmartPartInfoProvider

{

   ISelectionService _selectionService;

   [ServiceDependency]

   public ISelectionService SelectionService

   {

   set

   {

   _selectionService = value;

   _selectionService.SelectionChanged += new EventHandler(_selectionService_SelectionChanged);

   }

   get { return _selectionService; }

}

The cool thing about this, is instead of having to create an overloaded constructor to pass the existing instance of the Selection Service to the new object, Object Builder handles it all for you.  When creating the new PropertyGridToolWindow, just have ObjectBuilder do it:

PropertyGridToolWindow _propertyGrid;

_propertyGrid = ModuleWorkItem.SmartParts.AddNew<PropertyGridToolWindow>();

Thats it!  Object Builder will automatically set the reference to the Selection Service when the object is created.

I'll post some more cool things I discover here as I go.

Gavin

posted on Wednesday, December 27, 2006 7:55 PM

Feedback

# re: Microsoft CompositeUI Application Block 12/29/2006 6:36 AM Adron
Have you checked out the Smart Client Software Factory? It extends the CAB and provides a framework to utilize MVP/MVC frameworks. Check out my site I have two links for setting up and creating views in the SCSF/CAB World of MVP/MVC.

Post A Comment
Title:
Name:
Email:
Comment:
Verification: