我是MVC WebAPI和EF4的新手。我想知道是否最好将多个GET和/或PUT方法的大型控制器拆分为多个控制器,以避免“找到与请求匹配的多个操作”错误。我更喜欢只使用基于VERB的路由模式“api/controller/id”,如下所示。asp.net webapi控制器的设计考虑因素
GlobalConfiguration.Configuration.Routes.MapHttpRoute(
"Api",
"api/{controller}/{id}",
new { id = RouteParameter.Optional }
);
例如,我有两个域对象Doctor和Patient。一个ClinicController有下列行为:
getDoctors()
getPatientCohort(int doctorId)
getPatientPrimaryDr(int patientId)
getPatientDoctors(int patientId, int clinicId)
getPatients()
getPatient(int patientId)
putDoctor(Doctor doctor)
putPatient(Patient patient)
createDoctor(Doctor doctor)
createPatient(Patient patient)
如果我这个控制器分成DoctorController和PatientController使每个控制器只与一个域对象的交易。由于Patient Cohort是一个关联类,应该getPatientCohort(int doctorId)是PatientController还是DoctorController的方法?谢谢。