Where to place Settings classes that are populated with appsettings.json in a N-layer achitechture?

Hello, I'm creating a N-layer architechture REST api, and I want to create some classes that will store appsettings.json data, but in the N-layer architechture I don't know the best place to add them, as they will need to be accessible to all the layers. Should I create a new class library to store these kind of classes? The project structure looks like this in the image. Thank you so much in advance 🙏
13 Replies
chef drone builder
Why are you putting everything into different projects?
Eduardo Bagarrão
Thank you so much for the answer 👍 The idea is to create a layered architechture(I'm still learning this). Should I put everything in only three projects(Presentation, Business and Infraestructure) and folders inside then? But about the Settings, in which layer they should be added?
Mayor McCheese
Mayor McCheese15mo ago
Oh my Are those logical layers or a true ntier architecture
Eduardo Bagarrão
Hi, thank you for your time 👍 I don't understand what you're saying by logical layers, but it's a ntier architechture
Mayor McCheese
Mayor McCheese15mo ago
So you have an application tier, a presentation tier, a database tier, etc; but with physical separation
Eduardo Bagarrão
Oh okay, thank you! Yeah, I have physical separation, however I would like to know the best place to store Settings classes that I want to populate with appsettings settings. I'm currently adding them to the Model project(separated it from infraestructure layer)
Mayor McCheese
Mayor McCheese15mo ago
That will keep things simple but everything knows about everything else
Eduardo Bagarrão
In that case I only need it(for now) on the Audit layer, but I'll need it at least on the Infraestructure too. But it's bad practice to place Settings folder in more than one project right?
Mayor McCheese
Mayor McCheese15mo ago
You're treating models as primitives; which means they're going to be everywhere because they're primitive So if you have true physical separation how will you cross the barrier between web and application server? Http? Wcfcore? A service bus? Some custom tcp work? So ideally you have least privilege So only layers know the bare minimum
Eduardo Bagarrão
In this case I will use http Do you mean that I should separate them by different layers?
Mayor McCheese
Mayor McCheese15mo ago
Well if they're physical separations, each part is it's own isolated island; so settings won't cross boundaries; do each application needs it's own settings I wouldn't try to reuse settings in such a scenario Settings should be least privilege and least surprise
Eduardo Bagarrão
Okay, I'll do that way then! You're right, I only need settings classes on the own project! Thank you so much for the help once again 👍
Accord
Accord15mo ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.