WorkItem.Items Question

Topics: CAB & Smart Client Software Factory
Sep 16, 2006 at 6:45 AM
originally posted by: MarcoPaul

Ok, I understand what all the various collections are off of the workItem, but what exactly is the Items() collection use for? Also, what is the diff. btw ComponentDependency and ServiceDependency?
Sep 16, 2006 at 8:44 AM
originally posted by: wyldebill

Lets see if I get this like I think I am...

the Items collection exposes all the components under the WorkItems collection (Smartparts, Services, Workspaces, other WorkItems), anything you added with Add or AddNew. But, I think code like WorkItem.Items.Get<t> will return the first t type object it finds - which may not necessarily be the one you want.
Sep 16, 2006 at 8:48 AM
originally posted by: MarcoPaul

Ok, that makes sense. Any ideas about the ComponentDependency?
Sep 18, 2006 at 9:17 AM
originally posted by: MatthiasFG

you have to distinguish between the 3 attributes
1) ComponentDependencyAttribute
2) ServiceDepedencyAttribute
3) DependencyAttribute.

Number 1 and 2 come from the CAB team. Number 3 is part of the original ObjectBuilder which comes with CAB but is not part of CAB.

With 1 you have to support an id to specify the object which comes from the local WorkItem.Items collection. And you can tell if you want the runtime system to create a new instance if not found. The ComponentDependencyAttribute is more like a StateAttribute but looks at the local Items collection. Internally it is handled like number 3 with less options.

2 can only inject objects identified by type. You can not "name" it other than its type. The wanted object may be optional that is, you will get a null value if you specifiy "Required=false" and it is not found. The search is done using the WorkItem.Services collection.

And 3 is the most flexible one. With this attribute you can give a name, a type, where the object is searched (SearchMode), and how to react if the object is not found.

-Matthias