Castle Windsor Tips — specifying generic types in config file

If you have an inter­face like this:


with a con­crete class like this, which you want to wire up with Cas­tle:

Dal : IDal<IEntity>

Then here’s the syn­tax to spec­i­fy the com­po­nent in your Cas­tle Wind­sor con­fig­u­ra­tion file

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

Sim­i­lar­ly, imag­ine if you have more than one gener­ic type para­me­ter:

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"/>

Remem­ber, you need to use the back tick (), NOT apos­tro­phes (‘)!


Stack­Over­flow ques­tion on the syn­tax to declare gener­ic types in cas­tle con­fig

Stack­Over­flow ques­tion on declar­ing more than one para­me­ter type in cas­tle con­fig