1

我正在查看的源代码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”的代码示例吗?

4

0 回答 0