I. To add a service by specifying it in the shell application configuration file
- Add a section named CompositeUI to the application configuration.
- In this section, list the services that should be loaded as shown in the following code.
II. To add a service programmatically
type="Microsoft.Practices.CompositeUI.Configuration.SettingsSection,
Microsoft.Practices.CompositeUI"
allowExeDefinition="MachineToLocalUser" />
instanceType="MyApp.Services.MyService, MyApp"/>
- Call the Add or AddNew method of the Services collection of the WorkItem within which you want to use the service. To use an existing service instance you have already created, use the Add method.
RootWorkItem.Services.Add
(myServiceInstance); - To create a new instance of a service and add it to the WorkItem, use the AddNew method.
RootWorkItem.Services.AddNew
();
- You can place the Service attribute on a public class. The CAB infrastructure creates an instance of this class and registers it as a service during application startup
[Service(typeof(IMyService))]
public class MyService : IMyService
{
} - Services that do not provide different implementations may not implement an interface. In this case, you can register the service without using an interface reference.
[Service]
public class MyService
{
}
No comments:
Post a Comment