其中WCF配置的做法是聪明吗? [英] Which WCF configuration approach is smarter?
问题描述
即时阅读有关WCF两本书,其中一人是显示的配置为 App.Config中
,另一种是通过展示代码在C#
Im reading 2 books about WCf and one of them is showing Configuration as App.Config
and the other is showing via Code in C#
我想知道我应该使用哪种方法,什么是对方的利益。
做出WCF配置向导还支持背后配置的C#代码?
I want to know which approach should i use and what are the benefits for each other. Does the Wcf Configuration Wizard supports also the c# code behind configuration ?
感谢您的答案
推荐答案
我想这取决于你的需求。我个人倾向于用代码配置WCF,特别是对的事情,不可能永远不变。这可能包括错误处理/记录器,行为,认证模块,服务主机工厂等
I guess it depends on your needs. I personally tend to configure wcf with code, especially for things that are unlikely to ever change. That might include error handlers/logger, behaviors, authentication modules, service host factories, etc
有关更动态的东西,就像连接字符串,密码,文件路径等配置在.config文件。
For more dynamic stuff, like connection strings, passwords, file paths, etc are configured in .config files.
一个使用代码的最大好处是你的代码就可以支持诸如IOC /依赖注入,编译时检查等。
One of the biggest advantages of using code is that your code now can support things like IOC/Dependency injection, compile time checking, etc.
我不买的想法,一切都应该在配置文件中,因为它更容易去改变它。在大多数情况下,我已经看到了它从来没有在生产中发生变化。
I don't buy into the idea that everything should be in a config file because it's easier to change it. In most cases I've seen it never changes in production.
这篇关于其中WCF配置的做法是聪明吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!