Search code examples
c#enumsdata-access-layer

Accessing enum in data access layer


Is there any way to use/access an enum contained in a data access layer project without referencing the actual project (in order to try and keep certain things separate)?

For example I have one project say UI that references a project say MIDDLEMAN and another project say DAL. If my UI has a reference to MIDDLEMAN who in turn has a reference to DAL where the enum is contained, can I access the enum from UI?


Solution

  • You basically have two options:

    The first is to create a separate project that both the other layers can access and use the enum from. If you do this, make sure to keep that project as simple as possible. What I mean is be careful not to add logic there that is related directly to either of the other projects, and that will create unwanted dependencies.

    Your other option is to create a similar enum in your MiddleMan layer, and map from the enum in the DAL layer to this new enum. Since your UI can reference the MiddleMan, it should be able to use this new enum, while still keeping the lower level enum out of reach. Any changes to the lower level enum will then have to be adjusted for in the mapping logic.