我有一个ASP.NET MVC网站,可以处理汽车,CarParts和非HTTP动词。像这样:
/Honda/Engine/Build
/Honda/Wheel/Move
/Honda/Door/Rotate
/Ford/Engine/Move
/Ford/Wheel/Rotate
/Ford/Door/Build
/Delorean/Engine/Rotate
/Delorean/Wheel/Build
/Delorean/Door/Move
And so on ...
每辆车都会处理他们的部件和动词,与其他车不同 - 没有共享方法。我的控制器可能如下所示:
public class HondaController : Controller
{
public ActionResult BuildEngine()
{ ... }
public ActionResult MoveEngine()
{ ... }
public ActionResult RotateEngine()
{ ... }
public ActionResult BuildWheel()
{ ... }
public ActionResult MoveWheel()
{ ... }
public ActionResult RotateWheel()
{ ... }
public ActionResult BuildDoor()
{ ... }
public ActionResult MoveDoor()
{ ... }
public ActionResult RotateDoor()
{ ... }
}
然后对于FordController和DeloreanController完全相同。
我的问题是: 我如何制作一条路线,将CarPart和Verb组合成一个名为" VerbCarPart"的MVC动作?
我可以通过创建九条路线来做暴力,但这会破坏SRP。什么是优雅的解决方案?