If you have an inter­face like this:

IDal<T>

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 (‘)!

Ref­er­ences:

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

Share

2 Responses to “Castle Windsor Tips — specifying generic types in config file”

  1. nice post. thanks.

  2. […] to spec­ify an IEnumerable<T> instance which required tak­ing the tech­nique I showed in this post a little […]

Leave a Reply