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?
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)
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());
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With