使用Unity注入时的构造函数错误

时间:2014-09-23 12:43:40

标签: asp.net-mvc vb.net unity-container

为什么我收到此错误"类型MVCApplication1.HomeController没有使用Unity获取参数(IRepository_1,IRepository_2)" 的构造函数?

Public Class HomeController
Inherits Controller
Private _repo1 As IRepository_1
Private _repo2 As IRepository_2

Private Sub New(_repo1 As IRepository_1, _repo2 As IRepository_2)
    Me._repo1 = _repo1
    Me._repo2 = _repo2
End Sub

Function Index() As ActionResult

    Return View()
End Function
End Class

引导程序

container.RegisterType(Of HomeController)(New InjectionConstructor(New ResolvedParameter(Of IRepository_1), New ResolvedParameter(Of IRepository_2)))

1 个答案:

答案 0 :(得分:0)

您的构造函数需要公开

Public Sub New(_repo1 As IRepository_1, _repo2 As IRepository_2)
    Me._repo1 = _repo1
    Me._repo2 = _repo2
End Sub