I have been implementing Dependency Injection into an existing Winforms project and it has been going well so far, however I want to generalise the calling of the Forms, specifically the varying quantity of constructor parameters.
My code is as follows:
Public Shared Function GetForm(formObject As BaseObject, _
parameters As Dictionary(Of String, Object)) As Form
Select Case formObject.GetType()
Case GetType(Production.Task)
Return SMKernel.Kernel.Get(Of Forms.Production.Domain.ManageTask) _
(New Parameters.ConstructorArgument() _
{New Parameters.ConstructorArgument("task", _
CType(formObject, Production.RequiredTask))})
End Select
End Function
This works fine, the interface(s) are injected correctly, the constructor parameter "task" is populated and the Form works as expected.
As you can see I have a Dictionary that can contain several parameters which I need to add to the ConstructorArgument
part of the Get
method. Looking at the IntelliSense, I should be able to pass in an array of ConstructorArgument
objects, however no matter what I have tried, it doesn't seem to work for one reason or another.
How do you accomplish this in Ninject if it is at all possible. If this way isn't possible, how can you pass multiple parameters into a Form's constructor via Ninject?