2017-06-20 6 views
0

私はこのようUnityとインスタンスを登録して、インスタンスを解決:カントは、ユニティ・コンテナ

ContentSlideControlsEntity contentSlideControlsEntity = new ContentSlideControlsEntity(new Queue<uint>()); 
     container.RegisterInstance(typeof(ContentSlideControlsEntity), "contentSlideControlsEntity", contentSlideControlsEntity); 

そして、私は単にそれをresloveたい:

ContentSlideControlsEntity contentSlideControlsEntity2 = container.Resolve<ContentSlideControlsEntity>(); 

が、私は、次のランタイムエラーを取得する:

Microsoft.Practices.Unity.ResolutionFailedException: 'Resolution of the dependency failed, type = "MSDataLayer.Entities.ContentSlideControlsEntity", name = "(none)".

Exception occurred while: while resolving.

Exception is: InvalidOperationException - The type Queue`1 has multiple constructors of length 1. Unable to disambiguate.


At the time of the exception, the container was:

Resolving MSDataLayer.Entities.ContentSlideControlsEntity,(none)

Resolving parameter "slideIDQueue" of constructor MSDataLayer.Entities.ContentSlideControlsEntity(System.Collections.Generic.Queue`1[[System.UInt32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]] slideIDQueue)

Resolving System.Collections.Generic.Queue`1[System.UInt32],(none) 

答えて

1

インスタンスを名前付き登録として登録しましたが、名前なし登録を解決しています(d存在しない)。

container.RegisterInstance(typeof(ContentSlideControlsEntity), "contentSlideControlsEntity", contentSlideControlsEntity); 
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 

あなたは2つのオプションがあります:

1)という名前の一括登録

container.RegisterInstance(typeof(ContentSlideControlsEntity), contentSlideControlsEntity); 

2としてそれを登録しないでください)名前

container.Resolve<ContentSlideControlsEntity>("contentSlideControlsEntity"); 
でそれを解決します