Spring.Net \ DI \如何读取系统环境变量

时间:2012-10-29 15:42:06

标签: c# dependency-injection environment-variables spring.net

在我的依赖注入配置文件中 - 我不知道(并且找不到示例)如何将成员设置为某个预定义的环境变量文件。

无法告诉如何在Spring.Net中执行此操作 - 我们将非常感谢您的帮助。

2 个答案:

答案 0 :(得分:3)

使用EnvironmentVariableSource,目前的文档有点缺乏:http://springframework.net/docs/1.3.2/reference/html/objects.html#objects-variablesource。我已经写了一些额外的文档,它们可能会被包含在构建的下一个2.0版本中。在此期间,您还可以在Github https://github.com/serra/spring-net-examples/tree/master/Spring.IoCQuickStart.VariableSources上查看此示例代码。

答案 1 :(得分:2)

查看VariablePlaceholderConfigurer对象。它应该做的工作: http://www.springframework.net/doc-latest/reference/html/objects.html#objects-variablesource

<object type="Spring.Objects.Factory.Config.VariablePlaceholderConfigurer, Spring.Core">
   <property name="VariableSources">
      <list>
         <object type="Spring.Objects.Factory.Config.EnvironmentVariableSource, Spring.Core"/>
      </list>
   </property>
</object>

<object type="MyObject">
  <property name="MyProperty" value="${MyEnvironmentVariableName}"/>
</object>
相关问题