了解多项目(可互操作).NET 解决方案中的配置文件
场景
考虑有一个包含 4 个项目的解决方案:
1) ProjectSql:这是一个项目,其编译输出设置为 Library
,负责访问 SqlServer 数据库并执行某些操作。最终的库将能够提供 API 来管理最终应用程序的持久性。
2)ProjectWCF:这是一个项目,其编译输出设置为Library
,负责定义服务契约、数据契约和服务实现,让我的应用程序托管服务。
3)ProjectMiscellaneous:这是一个项目,其编译输出设置为Library
,负责为其他事物提供API。
4) ProjectApp:这是一个项目,其编译输出设置为Executable (Exe)
,它负责创建我的应用程序的业务逻辑。假设这是一个简单的控制台应用程序。该项目引用了所有其他项目。
假设:考虑每个项目都有自己的配置文件。例如,ProjectSql 定义了连接数据库的连接字符串等等...
问题:配置
好吧,我的问题如下:考虑到我的应用程序项目 ProjectApp 使用 ProjectSql,好吧,每次调用 ProjectSql 中的操作都需要连接到数据库,在这些调用中引用 ProjectSql 配置文件来获取连接字符串(对 System.Configuration.ConfigurationManager.... 的简单调用)。
我认为,如果我的 ProjectApp 具有自己的配置文件,调用 ProjectSql 中的操作,那么该操作将引用其自己的配置文件。
我的问题是:
我说的是真的吗???
配置文件是否尊重项目层次结构。
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 own 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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
System.Configuration.ConfigurationManager 可以被告知要读取哪个配置文件。任何给定的应用程序通常都有一个配置,例如 appname.exe.config 或 web.config。
所以你的问题的答案是否定的。
当您为任何类库调用 System.Configuration.ConfigurationManager 时,读取的是 ProjectApp.exe.config 文件。
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.