3

I am trying to create an index agent service for a multi-instance Solr install using SolrNet. I have created the service, which will use an interface to create multiple agents to index with. These agents are specified in an external configuration file and instantiated dynamically. There can be 0-n of each agent type, for instance (note the url differences):

PersonAgent    http://localhost:8080/solr
ProductAgent   http://localhost:8080/solr
ProductAgent   http://localhost:9999/solr

This of course needs to map to something like this:

ISolrOperations<Person> 
ISolrOperations<Product>
ISolrOperations<Product>

Based on my needs and the fact that SolrNet does not support multiple instances for its default container, I am trying to use Castle Windsor for this. According to the SolrNet wiki at http://code.google.com/p/solrnet/wiki/MultiCoreAccess this is pretty straightforward.

var solrFacility = new SolrNetFacility("http://localhost:8983/solr/defaultCore");
solrFacility.AddCore("core0-id", typeof(Product), "http://localhost:8983/solr/product");
solrFacility.AddCore("core1-id", typeof(Product), "http://localhost:8983/solr/product2");
solrFacility.AddCore(typeof(Person), "http://localhost:8983/solr/person"); // no need to set an explicit ID since it's the only core for Person
container.AddFacility("solr", solrFacility);

ISolrOperations<Person> solrPerson = container.Resolve<ISolrOperations<Person>>();
ISolrOperations<Product> solrProduct1 = container.Resolve<ISolrOperations<Product>>("core0-id"); // use proper Windsor service overrides instead of resolving like this
ISolrOperations<Product> solrProduct2 = container.Resolve<ISolrOperations<Product>>("core1-id");

I'm not completely lost with the idea of IoC, but I am unsure what the wiki author meant with the comment to "use proper Windsor service overrides instead of resolving like this" as stated in the code sample. Obviously the example explicitly identifies the core via an id, but is there a better/more flexible way?

Brendan Hannemann
  • 2,084
  • 1
  • 18
  • 33

1 Answers1

3

What I meant is that you normally don't resolve ISolrOperations<T> directly from the container.

Instead, you use service overrides or other Windsor mechanisms to define which ISolrOperations<T> component (which core) to pass to other components, especially when you have multiple cores with the same document type, e.g. in this example there are two components registered under the service type ISolrOperations<Product>.

Mauricio Scheffer
  • 98,863
  • 23
  • 192
  • 275
  • Is it technically bad to do it this way? I'm trying to keep the Windsor stuff contained so I don't have to use it everywhere just yet, so if I can just hand out my `ISolrOperations` objects instead of passing the container around that would be best for now. – Brendan Hannemann Aug 12 '11 at 17:30
  • Thanks, Mauricio. I edited my question slightly to add solr urls to my example agents above. Do you think this will work the way I am trying to use it (multiple instances/servers with single cores)? I'm getting mildly tripped up with the instance vs core jargon being interchangeable. – Brendan Hannemann Aug 12 '11 at 17:35