Castle Windsor Tips – specifying generic types in config file

If you have an interface like this:

IDal<T>

with a concrete class like this, which you want to wire up with Castle:

Dal : IDal<IEntity>

Then here’s the syntax to specify the component in your Castle Windsor configuration file

<component id="myDal"
           service="Namespace.IDal`1&#91;&#91;Namespace.IEntity, Assembly&#93;&#93;, Assembly"
           type="Namespace.Dal, Assembly"/>

Similarly, imagine if you have more than one generic type parameter:

IRetrievable<T, idT>
FooRetriever : IRetrievable<Foo, string>
<component id="FooRetriever"
           service="Namespace.IRetrievable`2&#91;&#91;Namespace.Foo, Assembly&#93;,&#91;System.String&#93;&#93;, Assembly"
           type="Namespace.FooRetriever, Assembly"/>

Remember, you need to use the back tick (`), NOT apostrophes (‘)!

References:

StackOverflow question on the syntax to declare generic types in castle config

StackOverflow question on declaring more than one parameter type in castle config