Use Service into a service

Topics: CAB & Smart Client Software Factory
Dec 19, 2007 at 10:32 PM
hello
can i use a service into another service ?
For example can i use a SecurityService into a UIMenuService to add or not a Item in a menu ?


thanks
Dec 21, 2007 at 1:06 PM
Hi.

You can add the ServiceDependency attribute to a property in your service to declaratively obtain a reference to another service:

private IAccountServices  _accountServices;
 
[ServiceDependency]
public IAccountServices AccountServices
{
   set { _accountServices = value; }
}

Also, you can use the ServiceDependency attribute for the arguments in your service constructor. This means that ObjectBuilder will instantiate the required services when it creates the dependent object.

private IAccountServices  _accountServices;
 
public MyService([ServiceDependency] IAccountServices accountServices)
{
   _accountServices = accountServices;
}

Thanks.

Sebastian Iacomuzzi
http://staff.southworks.net/blogs/siacomuzzi