开发者

Resolving Windsor dependency

During resolving Windsor dependencies I have the following exception:

Could not resolve non-optional dependency for 'Namespace.MyClass1' (Namespace.MyClass1). Parameter 'Namespace.MyClass2' type 'Namespace.MyClass2'

public class MyClass1
{
     public MyClass1(MyClass2 myClass2, MyClass3 myClass3)
     {
          this.MyClass2 = myClass2,
          this.MyClass3 = myClass3,
     }

     protected MyClass2 MyClass2 { get; private set; }
     public MyClass3 MyClass3 { get; set; }
}

There are no problems with resolving MyClass2 and MyClass3.

**Edit - test case **

I'm using Windsor 2.5.1 (or 2.5.2 - downloaded today via NuGet)

All code:

using Castle.MicroKernel.Registration;
using Castle.Windsor;
using Castle.Windsor.Configuration.Interpreters;
using Castle.Core.Resource;
namespace ConsoleApplication9
{
    class Program
    {
        static void Main(string[] args)
        {
            WindsorContainer container = new WindsorContainer(new XmlInterpreter(new ConfigResource()));

            container.Register(
                Component.For<MyClass2>(),
                Component.For<MyClass1>()
                    .DependsOn(
                        Property.ForKey("myClass2").Is<MyClass2>(),
     开发者_开发知识库                   Property.ForKey("myClass3").Is<MyClass3>()
                    )
            );

            container.Resolve<MyClass1>();
        }
    }

    public class MyClass3 { public MyClass3() {} }

    public class MyClass2 { public MyClass2() {} }

    public class MyClass1
    {
        public MyClass1(MyClass2 myClass2, MyClass3 myClass3)
        {
            this.MyClass2 = myClass2;
            this.MyClass3 = myClass3;
        }

        protected MyClass2 MyClass2 { get; private set; }

        public MyClass3 MyClass3 { get; set; }
    }
}

App.config:

<castle>
    <properties>      
    </properties>
    <include uri="file://windsor.config" />
</castle>

windsor.config

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <components>
    <component id="hoho" type="ConsoleApplication9.MyClass3"/>
  </components>
</configuration>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜