Implementing database functionality objects in an N-tier architecture?

I am adding functionality to our website, which runs lengthy processes asynchronously using MSMQ. The execution of this ansina, however, means that we must notify users of the completion of their requests. Using the command template, I created an interface * called INotify and compiled it into a message class, so the message processing class can simply call the GiveNotice () function in the INotify message. The first implementation, EmailNotify, was more complicated than expected, as I was surprised to find that MailMessage is not serializable, but got it.

Now I am working on a new concrete DBNotify notifier that will call some SP and update the status in the main transactional database. I stumbled that I would like to reuse the DAL architecture that we already created, but INotify is a member of the Model project, which is more fundamental than DAL.

Our hierarchy looks like this: General> Model> DAL> BAL

Here's more about the levels. Keep in mind, I inherited this from: Common is responsible for all the "utility" functions that are used in many places of the application, such as access to configuration settings, parsing strings, and non-business functionality.

A model is a business object that some people call data transfer objects, collections of getters and setters. I added some "smarts" at this level, but only internal rules for this object, such as "The element name must begin with an alphanumeric character."

DAL is the level of access to data, theoretically, everything that happens here is model objects that move to and from the database.

BAL is a business layer; in theory, business rules are applied that control the interaction of objects (ie, β€œA form must have at least two elements.”).

, INotify , (.. , TXT, ..). , , DAL. , INotify, SP .

- -, , N-?

Linq Sql, . ( ), ( ).

, StackExchange , , .

+5
6

, , , , .

, , , . , : . , "" , , .

, , .

0

, , - - .

, . . "" . . , , , .

, , TClient.Save TClient.Load, , , , , , , , , . ( GUI, , GUI), , DataStore.Load(ClientInstance) DataStore.Save(ClientInstance). , . # RTTI Delphi Client, .

- , " , ", , , , , , , /.

, , , .

( , - -, BAL):

+---+   +-------------+
| C |<--| Data Access |<--------------------------+
| o |   +-------------+                           |
| m |         |                                   |
| m |         |                                   |
| o |         v                                   |
| n |   +-------------+   +----------------+   +-----+
|   |<--| Model       +<--| Cross class    |<--| GUI |
|   |   +-------------+   | business rules |   |     |
|   |                     |                |   |     |
|   |<--------------------|                |   |     |
|   |                     +----------------+   |     |
|   |                                          |     |
|   |<-----------------------------------------|     |
+---+                                          +-----+

INotify, , , , , , .

, INotify "", , , / "", . , , , , . () , , .

, . - , , , , , "Logger". , , , / "".

        +--------------------------------------------+
  +-----| Cross cutting concerns                     |
  |     +--------------------------------------------+
  v           v^                                    ^
+---+   +-------------+                             |
| C |<--| Data Access |<--------------------------+ |
| o |   +-------------+                           | |
| m |         |                                   | |
| m |         |                                   | |
| o |         v                                   | v
| n |   +-------------+   +----------------+   +-----+
|   |<--| Model       +<--| Cross class    |<--| GUI |
|   |   +-------------+   | business rules |   |     |
|   |                     |                |   |     |
|   |<--------------------|                |   |     |
|   |                     +----------------+   |     |
|   |                                          |     |
|   |<-----------------------------------------|     |
+---+                                          +-----+
+3

, INotify , , . - , , . , , INotify. BAL ( BLL, Business Logic Layer?), , INotify. , , BLL DAL, sproc, DAL, ; , , ; .

- -, , N-?

, , :

: ,
: , DTO Data Transfer Objects, , . , , .
DAL: , , . () .
BAL/BLL: , , - , -.

, , . - Linq2Sql Entity Framework DAL; . , Entity Framework , "" ( Entity Framework), DAL, . T4 , , , IRepository, . NHibernate, , (, , ).

+2

Model DTO ( ), () "" .

, , MessageProcessing, BAL BAL DAL, , ( BAL).

+1

, POCOs. , . ( DataAccess)

. . , , . , , , .

, , , - ( IoC):

  • Core ( - orm)
  • ( . )
  • ( -, winforms, webapp)

. , Core , , .

ORM (FluentValidation DataAnnotations) ? .

+1

, , .

, //.

, . , .

, ( ) , .

Between the solution may be the use of interfaces / roles: Define for each level the interface / role that the object should play, and use this interface to transfer to this layer. Then the class (general) must implement the role (or many of them). This will provide a more loosely coupled system.

I learned a lot from this neat lecture on DCI (data, collaboration, and interaction)

0
source

All Articles