ObjectBuilder / IOC configuration

Topics: CAB & Smart Client Software Factory
Nov 16, 2005 at 3:36 AM
originally posted by: JamesMulvey

The documentation provides an example of configuring "core" services so that a different implementation is loaded.

My question is:
Is there a mechanism for localized IOC / ObjectBuilder configuration?

Consider the following:
A service is defined IMyService:
Two modules define an implementation MyServiceImpl1 and MyServiceImpl2.
I want to configure a WorkItem:
WorkItemA to receive MyServiceImpl1
WorkItemB to receive MyServiceImpl2

Conceptually this seems possible; configuration could define that the container of WorkItemA is configured with one service implementation and WorkItemB with another implementation.
Nov 16, 2005 at 7:39 AM
originally posted by: BradWilsonMSFT

Yes, you can do this.

Each WorkItem is a DI container of sorts, and they support hierarchy. If you add MyServiceImpl1, registered as IMyService, in the WorkItemA.Services collection, then WorkItemA and all its child items, and all WorkItems down the hierarchy, when asking for IMyService, will get MyServiceImpl1. Ditto for WorkItemB and MyServiceImpl2.

In this way, the WorkItem acts like the classic service locator pattern, with hierarchy support (like System.ComponentModel does).
Nov 24, 2005 at 7:29 AM
originally posted by: JamesMulvey

How is this externally configured?

I guessed that one could do what you were describing programmatically; but it is more a question of the IOC configuration by external configuration.
Nov 26, 2005 at 8:47 AM
originally posted by: BradWilsonMSFT

In CAB, the external configuration comes from the application's .config file. You can list services in the configuration file, and they are loaded during application startup and placed into the root WorkItem.

If your question is more about ObjectBuilder proper, I'm working on an article right now that describes a simple wrapper/facade on top of ObjectBuilder that gives it Spring-like container behavior, configured via XML.
Nov 29, 2005 at 2:03 AM
originally posted by: JamesMulvey

Okay I guess I'm talking about the ObjectBuilder proper (although there isn't so much distinction between the global and local config case in my view); so I'm right in thinking that out of the box you have two choices right now:
1) Configure services globally via config.
2) Configure services locally via programmatic insertion of types into the IOC container.

And that by sub-classing / modification it is possible to accomplish (2) via configuration (which is what I'm interested in doing)?
Nov 29, 2005 at 7:17 AM
originally posted by: BradWilsonMSFT

Today, with just ObjectBuilder, it's actually #2 we support out of the box. To get #1 you need a facade. The configuration aspect of CAB's use of ObjectBuilder is specific to CAB. The example I'm going to release is more properly an illustration of #1.

The example will actually show you how to convert configuration into programatic calls to ObjectBuilder, since that's the main job of the facade. There isn't really much documentation on how the internals of ObjectBuilder works with respect to the existing strategies, so this should provide at least a small amount of example code to show how the strategies and policies are intended to work.

I should be ready to release it very soon now. I hope this week, but I don't want to make promises. I just got off vacation, so I may end up being buried in things this week. :)