Hi Huseyin, Maybe you can't because IChild[] is not a collection, try the ArrayResolver:
http://docs.castleproject.org/%28S%28bcwix455ivqyod45twfzyj45%29%29/Windsor.Resolvers.ashx 2011/4/27 Huseyin Tufekcilerli <[email protected]> > Cross-posted with > http://stackoverflow.com/questions/5801397/resolving-parent-child-with-castle-windsor > > I am not sure calling this parent/child but here you go, I have a similar > case like this: > > namespace ConsoleApplication1 > { > using System.Diagnostics; > using System.Linq; > using Castle.MicroKernel.Registration; > using Castle.MicroKernel.Resolvers.SpecializedResolvers; > using Castle.Windsor; > > class Program > { > static void Main(string[] args) > { > var container = new WindsorContainer(); > > container.Kernel.Resolver.AddSubResolver(new > CollectionResolver(container.Kernel)); > > container.Register( > Component.For<Parent>().LifeStyle.Singleton, > > Component.For<IChild>().ImplementedBy<Child1>().LifeStyle.Singleton); > > var p = container.Resolve<Parent>(); > > // Fails... > Debug.Assert(p.Children.First().Parent == p, "Parent should be > resolved"); > } > } > > class Parent > { > public IChild[] Children { get; set; } > } > > interface IChild > { > Parent Parent { get; set; } > } > > class Child1 : IChild > { > public Parent Parent { get; set; } > } > } > > I have CollectionResolver added to the container. Both Parent and Child1 > (with IChild service) are registered as singletons in the container. > Whenever I try to resolve the Parent instance, I got my Children array > populated but the Child1 instance in that array has a Parent of null. What I > am expecting is the Parent property of the Child1 to be set to the Parent > instance I am trying to resolve at that moment. I can understand that Parent > is not fully activated yet, but since its ctor is run, can't Windsor inject > this property yet? Are there any way to make this work or should I manually > run some code to set Parents of child objects (which is far from ideal)? > > Thanks in advance! > > -- > 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. > -- R|<4r|)0 -- 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.
