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"]);
}
}
--
You received this message because you are subscribed to the Google Groups
"Castle Project Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/castle-project-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.