Inject App Settings using Windsor

Posted by Damian Powell on Stack Overflow See other posts from Stack Overflow or by Damian Powell
Published on 2008-10-28T21:28:48Z Indexed on 2010/04/17 17:23 UTC
Read the original article Hit count: 272

Filed under:
|

How can I inject the value of an appSettings entry (from app.config or web.config) into a service using the Windsor container? If I wanted to inject the value of a Windsor property into a service, I would do something like this:

<properties>
    <importantIntegerProperty>666</importantIntegerProperty>
</properties>
<component
    id="myComponent"
    service="MyApp.IService, MyApp"
    type="MyApp.Service, MyApp"
    >
    <parameters>
        <importantInteger>#{importantIntegerProperty}</importantInteger>
    </parameters>
</component>

However, what I'd really like to do is take the value represented by #{importantIntegerProperty} from an app settings variable which might be defined like this:

<appSettings>
    <add key="importantInteger" value="666"/>
</appSettings>

EDIT: To clarify; I realise that this is not natively possible with Windsor and the David Hayden article that sliderhouserules refers to is actually about his own (David Hayden's) IoC container, not Windsor.

I'm surely not the first person to have this problem so what I'd like to know is how have other people solved this issue?

© Stack Overflow or respective owner

Related posts about castle-windsor

Related posts about appsettings