简体   繁体   中英

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

如评论中所述,事实证明它在不同的上下文中运行,不受Application_Start的影响。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM