Which layer should i declare enums?

I would share my opinions regarding this concern:

  • Strategy 1: Domain layer defines an enum AddressType (having Home, Work...). Service layer defines another enum AddressTypeDto with all values Home, Work...) and they actually map from AddressType ==> AddressTypeDto. On presentation layer, the type AddressTypeDto will be used also.

  • Strategy 2: Create a layer (not really a layer) which contains common enum types and use it in different layers from Domain/Service/Presentation

The S1: it keeps all layers Domain/Service/Presentation independent but requires more classes to present the same thing.

The S2: it keeps all layers Domain/Service/Presentation independent but requires them depending on "common" dll.

I saw applications that implement one of the two strategies. I will choose the Strategy 2 as it's more efficient. Almost applications often have common things, some enum types should be there.


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 that needs to be used only in some specific layer, then declare it in that layer. If you want to use it in all the layers then it should be declared in some common layer and a reference should be added to all the layers that are using it.