Castle Windsor Tips – specifying generic types in config file

Yan Cui

I help clients go faster for less using serverless technologies.

This article is brought to you by

MongoDB 8.0 is here to change the game. Faster reads and inserts, and brand-new vector search to support modern AI-powered apps.

Learn More

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

Whenever you’re ready, here are 3 ways I can help you:

  1. Production-Ready Serverless: Join 20+ AWS Heroes & Community Builders and 1000+ other students in levelling up your serverless game. This is your one-stop shop for quickly levelling up your serverless skills.
  2. I help clients launch product ideas, improve their development processes and upskill their teams. If you’d like to work together, then let’s get in touch.
  3. Join my community on Discord, ask questions, and join the discussion on all things AWS and Serverless.

2 thoughts on “Castle Windsor Tips – specifying generic types in config file”

  1. Pingback: Castle Windsor Tips — specifying IEnumerable in config file | theburningmonk.com

Leave a Comment

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