當我想我可以用這個錯誤,沒有太多的多個內核上的Ninject變種,但我試圖用Ninject和SolrNet。同時充分利用完全鬆散的映射。所以我知道我需要使用Ninject命名的綁定。不能使用溫莎,它的dll似乎不適合我們目前的東西。ActivationException使用Ninject訪問多個內核在SolrNet
可疑代碼:
SolrServers cores = new SolrServers();
cores.Add(new SolrServerElement
{
Id = "index1",
DocumentType = typeof(ISolrOperations<Dictionary<string, object>>).AssemblyQualifiedName,
Url = "http://localhost:8080/solr/index1",
});
cores.Add(new SolrServerElement
{
Id = "index2",
DocumentType = typeof(ISolrOperations<Dictionary<string, object>>).AssemblyQualifiedName,
Url = "http://localhost:8080/solr/index2",
});
var kernal = new StandardKernel(new SolrNetModule(cores));
var operations = kernal.Get<ISolrOperations<Dictionary<string, object>>>("index1");
錯誤出品:
Test 'Test.DifferentTest' failed:
Ninject.ActivationException : Error activating ISolrOperations{Dictionary{string, Object}}
No matching bindings are available, and the type is not self-bindable.
Activation path:
1) Request for ISolrOperations{Dictionary{string, Object}}
我明白了DI的概念,但是我不知道遠不止這些,因爲在MVC中的一切似乎與我隱瞞。因此,任何額外的解釋,爲什麼這是愚蠢的/如何SolrNet與它交互,將不勝感激。
鏈接SolrNet模塊https://github.com/mausch/SolrNet/blob/master/Ninject.Integration.SolrNet/SolrNetModule.cs
請添加SolrNetModule實現的問題 – 2012-04-16 22:10:20