Level transfers

I would like to use the same enumeration on the three levels of my application (presentation -> bal -> dal). I defined an enumeration in the data layer, and I want to use the same enumeration in the presentation layer (the presentation layer does not have a link to the data layer). Using someone else's answer , I think this is a similar question, I built the following enumeration in the business layer:

namespace bal { public enum TransactionCode { Accepted = dal.TransactionCode.Accepted, AcceptedWithErrors = dal.TransactionCode.AcceptedWithErrors, InvalidVendorCredentials = dal.TransactionCode.InvalidVendorCredentials, BrokerOffline = dal.TransactionCode.BrokerOffline } } 

Is this a suitable way to create level transitions?

+4
source share
5 answers

One approach is to have one “layer” (well, actually, not such a layer as such), which is common to all layers.

I wrote about this a while ago (on a blog / project that is currently inactive, unfortunately). It may seem “unclean,” but it makes life a lot easier in many ways and reduces duplication. Of course, this also reduces flexibility - if you ever want the enumeration of a view different from the enumeration of a data layer, you will have to reorganize ...

+5
source

In these cases, I usually split my "data types" into my small assembly. Then refer to this assembly wherever you need it.

+2
source

Your listing is actually part of the API. When you think of layered software, it is often difficult to think of common types, but most of the time the set of types is always layered. Instead of just thinking about the standard layer:

 Presentation -> Business -> Data 

Think of it this way:

 Presentation -> API |-> Business ----^ |-> Data ----^ 

Where the API is a general aspect of your system. The API contains any common data types, entities, enumerations, service interfaces, etc. The API can be isolated in its own library and reused in its presentation, as well as being a gateway to your domain (which is business logic and data).

+2
source

If it were me, I would create another project with such things in it and have all the links to the projects.

+1
source

It really depends on how your interactions continue. Translating dal.TransactionCode to bal.TransactionCode will most likely not work in any operation where you are trying to establish equality.

If you really go through everything and NEEDS in all layers, I would either define it at the bal level, or refer to dal from the user interface.

0
source

All Articles