在Castle.Windsor框架中连接事件订阅者的问题

时间:2009-03-09 02:56:33

标签: c# inversion-of-control castle-windsor

我在为Castle.Windsor IoV组件连接事件时遇到问题。即使我已经确认了它们的方法和签名,它也会抛出一个异常,消息“对象与目标类型不匹配”。

任何人都可以解释一下它期待的对象吗?

我的布线如下:

  <component
    id="mailManager"
    service="Pop3Dispatcher.Mail.IMailManager, Pop3Dispatcher"
    type="Pop3Dispatcher.Mail.DefaultMailManagerImpl, Pop3Dispatcher"
    startable="true"
    loadCompletedMethod="Init">
    <subscribers>
      <subscriber id="emailFilterImpl" event="MessageRecieved" handler="OnReceivedMessage"/>
    </subscribers>
  </component>

  <component 
    id="emailFilterImpl" 
    service="Pop3Dispatcher.Filters.IFilter, Pop3Dispatcher"
    type="Pop3Dispatcher.Filters.EmailFilterImpl, Pop3Dispatcher" 
    startable="true">
  </component>

在有人问之前,是的,我已经包括:

<facilities>

  <facility
      id="event.wiring"
      type="Castle.Facilities.EventWiring.EventWiringFacility, Castle.MicroKernel" />

</facilities>

1 个答案:

答案 0 :(得分:0)

好的,问题解决了,显然在这种情况下,申报的顺序很重要。 Alos,它不支持“服务”,必须直接订阅该类型。

  <component 
    id="emailFilterImpl" 
    type="Pop3Dispatcher.Filters.EmailFilterImpl, Pop3Dispatcher" 
    startable="true">
  </component>

  <component
    id="mailManager"
    type="Pop3Dispatcher.Mail.DefaultMailManagerImpl, Pop3Dispatcher"
    startable="true"
    loadCompletedMethod="Init">
    <subscribers>
      <subscriber id="emailFilterImpl" event="MessageRecieved" handler="OnReceivedMessage"/>
    </subscribers>
  </component>