Phillip Powers - 70 - Aug 19, 2014

I’m interested in essentially swapping out the “New API” Service API in ServiceStack with my own, for part of our backend where I’m having to write a lot of the same boilerplate for interaction with the rest of the system for every Service that I write (not a fault in the ServiceStack API or anything like that, just due to how our other code is structured).

Essentially I want ServiceStack to do all of its serializing/deserializing/Request and Response hooks/etc, except swap out the part where the Service object is CREATED and CALLED - which I want to implement my own logic for.

I looked at the ServiceRunner hooks, and initially that looked OK except it seems that ServiceStack still creates the Service that is bound to the DTO (something I want to control) even if I implement an “Execute” hook.

So, I looked at the ServiceStack source and it looks like implementing  my own IServiceController would give me what I want. It “looks” like it’s designed to be user-swappable (ie, the “CreateServiceController” virtual method in AppHost, etc), but I can’t really find any reference to doing this in documentation or examples. 

I just wanted to verify that this is the “correct” ServiceStack way of doing things before I start heading down that path. 

Thanks.

It’s never been done before (outside SS) nor would I recommend it. ServiceStack already provides a number of extensibility hooks where you can apply custom logic as seen in: https://github.com/ServiceStack/ServiceStack/wiki/Order-of-Operations 

If that’s still too limiting you can reduce boilerplate by taking the code-gen approach that AutoQuery does:
https://github.com/ServiceStack/ServiceStack/blob/master/src/ServiceStack.Server/AutoQueryFeature.cs#L155

Jezz Santos:

You could have a look at building your own toolkit to generate your custom code for your service. Here’s an example of a ServiceStack toolkit to illustrate the idea: https://github.com/jezzsantos/servicestacktoolkit
In your case you would generate whatever it is that you need to generate to wire your stuff up.