Search code examples
dependency-injectionsolrsolrnetservice-locator

SolrNet - ServiceLocator.Current throws a null reference exception


I'm setting up my connection to Solr in the Application_Start method in the global.asax through: Startup.Init<ApartmentDoc>("http://localhost:8080/solr");

I have a DAO library project that I'm trying to use to make the calls to the Solr server. The problem is when I try to access the the instance of my solr connection from the library class, I get a null reference exception on ServiceLocator.Current.

var solr = ServiceLocator.Current.GetInstance<ISolrOperations<ApartmentDoc>>();

I'm new to DI and SolrNet, so any help would be appreciated.

Thanks, Drew


Solution

  • As explained in the comments, it turns out it was running in a different context, unaffected by Application_Start.