【发布时间】:2016-02-22 21:11:41
【问题描述】:
您好,我有一个非常大的问题。我需要与单一类型的一个核心建立/创建连接并进行任何操作。 现在它看起来像:
public class SolrMachine<T> : ISolrMachine<T> where T : ISolrRecord
{
private ISolrOperations<T> actuallyInstance { get; set; }
public SolrMachine(string coreName)
{
string url = String.Format("http://xxxx/solr/{0}", coreName);
ISolrConnection solrConnection = new SolrConnection(url) { HttpWebRequestFactory = new SolrAuthWebRequestFactory()};
Startup.Init<T>(solrConnection);
var myInstance = ServiceLocator.Current.GetInstance<ISolrOperations<T>>();
this.actuallyInstance = myInstance;
}
}
ISolrMachine<T> 是我在 solr 核心上操作的方法的接口。 ISolrRecord 是一个在我的内核中有属性的接口。
现在,当我与其他两个核心进行连接时,一切正常。
SolrMachine<SolrTypeOne> firstCoreConnection = new SolrMachine<SolrTypeOne>(firstCoreName);
SolrMachine<SolrTypeTwo> secondCoreConnection = new SolrMachine<SolrTypeTwo>(secondCoreName);
// operation on firstCoreConnection and secondCoreConnection works
但是当我尝试连接一种类型和一种 coreName 时,Startup.Init<T>(solrConnection) 出现异常。我知道Startup 容器阻止了与相同Type 和coreName 的连接,但我总是为这个SolrMachine 创建一个新实例。我希望这样:
class SomeClass
{
public MyMethod()
{
SolrMachine<SolrTypeOne> myConn = new SolrMachine<SolrTypeOne>(firstCoreName);
// operation
}
}
class SecondSomeClass
{
public MyMethod()
{
SolrMachine<SolrTypeOne> myConn2 = new SolrMachine<SolrTypeOne>(firstCoreName);
// here it's not work
}
}
如何避免这种情况?
【问题讨论】:
-
我的案子有答案了吗? :)
-
"内置容器目前仅限于访问具有不同映射类型的多个核心/实例。"
-
是的,我知道,我之前说过。现在我正在尝试使用结构图和温莎设施。在结构图中我有错误:
Cannot initialize type 'StructureMap.SolrNetIntegration.Config.SolrServers' with a collection initializer because it does not implement -
你能在github.com/mausch/SolrNet/issues 中发布那个 StructureMap 错误吗?