Click here to Skip to main content
15,868,016 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi Guys,

This may be a silly question, but I've been trying to improve my knowledge on Dependency Injection and am re-working an existing (fairly simple) project to utilise my new knowledge.

However, I have the following question and I'm not certain what the correct approach is.

I have an couple of common Enums, (FileTypeEnum, SurveyTypeEnum) they are static and cannot change due to the design requirements and legal requirements of the project.

They need to be accessed in the UI, the Domain logic and the Data Access Layer.

So my thought is to create a separate class library project called Common and put them in there, but how can can I do that without creating a hard dependency to it within each of the other modules? Or does that hard dependency not matter?

Hope you can enlighten me.

Regards
Posted
Comments
Nathan Minier 15-Jan-15 7:22am    
DI does not implicitly mean that static elements, like consts and enums, are not acceptable. To me, it's important to look at the purpose of the technology or, in this case, the design philosophy.

DI exists to make changing parts out easier as required. We avoid hard-coded dependencies because that makes it more difficult to modify a dependency without breaking the objects that use it. That being said, based on your needs, there is no compelling reason to wrap your enums in a dependency to hand out in your application; they simply are what they are.

And generally I do toss my constants and enums into a Common library. You can't think of references as "dependencies" in most IoC paradigms (although I suppose I can see how that would make a certain sense) or you will actually start losing out on modularity.
Pheonyx 15-Jan-15 7:55am    
Ahh, thank you!

I thought I was getting things a bit muddled as it didn't make sense in my head.
Knowing where to draw the line, even with classes is the area of all of this that I'm struggling with. I'm pleased to read that having a common library of things like enums is not deemed an horrific error.
gggustafson 16-Jan-15 10:12am    
This should be the answer.
Nathan Minier 16-Jan-15 10:17am    
I'm not sure, as an answer should really be objective. This particular topic is one that is largely debated, and each argument does have merits.

This is my opinion, hence the comment :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900