Spring.Net \ DI \ How to read system environment variable
-
15-07-2021 - |
Domanda
In my dependency injection configuration file - I don't know (and can't find an example) on how to set into a member some predefined environment variable file.
Can't tell how to do it in Spring.Net - your help will be appreciated.
Soluzione
Take a look to the VariablePlaceholderConfigurer
object. It should do the job:
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>
Altri suggerimenti
Use an EnvironmentVariableSource
, the current docs are somewhat lacking at the moment: http://springframework.net/docs/1.3.2/reference/html/objects.html#objects-variablesource. I've written some additional docs, they'll probably be included in the next 2.0 release of the build. In the meantime you can also check this example code on Github https://github.com/serra/spring-net-examples/tree/master/Spring.IoCQuickStart.VariableSources.