How do I make a class to be injectable?

Topics: CAB & Smart Client Software Factory
Feb 20, 2006 at 10:37 PM
originally posted by: RolandLi

As I know, the Service and WorkItem in CAB can be injected, but the others can not.
If I want my personal class to be injectable, what should I do?
I think it may be related with some Build Strategy and Build Policy, but I can't find which is.
Thanks in advance.

I've found way to do that by using the WorkItem.Services.AddNew<MyClass>();
Then MyClass is injectalbe.
But if you use WorkItem.Items.AddNew<MyClass>(); MyClass is not injectable
I mean the following code doesn't work.(Object Builder can't find the myclass in items);

public MyClass myclass
set{ _myclass = value;}

Can any one point out which code snippet in CAB is related with this issue?
Feb 21, 2006 at 6:11 AM
originally posted by: DLorenz

That's odd. I've created my own classes and injected them into CAB thru that WorkItem.Items.AddNew() call. Though, I wasn't using dependencies. Instead, I injected them so they could get/send EventSubscriptions/Publications.
Feb 21, 2006 at 4:57 PM
originally posted by: RolandLi

What I want is injecting MyClass to other classes.
CAB can do that by add MyClass as a service.
I want to know which code do that.
Thank you.
Feb 22, 2006 at 8:56 AM
originally posted by: BradWilsonMSFT

Mark MyClass with the Service attribute. Then the consumers of your class can use ServiceDependency to get to the singleton instance of MyClass in the root WorkItem.