Autofac and ServiceStack - Managing Life Cycle [2]

Warning: this is not working properly, check the latest version for better solution. Whilst the approach I used in the previous post is working fine for ASP.NET based ServiceStack solutions, it does not fit for the self-hosted approach since the request handling is done differently there.
To solve this issue, I tried to find ServiceStack native request/response hooks and the first thing I tried was a custom service runner with overrides for OnBeforeExecute and OnAfterExecute as described here. However, this did not work because the container method to resolve the service happens before ServiceRunner.OnBeforeExecute. I know that it sounds strange but this is what happens in reality, at least for ServiceStack version 3.9.
An alternative approach to interfere with the request/response cycle is using filters. And this worked like a charm. Here is the new gist that creates Autofac request scopes so I can use PerRequest registrations for my dependencies.


See also