Timeline for Can I use automatic dependency injection with computed search fields in Sitecore 8.1?
Current License: CC BY-SA 3.0
8 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Nov 4, 2022 at 21:52 | comment | added | Sebastian Tecsi | @DmytroShevchenko, did you manage to implement a fix for this? Just the other day I hit the same issue as you asked. | |
Nov 3, 2016 at 9:15 | comment | added | Andrey Bobrov | I have added an answer | |
Nov 3, 2016 at 9:14 | answer | added | Andrey Bobrov | timeline score: 3 | |
Nov 3, 2016 at 8:32 | comment | added | Dmytro Shevchenko | @adb That sounds interesting. Would you share this solution with more details as an answer? | |
Nov 3, 2016 at 8:28 | comment | added | Andrey Bobrov |
It is quite easy to find where the field is injected. So, when you add your computed index field there is a node with method in it: <fields hint="raw:AddComputedIndexField"> . The AddComputedIndexField leads us to the IDocumentBuilderOptions.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.
|
|
Nov 3, 2016 at 8:11 | comment | added | Dmytro Shevchenko | @adb Using the dependency resolver would defeat the purpose of using DI, which is the fact that my modules and components are not aware where the dependencies are coming from. Could you please clarify what you mean when you say I have to override the factory of index class? | |
Nov 3, 2016 at 8:05 | comment | added | Andrey Bobrov | I think if you want them to be inserted in the constructor (i.e. like in controller), you have to override the factory or index class. The easiest way is to use the standard Asp MVC dependency resolver + parameter-less constructor. p.s. Make sure that you investigate the computed field lifetime because I doubt it is being re-created each time it computes the value for indexing. | |
Nov 3, 2016 at 7:49 | history | asked | Dmytro Shevchenko | CC BY-SA 3.0 |