ServiceStack - a service consuming other services

I have a question about how iI should use services in ServiceStack from other services.

I have DTO answers for all my requests, witch implements the IReturn interface. With a client like JsonServiceClient , when I make requests, it returns an object response with a type implemented in IReturn , great!

Now, when I rephrase the project writing plugins for services that will be used in future projects, when I add the service to another service and make a request, it returns the type of the object, so I have to give it HttpResult , then draw the response of the object to the DTO type.

In most of my service method signatures, I have an object as the return type, and then return an HttpResult with the response. For instance:

 public object Get(Request request) { return new HttpResult(responseObj); } 

Do I have any alternative besides the fact that you use the services of a client?

I have a service and DTO only for views that consume other services from plugins. Therefore, I need to edit the DTO correctly (the services for the views act as controllers).

+4
source share
1 answer

I’m afraid I didn’t understand your question, and I’m off topic,

but I would use the same response object, changing only the request.

in the service model

  public class TestRequest : IReturn<TestResponse> { public int Id { get; set; } public string name { get; set; } } public class LowLevelRequest : IReturn<TestResponse> { public int Id { get; set; } public string name { get; set; } public string permissions { get; set; } } public class TestResponse { public bool success { get; set; } public string message { get; set; } } 

in the routing table

  Routes .Add<TestRequest>("/TestAPI/{Id}", "POST,GET, OPTIONS") .Add<LowLevelRequest>("/InternalAPI/{Id}", "POST,GET, OPTIONS"); 

in services

  public TestResponse Post(TestRequest request) { JsonServiceClient client=new JsonServiceClient(); LowLevelRequest lowrequest=new LowLevelRequest() { Id=request.Id, name=request.name, permissions="RW" } return client.Post<TestResponse>(lowrequest); } public TestResponse Post( LowLevelRequest request) { .... return new TestResponse() { success=true, message="done" }; } 
+2
source

Source: https://habr.com/ru/post/1492972/


All Articles