Namespace hierarchy in C#

I have a C# class library shared among several applications. The library is divided into a few smaller components which have dependencies shown in the picture below. Each component is placed in its own namespace to enforce the component boundaries:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>Core <- Component A <---- Component B <----- Application
^ ^------ Component C <---/
--- Component D <--/
</code>
<code>Core <- Component A <---- Component B <----- Application ^ ^------ Component C <---/ --- Component D <--/ </code>
Core <- Component A <---- Component B <----- Application
  ^               ^------ Component C <---/
   --- Component D <--/

Now I am thinking about the namespace hierarchy. So far I have found two different approaches:

  1. Nested namespace extends the parent namespace, so that the parent namespace can exist without the child components. Alternatively the nested namespace contains implementation of the interfaces from the parent namespace. I believe this approach is used in standard .NET libraries.

  2. Parent namespace acts as a mediator which interconnects nested namespaces to form the whole application/super component (described in this article).

Question: Shall the namespace (and folder) hierarchy reflect the namespace dependencies? What is the preferred way of dealing component/namespace dependencies in large projects?

Namespaces provide context in order to name things. They also provide means to avoid conflicts when two different organizations make the name.

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code> - CompanyA.File
- CompanyB.File
</code>
<code> - CompanyA.File - CompanyB.File </code>
 - CompanyA.File 
 - CompanyB.File

In this case, both use File but one can reference both in your application without conflict.

Usually a hierarchy is made in order to provide a means to classify components. Examples:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code> - Company.Core.Http
- Company.Core.Error
</code>
<code> - Company.Core.Http - Company.Core.Error </code>
 - Company.Core.Http 
 - Company.Core.Error

And then

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code> - Company.CoolApp.Dto.Product
</code>
<code> - Company.CoolApp.Dto.Product </code>
 - Company.CoolApp.Dto.Product

Here I have a created a hierarchy to define core components as well as a hierarchy for an application as well.

Usually these hierarchy’s are made up ahead of time and have some sort of convention to it. There is no right or wrong here.

But usually the first level is your ID, second level Common/Core or Application, and 3rd and beyond would be the hierarchy of components that are developed. This would also depend on how your company is structured as well.

Usually the top layer is what identifies you or your org. Under that it is usually grouped by core or common and then by application. As teams write code, components may be moved if an application component is deemed to be a common or core component.

Usually components that are cross cutting are in common or core. These include error handling, logging, etc.

Application components are specific to the application and are usually defined by the development teams. If an application uses Dto or Model as classes to define entities one might what to develop namespace standards that go across applications or products. For example, all entity classes go under a namespace called Model. Then you have some consistency across applications.

For example:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code> - Company.CoolApp.Model.Foo
- Company.CrappyApp.Model.Foo
- Company.CrappyApp.Model.Bar
</code>
<code> - Company.CoolApp.Model.Foo - Company.CrappyApp.Model.Foo - Company.CrappyApp.Model.Bar </code>
 - Company.CoolApp.Model.Foo 
 - Company.CrappyApp.Model.Foo
 - Company.CrappyApp.Model.Bar

This allows someone at a high level to determine if:

Company.Core.Model.Foo …should exist, since they can look across applications and determine if it can be consolidated.

3

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