Agreed - an exception on the value type registration would be correct behavior in this scenario. Should I open a bug in youtrack?
-r 2011/1/19 Krzysztof Koźmic <[email protected]> > That's expected behavior. > > Value types by definition are not components. I suppose Windsor should be > throwing when you try to register them in the first place... in order to > avoid confusion. > > > On 20/01/2011 9:28 AM, codekaizen wrote: > >> Castle maintainers - >> >> I've come across what appears to be a bug in DefaultKernel.ResolveAll >> when asking for instances of value types. Here's a test case: >> >> var kernel = new DefaultKernel(); >> >> kernel.Register(Component.For<String>().Named("A").Instance("A")); >> kernel.Register(Component.For<String>().Named("B").Instance("B")); >> >> // Works ok >> var stringResolution = kernel.ResolveAll<String>(); >> >> kernel.Register(Component.For<Int32>().Named("1").Instance(1)); >> kernel.Register(Component.For<Int32>().Named("2").Instance(2)); >> >> // Throws 'ArgumentException: Target array type is not compatible with >> the type of items in the collection.' >> var intResolution = kernel.ResolveAll<Int32>(); >> >> Note the ResolveAll<Int32>() throws an ArgumentException. This is due >> to ResolveAll using a generic Dictionary<IHandler, object>; value type >> instances are boxed and when the value collection is cast to >> ICollection so that CopyTo() is available, it apparently doesn't unbox >> the references into the array created to hold value type instances. >> >> I replaced the Dictionary<IHandler, object> with >> System.Collections.Hashtable, and the CopyTo method works as expected, >> so this could be a potential fix, however this then breaks the >> "ResolveAllTestCase.ResolveAll_honors_order_of_registration" test. The >> note on that test indicates that it is not a good test due to >> fragility, and I'd have to agree. I can't believe it works as it is >> with a Dictionary. >> >> Another fix would be to loop through the Values collection on the >> resolved instances and add them to the created array using >> Array.SetValue, however this reduces performance, since SetValue isn't >> optimized. >> >> Can anyone contribute to this discussion? >> >> -rory >> >> > -- > You received this message because you are subscribed to the Google Groups > "Castle Project Development List" group. > To post to this group, send email to [email protected] > . > To unsubscribe from this group, send email to > [email protected]<castle-project-devel%[email protected]> > . > For more options, visit this group at > http://groups.google.com/group/castle-project-devel?hl=en. > > -- You received this message because you are subscribed to the Google Groups "Castle Project Development List" 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-devel?hl=en.
