如何避免“垂直分区”中的命名空间和类名冲突组件?
我所说的“垂直分区”是指以模块而不是“层”命名的命名空间
因此,
- MyApp.Core
- MyApp.Accounting
- MyApp.OrderManagement
- MyApp.HR
而不是
- MyApp.UI
- MyApp.Business
- MyApp.Data
我正在运行的唯一问题问题在于,有时这些程序集可能具有与类型名称相同的命名空间的一部分。
假设我创建了一个与帐户相关的模块,并将其命名为 MyApp.Account.dll,基本命名空间为 MyApp.Account。不可避免地,我需要创建一个名为 Account 的类。然后我必须使用命名空间或类型别名。
除了对名称非常有创意之外,还有其他人经历过以这种方式切割程序集并处理名称冲突问题吗?
By "Vertically partitioned", I mean having namespaces named after modules rather than "layers"
So,
- MyApp.Core
- MyApp.Accounting
- MyApp.OrderManagement
- MyApp.HR
instead of,
- MyApp.UI
- MyApp.Business
- MyApp.Data
The only issue I am running into is that sometimes those assemblies might have a part of the namespace that is same as a type name.
Let's say I create an Account related module and I name it MyApp.Account.dll with the base namespace being MyApp.Account. Inevitably, I need to create a class named Account. Then I have to use namespace or type aliases.
Other than being very creative with names, has anyone else experience cutting assemblies this way and dealt with name collision issues?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
过去,我用两种方法处理这个问题:
1) 使名称空间复数或在适当的情况下将它们设为动名词(添加 -ing 后缀)。例如,
MyApp.Orders
可以安全地包含Order
类。 (同样,坚持使用“MyApp.Accounting”而不是“MyApp.Account”)。2)通过将
Domain
附加到命名空间(有点不满意,但有效)。In the past, I've dealt with this two ways:
1) Pluralizing the namespaces or making them gerunds where appropriate (adding an -ing suffix). For example,
MyApp.Orders
can safely contain anOrder
class. (Similarly, stick with "MyApp.Accounting" rather than "MyApp.Account").2) By appending
Domain
to the namespace (a bit unsatisfying, but effective).