如何在Windsor容器中注册ISolrFieldSerializer,以便SolrNet可以接收它 [英] How to register a ISolrFieldSerializer in Windsor container so that SolrNet can pick it up

查看:101
本文介绍了如何在Windsor容器中注册ISolrFieldSerializer,以便SolrNet可以接收它的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试获取一个枚举,以在发布到Solr时序列化为它的int值。

I am trying to get an enum to serialize to it's int value when posting to Solr.

所以我实现了 ISolrFieldSerializer 做到这一点,如建议此处。但是我似乎可以在 Windsor 容器被SolrNet使用的方式

So I have implemented a ISolrFieldSerializer to do this, As suggested here. But I can seem to register it within the Windsor container in a way that it then gets used by SolrNet

这里是我所拥有的:

这尽管序列化程序出现在容器组件列表中,但它没有被使用,但工作正常。有什么想法吗?

This works fine apart from the serializer does not get used, although it appears in the containers components list. Any ideas?

    container.Register(Component.For<ISolrFieldSerializer>().ImplementedBy<SolrEnumSerializer>());
    Startup.Init<SearchBox>("http://10.10.10.10:0000/solr/boxes");

    container.Register(Component.For<ISolrOperations<SearchBox>>()
                          .UsingFactoryMethod(k => ServiceLocator.Current.GetInstance<ISolrOperations<SearchBox>>()));


推荐答案

我通过删除默认实现并将其替换对它进行了排序并带有一个自定义变量:

I sorted this by removing the default implementation and replace it with a custom one:

Startup.Container.Remove<ISolrFieldSerializer>();

var fieldSerializer = new CustomSerializer();
Startup.Container.Register<ISolrFieldSerializer>(c => fieldSerializer);

自定义缩放器:

public class CustomSerializer : ISolrFieldSerializer 
    {
        private readonly AggregateFieldSerializer _serializer;

        public CustomSerializer()
        {
            _serializer = new AggregateFieldSerializer(new ISolrFieldSerializer[]
                                                          {
                                                              new MyCustom1Serializer(),
                                                              new MyCustom2Serializer(),
                                                              new CollectionFieldSerializer(this),
                                                              new GenericDictionaryFieldSerializer(this),
                                                              new NullableFieldSerializer(new BoolFieldSerializer()),
                                                              new NullableFieldSerializer(new DateTimeFieldSerializer()),
                                                              //new MoneyFieldSerializer(),
                                                              new FormattableFieldSerializer(),
                                                              new TypeConvertingFieldSerializer(),


                                                          });
        }

        public  bool CanHandleType(Type t)
        {
            return _serializer.CanHandleType(t);
        }

        public IEnumerable<PropertyNode> Serialize(object obj)
        {
            return _serializer.Serialize(obj);
        }
    }

这篇关于如何在Windsor容器中注册ISolrFieldSerializer,以便SolrNet可以接收它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆