In this article, a Nguestbook business logic layer is implemented.
In the practical application, the business logic layer is very important, he carries the whole system the core part, is also the customer most attention part. This part of the implementation, usually requires the cooperation of technical experts and field experts. Of course, in the demo of this article series, because of the simplicity of the business logic, it may not be obvious to see here.
In the business logic layer implementation of this article, the business logic layer mainly undertakes the following responsibilities:
1. Encapsulation of different data access layers. This allows the presentation layer to be indifferent to the specific data access layer.
2. The filling and conversion of business logic data. such as encryption of the administrator password.
3. The realization of the core business. Many of the business logic here have only one line of code, that is, a business logic method corresponds exactly to a data access method, but there are several methods of data access to achieve the business. The ChangePassword method in Adminbll, for example, invokes the Admindal GetByID and update two methods. In addition, although many methods call only one data access method, it can be seen from the naming to see the difference between the two. such as the Getbynameandpassword in Admindal, the name is clearly from the database point of view-refers to the specified name and password two fields of the value of the corresponding information, as the business meaning of doing so it does not need to know. In Adminbll, the way to call it is login, which is from a business point of view-that is, the method is an admin login.
The following step-by-step implementation of the business Logic layer:
1. Establishment of the project
In this architecture, the business logic layer can be replaced. And the business logic layer is not directly coupled to the presentation layer, but is realized by the dependency injection mechanism. So, instead of naming this business logic layer directly as BLL, we're creating a new project called SIMPLEBLL that places the relevant code for our business logic layer.
2. Configuring Dependency Injection
The business logic layer loads the appropriate data access layer through the reflection factory, which requires the configuration of the data access layer that needs to be used in the web.config. Open Web.config, locate the "DAL" item under the appsettings node and give the value of the data Access layer project name that we want to use, for example: To use Nbeardal, this should be the case:
<add key= "DAL" value= "Nbeardal"/>