Name collisions + space

I tried to organize my MVC project as pleasant, but had problems with naming collisions and wondered if there was a better solution than renaming things into non-logical names.

IE, there is a User class in my Application.Model.Entities namespace.

Then I have Application.Web.Areas.Admin.Models.User, the namespace in which I was going to place all my custom models. This causes a name clash, and when I try to instantiate a User object, it tells me that namespaces are not classes.

I understand why the error occurs, I'm just wondering if there is a better solution than renaming the MVC model folders. (What can I do - I can have ProgramViewModels, ProgramWhateverModels, etc., if necessary). Just curious!

+3
source share
2 answers

If you need to use both classes in the same fe namespace, you have the main class, where you must use both custom classes, you can declare something like:

using userEnt = Application.Model.Entities;
using userMod = Application.Web.Areas.Admin.Models.User;

and then just call userEnt.User and userMod.User and there will be no more conflicts.

+4
source

You can be more explicit in your instances:

Entities.User or Models.User.User instead of a simple user

+1
source

All Articles