Component installer question

10 views
Skip to first unread message

Scott_M

unread,
Apr 23, 2013, 10:43:27 PM4/23/13
to castle-pro...@googlegroups.com
I have a keyed dictionary component dependency similar to the following (from http://stackoverflow.com/questions/890287/windsor-castle-inject-dictionary-of-interfaces-via-configuration).  Currently using XML component registration but want to switch to a custom installer.  How do you represent the IDictionary<string, IService> component dependency in a windsor installer?
namespace WindsorTests {
    public interface IService {}    
    public class Service1 : IService {}    
    public class Service2 : IService {}    
    public class Consumer {
        private readonly IDictionary<string, IService> services;    
        public IDictionary<string, IService> Services {
            get { return services; }
        }    
        public Consumer(IDictionary<string, IService> services) {
            this.services = services;
        }
    }    

    [TestFixture]
    public class WindsorTests {    
        [Test]
        public void DictTest() {
            var container = new WindsorContainer(new XmlInterpreter(new StaticContentResource(@"<castle>
<components>
    <component id=""service1"" service=""WindsorTests.IService, MyAssembly"" type=""WindsorTests.Service1, MyAssembly""/>
    <component id=""service2"" service=""WindsorTests.IService, MyAssembly"" type=""WindsorTests.Service2, MyAssembly""/>
    <component id=""consumer"" type=""WindsorTests.Consumer, MyAssembly"">
        <parameters>
            <services>
                <dictionary>
                    <entry key=""one"">${service1}</entry>
                    <entry key=""two"">${service2}</entry>
                </dictionary>
            </services>
        </parameters>
    </component>
</components>
</castle>")));
            var consumer = container.Resolve<Consumer>();
            Assert.AreEqual(2, consumer.Services.Count);
            Assert.IsInstanceOfType(typeof(Service1), consumer.Services["one"]);
            Assert.IsInstanceOfType(typeof(Service2), consumer.Services["two"]);
        }
    }
Reply all
Reply to author
Forward
0 new messages