This isn't a bug, it's by design.

I think you're confusing what Named() does.  It's not used to specify
which property to inject...rather, it doesn't have anything to do with
the dependency itself.  It is only for Windsor internally to
differentiate between different components.  Windsor uses the 1st
registration as default, which is why your class got injected with
"string1", which was registered first.

To specify dependency overrides, take a look
at .DependsOn, .ServiceOverrides, and .DynamicParameters

Hope that helps!

On Apr 21, 5:35 am, Konstantin <[email protected]> wrote:
> When I have a class with public property, and several components of
> property type are registered. I expected that castle to  push the
> component with name matching the property name if exists.
>
> here is code illustrating that it is not so but at the same moment
> DependencyKey of prop dependency is set to property name.
>
> Looks quite strange , may be a bug...
>
>   public class ClassWithProperty
>     {
>         public IComparable Value { get; set; }
>     }
>
>   [Test]
>         public void PropertyInjectionTest()
>         {
>             WindsorContainer c=new WindsorContainer();
>             c.Register(
>                 Component.For<ClassWithProperty>(),
>                 Component.For<IComparable>().Instance("string1"),
>
> Component.For<IComparable>().Instance("string2").Named("Value")
>                 );
>             ComponentModel model = c.Kernel.GraphNodes.Where(n => (n
> as ComponentModel).Implementation ==
> typeof(ClassWithProperty)).First() as ComponentModel;
>             var prop = typeof (ClassWithProperty).GetProperty("Value",
> BindingFlags.Public | BindingFlags.Instance);
>             PropertySet propSet =
> model.Properties.FindByPropertyInfo(prop);
>             Assert.AreEqual("Value",
> propSet.Dependency.DependencyKey,"Dependency key was not set");
>
>             var instance = c.Resolve<ClassWithProperty>();
>             Assert.AreEqual("string2", instance.Value, "wrong value
> was injected");
>
>         }
>
> --
> 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 
> athttp://groups.google.com/group/castle-project-users?hl=en.

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