I am currently have a WCF service that uses a COM DLL for its service. The COM object is only loaded once and saved via a singleton. The problem is the first run takes about 1 minute to load the COM Object. The WCF service is hosted via a Windows Service. I am wondering how can I load the COM Object singleton via the startup of the Windows Service.
protected override void OnStart(string[] args)
{
if (host != null)
{
host.Close();
}
Type serviceType = typeof(MyService);
host = new ServiceHost(serviceType);
host.Open();
objectConn.getInstance()
}
When I try to add the load of the Singleton in the OnStart of the Windows Service startup, it always fails. I would like to ask if this i the proper way to add startup routine for the objectConn instance. I tried to place the singleton loading in the MyService construtor but it is only called with the first call to the web service operation/method that I invoke which makes the first service call awkward.
I read about DependencyInjection but I think the added behavior is not applicable since I just want to load the COM object source once.