1

I have some configuration settings stored in my web.config file of my front end project.

I wanted to access them in the database layer, I am able to get them using this

ConfigurationManager.AppSettings["Setting"]

But I was wondering is it a good practice to access the settings in the database layer or should I access and pass this value from my WebApi control down to the database layer?

Pawan Nogariya
  • 8,330
  • 12
  • 52
  • 105
  • The Context usually gets its connection string from the Config, however, what sort of configurable data is in your DAL anyway, also this question is too broad, subjective, opinionated and even if it wasn't, is lacking a lot of information – TheGeneral Nov 15 '18 at 08:56
  • Depends on what do you want to do with your project. Do you want to do integration testing? in that case accesing the config file would be problematic. IMHO this question is quite subjective. – Cleptus Nov 15 '18 at 09:18

1 Answers1

0

I agree this question is broad and subjective. But we could provide an answer based on programming principles that are widely accepted, like SOLID, to read up on SOLID this stack answer is very good: Can't seem to understand SOLID principles and design patterns

So if we look at the "S": A class should only have a single responsibility, so IMHO you should probably have a class on start up in your main project that pulls all the configuration settings for your project and then you can call on the class FROM ANY PROJECT to retrieve that info.

If you dont want to do that and just want to use the ConfigurationManager that is also fine, and calling it from any project is fine as that is the classes responsibility.

JohnChris
  • 1,360
  • 15
  • 29