2012-01-06 15 views
0

からアセンブリを呼び出すときに、私は依存性注入といくつかの問題が..私は次のエラーを取得することだ:DIエラーを注入アセンブリ

Error activating IDocumentReadRepository No matching bindings are available, and the type is not self-bindable. Activation path: 3) Injection of dependency IDocumentReadRepository into parameter readRepository of constructor of type ReadOrchestrator 2) Injection of dependency IReadOrchestrator into parameter

ので、私は私のMVC3アプリに私のreadOrchestratorを注入していますこれは問題ありませんが、私のreadOrchestratorではIDocumentReadRepositoryのメソッドを呼び出すと問題が発生します。

私ReadOrchestratorは、次のようになります。

public class ReadOrchestrator : IReadOrchestrator 
{ 
    private readonly IDocumentReadRepository _readRepository; 

    public ReadOrchestrator(IDocumentReadRepository readRepository) 
    { 
     _readRepository = readRepository; 
    } 

    public UserFeed GetUserFeed(string userName, int pageNumber, int pageSize) 
    { 
     var feed = _readRepository.Query<UserFeed>(x => x.UserName == (string)userName 
      .Page(pageNumber, pageSize)); 
     return feed; 
    } 
} 

    public class DocumentReadRepository : IDocumentReadRepository 
    { 
     readonly IDocumentStore _documentStore; 

     public DocumentReadRepository(IDocumentStore documentStore) 
     { 
      _documentStore = documentStore; 
     } 
... 
} 

私はこのような状況でDIを使用する必要がありますか。もしそうなら、どうやってIDocumentReadRepositoryのバインディングを行うべきですか?または私はReadOrchestratorを呼び出すたびにそのインスタンスを新たに作成する必要がありますか?

感謝

確かに
+0

同様

? 'DocumentReadRepository'に対しても同じことをします。 –

答えて

1

はいあなたが登録したり、具体的な実装、すなわちDocumentReadRepositoryIDocumentReadRepositoryをバインドする必要があります。

コードベースのどこかにBindModuleがあります。

DocumentReadRepositoryのバインディングを実行し、ReadOrchestratorのインスタンスを作成する場合、ninjectが依存関係を結び付けます。 `ReadOrchestrator`を注入するにはどうすればよいこの

this.Bind<IDocumentReadRepository>.To<DocumentReadRepository>(); 
+0

MVCレベルでkernalをバインドしようとしましたが、動作しませんでした。 – nologo

+0

'Ninject'コードからプロジェクトを消去し、NinjectとNinject.Web.MvcをNuGetで追加し、それを設定します。 –

+0

それは問題でした、私は正しく参照されたninjectを持っていませんでした! – nologo