I've solved it in a bit different way - I'm using the NonOptional
Attribute to marke properties that are mandatory dependencies so i've
added the following code to NonOptionalInspector

                    propSet.Dependency.IsOptional = false;
                    propSet.Dependency.DependencyType =
DependencyType.ServiceOverride;

and it did the thing.




On Apr 23, 9:36 am, Krzysztof Koźmic <[email protected]>
wrote:
> Alternatively if you do want that behavior, there's nothing stopping you
> from having it :)
>
> Take a look at this 
> post:http://kozmic.pl/archive/0001/01/01/convention-based-dependency-injec...
>
> On 2010-04-23 05:50, bling wrote:
>
>
>
>
>
> > 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 
> 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