This project is read-only.

Access WorkItem's collection

Nov 23, 2007 at 3:56 AM
Edited Nov 23, 2007 at 3:58 AM
I believe I have to add every object that I want to access via dependency injection into the WorkItems collection and access them via the workItems collection only. Ex. ImyService serv = WorkItem.Items"myservicestring" Or WorkItem.Services.Get[]...

If so, say I have a class MyService which i need to use in multiple classes in my module. So I add an instance of the class as a service in the AddServices section of my ModuleController.

How do I access this instance from other classes in the module. How do i access the WorkItem's Item or services collection from a class that is neither a service nor a smartpart but needs access to the WorkItem's collection.

If I access MyService in other classes via the Servicedependency attribute. looks like I can only get the service injected if I also add the class to the WorkItem's Collection and retrieve them via the example shown above.

wondering if there is any other way to about this. basically, I have some classes in my module to need to access the workItem's collection and they are neither smartparts nor service, just helper classes that need access to the same instance myService class that exists in the workItem's collection - for reasons of state management.

I am also assuming that the instance I add will be a singleton unless I use the CreateNew attribute to access it from any downstream member
Nov 25, 2007 at 10:40 PM
Every class where you want injection to happen needs to be added with the container
WorkItem.Services.AddNew<MyClass, IMyClass>();
or if you want to create MyClass yourself and then add it to the container,
or if you want to add the service to the root workitem automatically
public class MyClass : IMyClass ...

Then you use a service like this
in a ctor or property

Nov 27, 2007 at 2:37 AM

Thanks Matiaswoloski.

I think I am beginning to understand the SCSF framework.

Really appreciate your help.