views:

398

answers:

1

I'm following the Windsor Inversion of Control (IoC) Getting Started example, which is in C#, but I'm implementing it in VB.Net, and I've run into a small problem..

Here's the exception I'm getting in full:

Can't create component 'form.component' as it has dependencies to be satisfied. form.component is waiting for the following dependencies:

Services: - InversionOfControl.HttpServiceWatcher& which was not registered.

but I think I am registering it - it's the first one registered!

I'm using VB 8 (Visual Studio 2005 / .Net 2.0), and Windsor 1.0 RC3.


Here's my 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 and EmailFailureNotifier both implement IFailureNotifier but the Notify() methods are empty


I've tried changing the order by putting the IFailureNotifier's first, HttpServiceWatcher 3rd and Form last but I get the same error.

I've done a Clean and rebuild, but I get the same error.

I'm obviously new to this (as I'm going through the 'Getting Started'), can you point out what I've missed please?

Thank you :o)

+1  A: 

I'm not a VB wiz, but I suspect the problem is the ByRef keyword in the New sub. Try changing it to:

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
kern
Thanks for the tip - when I removed the 'ByRef' it got replaced with 'ByVal' (I thought it had to be one or the other, but I gave it a try with nothing anyway!), and I changed both constructors in the project: Form1 and HttpServiceWatcher, and that sorted it. Thanks again :o)
Andrew