Home > Software engineering >  How do I set common values (abstract) for a C# solution in Visual Studio with multiple sub projects?
How do I set common values (abstract) for a C# solution in Visual Studio with multiple sub projects?

Time:09-23

I have a solution with multiple projects each of which connects to the same DB and uses overlapping constant values that I would like to set somewhere instead of replicating manually. I have tried a variety of things online like making a custom class and linking projects to it, setting constants in a project config file (which doesn't exist like the guides claim), and so on. I've been unable to figure this out after more than an hour of searching and experimenting so if you have any ideas, let me know. The structure looks like this (the blue-underlined stuff are some of the projects in the list):

project listing in solution

CodePudding user response:

You can make another project under the solution to contain your class.

All the other projects can then reference that project, meaning the same functionality will be available in all the other projects without having to duplicate anything.

CodePudding user response:

I will extend the previous correct answer with some more information.

Your solution structure is something to think very carefully as it is a combination of application design/architecture and leads to extensibillity, scalability and future maintainability.

Take for example the following article Common web application architectures.

  • You can see the Clean Architecture (AKA Hexagonal) which leads to specific projects withing a solution
  • You can see older designs where the DB access would go into a project called ..DAL

Simple projects can use the second one, more business rich ones the first or something in between.

Check this this article on shared code projects to see about net standard projects

  • Related