views:

95

answers:

1

Currently I have a class that looks like this:

public class MyClass : IMyClass
{
   public MyClass()
   {
      //...
   }
   public MyClass(IMyRepository repository)
   {
      //...
   }
}

In my config file I have IMyClass registered, but not IMyRepository. My intention is for Windsor to use the constructor that doesn't take any parameters, but I am getting this message:

Can't create component 'MyClass' as it has dependencies to be satisified. MyClass is waiting for the following dependencies:

Services: - Namespace.IMyRepository which was not registered.

I found another post that says that the container will call the constructor with the most arguments that it can satisfy. So why is it trying to call the constructor with an argument that it doesn't know how to satisfy?

+1  A: 

Maybe you're using an old version of Windsor... this works just fine for me:

[TestFixture]
public class WindsorTests {

    public interface ISomeInterface {}

    public class AService {
        public int Id { get; private set; }

        public AService() {
            Id = 1;
        }

        public AService(ISomeInterface s) {
            Id = 2;
        }
    }

    [Test]
    public void Parameters() {
        var container = new WindsorContainer();
        container.AddComponent<AService>();
        var service = container.Resolve<AService>();
        Assert.AreEqual(1, service.Id);
    }
}
Mauricio Scheffer
I downloaded the latest build and it is working, thanks!
MrDustpan