I think I could be using this wrong, there wasn't much on the Ninject variant of multiple cores, but I'm trying to use Ninject and SolrNet. While taking advantage of fully loose mapping. So I know I need to use Ninject named bindings. Can't use Windsor, it's dll's don't seem to play well with our current stuff.
Suspect code:
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");
Error Produced:
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}}
I understand the concept of DI, however I don't know much more than that because in MVC everything seemed hidden from me. So any additional explanation, on why this is dumb/how SolrNet interacts with it, would be appreciated.
Link to SolrNet Module https://github.com/mausch/SolrNet/blob/master/Ninject.Integration.SolrNet/SolrNetModule.cs
Since I see that you are using the fully loose mapping capabilities of SolrNet, you could implement the following dynamic mappings as a workaround until support for the same type/class is added to SolrNet for Ninject.
public class Index1Item
{
SolrField["*"]
public IDictionary<string, object> Fields { get; set; }
}
public class Index2Item
{
SolrField["*"]
public IDictionary<string, object> Fields { get; set; }
}
Please see Mappings on SolrNet project page for more details on this dynamic mapping.
Then your SolrNet setup would change to the following:
SolrServers cores = new SolrServers();
cores.Add(new SolrServerElement
{
Id = "index1",
DocumentType = typeof(Index1Item).AssemblyQualifiedName,
Url = "http://localhost:8080/solr/index1",
});
cores.Add(new SolrServerElement
{
Id = "index2",
DocumentType = typeof(Index2Item).AssemblyQualifiedName,
Url = "http://localhost:8080/solr/index2",
});
var kernal = new StandardKernel(new SolrNetModule(cores));
var operations = kernal.Get<ISolrOperations<Index1Item>>("index1");
Hopefully this will help...