Archive for category Wcf

SoC - The Plug-in way

Soc (Separation of Concerns) is one of the fundamental OO principles I try follow.

In a recent feature I implemented, I had to add a management operation through http. Our system exposes a management http api that supports operations such as restart and shutdown which are pure management operations the effect the system as a whole.

Our system is a SOA system in which the management component, called WatchDog is responsible for tracking and maintaining the health of the services without caring about the nature of the service.

image

The new operation however, tells just one component to refresh its state. It is a specific component and knowing the component, how to contact it and tell it what to do just felt wrong to add to the WatchDog’s management api - it will break SoC since now the WatchDog will know and handle things it is not supposed to.

After some thinking, I decided to solve this problem by introducing a simple plug-in mechanism to extend the http management api.

image

 

I added a url mapping to the management http api. Every call with the following pattern:

http://myhost/management/{pluginName}

 

Is mapped to a method on a wcf service which will look for a preconfigured plugin with that name and will invoke it. The mapping was declared as follows:

[OperationContract]
[WebInvoke(Method = "POST", UriTemplate = "/management/{pluginName}")]
ManagementOperationResult InvokePlugin(string pluginName);

 

Currently the plug-ins are simply pre-configured by code and are available through the following interface:

public interface IPluginProvider
{
    IEnumerable<IManagementPlugin> GetPlugins();
}

 

The interface for a plugin is this:

public interface IManagementPlugin
{
    void Plug(IPluginServices services);
    ManagementOperationResult Execute();
}

The Plug method “hosts” the plugin and the Execute method is used to invoke the plug-in and returns a result that is serialized and returned to the calling client.

Thanks to this approach, the management system can be extended without having to know stuff it should not know. All the operation specific behavior is fully implemented in the plug-in and the Separation of Concerns is kept.

1 Comment