Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ServiceStack How to call my service from code

how can i call my own service?

I have a service that use other services to compose information.

I want to call other services within the code of this service.

How can I do that?

like image 794
Tom Avatar asked Oct 10 '12 02:10

Tom


2 Answers

There is a base method called base.ResolveService<TMyService>() which just resolves your autowired service from the IOC and injects the current request context

So just call:

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

You can also call a Service with just a Request DTO which will also execute the Services Global Request Filters:

base.ExecuteRequest(new MyRequest());

This is just a wrapper around ServiceController which can be called statically:

HostContext.ServiceController.Execute(new MyRequest(), base.Request)
like image 80
Tom Avatar answered Sep 22 '22 17:09

Tom


Jumping in a bit late, since this popped up on a search engine. The new way as of about ServiceStack v4.5 is to use ServiceGateway. Every SS Service now has a Gateway property which can be executed against:

var response = this.Gateway.Send(new MyRequest());
like image 26
jklemmack Avatar answered Sep 22 '22 17:09

jklemmack