Inject Logwriter to startup object

Topics: Logging Application Block, Policy Injection Application Block
Jan 8, 2010 at 4:11 AM

Hi All,

I may not have understood the concept of dependency injection but here is the question.

I have created a ServiceLocator class that configures the container with the dependent objects.

The startup object for my application is Form1.vb (lets say). I have set this in the project properties.

If i want to get hold of a LogWriter in Form1.Vb, how would i go about doing this?

the ServiceLocator looks like this

Private Shared Sub ConfigureContainer()

 

_container = New UnityContainer
        _container.AddNewExtension(Of EnterpriseLibraryCoreExtension)()
        _container.AddNewExtension(Of LoggingBlockExtension)()

        _container.RegisterType(Of IExtractor, CSONYExtractor)(Constants.SONY)

Private Shared Sub ConfigureContainer()

_container = New UnityContainer

        _container.AddNewExtension(Of EnterpriseLibraryCoreExtension)()

        _container.AddNewExtension(Of LoggingBlockExtension)()

        _container.RegisterType(Of IExtractor, CSONYExtractor)(Constants.SONY)

end sub

In my client tools, this is what i have done.

    Private _logWriter As LogWriter

    Public Sub New(ByVal logWriter As LogWriter)

        _logWriter = logWriter

    End Sub

Any advice on this would be very helpful.
thanks, Hari.

 

Jan 8, 2010 at 4:34 AM

Please post this in the Unity forum - http://www.codeplex.com/unity/Thread/List.aspx

 

Sarah Urmeneta
Global Technology & Solutions
Avanade, Inc.

entlib.support@avanade.com