gpt4 book ai didi

c# - 使用适当的 Windsor 服务覆盖是什么意思?

转载 作者:行者123 更新时间:2023-11-30 16:28:33 25 4
gpt4 key购买 nike

我正在尝试使用 SolrNet 为多实例 Solr 安装创建索引代理服务。我已经创建了该服务,它将使用一个接口(interface)来创建多个用于索引的代理。这些代理在外部配置文件中指定并动态实例化。例如,每种代理类型可以有 0-n 个(注意 url 差异):

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

这当然需要映射到这样的东西:

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

基于我的需要以及 SolrNet 不支持其默认容器的多个实例这一事实,我正在尝试为此使用 CaSTLe Windsor。根据位于 http://code.google.com/p/solrnet/wiki/MultiCoreAccess 的 SolrNet wiki这很简单。

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");

我并没有完全迷失 IoC 的概念,但我不确定 wiki 作者对 “使用适当的 Windsor 服务覆盖而不是像这样解析” 的评论是什么意思,如代码示例。显然该示例通过 id 明确标识了核心,但是否有更好/更灵活的方式?

最佳答案

我的意思是您通常不会解析ISolrOperations<T>直接从容器中。

相反,您使用 service overrides或其他温莎机制来定义哪些 ISolrOperations<T>组件(哪个核心)传递给其他组件,尤其是当您有多个具有相同文档类型的核心时,例如在此示例中,有两个组件在服务类型 ISolrOperations<Product> 下注册.

关于c# - 使用适当的 Windsor 服务覆盖是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7041730/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com