[英]Servicestack - Multiple IReturn on Request DTO
Is it possible to have multiple IReturn<>
on a request DTO? 请求DTO上可以有多个
IReturn<>
吗?
For example following route: 例如,以下路线:
[Route("/api/whatever", "GET,POST,PUT,DELETE")]
public class WhateverRequest : IReturn<bool>, IReturn<List<Whatever>>
{
public string WhateverId { get; set; }
}
Depending on the request method I want to have another IReturn
. 根据请求方法,我想要另一个
IReturn
。 Post-Put-Delete Request should only return a acknowledge if the request was successful: 放入删除后请求仅在请求成功后才返回确认:
IReturn<bool>
but on a GET request I want to have a: 但在GET请求中,我想要一个:
IReturn<List<Whatever>>
It would also be good if there is a way to reflect this in Swagger Api/ Metadata Page. 如果有一种方法可以在Swagger Api /元数据页面中反映出来,那也很好。 Currently only the first
IReturn
is shown. 当前仅显示第一个
IReturn
。
Is this possible or would it be better to create a route for each different IReturn
? 这是否可能,或者为每个不同的
IReturn
创建路由会更好吗?
You definitely want to be creating different routes to handle the multiple return types. 您肯定要创建不同的路线来处理多种返回类型。 Only one
IReturn<T>
or IReturnVoid
is expected, or consuming clients wouldn't know how to type the returned data correctly. 仅预期有一个
IReturn<T>
或IReturnVoid
,否则使用方客户端将不知道如何正确键入返回的数据。
[Route("/api/whatever", "GET")]
public class ListWhateverRequest : IReturn<List<Whatever>>
{
public string WhateverId { get; set; }
}
// Action
public List<Whatever> Get(ListWhateverRequest request)
{
...
}
[Route("/api/whatever", "POST,PUT,DELETE")]
public class UpdateWhateverRequest : IReturn<bool>
{
public string WhateverId { get; set; }
}
// Action
public bool Post(UpdateWhateverRequest request)
{
...
}
public bool Put(UpdateWhateverRequest request)
{
...
}
public bool Delete(UpdateWhateverRequest request)
{
...
}
I presume you are returning true
from these methods to show they completed successfully. 我认为您从这些方法返回的是
true
,以表明它们已成功完成。 Do the methods ever return false
when something goes wrong, or is an exception thrown instead? 当出现问题时,这些方法是否返回
false
,或者抛出异常? If you are only throwing exception in the method, and never returning false then instead of returning bool
consider using void
methods with IReturnVoid
. 如果你只在方法抛出异常,永不返回false然后而不是返回
bool
考虑使用void
与方法IReturnVoid
。 The request is therefore successful if it doesn't throw an exception. 因此,如果没有引发异常,则请求成功。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.