Naming conventions DAL, BAL, and UI Layer [closed]

I am developing a typical Web Application with the following layers

  1. UI Layer (MVC)
  2. Business Logic Layer (BAL)
  3. Data Access Layer (DAL)

Each layer has its own DTO object including the BAL and DAL. My questions regarding this are as follows

  1. The DTO returned by the DAL is simply converted to the corresponding DTO in the BAL and sent to the UI Layer. Both attributes and the structure of the DTO objects are the same in some cases. In such scenarios is it better to simply return the DTO in the DAL to the UI layer without including an intermediate object.

  2. What is the best way to name these DTO objects and other objects in each layer. Should I use some prefix such as DTOName, ServiceName? The reason why I am asking to use a prefix is because if not the classes in my Solution clashes with other classes in the Framework and with a prefix it is easier for me to understand where each class belongs?

3

Preface

Hopefully this is obvious, but… in the suggested namespaces below, you would replace MyCompany and MyProject with the actual names of your company and project.

DTOs

I would recommend using the same DTO classes across all layers. Fewer points of maintenance that way. I usually put them under a MyCompany.MyProject.Models namespace, in their own VS project of the same name. And I usually name them simply after the real-world entity that they represent. (Ideally, the database tables use the same names too, but sometimes it makes sense to set up the schema a bit differently there.)

Examples: Person, Address, Product

Dependencies: None (other than standard .NET or helper libraries)

DAL

My personal preference here is to use a one-for-one set of DAL classes matching the DTO classes, but in a MyCompany.MyProject.DataAccess namespace/project. Class names here end with an Engine suffix in order to avoid conflicts. (If you don’t like that term, then a DataAccess suffix would work fine too. Just be consistent with whatever you choose.) Each class provides simple CRUD options hitting the database, using the DTO classes for most input parameters and return types (inside a generic List when there are more than one, e.g., the return from a Find() method).

Examples: PersonEngine, AddressEngine, ProductEngine

Dependencies: MyCompany.MyProject.Models

BAL/BLL

Also a one-for-one mapping here, but in a MyCompany.MyProject.Logic namespace/project, and with classes getting a Logic suffix. This should be the only layer that calls the DAL! Classes here are quite often just a simple pass-through to the DAL, but if & when business rules need to be implemented, this is the place for it.

Examples: PersonLogic, AddressLogic, ProductLogic

Dependencies: MyCompany.MyProject.Models, MyCompany.MyProject.DataAccess

API

If there’s a web services API layer, I use the same one-for-one approach, but in a MyCompany.MyProject.WebApi namespace/project, with Services as the class suffix. (Unless you’re using ASP.NET Web API, in which case you would of course use the Controller suffix instead).

Examples: PersonServices, AddressServices, ProductServices

Dependencies: MyCompany.MyProject.Models, MyCompany.MyProject.Logic (never bypass this by calling the DAL directly!)

An Observation on Business Logic

It seems to be increasingly more common for people to leave out the BAL/BLL, and instead implement business logic in one or more of the other layers, wherever it makes the most sense. If you do this, just be absolutely certain that (1) all application code goes through the layer(s) with the business logic, and (2) it’s obvious and/or well-documented where each particular business rule has been implemented. If in doubt, don’t try this at home.

A Final Note on Enterprise-Level Architecture

If you’re in a large company, or other situation where the same database tables get shared across multiple applications, then I would recommend leaving the MyProject portion out of the above namespaces/projects. That way those layers can be shared by multiple front-end applications (and also behind-the-scenes utilities like Windows Services). But only do this if you have strong cross-team communication and thorough automated regressing testing in place!!! Otherwise, one team’s changes to a shared core component are likely to break another team’s application.

4

I usually build application as

ProjectName.Core            // "framework"/common stuff
|- Extenders
|- Gravatar.cs

ProjectName.DataProvider    // database provider layer
|- Migrations
|- ApplicationDbContext.cs  // entity framework

ProjectName.Domain          // database objects
|- Post.cs
|- Tag.cs

ProjectName.Services        // validations, database stuff
|- PostService.cs

It is somewhat similar to Sharp-Lite.

About prefixes, I hate them. Microsoft’s Internal Coding Guidelines hate them as well. Also there is a tool called StyleCop that complains about prefixes as well.

1

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa

Naming conventions DAL, BAL, and UI Layer [closed]

I am developing a typical Web Application with the following layers

  1. UI Layer (MVC)
  2. Business Logic Layer (BAL)
  3. Data Access Layer (DAL)

Each layer has its own DTO object including the BAL and DAL. My questions regarding this are as follows

  1. The DTO returned by the DAL is simply converted to the corresponding DTO in the BAL and sent to the UI Layer. Both attributes and the structure of the DTO objects are the same in some cases. In such scenarios is it better to simply return the DTO in the DAL to the UI layer without including an intermediate object.

  2. What is the best way to name these DTO objects and other objects in each layer. Should I use some prefix such as DTOName, ServiceName? The reason why I am asking to use a prefix is because if not the classes in my Solution clashes with other classes in the Framework and with a prefix it is easier for me to understand where each class belongs?

3

Preface

Hopefully this is obvious, but… in the suggested namespaces below, you would replace MyCompany and MyProject with the actual names of your company and project.

DTOs

I would recommend using the same DTO classes across all layers. Fewer points of maintenance that way. I usually put them under a MyCompany.MyProject.Models namespace, in their own VS project of the same name. And I usually name them simply after the real-world entity that they represent. (Ideally, the database tables use the same names too, but sometimes it makes sense to set up the schema a bit differently there.)

Examples: Person, Address, Product

Dependencies: None (other than standard .NET or helper libraries)

DAL

My personal preference here is to use a one-for-one set of DAL classes matching the DTO classes, but in a MyCompany.MyProject.DataAccess namespace/project. Class names here end with an Engine suffix in order to avoid conflicts. (If you don’t like that term, then a DataAccess suffix would work fine too. Just be consistent with whatever you choose.) Each class provides simple CRUD options hitting the database, using the DTO classes for most input parameters and return types (inside a generic List when there are more than one, e.g., the return from a Find() method).

Examples: PersonEngine, AddressEngine, ProductEngine

Dependencies: MyCompany.MyProject.Models

BAL/BLL

Also a one-for-one mapping here, but in a MyCompany.MyProject.Logic namespace/project, and with classes getting a Logic suffix. This should be the only layer that calls the DAL! Classes here are quite often just a simple pass-through to the DAL, but if & when business rules need to be implemented, this is the place for it.

Examples: PersonLogic, AddressLogic, ProductLogic

Dependencies: MyCompany.MyProject.Models, MyCompany.MyProject.DataAccess

API

If there’s a web services API layer, I use the same one-for-one approach, but in a MyCompany.MyProject.WebApi namespace/project, with Services as the class suffix. (Unless you’re using ASP.NET Web API, in which case you would of course use the Controller suffix instead).

Examples: PersonServices, AddressServices, ProductServices

Dependencies: MyCompany.MyProject.Models, MyCompany.MyProject.Logic (never bypass this by calling the DAL directly!)

An Observation on Business Logic

It seems to be increasingly more common for people to leave out the BAL/BLL, and instead implement business logic in one or more of the other layers, wherever it makes the most sense. If you do this, just be absolutely certain that (1) all application code goes through the layer(s) with the business logic, and (2) it’s obvious and/or well-documented where each particular business rule has been implemented. If in doubt, don’t try this at home.

A Final Note on Enterprise-Level Architecture

If you’re in a large company, or other situation where the same database tables get shared across multiple applications, then I would recommend leaving the MyProject portion out of the above namespaces/projects. That way those layers can be shared by multiple front-end applications (and also behind-the-scenes utilities like Windows Services). But only do this if you have strong cross-team communication and thorough automated regressing testing in place!!! Otherwise, one team’s changes to a shared core component are likely to break another team’s application.

4

I usually build application as

ProjectName.Core            // "framework"/common stuff
|- Extenders
|- Gravatar.cs

ProjectName.DataProvider    // database provider layer
|- Migrations
|- ApplicationDbContext.cs  // entity framework

ProjectName.Domain          // database objects
|- Post.cs
|- Tag.cs

ProjectName.Services        // validations, database stuff
|- PostService.cs

It is somewhat similar to Sharp-Lite.

About prefixes, I hate them. Microsoft’s Internal Coding Guidelines hate them as well. Also there is a tool called StyleCop that complains about prefixes as well.

1

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật