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?
我怎样才能做到这一点?
2 个解决方案
#1
17
There is a base method called base.ResolveService<TMyService>()
which just resolves your autowired service from the IOC and injects the current request context
有一个名为base.ResolveService
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:
您也可以使用请求DTO调用服务,该服务也将执行服务全局请求过滤器:
base.ExecuteRequest(new MyRequest());
This is just a wrapper around ServiceController which can be called statically:
这只是ServiceController的一个包装器,可以静态调用:
HostContext.ServiceController.Execute(new MyRequest(), base.Request)
#2
1
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:
跳得有点晚,因为这出现在搜索引擎上。关于ServiceStack v4.5的新方法是使用ServiceGateway。每个SS服务现在都有一个Gateway属性,可以执行以下操作:
var response = this.Gateway.Send(new MyRequest());
#1
17
There is a base method called base.ResolveService<TMyService>()
which just resolves your autowired service from the IOC and injects the current request context
有一个名为base.ResolveService
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:
您也可以使用请求DTO调用服务,该服务也将执行服务全局请求过滤器:
base.ExecuteRequest(new MyRequest());
This is just a wrapper around ServiceController which can be called statically:
这只是ServiceController的一个包装器,可以静态调用:
HostContext.ServiceController.Execute(new MyRequest(), base.Request)
#2
1
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:
跳得有点晚,因为这出现在搜索引擎上。关于ServiceStack v4.5的新方法是使用ServiceGateway。每个SS服务现在都有一个Gateway属性,可以执行以下操作:
var response = this.Gateway.Send(new MyRequest());