我想配置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