I am developing an ASP.NET MVC app and I've been looking into using Data Annotations on my POCO's which are defined in my Service Layer. As long as I have a reference to System.ComponentModel & System.ComponentModel.DataAnnotations this is no problem and what I like about this is that it allows me to reuse my Service Layer in a Win Forms app.
I'm now looking to do some Remote Validation using Data Annotations and have taken a look at this article: http://msdn.microsoft.com/en-us/library/ff398048(VS.100).aspx
However, to use the Data Annotations in this context I need to reference System.Web.MVC, System.Web and System.Web.Routing. This introduces a dependency on the Web DLL's, which limits me somewhat.
Can anyone recommend a good clean way to implement Remote Data Validation using Data Annota开发者_StackOverflow社区tions that isn't coupled with ASP.NET MVC or maybe suggest a better alternative.
Thanks for the help !
I resolved this in the end by backing away from putting DataAnnotations on my POCO's and instead I put them on my ViewModels and use AutoMapper to Map between my ViewModel and POCO (which saves me some time doing tedious mapping). There's a great video on Automapper here http://perseus.franklins.net/dnrtvplayer/player.aspx?ShowNum=0155
精彩评论