Service Attribute - But object not created

Topics: CAB & Smart Client Software Factory
Jun 19, 2007 at 4:55 PM
Hi,

I have a class that implements an interface (both created in the same file and namespace) positioned in the Infrastructure.Layout project of my SmartClient solution. I have marked this class with the Service attribute, so that CAB will create this class for me and add it to the Services collection of the root WorkItem (at least, this is what I want it to do!).

So the class looks like this:

Service(typeof(IMyClass))
public class MyClass : IMyClass
{
/// ....continued
}

However, the object is not getting created by the time I hit 'AfterShellCreated' method in ShellApplication (the constructor is never called). Worse still - it doesn't seem to get created at all!

I would be grateful if anyone could:
A) Suggest why my object marked with the Service attribute is not getting created by CAB.
B) Confirm that the object should have been created by the time the ShellApplication's 'AfterShellCreated' method is called.

Thanks!

Regards,
Russell
Jun 19, 2007 at 6:23 PM
A) If you have the proper declaration above the class Service(typeof(IServiceName)), then my first guess would be that the CAB module is not loading. If you put a breakpoint in the "InjectionConstructor" of Module.cs in Infrastructure.Layout, will it hit that breakpoint on load?
If if it does, then my next guess question is this: do you have a line code that instantiates your service in the AddServices Method of Infrastructure.Layout's ModuleController.cs class?
e.g. this.WorkItem.Services.AddNew<MyServiceName IMyServiceName>();

B) I can't say this definitively, but in my application the Services Load AFTER 'AfterShellCreated' is loaded
Jun 21, 2007 at 7:04 PM
Hi Russell,

I tried to reproduce what you are describing. It actually calls the AfterShellCreated before loading the services in the Infrastructure.Layout project. Because of this, a possible workaround would be to add the service programmatically (instead of using the Service decorator) inside your AfterShelCreated implementation:

RootWorkItem.Services.AddNew<Service>();

Hope it helps!

Luciano G. Panaro
http://staff.southworks.net/blogs/lpanaro