I want to keep things DRY, so I'm trying to figure out: Is it possible to remove repetitive parameters and code from ASP.NET MVC Controller actions? eg given these Actions:
public ActionResult List(string key, string signature) { GetSignature(key); // etc }
public ActionResult Add(string key, string signature) { GetSignature(key); // etc }
public ActionResult Update(string key, int id, string signature) { GetSignature(key, id.ToString()); // etc}
public ActionResult Delete(string key, int id, string signature) { GetSignature(key, id.ToString()); // etc}
public ActionResult Action1(string key, string x, string y, string z, string signature) { GetSignature(key, x, y, z);//etc}
Is there any way to refactor out the repetitive key
and signature
parameters, and the call to GetSignature()
?
There are two obstacles to refactoring I can think of:
- It's MVC so the Actions are the first port of call - it may not be possible to have a refactored method that is called before the Action.
- The GetSignature() method is called using all of the Action's parameters, so it may be difficult to refactor.