0
我試圖自動註冊在團結容器中的所有報告。團結集裝箱類型註冊夸克
所有報告落實iReport的,也有其定義標題,描述和唯一的密鑰(這樣我就可以讀取這些沒有實例的具體類)報表()屬性。
所以......
我得到的報告類型這樣
Public Shared Function GetClassesWhichimplementInterface(Of T)() As IEnumerable(Of Type)
Dim InterfaceType = GetType(T)
Dim Types As IEnumerable(Of Type)
Types = Reflection.Assembly.GetCallingAssembly.GetTypes()
Return Types.Where(Function(x) InterfaceType.IsAssignableFrom(x))
End Function
而且這樣註冊它們:
Public Sub RegisterReports()
Dim ReportTypes = ReflectionHelper.GetClassesWhichimplementInterface(Of IReport)()
For Each ReportType In ReportTypes
''Previously I was reading the report attribute here and using the defined unique key. I've stopped using this code to remove possible problems while debugging.
Container.RegisterType(GetType(IReport), ReportType, ReportType.Name)
Next
End Sub
有通過調用返回到GetClassesWhichimplementInterface()
類型和Container.RegisterType()調用沒有錯誤。如果我的電話登記後,立即打電話Container.Resolve(of Interfaces.IReport)
,我得到以下異常:
Resolution of the dependency failed, type = "MyProject.Interfaces.IReport", name = "(none)".
Exception occurred while: while resolving.
Exception is: InvalidOperationException - The current type, MyProject.Interfaces.IReport, is an interface and cannot be constructed. Are you missing a type mapping?
-----------------------------------------------
At the time of the exception, the container was:
Resolving MyProject.Interfaces.IReport,(none)
誰能告訴我,爲什麼在容器未保存登記?
感謝您發現愚蠢的錯誤 – Basic 2010-10-28 14:01:34