so i’m having a few problems with dependency injection.. i get the following error:
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
so i’m injecting my readOrchestrator into my MVC3 app which is fine.. but the problem arises when in my readOrchestrator i call a method in my IDocumentReadRepository.
my ReadOrchestrator looks like:
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;
}
...
}
Should i be using DI in this situation? if so, how/where should i do the binding for the IDocumentReadRepository? or should i just be creating a new instance of it each time i call my ReadOrchestrator?
thanks
Yes for sure you need to register or bind
IDocumentReadRepositoryto a concrete implementation namelyDocumentReadRepository.You have a BindModule somewhere in your codebase.
Do the binding for
DocumentReadRepositoryand ninject will wire the dependencies for you when an instance ofReadOrchestratorwants to be created.Like this