This content is outdated and is no longer being maintained. It is provided as a courtesy for individuals who are still using these technologies.
Typically, an application contains multiple WorkItems and services. Any WorkItem can contain only a single instance of a service type, but instances of the same service type can be placed in multiple WorkItems. You want to use instances of services from multiple WorkItems. You also want the ability to override instances of a service type in a WorkItem. Each WorkItem requires the ability to obtain the correct instance of a service from its current location in the WorkItem hierarchy.
In the Composite UI Application Block, the Locator object has the responsibility for locating services in WorkItems or their ancestors. Each WorkItem holds an instance of the Locator object, which is created at the time the work item is initialized. If the WorkItem has a parent WorkItem, the Locator object for the child WorkItem contains a reference to the Locator object of the parent (the Locator objects are connected in their inheritance hierarchy).
The Locator object contains references to the services in the WorkItem. The following line of code returns an instance of the IMyService service. This instance can be from the myWorkItemWorkItem or one of its ancestors. The call to myWorkItem.Sevices.Get<service interface> is handled by the Locator object associated with the myWorkItemWorkItem.
To add a service instance to a WorkItem, you can either explicitly create an instance and add it to the WorkItem or instruct ObjectBuilder to create the instance for you.
The following code explicitly creates a service instance.
In the following code, ObjectBuilder constructs the instance of the service.