0

I have an ASP.NET MVC site that processes, say, Cars, CarParts, and non-HTTP verbs. Like this sort of:

/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 ...

Each car will handle their parts and verbs unlike the others -- no sharing of methods. My controllers may look like this:

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()
    { ... }
}

And then exactly the same for the FordController and the DeloreanController.

My question is this: How can I make a route that will combine the CarPart and Verb into an MVC action called "VerbCarPart"?

I can do it brute force by creating nine routes, but that breaks SRP. What is the elegant solution?

Rap
  • 6,851
  • 3
  • 50
  • 88
  • The pattern you've laid out at the top of your question can be achieved with one controller method and one route. Or, you can do it with three controller methods and still have one route. Why do you need multiple controller methods when you can simply pass the part to Rotate(), or the action to Wheel()? – Robert Harvey Jul 21 '14 at 21:04
  • @RobertHarvey I *could* do that; you're right. In fact, I already am doing that. But neither option seems elegant. Just wondering if you can engineer Routes to combine words into an {action}. – Rap Jul 21 '14 at 21:59
  • You probably could. I wouldn't. They should be kept separate. – Robert Harvey Jul 21 '14 at 22:01

0 Answers0