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 Castle:

Dal : IDal<IEntity>

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

<component id="myDal"
           service="Namespace.IDal`1[[Namespace.IEntity, Assembly]], Assembly"
           type="Namespace.Dal, Assembly"/>

Sim­i­larly, imag­ine if you have more than one generic type parameter:

IRetrievable<T, idT>
FooRetriever : IRetrievable<Foo, string>
<component id="FooRetriever"
           service="Namespace.IRetrievable`2[[Namespace.Foo, Assembly],[System.String]], Assembly"
           type="Namespace.FooRetriever, Assembly"/>

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


Stack­Over­flow ques­tion on the syn­tax to declare generic types in cas­tle config

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