インターフェイスを、たとえばITest
というように、構造体、たとえばstruct Test
に解決するようにUnityを設定します。これまでのところ私は、次があります。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