ServiceStack: Reinstate pipeline when invoking a Service manually?

后端 未结 1 1201
庸人自扰
庸人自扰 2021-01-27 10:43

As a follow-up to this question, I wanted to understand how my invoking of a Service manually can be improved. This became longer than I wanted, but I feel the background info i

相关标签:
1条回答
  • 2021-01-27 11:26

    What parts of the pipeline is lost?

    None of the request pipeline is executed:

    myRequestService.Any(e.Request);
    

    Is physically only invoking the Any C# method of your MyRequestService class, it doesn't (nor cannot) do anything else.

    The recommended way for invoking other Services during a Service Request is to use the Service Gateway.

    But if you want to invoke a Service outside of a HTTP Request you can use the RPC Gateway for executing non-trusted services as it invokes the full Request Pipeline & converts HTTP Error responses into Typed Error Responses:

    HostContext.AppHost.RpcGateway.ExecuteAsync()
    

    For executing internal/trusted Services outside of a Service Request you can use HostContext.AppHost.ExecuteMessage as used by ServiceStack MQ which applies Message Request Request/Response Filters, Service Action Filters & Events.

    I have registered with container.AddScoped

    Do not use Request Scoped dependencies outside of a HTTP Request, use Singleton if the dependencies are ThreadSafe, otherwise register them as Transient. If you need to pass per-request storage pass them in IRequest.Items.

    0 讨论(0)
提交回复
热议问题