我应该如何组织我的 C# 解决方案?
我的 C# 4 解决方案中有三个项目。
- MooDB: 在 NHibernate 映射、表示类中包含我的域对象。
- 数据:有我的数据访问层类(使用NHibernate)
- 测试:有我的测试类
这是一个屏幕截图:
我注意到我的 app.config
和 hibernate.cfg.xml
>测试项目。这看起来确实是对的。我的 Data
项目中没有 app.config
,这是一个问题,因为我想在我的 Data 中使用
项目,但如果那里没有 log4net
app.config
我无法配置它。
设置解决方案的最佳方式是什么?每个项目或整个解决方案都应该有一个 app.config
吗?我的测试
项目需要一个吗?我是否按照“最佳实践”组织它?
I have three projects in my C# 4 solution.
- MooDB: Has my domain objects in, NHibernate mappings, presentation classes.
- Data: Has my data access layer classes (using NHibernate)
- Test: Has my test classes
Here's a screenshot:
I've noticed that I've got app.config
and hibernate.cfg.xml
in my Test
project. This does seem right. I don't have an app.config
in my Data
project which is a problem because I want to use log4net
in my Data
project but I can't configure it if there's no app.config
there.
What's the best way to set up my solution? Should there be an app.config
for each project or for the solution as a whole? Do I need one for my Test
project? Have I organized it according to "best practise"?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我通常会在最高层看到配置文件;通常是 UI 或测试。
这是有道理的(至少对我来说),因为应用程序将数据层定向到应该从中获取数据的存储库。您的测试层可能会去往与生产应用程序不同的地方;因此,在数据项目中进行配置对我来说没有多大意义......它是“配置”底层的顶层。
I usually see config files at the highest layer; which is usually the UI or Test.
This makes sense (to me at least), because the application is directing the data layer to which repository it should be fetching the data from. Your test layer is probably going to go to a different place than your production application; so having config in the Data project wouldn't make much sense to me... it's the top layer that's "configuring" the bottom layers.
如果您想要在一个地方进行配置更改,您可以在主项目中配置文件并使用 构建后事件,将生成的输出文件复制到其他可执行项目的 bin 文件夹中。
您需要考虑在主应用程序中使用的配置是否与您想要在单元测试中使用的配置相同。如果没有,那么单独的配置文件绝对没问题。
If you want a single place to make config changes, you can config files in your main project and use post-build events to copy the resulting output files to the bin folders of your other executable projects.
You need to consider whether the configuration that you use in your main application is the same as the one you want to use in your unit tests though. If not, then separate config files are absolutely ok.