0

我正在关注 C# 中的Windsor Inversion of Control (IoC) Getting Started example,但我在 VB.Net 中实现它,我遇到了一个小问题..

这是我完整的例外:

无法创建组件“form.component”,因为它需要满足依赖关系。form.component 正在等待以下依赖项:

服务: - 未注册的 InversionOfControl.HttpServiceWatcher&。

但我想我正在注册它 - 这是第一个注册的!

我正在使用 VB 8 (Visual Studio 2005 / .Net 2.0) 和Windsor 1.0 RC3


这是我的App.vb

进口 Castle.Windsor

公开课应用

    公共共享子 Main()

        昏暗容器作为新的 WindsorContainer

        '注册组件
        container.AddComponent("httpservicewatcher", _
           GetType(HttpServiceWatcher))
        container.AddComponent("email.notifier", GetType(IFailureNotifier), _
           GetType(EmailFailureNotifier))
        container.AddComponent("alarm.notifier", GetType(IFailureNotifier), _
           GetType(AlarmFailureNotifier))
        container.AddComponent("form.component", GetType(Form1))

        '从容器中请求组件
        Dim aForm As Form = container(GetType(Form1))

        '用它!
        应用程序.Run(aForm)

        '释放它
        容器.Release(aForm)

    结束子

结束类

表格1

公开课形式1

    私有 oServiceWatcher 作为 HttpServiceWatcher

    Sub New(ByRef ServiceWatcher As HttpServiceWatcher)

        ' Windows 窗体设计器需要此调用。
        初始化组件()

        ' 在 InitializeComponent() 调用之后添加任何初始化。
        Me.oServiceWatcher = ServiceWatcher
    结束子
结束类

HttpServiceWatcher

公共类 HttpServiceWatcher

    私有 oNotifier 作为 IFailureNotifier

    Sub New(ByRef Notifier As IFailureNotifier)
        oNotifier = 通知者
    结束子

    子开始观看()

        '应该启动一个线程来ping服务
        '如果(pingresult = 失败)
        oNotifier.Notify()
        '万一

    结束子

    子秒表()

        '停止线程

    结束子

结束类

IFailureNotifier

公共接口 IFailureNotifier

    子通知()

端接口

AlarmFailureNotifierEmailFailureNotifier都实现了 IFailureNotifier 但Notify()方法为空


我尝试通过将 IFailureNotifier 放在第一个、HttpServiceWatcher 3rd 和 Form 最后来更改顺序,但我得到了同样的错误。

我已经完成了清理和重建,但我得到了同样的错误。

我显然对此很陌生(因为我正在经历“入门”),你能指出我错过了什么吗?

谢谢 :o)

4

1 回答 1

1

我不是 VB 奇才,但我怀疑问题出在 New sub 中的 ByRef 关键字。尝试将其更改为:

Public Class Form1

    Private oServiceWatcher As HttpServiceWatcher

    Sub New(ServiceWatcher As HttpServiceWatcher)

        ' This call is required by the Windows Form Designer.
        InitializeComponent()

        ' Add any initialization after the InitializeComponent() call.
        Me.oServiceWatcher = ServiceWatcher
    End Sub
End Class
于 2009-02-10T17:20:03.037 回答