我为员工提供DTO服务
[Route("/employee/{id}", "GET PUT DELETE")]
[Route("/employees", "POST")]
public class Employee : Person
{
public Employee() : base() {
this.dependents = new List<Dependent>();
}
public List<Dependent> dependents { get; set; }
}
我想了解如何处理我想要返回dependents集合的情况。我希望网址是/ employee / {id} / dependents。作为ServiceStack的新手,我很难想到如何将其映射到EmployeeService中的服务处理程序。非常感谢!
答案 0 :(得分:0)
我想了解如何处理我想要的情况 返回dependents集合。我希望网址是 /雇员/ {ID} /受抚养人
首先,您需要提供与您想要的网址匹配的路线:
[Route("/employee/{id}/dependents")]
public class Employee : IReturn<List<Dependent>>
{
public Employee() {
this.dependents = new List<Dependent>();
}
public List<Dependent> dependents { get; set; }
}
我也鼓励你not to use inheritance in DTOs,因为它隐藏了你的服务的意图和声明结构。
您的服务实施应该非常直接:
public class EmployeeService : Service
{
public List<Dependent> Get(Employee request)
{
return request.dependents; //just return the dependents collection?
}
}