Using Castle.Windsor 2.5.4.32 and Castle.Core 2.5.2.0.
I’ve got a component that needs a string[] in its ctor. The string[]
comes from a “settings” class. I don’t want the component dependent
on the settings class since it just needs the string[]. So I used
DynamicProperties to pull the data from the settings class, which was pulled from the container. At least,
that’s what I thought would happen. Windsor is not able to resolve my
component as it says there’s a missing dependency (the string[]).
Here’s a quick (MSTest) test case. This is the first time I’ve used
DynamicParameters so I might be doing something wrong. Any ideas?
namespace WindsorTests.DynamicParametersTest
{
using Castle.MicroKernel.Registration;
using Castle.Windsor;
using Microsoft.VisualStudio.TestTools.UnitTesting;
[TestClass]
public class DPTest
{
[TestMethod]
public void TestMethod1()
{
var container = new WindsorContainer();
container.Register(
Component.For<ISettings>().ImplementedBy<Settings>(),
Component.For<Foo>().DynamicParameters((k, p) =>
{
var settings = k.Resolve<ISettings>();
p["data"] = settings.MoreData;
})
);
var bar = container.Resolve<Foo>();
}
}
public interface ISettings
{
string[] MoreData { get; }
}
public class Settings : ISettings
{
public string[] MoreData
{
get { return new[] {"A", "B", "C"}; }
}
}
public class Foo
{
public Foo(string[] data)
{
}
}
}
Your usage is perfectly fine.
I just ran the test case on Windsor 3 and it’s passing. So I suppose that might be a bug in 2.5.x