locked
Best Practise of reusing code in n tier architecture RRS feed

  • Question

  • User-525411387 posted

    I have many service classes in Business Logic Layer similarly many classes in the Data Access Layer. and i have to reuse functions of different services/entities now i have a question which is the best practice that in a business logic layer should i call data access layer function or business logic layers function. 

    For example, in order service i need customers and products so should i call BAL customer, product or i have to call DAL customer, product 

    Saturday, October 10, 2020 10:21 PM

All replies

  • User-474980206 posted

    the DAL should be an abstraction of the database. it should just support queries and updates to the database. This abstraction allows changing the database vendor. if asp.net core, you might want this to be EF core context and entries. 

    the BL layer is the logical layer. It should have its own interface and should avoid exposing DAL entities. this allows changing the DAL layer, without changing the BL api. 

    the DAL should only be called by BL layer. 

    a service should only call the BL layer.

    in n-tier, there are public/intranet facing services (UI / webapi) and there are backend (behind firewall) tiers. only backend tiers should access the DAL.  

     

    Sunday, October 11, 2020 1:54 AM
  • User1120430333 posted

    For example, in order service i need customers and products so should i call BAL customer, product or i have to call DAL customer, product 

    Is the BLL anemic of any business logic,  it is acting as passthrough logic to access the DAL and you don't need it?

    https://www.oreilly.com/library/view/software-architecture-patterns/9781491971437/ch01.html

    Also, understand what architectural style you really are using. Is it layered or n-tier?

    https://docs.microsoft.com/en-us/previous-versions/msp-n-p/ee658117(v=pandp.10)

    Sunday, October 11, 2020 9:16 PM