How is model state passed to service layer?
When the product service is created, the model state dictionary is passed to the service. The product service uses model state to pass validation error messages back to the controller. We have failed to isolate the controller and service layers in one respect. The controller and service layers communicate through model state.
Is the business layer on top of the domain model?
The business layer sits on top of the data model and uses the data model just as data. The anemic domain model is just a procedural style design. Anemic entity objects are not real objects because they lack behavior (methods).
What does a service layer do in MVC?
A service layer is an additional layer in an ASP.NET MVC application that mediates communication between a controller and repository layer. The service layer contains business logic. In particular, it contains validation logic.
How does validating with a service layer work?
The CreateProduct() method calls the ValidateProduct() method to validate a new product before passing the product to the product repository. The Product controller has been updated in Listing 4 to use the service layer instead of the repository layer. The controller layer talks to the service layer.
Where does database logic go in service layer?
The recommendation is that you place all of your database logic in a separate repository layer. For example, Listing 1 contains a simple repository named the ProductRepository. The product repository contains all of the data access code for the application.
What does a service layer do in ASP.NET?
A service layer is an additional layer in an ASP.NET MVC application that mediates communication between a controller and repository layer. The service layer contains business logic. In particular, it contains validation logic. For example, the product service layer in Listing 3 has a CreateProduct() method.