tier application with 4 layers like:
Presentation layer (MVC4)
Business layer (C# library project)
Data Access layer (c# library project)
Model layer (c# library project that contains models, EF dbcontext, etc)
So on this application, the model layers contain the EF db context, some custom models and other stuff like it, the data access layer contains the query to ef and some direct queries to the db, Business layer contains business logic and presentation is an mvc4 project.
Business, data and model layers are library projects.
mvc4 presentation layer has references to BL and ML.
BL has references to DAL and ML.
DAL has references to ML.
So the question is: Where should I keep my string connections and my global variables? And most important is how?
Should I keep them in the web.conf of mu mvc4 application? If so, how can the ML access it?
or should it be on the ML?
Yes, Connection Strings go into the web.config
of the MVC4 application. In the Model layer you just use the 'System.Configuration.ConfigurationManger' object to retrieve the named connection string from the application's configuration.
Connection string and other configuration items, when accessed in a referenced DLL, are obtained from the configuration of the application that is running the DLL. This allows you to have different configuration for the DLL component depending on how you're using it.
For example, you'll normally have one connection string pointing to a real database in the web.config
of the MVC4 app. In order to write tests for your Model DLL, though, you can have a different connection string, pointing to a test data set, in the app.config
file of your test project. As long as the two connection strings have the same name the Model.DLL doesn't have to know or care where they come from.