Which version are you using?

Generally in Widnsor you wouldn't register a collection explicitly, but all the elements you want to resolve and use ArrayResolver.

Anyways - this should work, so I'll get a look.

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.

Reply via email to