I am using ASP.NET MVC in my application. I have divided my application into three layer architecture. 1) Data Access Layer (using Entity Framework), 2) Application/Business Layer, 3)Presentation Layer (ASP.NET MVC).
Because I am using MVC framework on my presentation layer, I am confused about the business logic. I need to know where do I put my business logic in MVC pattern. In other words we can say from where I need to call my middle layer. From the Models or from the Controllers?
If I call my business logic from Controller then It seem like the Models are useless. Other wise if I call business logic from the model then it seems like unnecessary bidden on the system because Business Object maps with model and then model is passed to the Controller. Model does exactly what DTO is doing.
Any help will be appreciated
ASP.NET MVClayer or tier doesn’t contains neither business logic nor business model.MinMVCstands for UI model, not the model of your application core andMVC(as well as otherMV*patterns) is generally pattern for separating UI concerns. You should send messages (call) your Business Layer (BL) from Controllers, aggregate data, create or map it results into UI model and pass it to view. Your UI model should know nothing of BL model – this distinction makes loosely coupled layers of your application.Definitely from Controllers. You inject dependencies to it and call them from your Action methods. ASP.NET MVC provide lots of mechanisms of injection dependencies into controllers and integrates nicely with NInject, StructureMap and some other IoC containers.
Dependencies between components in MVC is given below
Picture is takes from Martin’s Fowler article on GUI Architecture, which by the way, very nice reading regarding MVC and MVP.
Also, Pluralsight has set of videos on Software Practices, which covers Design Patterns. I’ve learned a lot from their definition of MVVM and MVP.
Reading this materials should increase your understanding not only on patterns itself, but also in how they fit into application environment and interact with it.