2
votes

We have a service layer within our MVC3 application using an almost identical approach as described here: http://www.asp.net/mvc/tutorials/older-versions/models-(data)/validating-with-a-service-layer-cs

The service layer doesn't depend on MVC.

The issue is we have a legacy webforms application that needs to also create these services and I'm trying to come up with the best approach on how to instantiate these services. It would also be nice to have the Validate() method return the validation errors.

An individual service requires an IValidationDictionary at construction which within our MVC app we simply use the ModelStateWrapper(this.modelstate) however in Webforms we obviously don't have the concept of ModelState (as in Controller.ModelState)

So my question would be how would you construct a service layer with model validation that can be used within an MVC and Webforms application?

At this stage we're not considering an IoC

On a side note:

Am I missing something obvious with ModelStateDictionary? It's within the MVC namespace but doesn't appear to be dependant on the MVC framework? Isn't it just a wrapper for a Dictionary with a setup?

1
Don't call it simply "MVC" when you are talking in about ASP.NET MVC framewoerk. I's like referring to IE as "the internet".tereško

1 Answers

0
votes

The ModelStateWrapper is a good approach for MVC but like it's an implementation of the IValidationDictionary. You could do a web form implementation but instead use a validation summary control instead of the model state.

Sorry I don't have any code to show you at this time.