Help creating "Global Service"

Topics: CAB & Smart Client Software Factory
Feb 14, 2007 at 4:47 PM
That may not be the correct term. But I am trying to create a foundation module that will hold our own services.

I have created the FM.
Added a interface and class for a SysConfig type service.

Service(typeof(ISystemConfiguration))
public class SystemConfiguration : ISystemConfiguration

I added this ( RootWorkItem.Services.AddNew<SystemConfiguration>(); )
to the class ShellApplication : SmartClientApplication<WorkItem, ShellForm> AfterShellCreated() method and My new service is instanciated.

My two questions are...
Is this the right place for a global type service to be instanciated.
How do I access the service in my various work items and other services??

Thanks.
Rob


Where do I put the code that instanciates the service?
Feb 14, 2007 at 5:09 PM
First, if your interface implements an interface, you should create the service in the rootworkitem like this "RootWorkItem.Services.AddNew<SystemConfiguration, ISystemConfiguration>()".

The object builder will create your object automatically if you add the module name in the profile catalog. (check the samples for that)

By adding your foundation model SystemConfiguration to the rootWorkItem in the Services section, you allow every child workitem to access it just by doing "WorkItem.Services.Get<ISystemConfiguration>()". The instance is always the same so be shure you want it public.

You can also use the AddOnDemand method so that it will be created only when you need the service.

João Melo
Feb 14, 2007 at 10:27 PM
Thanks that worked great.

"The instance is always the same so be shure you want it public."

I do.

Thanks again/

rob


rrodgers wrote:
First, if your interface implements an interface, you should create the service in the rootworkitem like this "RootWorkItem.Services.AddNew<SystemConfiguration, ISystemConfiguration>()".

The object builder will create your object automatically if you add the module name in the profile catalog. (check the samples for that)

By adding your foundation model SystemConfiguration to the rootWorkItem in the Services section, you allow every child workitem to access it just by doing "WorkItem.Services.Get<ISystemConfiguration>()". The instance is always the same so be shure you want it public.

You can also use the AddOnDemand method so that it will be created only when you need the service.

João Melo

Feb 15, 2007 at 4:16 PM
I have another question.

In a business module this syntax works.

"WorkItem.Services.Get"

What do I use in the foundation modules?

Thanks.
Rob

{quote}
rrodgers wrote:
Thanks that worked great.

"The instance is always the same so be shure you want it public."

I do.

Thanks again/

rob
Feb 16, 2007 at 12:41 PM
If you have a workitem in the foundation module the same sintax should work.