Reputation: 138
According to Microsoft guidelines
X DO NOT use the same name for a namespace and a type in that namespace.
Following that rule feels mandatory yet not that easy. To demonstrate my problem lets take an generic Account
feature. Let's say there is an Account
which is abstract base with some additional features like Inbox
and two implementations User
and Device
. Of Course each of it's underfeachures will require some models.
Account
+--- Account.cs
+--- AccountController.cs
+--- Inbox
| +--- Inbox.cs
| +--- InboxController.cs
| \--- Message.cs
+--- Device
| +--- Device.cs
| \--- DeviceController.cs
+--- User
+--- User.cs
\--- DeviceController.cs
That structure clearly has a naming conflict between namespace (folder name) and class (model name). I could easily solve first conflict by changing name of main feature Account
to something more fancy like Identity
but that still leaves two other (User
and Devices
) conflicts unsolved. Do i always need to find 'better fancy name' for each feature to avoid this problem ?
Keep in mind that i want to follow folder-by-feature
structure, so creating new folder/namespace only for models is not an option.
Upvotes: 2
Views: 891
Reputation: 2801
The guidelines are actually called "Framework Design Guidelines". They are intended to be used by people who write libraries for others to use. They are guidelines, it is not required that you follow them. They essentially make clear what a user of your code would expect, not what you have to do.
On the same page that you link to is the guideline "CONSIDER using plural namespace names where appropriate". Following that would solve most of your problems.
StyleCop has a guideline to not create namespaces with fewer than five types in them.
Your specific problem could be solved by calling the namespace accounts and placing all your classes in that. Adding new namespaces only if it adds value.
Upvotes: 1