Shared State And Nested Workitems

Topics: CAB & Smart Client Software Factory
Oct 5, 2005 at 11:44 PM
originally posted by: markgmarkg

In the case of nested workitems, what is a guideline to share a state between the parent workitem and the child one?
Oct 8, 2005 at 6:04 PM
originally posted by: BradWilsonMSFT

To maximize reusability, I'd suggest passing the state via constructor to the new WorkItem rather than using State injection, since it allows the WorkItem to be reused with anybody that has the information (without presuming that the information comes from the WorkItem above).
Oct 9, 2005 at 11:23 PM
originally posted by: markgmarkg

Can I conclude that State injection is useful only in the scope of a single workitem?

In the case when the nested workitem acts slightly different in different contexts (e.g. view changes), do you suggest to provide multiple ctor overloads?
Oct 10, 2005 at 4:44 AM
originally posted by: BradWilsonMSFT

Yes, State injection gives you only state from your containing WorkItem.

The oddity is specifically with a WorkItem in a WorkItem, where the child WorkItem using State is presuming that a piece of state will be in its parent WorkItem. For purposes of reusability, this isn't a good situation to be in (which is why I suggested an alterative).