Autofac and ServiceStack - Managing Life Cycle [3]

less than 1 minute read

In the previous part 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: