Autofac and ServiceStack - Managing Life Cycle [3]

In the [previous part](../autofac-and-servicestack-managing-life.html) I suggested storing current scope in a static property. This seems to break under higher load because the scope is shared across too many instances of the same service and after the first request it gets disposed, leaving all other requests with dependencies from the disposed scope in unknown state, i.e. closed database session. After some more digging I found a way that really works. ServiceStack supplies a nice object collection at HostContext.Instance.Items. It is request specific and when request dies, all items in this collection are also disposed. So, here is the updated version: {% gist alexeyzimarev/4f7e1f0100ef33a5e341 %}

See also