Castle Windsor Tips – specifying IEnumerable in config file

Presently sponsored by Serverless Guru: Your guide to cloud excellence, helping you every step of your serverless journey, including team training, pattern development, mass service migrations, architecting, and developing new solutions. Speak to a Guru today.
One of the more obscure things I have had to do inside a Castle config is to specify an IEnumerable<T> instance which required taking the technique I showed in this post a little further:
<component id="MyTypes"
           service="System.Collections.Generic.IEnumerable`1[[Type, Assembly]], mscorlib"
           type="System.Collections.Generic.List`1[[Type, Assembly]], mscorlib"
           lifestyle="singleton">
    <parameters>
        <collection>
            <array>
                <item>${Item1}</item>
                <item>${Item2}</item>
            </array>
        </collection>
    </parameters>
</component>

I specified the lifestyle of this IEnumerable<T> to be singleton as in most cases where you would want to do something like this is to be able to configure something once and use it everywhere, but you should change it to suit your needs.

1 thought on “Castle Windsor Tips – specifying IEnumerable<T> in config file”

Leave a Comment

Your email address will not be published. Required fields are marked *