Ok, so long story short - this is the result of an odd leftover from XML
years of Windsor, that it's arbitrarily treats collections as parameters
and expects them to be provided inline, not as other services. So I
think it's best if you don't just register the collection explicitly but
instead register the components you want to put in the collection, and
use ArrayResolver to have the container pull them together and inject as
your ICollection<Foo>
This odd behavior will be changed but not in the nearest version 2.5 I'm
afraid, but in v3 unless we get a patch
On 2010-06-02 02:12, Tim wrote:
Hello all.
I'm having problems with some code which has a constructor dependency
of type ICollection<T> which reports that the dependency can not be
satisfied. However, if I write a test which specifically resolves the
collection, it passes.
However, if I change the constructor parameter to Collection<T> (and
amend the registration) then this works... except I want to use the
interface, that is.
Has anyone come across this situation? Am I doing something wrong? Is
this a known issue?
Thanks for any help :)
- Tim.
Here is a couple of tests which demonstrates the problem:
namespace CollectionDependencyExample
{
using System.Collections.Generic;
using System.Collections.ObjectModel;
using Castle.MicroKernel.Registration;
using Castle.Windsor;
using NUnit.Framework;
using NUnit.Framework.Extensions;
[ TestFixture ]
public class CollectionDependencyTests
{
private WindsorContainer container;
[ SetUp ]
public void Set_up_test_context()
{
container = new WindsorContainer();
container.Register(
Component.For<ICollection<object>>().ImplementedBy<Collection<object>>() );
container.Register( Component.For<CollectionUser>() );
}
[ Test ]
public void Should_be_able_to_resolve_the_collection()
{
container.Resolve<ICollection<object>>().Should(
Be.Not.Null.And.TypeOf<Collection<object>>() ); //
Passes
}
[ Test ]
public void
Should_be_able_to_resolve_class_with_collection_dependency()
{
container.Resolve<CollectionUser>().Should( Be.Not.Null ); //
Fails
}
}
public class CollectionUser
{
public CollectionUser( Collection<object> objects ) {}
}
}
--
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.