c# - How is BLL (CRUD and Business Object) typically structured? -


This is in relation to this question:

In response to this question (I have not yet chosen any answer because I can be willing to comment on others to make it clear), I have come to the conclusion that the CRUD will be included in the BLL and as per the requirement, the DAL will be reached.

My main problem now looks like my BLL? For example, for an order object CRUD, I see some implementation that has an order service which is part of BLL in this way:

  public class order service { Public int update order (order order) {...} public int UpdateOrder (order order)) Other code for {...} // ... CRUD}  

this thing One side of the business object, I have a business object in BLR Classes are?

While doing something else they do something like this:

  public class order {public int id {get; Set; } Receive the public decimal amount { Set; } // ... e.t.c. Public int build () {...} public int update () {...}}  

but it is in some way wrong (combination of CRUD operation) and properties).

How is BLL (CRUD and Business Object) generally structured?

In addition, because the data will generally come from UI input, then it will come from the business object, how will I validate the data? For example, I have total assets for the order and list, the total order should be equal to the total amount of the item. When ordering, order order, how do I start legalization? I always thought that verification should be done inside the actual property sets. How do I add it during the CRUD? Should I apply a valid method to business object?

Any input about this will be very welcome. Based on my experience, I want to use the first one if there is a more sophisticated business logic. Undoubtedly. Usually I have the following layers in the complex application:

  • See. Razor Pages
  • Models. The model is that being displayed represents something, from the database nothing.
  • Controller. Administrators can only add presentations and business logic.
  • Business Arguments In a separate library (BLL) BL business logic communicates with MVC controllers (through DTO) and data level.
  • Data Layer manipulation through EF.

DTO can be made from many DB objects; If you want to hide some details, they can also be partial representation. Read more. DTO is a good way to force yourself to stop - or see.

In small applications, BLL is not required, where administrators can do everything but in large applications where you should use different services and aspects, you should use it. Some people say that the BLL is part of the model - well, some, yes, but it is much more than stuff to fill ideas.

And highlight me again: Do not use a cannon to shoot sparrows ... Simple tasks require simple solutions.

ADD-ON

You can map the DTO organizations to DBO institutions by selective expressions. One example, I thought that there is a kitten in the database table, put another below

  class pest {public static expression & lt; Funk & lt; DB Kate, Kitten> & gt; = (Kitten) => New kitten back () {id = id, name = name, customdataNotInDb = 42}; Public entry id; The name of the public string; Public int CustomDataNotInDb; }  

Then you can use it:

  var kittenDto = context.Kittens. Single (k = & gt; KID == given ID). Select (KittenDto.Selector);  

If the selector is an expression , then it is executed locally. If this is a expression , then it is converted to a query and DB does the rest of the DB result as a KittenDto object (or more accurate: only in There are requested properties, and nothing else).

Also keep in mind that complex expressions can be hard to write - or it was when I used it last time around Net 4.5. For example, function calls can not be executed in DB queries, only some very common (like some string operations).


Comments