2014-09-23 68 views
0

爲什麼我得到這個錯誤「MVCApplication1.HomeController類型沒有一個構造函數使用Unity的參數(IRepository_1,IRepository_2)」使用Unity注入時的構造函數錯誤

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))) 

回答

0

你的構造函數必須是公共

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

完美,感謝埃文。 – imperialx 2014-09-23 13:09:16

相關問題