Initialization and disposing of services in a WCF application is a bit of a hassle to control when running on an IIS instance, since the application starts and stops every now and then based on server requests. It doesnt make it easier when using an IOC, as in our case MEF. To have total control of the startup and shutdown events we began with adding a service factory to all our WCF services. <%@ ServiceHost Language="C#" Debug="true" Service="WcfService" Factory="CustomServiceHostFactory" %> When ever the application gets woke up by a request to any of the services, the service factory will be used to instantiate the service. This means we can add any logic to these methods to have full control of the WCF application initialization. Here is what a service factory class could look like. (Composition is a static class containing a reference to the MEF container) public class CustomServiceHostFactory : ServiceHostFactory { priva...
.NET, TFS, Azure or anything Microsoft