I like to start my question by stating that I am new to .NET framework and ASP.NET altogether. However, I am trying to learn ASP.NET 5 MVC 6. I have read many tutorial to get me up to speed. The main tutorial that I have learned a lot from was "Learn MVC in 7 Days"
I think I get the MVC
architecture over all, but there is some terminology/layers that are confusing me i.e. Model, Business Logic layer, Data Access layer and View Model.
Here is my overall understanding of the MVC architecture "Please correct me if wrong"
- (M) Model: is an object that represent a database table. Each table in the database is a model. Each column with in each table is an attribute in the model's object. For example, if I have a table called "users" with the following columns
id
,firstname
,lastname
andusername
then the model will be calleduser
and "id
,firstname
,lastname
andusername
" are attributes. - (V) View: is the way to present the data to the end user by placing data into HTML page.
- (C) Controller: is a layer that will be called by the route engine. The controller class holds some logic on what data/views should the user see. For example,
UsersController
class has a method calledIndex()
which request some data from theuser
model and then returns a view calledShowAllUsers
.
However, Model seems to have another 3 layers underneath it like so
- View Model: which seems to be a way to transform the raw data coming from the model into a presentable "view ready" format. For example, if we want to present the user's Full Name to the end user but we do not have fullname as an attribute in the model. Then we this layer will create a new object which is the same at the model object with one additional virtual attribute called fullname. Therefore, we now can display obj.fullname in the view.
- Business Logic Layer
- Data Access layer
Additionally, if I want to have a repository for my controller, where would this fit here? I do understand this may not be necessary for a small application, but I am just trying to understand and learn the correct way then I can decide whether this is needed in my app or not.
My question here is what is the business logic layer and what is data access layer? and where would the repository fit here?
I will appreciate an explanation with an example.