1

I want services in my code to be able to call other servicestack services directly and with request validation.

In my mind it would be ideal to not to have the use the JsonServiceClient, with all the serialisation and http request etc as the service is running in the same process.

I know I can call:

using (var service = base.ResolveService<MyService>()) { 
    service.Post(new MyRequest()); 
}

However this approach does not enforce my request validation code that is built using the standard servicestack fluent validation classes.

Ideally I'd be able to optionally change the request context too, to enable running with different privileges etc.

Could someone please advice how to achieve this.

Thanks.

richardwhatever
  • 4,564
  • 5
  • 23
  • 26

1 Answers1

4

You can use HostContext.ServiceController.ExecuteMessage(new Message<T>(requestDto), httpReq);. This will pass the request through the complete pipeline.

More details are given in this question, alongside my more detailed answer.

Community
  • 1
  • 1
Scott
  • 21,211
  • 8
  • 65
  • 72
  • 4
    Yep, and this is also available in the Service with `base.ExecuteRequest(requestDto)`. – mythz Jan 16 '15 at 14:59
  • Hi Scott, thanks for the prompt answer. The provided method doesn't apply validation filters, the the method used in the the referenced question works great: HostContext.ServiceController.ExecuteMessage(new Message(requestDto), httpReq); – richardwhatever Jan 16 '15 at 15:12
  • @richardwhatever You're right I didn't read my own previous answer properly. I have updated this one now. – Scott Jan 16 '15 at 15:15
  • 1
    Hi @mythz. I don't think the method you suggest actually applies Validation. It requires a calling of HostContext.ServiceController.ExecuteMessage(new Message(requestDto), httpReq); to invoke the validation filter. – richardwhatever Sep 29 '15 at 12:55