I have a WCF service that uses a custom UserPasswordValidator. The validator must access the context of the environment of my object.
I would like to create one ObjectContext for the whole service call, and then destroy it at the end of the call. So I created a static singleton class that provided this functionality, however, what is happening now is that if two calls to the service happen simultaneously, one of the calls provides a singleton.
I either keep a local reference to the ObjectContext, and in this case the second service that uses it sees it as deleted, throws it wrong, or I put the wrapper property around the Singleton class where necessary, and then all my changes are discarded because I get a new instance of the object if another call placed it.
So basically, my question is how to instantiate an ObjectContext for a single service call?
NOTE. The instance must be available both in the service code and in the user code UserPasswordValidator.
I cannot just do this in the constructor or use the using statement, because the custom UsernamePasswordValidator does not have access to it . Is there a way to have a static class for every call? It sounds impossible, but how does it happen? Should I cache an object in a session?
My service is hosted on IIS.
UPDATE:
Thus, I nailed this to state persistence in a Context instance using an IExtension object. But how do I access the current InstanceContext instance in UserPasswordValidator?
source
share