Collection of dependencies in castle windsor
Posted
by jonnii
on Stack Overflow
See other posts from Stack Overflow
or by jonnii
Published on 2010-06-16T18:19:15Z
Indexed on
2010/06/16
18:22 UTC
Read the original article
Hit count: 246
c#
|castle-windsor
I have the following scenario:
public class FirstChildService : IChildService { }
public class SecondChildService : IChildService { }
public class MyService : IService {
public MyService(IEnumerable<IChildService> childServices){ ... }
}
I'm currently registering all the child services and explicitly depending on them in the constructor of MyService
, but what I'd like to do is have them all injected as part of a collection.
I can think of a few ways to do this:
- Using a facility
- Using a component property
- Registering the collection as a service
But all of them feel a bit... icky. What's the best way to manage this? Also, ideally I'd like to do this using the fluent API and constructor injection. I know it's possible to do something similar using properties:
http://www.castleproject.org/container/documentation/trunk/usersguide/arrayslistsanddicts.html
© Stack Overflow or respective owner