2012-05-02 2 views
1

UnityでサンプルWCF​​ Dependency Injectionを実装しようとすると、このエラーが発生します。正しくマップされたユニティ例外の解決タイプ。どうして?

Resolution of the dependency failed, type = "SampleServiceUsingUnity.ExampleService", name = "(none)". 
Exception occurred while: while resolving. 
Exception is: InvalidOperationException - The current type, ExampleServiceUsingUnity.IExampleManager, is an interface and cannot be constructed. Are you missing a type mapping? 
----------------------------------------------- 
At the time of the exception, the container was: 
Resolving SampleServiceUsingUnity.ExampleService,(none) 
Resolving parameter "exampleManager" of constructor  SampleServiceUsingUnity.ExampleService(SampleServiceUsingUnity.IExampleManager exampleManager) 
Resolving SampleServiceUsingUnity.IExampleManager,(none) 

問題は...私も、明示的に型をマップしようとした、と私は、コードをデバッグするとき、私はすぐに窓に行き、登録を見てください。以下を参照してください:

マッピングが正しいように見えますが、サービスがResolveを使用してそのインターフェイスをインスタンス化しようとすると、エラーが発生します。登録がIExampleRepositoryについてであるが、例外がIExampleManager話している

http://msdn.microsoft.com/en-us/library/hh323725.aspx
+0

登録は 'IExampleRepository'についての例外ですが、例外は' IExampleManager'です。あなたがマネージャのマッピングを紛失していて、代わりにリポジトリ用のマッピングを提供しているとしたら、 –

+0

投稿の冒頭でエラーを修正する必要がありますが、まもなくそうなります。どうやら別のものを試してみたのと同じ例外が貼り付けられたようです。コード行は以下のとおりで、サービスがインスタンス化されたときに呼び出されました。 DependencyFactory.Container.RegisterType (new ContainerControlledLifetimeManager()); DependencyFactory.Container.RegisterType(typeof(ExampleRepository)); –

+0

あなたはそれを正しく持っていません。私はうんざりした。私はExampleServiceとExampleRepositoryに焦点を当ててとても忙しかった。 (私の目は、例題という言葉であいまいになっている)。私はちょうどピア・プログラミングのために大きな議論をしました。ありがとう! –

答えて

1

コード例は、で供給されます。あなたがマネージャのマッピングを紛失していて、代わりにリポジトリ用のマッピングを提供しているとしたら、

関連する問題