0

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

Matthew Rhoden
  • 688
  • 1
  • 10
  • 20

3 Answers3

0

I have not yet used Solr but from the Module I found on github I'd say you have to assign the generic type argument to the document type instead of ISolrOperations

Remo Gloor
  • 32,665
  • 4
  • 68
  • 98
  • The SolrNet Module is a part of the SolrNet library, I could post their source code I guess. I updated with your suggestion and now I'm getting: `Error activating ISolrBasicOperations{Dictionary{string, Object}} More than one matching bindings are available.` – Matthew Rhoden Apr 17 '12 at 13:18
  • I added a link to the SolrNetModule, no file upload on StackOverflow. – Matthew Rhoden Apr 17 '12 at 13:22
  • 1
    This is the correct approach for this binding. However, if you look at the last test case in https://github.com/mausch/SolrNet/blob/master/Ninject.Integration.SolrNet.Tests/MultiCoreTests.cs You will see that this scenario, binding the same class/type to multiple cores is not yet supported. – Paige Cook Apr 17 '12 at 13:37
  • Can't believe I missed that test case. Thanks a lot! :) – Matthew Rhoden Apr 17 '12 at 15:20
0

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...

Paige Cook
  • 22,415
  • 3
  • 57
  • 68
0

SolrNet has since been updated to support multiple cores of the same DocumentType with named bindings so your suspect code should work now.

Jerry Wang
  • 588
  • 5
  • 6
  • Thanks for adding the support, I found anther problem though. When I get the results back, the mapping seems to be messed up. I receive a `SolrQueryResults>` object back with the correct result count, but there are no entries in the dictionaries. I used fiddler to double check that I'm actually getting results from the server. Am I missing something? I can make another entry on stackoverflow with code if you'd like. – Matthew Rhoden May 02 '12 at 18:25
  • Sorry for the late response. In case you haven't solved it yet. I just realized you should probably still use the suggested IndexItem object approach. You just won't need two different objects (Index1Item, Index2Item) since multicore of the same documenttype is now supported. – Jerry Wang May 30 '12 at 18:06