Strange problem adding services in a work item

Topics: CAB & Smart Client Software Factory
May 20, 2006 at 1:30 AM
originally posted by: Felice_Pollano

I've a work item that want declare itself as exposing two services via two different interfaces.
In the OnRunStarted I just did something like:
the second call fails, because the service subsystem seems not to be aware that the item is already built, and try to built from scratch.
It works if I register the services at an Higher level, for instance
Is ok. Why this ? is a regular behaviour or not ?
May 26, 2006 at 3:58 AM
originally posted by: DLorenz

What is the exact error you get? You should be able to add services at any level, assuming the service you are adding wasn't already added higher up.
May 26, 2006 at 4:02 AM
originally posted by: Felice_Pollano

The problem seems to be related to the fact that, even if the two services are exposed by two different interfaces, the underlaying instance is the same. The CAB seems not to understand that the same instance is in the collection, and try to build from scratch the object, causing an "invalid object state" exception....
May 26, 2006 at 4:34 AM
originally posted by: DLorenz

Hmm, is there a reason why you are passing "this" in as a parameter? You should probably call AddNew like this (This is VB.NET syntax):

Dim sService as SomeService = New SomeService()

Services.AddNew(GetType(ISomeService), sService)
May 26, 2006 at 4:47 AM
originally posted by: Felice_Pollano

Yes, there is a reason,
I'm passing this, because the object now exposing both the service is the WorkItem itself.
May 26, 2006 at 5:09 AM
originally posted by: DLorenz

So the WorkItem is implementing those two interfaces then?
May 26, 2006 at 5:14 AM
originally posted by: Felice_Pollano

yes it is. I supposed there should be no problem for an instance to implement more than one service, and anyway it works at the root item level. Please note that at the root level, the instance is already present in the service collection ( because is a workitem too ).