I have a C# N-Layer Project that has 5 Layers: 1-Infrastructure 2-Domain 3-AppService 4-Distributed Service 5-Presentation
I want to use enums in my project. but I don't know which layer describe them. I have two ideas about it.
1- declare enums in Domain and pass through network by WCF DataContract.
2- declare enums in a class library project(ex: in common layer) and build it as dll and use it in all layer.
Help me to choose one.
If only your class members use the enum it is preferable to declare the enum inside the class. It is more intutive for users of the class, it helps the user to know that the enum will only be used by the class.
Enum ValuesBy default, the first item of an enum has the value 0. The second has the value 1, and so on.
Enum Values The first member of an enum will be 0, and the value of each successive enum member is increased by 1.
It depends on where you need to use the values that the enum's represent. If these are values that your presentation layer would need, then that is where they should go. If it is something that your service layer would rely on, then you need to put them in there.
I'm not to sure the best approach is to lump all of your enums into a single location. They should be spread-out across the app, at the lowest layer that relies on them, usually in the same namespace as the class that consumes the enum and performs some logic on them.
If the app and the domain will use them, then declare them in the domain and pass the value through the network.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With