我有 RequestDTO,该类中有另一个 DTO,它看起来像这样:
[Route("/TheDtoRequest", "GET")]
[Route("/TheDtoRequest/{do_something_here_to_fill_foobar}", "GET")]
public class TheDtoRequest
{
public string Foo { get; set; }
public int Bar { get; set; }
public FooBar Foobar { get; set; }
}
public class FooBar
{
public string AnotherFoo {get; set;}
public int AnotherBar {get; set;}
}
如何使用 AnotherFoo 参数进行请求?
最佳答案
您可以使用 JSV 格式将 GET 请求中的 FooBar
参数填充到 /TheDtoRequest
。您可以了解JSV format here 。 JSV 格式(即类似 JSON 的分隔值)是一种受 JSON 启发的格式,它使用 CSV 样式的转义来实现最少的开销和最佳的性能。
/TheDtoRequest?Foo=hello&Bar=1&FooBar={AnotherFoo:HelloWorld,AnotherBar:123}
因此,对 /TheDtoRequest
路由的查询会导致类被填充。但您也可以在路由中使用 JSV。因此给出这条路线:
/TheDtoRequest/{Foobar}
查询将产生相同的填充对象:
/TheDtoRequest/{AnotherFoo:HelloWorld,AnotherBar:123}?Foo=hello&Bar=1
或者这条路线:
/TheDtoRequest/{Foo}/{Bar}/{Foobar}
/TheDtoRequest/hello/1/{AnotherFoo:HelloWorld,AnotherBar:123}
有一个很好的例子 more complex object represented as JSV here .
希望这有帮助。
关于ServiceStack - 具有多个 DTO 层的路由,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22244343/