我在跟踪
Windsor Inversion of Control (IoC) Getting Started example
,它是用C#编写的,但我在VB.Net中实现它,遇到了一个小问题。。
以下是我完全理解的例外情况:
无法创建组件“form.component”,因为它需要满足依赖关系。
form.comcomponent正在等待以下依赖项:
服务:
-控制反转。HttpServiceWatcher&;未注册。
我使用的是VB 8(Visual Studio 2005/.Net 2.0)
Windsor 1.0 RC3
.
这是我的
App.vb
:
Imports Castle.Windsor
Public Class App
Public Shared Sub Main()
Dim container As New WindsorContainer
'register the components
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))
'request the component from the container
Dim aForm As Form = container(GetType(Form1))
'use it!
Application.Run(aForm)
'release it
container.Release(aForm)
End Sub
End Class
Public Class Form1
Private oServiceWatcher As HttpServiceWatcher
Sub New(ByRef 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
Public Class HttpServiceWatcher
Private oNotifier As IFailureNotifier
Sub New(ByRef Notifier As IFailureNotifier)
oNotifier = Notifier
End Sub
Sub StartWatching()
'should start a thread to ping the service
'if (pingresult = Failed)
oNotifier.Notify()
'end if
End Sub
Sub StopWatching()
'stop thread
End Sub
End Class
IFailureNotifier
Public Interface IFailureNotifier
Sub Notify()
End Interface
和
Notify()
方法为空
我试图通过将IFailureNotifier放在第一位、HttpServiceWatcher放在第三位、Form放在最后来更改顺序,但我得到了同样的错误。
我做了一次清理和重建,但我还是犯了同样的错误。
谢谢:o)