我想配置Unity來將一個接口(比如說ITest
)解析爲一個結構,比如struct Test
。到目前爲止,我有未來:是否可以將結構綁定到Unity中的接口?
<unity>
<containers>
<container>
<types>
<type
type="my.ITest, asm"
mapTo="my.Test, asm">
</type>
</types>
</container>
</containers>
</unity>
但我發現了一個錯誤:
Resolution of the dependency failed, type = "my.ITest", name = "(none)".
Exception occurred while: while resolving.
Exception is: InvalidOperationException - The type Test cannot be constructed. You must configure the container to supply this value.
At the time of the exception, the container was:
Resolving my.Test,(none) (mapped from my.ITest,(none))
爲什麼?
爲什麼'Activator.CreateInstance'不能夠創建一個結構? – Lee
我測試了這一點;當結構體上有一個接口時,CreateInstance調用失敗。不明原因。 – Tejs
'Int32'實現了許多接口,工作正常。 – Lee