将列表作为参数从存储库传递到 .Net Core 中的控制器
我需要在不修改服务的情况下将存储库层中填充的列表带到控制器层,该服务已经返回DTO,因此想法是将列表作为参数通过服务层传递给控制器。
流程是控制器->服务->回购所以我必须将回购中创建的列表传递给控制器。
repo.cs
public ListDTO Register(RegisterDTO newProduct)
{
List<NewListDTO> NewList = new List<NewListDTO>();
NewList.Add(field); // pass list to controller
return new ListDTO{
field1,
field2
}
}
服务.cs
public ListDTO Register(RegisterDTO newProduct)
{
return unit.Repository.Register(newProduct);
}
控制器.cs
public ListDTO Register(RegisterDTO newProduct)
{
var response = service.Register(newProduct);
//here would go the list that comes from the repo
return response;
}
I need to take a list that is filled in the repository layer to the controller layer without modifying the service, which already returns a DTO, so the idea is to pass the list as a parameter to the controller through the service layer.
the flow is controller -> service -> repo so i have to pass the list which is created in repo to the controller.
repo.cs
public ListDTO Register(RegisterDTO newProduct)
{
List<NewListDTO> NewList = new List<NewListDTO>();
NewList.Add(field); // pass list to controller
return new ListDTO{
field1,
field2
}
}
service.cs
public ListDTO Register(RegisterDTO newProduct)
{
return unit.Repository.Register(newProduct);
}
controller.cs
public ListDTO Register(RegisterDTO newProduct)
{
var response = service.Register(newProduct);
//here would go the list that comes from the repo
return response;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论