Service attribute problem

Topics: CAB & Smart Client Software Factory
Mar 4, 2006 at 9:27 AM
originally posted by: DingDongLars

Hi

I have problems getting a class (let's call it A) annotated with the Service attributes built and added to the root workitems services collection. The problem manifests itself when I I do an AddNew to build an instance of a class (B) that uses the ServiceDependency attribute to get a reference to the instance of class A.

I get an exception "Service ClassA is not available in the current context". Here's te last bit of the call stack:

at Microsoft.Practices.CompositeUI.Collections.ServiceCollection.Get(Type serviceType, Boolean ensureExists)
at Microsoft.Practices.CompositeUI.Collections.ServiceCollection.Get(Type serviceType, Boolean ensureExists)
at Microsoft.Practices.CompositeUI.Collections.ServiceCollection.Get(Type serviceType, Boolean ensureExists)
at Microsoft.Practices.CompositeUI.ServiceDependencyAttribute.ServiceDependencyParameter.GetValue(IBuilderContext context)
at Microsoft.Practices.ObjectBuilder.PropertySetterInfo.GetValue(IBuilderContext context, Type type, String id, PropertyInfo propInfo)
at Microsoft.Practices.ObjectBuilder.PropertySetterStrategy.InjectProperties(IBuilderContext context, Object obj, String id)
....

Using the visualizer, I must agree that the classA instance never is known in the services collection. But if I - in the workitem - do the work by hand with _workItem.Services.AddNew<ClassA>() everythinng works fine. So my ClassA must be ok.

ClassB's work item does not inherit form ModuleInit, I instantiate it myself with _workitem-WorkItems.AddNew<ClassB>("thisone");.

The 2 classes resides in different class libraries, but should that matter.

What do I do wrong. Please help.

Thanks

Lars

PS: Not as much a newbie as last week - learning by doing and having a great time with a truly powerful CAB