Where to place ApplicaitonSettings in a tiered mvc project?

I have a basic asp.net MVC project that has a web project, a service dll project and a Data dll project. I started to store configuration values ​​in the settings of the web project application, but I came across several examples where I need them at the service level. The only way I can think of sharing values ​​is to pass them to the service level through parameters. Is there any other way to have one configuration value available for all projects?

+4
source share
2 answers

I usually snap to the outermost layer (where it is defined in app.config or web.config), and this layer explicitly skips any values ​​needed for domain logic or infrastructure, and that should be what the lower level layers contain.

I find the concept of having configuration values ​​contained in the outer layer that are “magically” used by lower layer layers to be unintuitive and opaque.

+5
source

I know this was answered .. but .. you should never have dependencies on * .config files in service or data layers. This is an advertisement of a very tight connection. The best way is to pass them through the parameters. For example, through constructors.

Even on your site you still shouldn't, IMO. I would use Dependency Injection and inject them into the controllers if you really need them. What for? Good → unit testing. Unit tests do not require any * .config files. Thus, if your controllers are passed in data, then your code now has no dependencies -> which is surprising.

Here is an example of a controller that has no dependencies on web.config and this is how application settings records are passed to the VIA controller dependency injection.

Check this:)

+3
source

Source: https://habr.com/ru/post/1384209/


All Articles