Пример справки Windsor IoC - «HttpServiceWatcher &, который не был зарегистрирован». - PullRequest
0 голосов
/ 10 февраля 2009

Я следую примеру Windsor Inversion of Control (IoC), начинающему работу , который находится в C #, но я внедряю его в VB.Net и столкнулся с небольшой проблемой ..

Вот исключение, которое я получаю в полном объеме:

Невозможно создать компонент form.component, так как он имеет зависимости, которые должны быть удовлетворены. form.component ожидает следующих зависимостей:

Услуги: - InversionOfControl.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

Form1

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

HttpServiceWatcher

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

AlarmFailureNotifier и EmailFailureNotifier оба реализуют IFailureNotifier, но методы Notify() пусты


Я попытался изменить порядок, поместив сначала IFailureNotifier, HttpServiceWatcher 3rd и Form, но я получаю ту же ошибку.

Я сделал Очистку и перестройку, но я получаю ту же ошибку.

Я, очевидно, новичок в этом (когда я прохожу «Начало работы»), не могли бы вы указать, что я пропустил, пожалуйста?

Спасибо: о)

1 Ответ

1 голос
/ 10 февраля 2009

Я не специалист по VB, но подозреваю, что проблема в ключевом слове 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
...