Getting Workitem in a service

Topics: CAB & Smart Client Software Factory
May 7, 2007 at 8:16 PM
I recently implemented a service that I am injecting in the ModuleController. I created an AddServices() and call it from the Run() in the ModuleController. I have a member in my service called _workItem that is of type WorkItem, and a get method:

public WorkItem WorkItem {get return _workItem;}

In my service I am accessing the WorkItem, but the program crashes, and when I debug the line of code trying to access the WorkItem, it says that it is null.

I was just wondering, am I properly injecting the workitem in the service for use, or am I doing something wrong? Any help would be much appreciated.
Coordinator
May 8, 2007 at 2:28 AM
[ServiceDependency]
public WorkItem WorkItem {
  get { return _workItem; }
  set { _workItem = value; }
}

Matias
http://staff.southworks.net/blogs/matiaswoloski
Jun 3, 2008 at 10:05 PM


matiaswoloski wrote:
[ServiceDependency]
public WorkItem WorkItem {
get { return _workItem; }
set { _workItem = value; }
}
Hi Matias,
   I used this solution, but I have got problem that it didn't set right WorkItem. How can I assure that specific business WorkItem will be set? Does it depend on place where the service is injected? I set my service in presenter class, as this:

      private IToolbarProviderService _toolbarProviderService;
      [ServiceDependency]
      public IToolbarProviderService ToolbarProviderService
      {
         set { _toolbarProviderService = value; }
      }

     Thanks for any tip. X.


Jun 4, 2008 at 4:06 PM

The WorkItem that gets injected is the WorkItem in which you created and/or added the service. So, to assure that specific business WorkItem will be set, you should add the item to that specific business WorkItem.

 

Ignacio Baumann Fonay

http://staff.southworks.net/blogs/ibaumann/

Jun 11, 2008 at 2:13 PM
Edited Jun 11, 2008 at 2:14 PM
Another possibility would be a Dependency on the WorkItem's name:

[
Dependency(Name="MyBusinessWorkItem",SearchMode=SearchMode.Up)]
public WorkItem BusinessWorkItem{get;set;}

therefore you have to explicitly set the ID of the WorkItem after it was added to a WorkItemsCollection above the hierarchy:

WorkItem BusinessWorkItem = RootWorkItem.WorkItems.AddNew<WorkItem>();
BusinessWorkItem.ID =
"MyBusinessWorkItem";