ServiceStack ServiceExtensions RunAction方法

时间:2013-09-10 02:50:00

标签: c# servicestack

我正在查看ServiceExtensions RunAction的源代码。这看起来很有趣:

public static object RunAction<TService, TRequest>(
    this TService service, TRequest request, Func<TService, TRequest, object> invokeAction,
    IRequestContext requestContext = null)
    where TService : IService
{
    var actionCtx = new ActionContext
    {
        RequestFilters = new IHasRequestFilter[0],
        ResponseFilters = new IHasResponseFilter[0],
        RequestType = service.GetType(),
        ServiceAction = (instance, req) => invokeAction(service, request)
    };

    requestContext = requestContext ?? new MockRequestContext();
    var runner = new ServiceRunner<TRequest>(EndpointHost.AppHost, actionCtx);
    var response = runner.Execute(requestContext, service, request);
    return response;
}

这是否意味着我可以使用此方法调用其他服务中的方法?有人能给我一个如何正确运行“RunAction”的代码示例吗?

0 个答案:

没有答案