Hi, I have the following class:

        public class Service
        {
            public ComponentX X { get; private set; }
            public ComponentY Y { get; private set; }
            public ComponentA A { get; private set; }

            public Service(ComponentA a)
            {
                A = a;
            }

            public Service(ComponentX x, ComponentY y)
            {
                X = x;
                Y = y;
            }
        }

and the following test:

        [Test]
        public void Kernel_should_select_ctor_with_available_dependencies()
        {
            var kernel = new DefaultKernel();
            kernel.AddComponent<ComponentX>();
            kernel.AddComponent<ComponentY>();
            kernel.AddComponent<Service>();

            var service = kernel.Resolve<Service>();

            Assert.That(service.A, Is.Null);
            Assert.That(service.X, Is.Not.Null);
            Assert.That(service.Y, Is.Not.Null);
        }

The test fails with this message:

TestCase
'Castle.MicroKernel.Tests.xxx.Kernel_should_select_ctor_with_available_dependencies'
failed: Castle.MicroKernel.Handlers.HandlerException : Can't create
component 'Castle.MicroKernel.Tests.xxx+Service' as it has dependencies to
be satisfied.
Castle.MicroKernel.Tests.xxx+Service is waiting for the following
dependencies:

Services:
- Castle.MicroKernel.Tests.xxx+ComponentA which was not registered.
    Handlers\DefaultHandler.cs(114,0): at
Castle.MicroKernel.Handlers.DefaultHandler.AssertNotWaitingForDependency()
    Handlers\DefaultHandler.cs(53,0): at
Castle.MicroKernel.Handlers.DefaultHandler.ResolveCore(CreationContext
context, Boolean track)
    Handlers\AbstractHandler.cs(189,0): at
Castle.MicroKernel.Handlers.AbstractHandler.Resolve(CreationContext context)
    DefaultKernel.cs(936,0): at
Castle.MicroKernel.DefaultKernel.ResolveComponent(IHandler handler, Type
service, IDictionary additionalArguments)
    DefaultKernel.cs(918,0): at
Castle.MicroKernel.DefaultKernel.ResolveComponent(IHandler handler, Type
service)
    DefaultKernel_Resolve.cs(68,0): at
Castle.MicroKernel.DefaultKernel.get_Item(Type service)
    DefaultKernel_Resolve.cs(199,0): at
Castle.MicroKernel.DefaultKernel.Resolve(Type service)
    DefaultKernel_Resolve.cs(157,0): at
Castle.MicroKernel.DefaultKernel.Resolve[T]()
    BestConstructorTestCase.cs(213,0): at
Castle.MicroKernel.Tests.xxx.Kernel_should_select_ctor_with_available_dependencies()


Is this behavior by design?
I don't want to (cannot) register ComponentA in the kernel. How can I tell
MK to use the second ctor?

-- 
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