Question

In a N-tier application, my website connects to a web reference to access business layer logic and to get business layer DTOs. For example, the BL may provide a definition for a Car:

public class Car() {
    public string Make { get; set; }
    public string Model { get; set; }
    . . .
}

In my ASP.NET MVC website, I need to create my own Car model object. (Maybe to add/remove a field or to add validation via data annotations).

Since I already have an object in my namespace named Car, I need to name my model object something else. There really isn't a better name for the object though. Is there an easier way to handle these name conflicts? Alternatively, I could fully qualify the models, but this doesn't seem ideal.

Another possibility, can I use the object from the BL, but extend it so I can add data annotations for validation?

Was it helpful?

Solution

I have seen people simply append Model to these classes when dealing with them in their MVC applications. In your case, the class would be CarModel.

As for extending the object, I would not recommend leaking business layer objects through to the presentation layer, as you will run into trouble later if the data changes. Rather than having to change the presentation code in every place the data is used, it will be easier to only have to change it in the conversion from Car to CarModel.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top