When you add a computed index field to the configuration, the section uses a certain method to instantiate resulting .Net objects for each computed field type:
<fields hint="raw:AddComputedIndexField">
As we can see here, the method is the AddComputedIndexField function from the IDocumentBuilderOptions interface.
Depending on your configuration you should either override the Solr or Lucene document builder.
All in all they work kinda same. You should override the:
public virtual void AddComputedIndexField(XmlNode configNode)
Inside the AddComputedIndexField method it is calling the protected static CreateComputedIndexfield method that actually creates a field instance. You should probably copy its body (use reflector or dotPeek) and add something like
Container.GetInstance(typeName) as IComputedIndexField
in the end instead of standard reflection code.
The document builder can be replaced in the index configuration as follows:
<documentOptions type="TypeName, Assembly">
I haven't tested this approach, but it should work. Please, let me know if it worked for you.
<fields hint="raw:AddComputedIndexField">
. The AddComputedIndexField leads us to theIDocumentBuilderOptions.AddComputedIndexField(XmlNode configNode)
. Here you can see that field is created from the type attribute using reflection. This is a place to put your custom constructor behavior with DI.