所以我在與依賴注入的幾個問題..我得到以下錯誤: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
所以我注入我的readOrchestrator到我MVC3應用這很好..但問題出現在我的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時創建它的新實例?
感謝
如何注入'ReadOrchestrator'?對「DocumentReadRepository」執行相同操作。 – 2012-01-06 11:24:25