Question

I'm sure this is obvious but I haven't been able to find a very specific clean answer to the lifetime of a container in a IIS 7.5 hosted WCF service.

If the container lives in my service code, it would be created on every request unless InstanceContextMode is set to single? (I know bad idea)

If I configure WCF using ServiceHostFactory and IInstanceProvider to use a container to resolve the service object on every call how would the InstanceContextMode work? Wouldn't it depend on the lifetime policy used by the container?

If its a singleton created in the factory is that sufficient such that the container won't reinitialize on every call?

Thanks

Was it helpful?

Solution

You should host the container in a custom ServiceHostFactory since there's only a single instance of the ServiceHostFactory for a given WCF service.

This ensures that the container itself is a single instance, thus enabling it to effectively manage lifetime of all components.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top