使用 Spring.NET 配置文件中的设置的更好方法?
在 Spring.NET 配置文件中使用设置(由 Visial Stidio 设置编辑器生成)是否有比使用 PropertyRetreeringFactoryObject: 更好的方法
<object id="myUri" type="Spring.Objects.Factory.Config.PropertyRetrievingFactoryObject, Spring.Core">
<property name="TargetObject">
<object type="Properties.Settings, MyAssembly">
</object>
</property>
<property name="TargetProperty" value="Default.MyUri" />
</object>
<object name="..." type="...">
<property name="Uri">
<ref object="myUri" />
</property>
</object>
?
对每个设置都这样做感觉不太合适......
Is there a better way for using settings (generated by Visial Stidio Settings editor) in Spring.NET configuration file than using PropertyRetrievingFactoryObject:
<object id="myUri" type="Spring.Objects.Factory.Config.PropertyRetrievingFactoryObject, Spring.Core">
<property name="TargetObject">
<object type="Properties.Settings, MyAssembly">
</object>
</property>
<property name="TargetProperty" value="Default.MyUri" />
</object>
<object name="..." type="...">
<property name="Uri">
<ref object="myUri" />
</property>
</object>
?
It does not feel right to do this for every setting...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先,为什么不直接将 url 放入 Spring.NET 配置文件中?
有多种方法来配置应用程序可能会有点混乱。
如果此文件是由于您添加了 Web 引用而由 Visual Studio 生成的,则应将 Web 引用的“Url Behaviour”属性从“动态”更改为“静态”。
然后你可以删除App.config/Web.config中VS生成的所有内容、设置文件和配置代码。
要配置代理,只需将其添加到容器中并使用 DI 注入 Url 属性即可。
无论如何,您可以使用 Spring Expression 语言实现您想要做的事情:
另一个解决方案是将 VariablePlaceholderConfigurer 组件与 IVariableSource 接口结合使用:
http://www.springframework.net/doc- latest/reference/html/objects.html#objects-variablesource
MyCustomImplementationVariableSource 是 IVariableSource 的实现,它将从您想要的位置(例如从您的 Settings 类)解析变量。
First, why not just put the url in the Spring.NET configuration file ?
Having multiple ways to configure your application can be a bit confused.
If this file have been generated by Visual Studio because you added a Web Reference, you should change the 'Url Behavior' property of your Web references from 'Dynamic' to 'Static'.
then you can remove all the stuffs VS generates, the settings files and the configuration code in the App.config/Web.config.
To configure your proxy, just add it to the container and use DI to inject the Url property.
Anyway, you can achieve what you wanted to do with the Spring Expression language :
Another solution is to use the VariablePlaceholderConfigurer component with the IVariableSource interface :
http://www.springframework.net/doc-latest/reference/html/objects.html#objects-variablesource
MyCustomImplementationVariableSource is an implementation of the IVariableSource that will resolve variables from where you want (for example from your Settings class).