MVC DAL & BLL concept

I'm used to Classic Asp, where I never used the DAL / BLL concept, and now I'm learning MVC and trying to stay away from BAD habits (for example, writing SQL queries on the ASP page itself). I read about the data access layer and business logic ... they make sense, but I'm trying to figure out how to put them in the current application.

Its a shopping app.

I currently DO NOT use EF or SQL for Entities, a plain old ADO.NET where my functions return a DataTable.

Let me give you an example.

1 - I need to Return Products From SQL Table 2 - My Products Model Class will hold the SQL Table output 3 - and then I will show the output to View 

Product Request

 Select * From Products Where title = 'Bluh' 

ProductsModelView.vb

 Class ProductsModelView Public title as string Public sku as string ....etc End Class 

Now my view will simply display the result (from the list (ProductModelView))

Now my question is: how can I add DAL and BAL levels over stages.

+4
source share
1 answer

The main way to get started is to create 3 projects:

  • DAL Project
  • BLL Project
  • User Interface Project (your MVC application)

In a DAL project, you must create a repository class. What this class does is execute the query in the database and convert the DataTable to your model.

Your BLL project must have a class service . This class has a reference to DAL and calls a method to get a list of objects you need (DAL processes DB-code). In this class, you can apply logic. NOTE. At the moment, you do not have real logic in your application. This is normal, your service can immediately return the list from DAL. It will provide you with a place where you can add logic later without affecting the data access code.

In the user interface, your controller will call the service and pass the result to a view, which is then responsible for providing the result.

This is a basic starting point. You can go further with this and fully combine it. At the moment, you still have a strong dependency on UI => BLL => DAL.

I recently wrote an article on how you can make sure that you are not creating hard dependencies: http://www.kenneth-truyers.net/2013/05/12/the-n-layer-myth-and-basic-dependency -injection /

+16
source

Source: https://habr.com/ru/post/1483239/


All Articles