Castle Windsor Tips – specifying generic types in config file

Yan Cui

I help clients go faster for less using serverless technologies.

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.
  2. Consulting: If you want to improve feature velocity, reduce costs, and make your systems more scalable, secure, and resilient, then let’s work together and make it happen.
  3. Join my FREE Community on Skool, where you can ask for help, share your success stories and hang out with me and other like-minded people without all the negativity from social media.

 

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 *