As I am learning and working on Asp.Net MVC application, I want to know that what is the better place to write Business Logic
and Data Access logic
in MVC
.
Where should I write DataAccess and Business Logic among three layers (Model, View and Controller
) ??
Could anybody please tell me the correct way to write the code for this.
Scenario: I want to retrieve all the employees where employee name like 'Mi%'
( I have SQL procedure to execute and retrieve the data.
)
PS: Want to know that where I should create instance of Business Logic class and where I should create instance of Data Access layers class?
Thanks in advance.
The business logic should be placed in the model, and we should be aiming for fat models and skinny controllers. As a start point, we should start from the controller logic. For example: on update, your controller should direct your code to the method/service that delivers your changes to the model.
Business logic should live in the data model. And, what's more, it should live in the graph data model because that's the right abstraction for the next twenty years. If you've been paying attention to this blog or to Stardog generally, then you must have known this is where we were going to end up.
For non trivial applications, business logic/business rules/data access should not be placed directly into Models, Views, or Controllers. To do so would be placing business logic in your presentation layer and thus reducing reuse and maintainability of your code.
Two good reasons for putting the business logic in the database are: It secures your logic and data against additional applications that may access the database that don't implement similar logic.
Business logic (BL) and data access (DAO) should be in separate layers. Models should only keep data and contain no logic. Controller should only receive data from view and send it to BL layer (or send from BL to view).
It's not a strict rules, but most recently used approach
Business logic should be in the Model.
Data Access can either be its own later your Controllers call, or automated in an ORM that your Controller will call through repositories.
A walk-through covering this can be found in Nerd Dinner, look for the free download section.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With