我正在爲一個應用程序構建一個WebAPI服務,並且我被困在一個交叉路口,我理解了SOLID原則並希望按照這些原則實現我的WebAPI服務,但是我花了最後幾天在執行中掙扎,並希望得到社區的一些建議。單一責任原則webapi
,每類應該有過的由軟件提供的功能單一的一部分責任單一職責原則規定(見Solid Principles)
我目前有兩個ApiControllers但會有更多的,而且這兩個目前都有Get,Post和Put功能,但是每個控制器也需要一個Search函數,我的問題是如果搜索方法被移入一個單獨的ApiController,例如SearchController。
例如:
我有一個用戶控制器
public class UserController : ApiController {
Get - returns a User
Post and Put - Add and update a User
}
和我有沿着相同的路線的患者控制器如上,我應該具有在每個控制器我的搜索方法應我有一個SearchController,例如。
public class SearchController : ApiController {
SearchUsers() - returns ICollection<User>
SearchPatients() - returns ICollection<Patient>
}
我知道有沒有明確的答案,並會就像上最好的做法有些意見
「搜索」可能只是一個過濾器的GET,對吧? – Padraic