dinsdag 3 maart 2009

Entering string parameters in constructors with Unity

A Microsoft.Practices.Unity container will try to resolve any parameters that a constructor expects. However, for simple string (or int) parameters, that won't work. My example for this was a queue that expects a name parameter:

Public Class Queue
Private mName As String
Public Sub New (name As String)
mName = name
End Sub
End Class

This can be solved, and Microsoft explains how in this section of the documentation.

In this case it results in code like this:

MyContainer.Configure(Of InjectedMembers)() _
.ConfigureInjectionFor(Of Queue)( _
New InjectionConstructor("testqueue"))

Geen opmerkingen: