How to build business layer in MVC3 project?
-
I've already read some articles about this matter, but I'm not sure how to solve my problem. I work on project in which we use MVC3. The project should manage school system (schools, pupils, teachers, parents, users, roles and so on. In the center of such a school management system is - schedule of subjects. We get data from MS SQL Server through EF4 (database first approach), which means all entity classes are created automatically. Therefore, I have such a classes that represent database tables such as School, Pupil, Teacher, Role and so on. And I have DbContext derived class. We primarily know how our presentation (UI) layer should look like. The problem is in layer between UI and classes we got automatically by using EF4 that I've already mentioned. I've read about repository and unit of work patterns and understood how they work. I've thought we could apply those patterns, but our project architect wants to use something else. He wants to have clear separation of layers. He wants to call simple methods from controllers that are placed in business layer, which means almost whole logic should not be in controllers, but in that business layer. I'm not sure now what I should start with. I have all those entity classes School, Pupil, Teacher, Role and so on. And I have DbContext derived class. That means those classes are input for business layer. What should be output of business layer? How could I design business layer? Thank you in advance. Goran
-
I've already read some articles about this matter, but I'm not sure how to solve my problem. I work on project in which we use MVC3. The project should manage school system (schools, pupils, teachers, parents, users, roles and so on. In the center of such a school management system is - schedule of subjects. We get data from MS SQL Server through EF4 (database first approach), which means all entity classes are created automatically. Therefore, I have such a classes that represent database tables such as School, Pupil, Teacher, Role and so on. And I have DbContext derived class. We primarily know how our presentation (UI) layer should look like. The problem is in layer between UI and classes we got automatically by using EF4 that I've already mentioned. I've read about repository and unit of work patterns and understood how they work. I've thought we could apply those patterns, but our project architect wants to use something else. He wants to have clear separation of layers. He wants to call simple methods from controllers that are placed in business layer, which means almost whole logic should not be in controllers, but in that business layer. I'm not sure now what I should start with. I have all those entity classes School, Pupil, Teacher, Role and so on. And I have DbContext derived class. That means those classes are input for business layer. What should be output of business layer? How could I design business layer? Thank you in advance. Goran
I would suggest to keep your entity classes (generated from EF4) into database layer (separate C# class library). Don't keep them in models folder. Your business layer methods should call them. Your controller can call these business layer methods. To use Entity class in your web project, add reference of your database layer. This kind of architecture will give you a lot of flexibility in future.
Anurag Gandhi.
http://www.gandhisoft.com
Life is a computer program and every one is the programmer of his own life.
My latest article: Group GridView Data