views:

75

answers:

1

I have been working on validation with the ASP.NET MVC BETA 2. Some of the reading that I have done is very critical of the buddy class approach because it isn't DRY (Don't Repeat Yourself) and because it puts the buddy class in the model layer and not in the web layer. I understand these arguments and through lots of searching I found an old reference to the MVC Toolkit 3.5 Preview 1.

Inside the toolkit is an XmlMetadataProvider. It is fairly basic but easy enough to extend. This would put the meta data for the model into an XML file with the web project and it seems that it would solve the issues raised by others with the Buddy Classes.

Does anyone have any thoughts or feedback on this toolkit approach? Have you used it? Do you know where I can get a more up to date example?

Old MVC Toolkit

A: 

Huh, I have to say I disagree with those arguments. The reason I use buddy classes is that that model is often regenerated if you use SubSonic or a LINQ2SQL provider. One would have to rewrite the properties on the fields if buddy classes wern't used. Buddy classes should be in the model, they are annotations of the model. Saying "this field is required" does not vary from view to view. As for the DRY issue I can see where people are coming from but it is really the simplest approach. Blindly adhering to rules in even the best programming books is a recipie for disaster.

Stick with the buddy classes.

stimms