In the face of frustration.

I love to write code. I’ve written code in one form or another for the past 25 years and I’ll probably still write code for the upcoming 25. I love the pure power of creation and freedom to let creativity flow that code gives me. But like in any love story there is times when it just frustrates the hell out of me.

I have a confession. I’m not proud of this, I know it’s morally wrong and I would never do this in any other setting; I’ve taken on a mistress.

My mistress is business value. Not that code can’t be business value, but sometimes other options can more quickly satisfy business values and in the face of frustration I’ve started to indulge in those options.

In the past I’ve easily accepted blame for throwing code at most problems and tried to deliver features at a rapid agile pace. Often and early. Sometimes code is just not as rapid as I want.

Now if just the platforms I choose to install to meet business needs quickly wasn’t so frustrating to code for…

Standard products – Can’t live without them, can’t live with them.

Common Service Host for Windows Communication Foundation

After having to write new instance providers, host factories and service behaviors for almost every new WCF project; I decided to write a simple reusable component for WCF and dependency injection and put it on codeplex so that I never had to write that again.

The idea is simple, when creating service hosts you more often then not want a centralized controlling factory that handles your dependency wiring and life time management of said dependencies. WCF requires you to add custom code to the initialization extension points.

Enter the Common Service Host. Based on the Common Service Locator interface and model it allows for a single library with classes for any DI-Framework to automatically wire up your service instances. From the codeplex documentation:

Example host configuration:

public class AppContainer : UnityContainerProvider
{
        public void EnsureConfiguration()
        {
            UnityContainer.RegisterType<IRepository, Repository>();
        }
} 

Example self-hosted usage:

using(var host = new CommonServiceHost<AppContainer>())
{
    host.Open();
}

Example usage for a .svc file:

<%@ ServiceHost Language="C#" 
      Service="Sogeti.Guidelines.Examples.Service1" 
      Factory="Sogeti.Guidelines.WCF.Hosting.CommonServiceHostFactory`1
	[[Sogeti.Guidelines.Examples.AppContainer,
 Sogeti.Guidelines.Examples.Service]], Sogeti.Guidelines.WCF.Hosting" %>

 

Included providers in the current release for Unity and spring.net

Get your copy here: http://commonservicehost.codeplex.com