开发者

Understanding configuration files in multiproject (interoperable) .NET solutions

开发者 https://www.devze.com 2023-03-13 06:40 出处:网络
Scenario Consider having a solutions with 4 projects in it: 1) ProjectSql: This is a project, whose compilation output is set to Library, and this is responsible of accessing a SqlServer database an

Scenario

Consider having a solutions with 4 projects in it:

1) ProjectSql: This is a project, whose compilation output is set to Library, and this is responsible of accessing a SqlServer database and do something. The final library will be able to provide APIs in order to manage persistency for the final application.

2) ProjectWCF: This is a project, whose compilation output is set to Library, and this is responsible for defining service contracts, data contracts and service implementations to let my application host a service.

3) ProjectMiscellaneous: This is a project, whose compilation output is set to Library, and this is responsibe to provide APIs for other things.

4) ProjectApp: This is a project, whose compilation output is set to Executable (Exe), and this is responsible for creating the business logic of my application. Suppose this to be a simple Console application. This projects has references to all the other ones.

Assumption: Consider that every project has its o开发者_运维问答wn configuration file. ProjectSql, for example, defines connection strings to connect to a database and so on...

Problem: Configuration

Well, my problem is the following: consider that my application project ProjectApp uses ProjectSql, well, every call to a operation in ProjectSql needs to connect to database, in these calls the ProjectSql configuration file is referenced to get connection strings (a simple call to System.Configuration.ConfigurationManager....).

I think that if my ProjectApp, with its own configuration file, makes a call to an operation in ProjectSql, then, that operation will reference to its own configuration file.

My question is:

What I said, is it true???

Do configuration files respect the project hierarchy.


System.Configuration.ConfigurationManager can be told which config file to read. Any given app will normally have one config like appname.exe.config or web.config.

So the answer to you question is NO.

When you call System.Configuration.ConfigurationManager for any of the class libraries, it is the ProjectApp.exe.config file that is read.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号