Monday 31 December 2012

MVC Best Practice Questions

As I'm developing, I often ask myself: "what is the best way to do XYZ".

Here are a list of questions I've asked myself which I hope to have answered:

1. How best to deal with Enum values which are passed to the Repository by a Controller?
Option - encapsulate the Enum type within the Data layer and make the Repository method accept a string which it then attempts to convert to an Enum value.
Con: The Repository method is not type safe in that any old string can be passed in.
Pro: The consumer (i.e. an MVC Controller) does not have to know about the Enum type - it can pass in what ever string it has to hand (i.e. passed as an action parameter).
Question: In this scenario, how does one deal with Errors whereby the Repository get passed a string which does not parse successfully into an Enum value - does the Repository throw an exception and then its up to the Controller to catch the Exception and handle it? This has a definite code smell to it...

No comments:

Post a Comment