简体   繁体   English

程序集命名约定

[英]assembly naming conventions

Assuming you have a namespace that is useful to more than one project in your company, in the format of "MyCompany.Core", would you have an assembly named exactly the same way or just "Core". 假设您有一个对公司中多个项目有用的命名空间,格式为“MyCompany.Core”,您是否有一个名称完全相同或只是“Core”的程序集。 Why or why not? 为什么或者为什么不?

Use the standard .NET naming conventions, assembly names are covered here . 使用标准.NET命名约定, 此处介绍了程序集名称。 I'll save you the (short) read: 我会救你(简短)阅读:

Do choose names for your assembly DLLs that suggest large chunks of functionality such as System.Data. 请为汇编DLL选择名称,这些DLL建议使用大量功能块,例如System.Data。 Assembly and DLL names do not have to correspond to namespace names but it is reasonable to follow the namespace name when naming assemblies. 程序集和DLL名称不必与命名空间名称相对应,但在命名程序集时遵循命名空间名称是合理的。

Consider naming DLLs according to the following pattern: 考虑根据以下模式命名DLL:
<Company>.<Component>.dll
Where <Component> contains one or more dot-separated clauses. 其中<Component>包含一个或多个以点分隔的子句。

For example, Contoso.WebControls.dll. 例如,Contoso.WebControls.dll。

I believe it's best (opinion here!) to name the assembly after the root namespace it contains, in your case MyCompany.Core.dll . 我认为最好(在这里看到!)在它包含的根命名空间之后命名程序集,在你的情况下是MyCompany.Core.dll You never know if that file will make its way outside the company, and keeping track of it is just easier in general. 您永远不知道该文件是否会在公司之外进行,并且跟踪它通常会更容易。

Imagine if Microsoft named System.Core just Core.dll (System.Core) , then you had Core.dll (MyCompany.Core) ....you imagine how that gets hairy fast. 想象一下,如果微软将System.Core命名为Core.dll (System.Core) ,那么你就拥有了Core.dll (MyCompany.Core) ....你可以想象它是如何变得毛茸茸的。

我更喜欢MyCompany.ApplicationName.Core.DLL,如果MyCompany有两个或更多应用程序,这可以消除冲突的可能性。

I would name the assembly the same as the root namespace. 我将程序集命名为根命名空间。 This makes it easy to figure out what code is in which assembly, and prevents collisions with other projects (from other companies) that might also be using the ambiguious name "Core.dll". 这样可以很容易地找出哪个代码在哪个程序集中,并防止与可能也使用含糊名称“Core.dll”的其他项目(来自其他公司)发生冲突。

if developing in a enterprise environment, this convention may be useful: 如果在企业环境中开发,这个约定可能有用:

Namespaces follow the [DomainEntityName].[AssemblyName].[Purpose].[RelatedPurpose] format where the DomainEntityName is the root business functionality name and the AssemblyName is the functionally that is supporting the Business requirement. 命名空间遵循[DomainEntityName]。[AssemblyName]。[目的]。[RelatedPurpose]格式,其中DomainEntityName是根业务功能名称,而AssemblyName在功能上支持业务需求。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM