I am just getting into MEF and I have come across a problem that I cannot resolve. I have a windows service that is reading in my DLLs (via MEF) and each DLL is a WCF Service Host. When I run my windows service and read in the DLLs everything runs fine, except that whenever one of the WCF DLLs get any "activity" then they reinstantiate and then process the data coming in. I need them to just instantiate once at the beginning. Is this possible?
WCF services default to a per call instance mode. This means that a new instance of your WCF service is instantiated for each incoming method invocation. It sounds like what you're wanting is a singleton instance mode, but you really want to avoid this if scability is an issue.
The way I've gotten around this is to use the per call instance mode, but have a static data store behind the scenes that I synchronize access to. This at least allows clients to connect, even if they have to block momentarily while the data store is in use once the connection is established.
Refer to the MSDN help on System.ServiceModel.InstanceContextMode for more details.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With