Container Lifetime and web requests
I recently encountered a strange issue with a WCF service I'm helping to develop. Subsequent requests to a service operation was returning the same results, regardless of input.
When debugging this service in Visual Studio it worked fine (using the internal web server), but as soon as I deployed it to a staging environment (IIS 7.5, SSL & Message level security turned on) the service started to appear to cache responses.
To cut a long story short: it was our DI container not creating objects per web request, but per application lifetime. If you use autofac for ASP MVC, you're probably used to it having a per request lifetime: the autofac integration rigs this up for you. If you try this in a web service though, you'll need to go and DIY.
This comprehensive article explains it all better than I can, but if its a case of tl;dr....here is a good takeaway straight from Nicks playbook:
Don’t resolve from the root container. Always resolve from and then release a lifetime scope.
...good advice!