I am using Ninject for DI in my project. I am using solrnet for search functionality and I am trying to incorporate Solr to Ninject. Below is the code i have added in Global.asax
protected override IKernel CreateKernel()
{
return new StandardKernel(new ServiceModule(), new SolrNetModule(ConfigurationManager.AppSettings["SearchServer"]));
}
SolrnetModule.cs
public class SolrNetModule : NinjectModule
{
private readonly string serverURL;
public IReadOnlyMappingManager Mapper { get; set; }
public SolrNetModule(string serverURL)
{
this.serverURL = serverURL;
}
public override void Load()
{
var mapper = Mapper ?? new MemoizingMappingManager(new AttributesMappingManager());
Bind<IReadOnlyMappingManager>().ToConstant(mapper);
Bind<ISolrConnection>().ToConstant(new SolrConnection(serverURL));
Bind(typeof(ISolrQueryResultParser<SolrSku>)).To(typeof(SolrQueryResultParser<SolrSku>));
Bind(typeof(ISolrQueryExecuter<SolrSku>)).To(typeof(SolrQueryExecuter<SolrSku>));
Bind(typeof(ISolrDocumentSerializer<SolrSku>)).To(typeof(SolrDocumentSerializer<SolrSku>));
Bind(typeof(ISolrBasicOperations<SolrSku>)).To(typeof(SolrBasicServer<SolrSku>));
Bind(typeof(ISolrOperations<SolrSku>)).To(typeof(SolrServer<SolrSku>));
Bind(typeof(ISolrReadOnlyOperations<SolrSku>)).To(typeof(SolrServer<SolrSku>));
Bind<ISolrService>().To<SolrService>();
}
}
Solrservice.cs
public class SolrService : ISolrService
{
public readonly ISolrReadOnlyOperations<SolrSku> _solr;
public SolrService(ISolrReadOnlyOperations<SolrSku> solr)
{
_solr = solr;
}
public ISolrQueryResults<SolrSku> SearchAll(string query)
{
var qopts = BuildParameters();
var results = _solr.Query(query, qopts);
return results;
}
private QueryOptions BuildParameters()
{
var qopts = new QueryOptions();
qopts.AddOrder(new SortOrder("dateAdded", Order.DESC));
return qopts;
}
}
While running the application, I am recieving the below error "Error activating ISolrQuerySerializer
No matching bindings are available, and the type is not self-bindable."
Am i missing something here or the way i am trying to use Solr in NInject is wrong?