I have written a desktop application, and now I'm working on the ASP.net MVC version of the same program. Many of the business models are in a .dll library which I share between both the desktop program and the MVC program.
I'd like to use features of MVC, like validation, but to this end I'd need to add attributes to the model classes defined in the .dll. Since it is my own library I could do it, but what if I needed to use a library I cannot access. What is best practice? Writing a wrapper class, like this?
As an example, let this be a simple class in the .dll
public class A {
public string Name {get; set;}
public A(string _name){
this.Name = _name
}
}
In the MVC project I would like to use A
, but would also like to add DataAnnotations to its property. I could then define a new class like this:
public class A_Web {
private _a;
[Required(ErrorMessage = "A Name is required")]
public string Name {get {return _a.Name;} set {_a.Name = value;}}
public A_Web(string _name){
this._a = new A(_name)
}
}
Is there a better way? This seems like a lot of code for bigger classes...