创建连接文件的最佳实践
我有一个应用程序,其中有一些缓存、队列和数据库的配置文件。
public class ServerConfiguration: ConfigurationSection
{
[ ConfigurationProperty( FOO, DefaultValue = "", IsRequired = false ) ]
public string FOO
{
get { return (string)this[FOO]; }
set { this[FOO] = value; }
}
}
这就是我对配置文件所做的事情,并且我还有一些继承层次结构。
您使用什么来处理配置?为此目的有哪些最佳实践?
I have an application which i have some configuration files for cache, queue, and database.
public class ServerConfiguration: ConfigurationSection
{
[ ConfigurationProperty( FOO, DefaultValue = "", IsRequired = false ) ]
public string FOO
{
get { return (string)this[FOO]; }
set { this[FOO] = value; }
}
}
this is what i do for config files and I also have some inheritance hierarchy.
What do you use to handle configurations and what are some best practices for this purpose?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我喜欢并广泛使用 Microsoft 配置库,但我尝试确保我的应用程序不依赖于它。这通常涉及让我的配置部分实现一个接口,因此您的示例如下所示:
现在,无论您在代码中使用您的配置,您只需要担心 IServerConfiguration 并且可以更改您的实现,而无需更改用法。有时,我只是在开发过程中从硬编码的类开始,只有当我实际上需要在不同的环境中具有不同的值时才将其更改为配置部分。
如果您使用配置部分,您还依赖于 ConfigurationManager。我通过使用 IConfigurationProvider[T] 从我的代码中隐藏了这一点,其中 T 是 IServerConfiguration,您可以在我的博客上的配置忽略下看到此示例。
http://bronumski.blogspot.com/search/label/Configuration
I love and use the Microsoft configuration library extensively but I try to make sure that my applications are not dependent on it. This usually involves having my configuration section implement an interface, so your example would look like:
Now where ever you use your configuration in your code you only need to worry about IServerConfiguration and you can change your implementation without having to change the usages. Sometimes I just start of with a hard coded class during development and only change it to a configuration section when I actually need to have different values in different environments.
If you are using a configuration section you are also dependent on the ConfigurationManager. I have hidden this from my code by using an IConfigurationProvider[T] where T would be IServerConfiguration, you can see an example of this on my blog under configuration ignorance.
http://bronumski.blogspot.com/search/label/Configuration