In an MVC project structure, where should enums go?

.net domain-driven-design entity-framework enums


I'm using the Code-First method with.NET MVC 3. There is a thing in my domain calledQuestion this organization has aScore real estate that isByte and I'd want to switch out that property for anEnum and what is thisEnum to Score where I may enter numbers between 0 and 10.

Where in that building should Enums reside? In my Model folder's Enums folder?


My project structure is included in the folder Models.

enter image description here

8/9/2011 6:20:20 PM

Accepted Answer

You seem to possess a valuable thing. It actually depends on your folder layout, but I'd put it where you'd put other value objects in your domain. Definitely in the Model folder, however it depends on how you're doing it if you're subdividing the Model folder. Do you have a subfolder for Q&A? Perhaps it appears there after the questions. Or do you have a subdirectory for Value Objects? maybe there.

8/9/2011 6:12:23 PM

Popular Answer

The namespace of your enums is what you should truly be worried about.

Your code will depend on the namespaces regardless of where your class file is located in the solution. I believe you would likely prefer a namespace like:Questiona2011.Enums . The Enum classes shouldn't be connected to theModels Although it is possible, there are situations when the views may need to communicate with your enums. Therefore, I usually give my enums their own namespace.

The main consideration is the namespace, therefore you don't absolutely need to create a subdirectory for the class file; you may keep it in the root directory if you like.

Therefore, build a class with the following namespace:

using System;

namespace Questiona2011.Enums
    public enum Score
        One = 1,
        Two = 2,
        Ten = 10

After that, I would only place the class file in the Models folder.:)

Related Questions


Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow