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 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.

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)
                {
                }
        }
}

---
Patrick Steele
http://weblogs.asp.net/psteele

-- 
You received this message because you are subscribed to the Google Groups 
"Castle Project Users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/castle-project-users?hl=en.

Reply via email to