Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Update based on feedback

...

Please keep the discussion on the mailing list rather than commenting on the wiki (wiki discussions get unwieldy fast). Confluence supports inline comments that can also be used.

Motivation

  • Use a standardized dependency injection in Solr instead of

...

  • several brittle home grown

...

  • interfaces (@SolrCoreAware, @ResourceLoaderAware, @SchemaAware

...

Proposal is to do a trial with Dagger2 (https://github.com/google/dagger) which is a compile-time depenency injection framework.

Public Interfaces

  • ) that tend to not work in all situations.
  • Limit huge constructors that pass instances around
  • Easier code maintenance 

Public Interfaces

No user-facing changes on HTTP APIs or configs.

Some plugins will change API that is not Many plugins will change API which will affect back-compat.

Proposed Changes

Too early to propose concrete design now, but start with a POC to prove the concept on a limited part of the code.

Introduce a well supported IOC/DI framework to gradually replace the home-grown interfaces which are brittle (see

Jira
serverASF JIRA
serverId5aa69414-a9e9-3523-82ec-879b028fb15b
keySOLR-16203
,
Jira
serverASF JIRA
serverId5aa69414-a9e9-3523-82ec-879b028fb15b
keySOLR-8311
https://github.com/apache/solr/blob/main/solr/core/src/java/org/apache/solr/core/SolrResourceLoader.java#L815-L816)).

This will be a large change across the entire code base. Dagger The framework will scan the codebase for annotations and generate new Java code that will be used run-time.

There are several CI frameworks to choose from, and the next section details some of them. 

There are several CI frameworks to choose from, see sub section "Choice of DI framework". I'd favour a compile-time framework like Avaje or Dagger2.

Choice of DI framework

Here is a list stolen from a reddit thread:

  • Avaje*
  • Dagger 2*
  • Dirk
  • Feather
  • Guice
  • Glassfish HK2 (Solr already has limited use of this in Jersey JAX-RS)
  • Inverno*
  • Jaywire
  • JBock*
  • Spring
  • Weld

Some of these use runtime reflection to build the graph, others (the ones marked with an asterisk) use compile-time code generation.

Code samples for each can be found in this repo: https://github.com/Col-E/Useful-Things/tree/master/tutorials/dependency-injection

Wrt the existing use of HK2 it can be investigated whether we can keep it in parallel with Avaje/Dagger or switch overThe exact scope is still unclear, but we recommend starting with a small module or one interface.

Compatibility, Deprecation, and Migration Plan

...

Rejected Alternatives

  • Spring Framework, Micronaut or other larger framework - too intrusive
  • Guice and other reflection based frameworks - injection happens during runtime, hard to debug
  • Continue as we do, Improve our own home grown annotations