Start Validating an index

Validating an index

One option is to place your validation logic in a . NET MVC application that mediates communication between a controller and repository layer. The Create Product() method calls the Validate Product() method to validate a new product before passing the product to the product repository. When the product service is created, the model state dictionary is passed to the service.

Listing 2 - Controllers\Product So, application flow control logic belongs in a controller and data access logic belongs in a repository.

In that case, where do you put your validation logic? For example, the product service layer in Listing 3 has a Create Product() method. Listing 4 - Controllers\Product Notice that the product service is created in the product controller constructor.

The goal of this tutorial was to discuss one approach to performing validation in an ASP. In this tutorial, you learned how to move all of your validation logic out of your controllers and into a separate service layer.

You also learned how to isolate your service layer from your controller layer by creating a Model State Wrapper class.

Learn how to move your validation logic out of your controller actions and into a separate service layer.

In this tutorial, Stephen Walther explains how you can maintain a sharp separation of concerns by isolating your service layer from your controller layer.

Creating a repository layer enables you to maintain a clean separation of concerns.

Controllers are responsible for application flow control logic and the repository is responsible for data access logic.

In other words, the service layer has a dependency on a particular feature of the ASP. We want to isolate the service layer from our controller layer as much as possible.

In theory, we should be able to use the service layer with any type of application and not only an ASP. For example, in the future, we might want to build a WPF front-end for our application.

We should find a way to remove the dependency on ASP. In Listing 5, the service layer has been updated so that it no longer uses model state.