Both host and plugin will use service interfaces to advertise and implement a specific service.

A service is a coherent set of functionality that is autonomous

A service consumer can discover services by asking for it by an identifying name. The Service Provider is the entry point for these queries and can be both implemented by the host and the plugin.

The host will query the Service Provider of the plugin to discover its capabilities and likewise will the plugin query the host's services to know what capabilities the host can perform. All service consumers MUST handle absence of any requested services gracefully - disabling portions of functionality that rely on that service.

A service is ALWAYS defined as an interface. This decouples the use of the service by the service consumer and the implementation of the service by the service provider. The interface definition can use normal classes (or structs) for support structures but these must keep extensibility in mind - protected / virtuals etc.

A Service Container is an object that manages a set of services for one party (host or plugin). A service container can be setup in a hierarchical way so that the scope (accessibility) for each service can be managed. For instance a host could have a service container on a global level and a child container for each plugin. This would allow the host to precisely manage the implementation and accessibility of each service. When a service is not available in a container, the request is passed on to its parent up the hierarchy.

The IServiceProvider interface could be a simple as this.
public interface IServiceProvider : IDisposable
  object GetService(string serviceIdentifier);
  object TryGetService(string serviceIdentifier);

Last edited Oct 6, 2013 at 8:42 AM by obiwanjacobi, version 9