ServiceStack/ServiceStack — pull request #942 by tvjames (2014-09-18 23:28:30+00:00)
Title: Hooks to enable 'Request Scoped' dependencies in MQ message handling

Hi Demis,

The purpose of this change is to allow each message processed through a MessageHandler to be treated the same as a web "request scope" for the purpose of wiring up dependencies configured with ```ReusedWithin(ReuseScope.Request)``` and release those dependencies after each message has been processed.

I was unsure of the preferred approach so I've provided two options:

1. Use ```mqServer.RegisterHandler(ServiceController.ExecuteMessageInRequestScope)``` in place of ```mqServer.RegisterHandler(ServiceController.ExecuteMessage)```. This will call OnEndRequest right before the response is handed back to the message handler for processing; OR

2. Register a ```PostMessageHandler``` against either the RabbitMqServer or RedisMqServer which is then passed into the ```MessageHandler``` to be called in the finally block after the message is ```Ack```ed. This then allows every message received to be handled the same way, while the above approach is more an exception-to-the-rule if over registered handlers don't need to be treated as a request.

Doing this means our message handling depending on request scoped dependencies are no different from those handling web requests.

This PR maintains existing code compatibility by preserving the default behaviour.