eclipse-sisu / sisu-project

Sisu Inject
https://www.eclipse.org/sisu
Eclipse Public License 2.0
17 stars 15 forks source link

Cache binding lookups for single bean providers #45

Closed mcculls closed 2 years ago

mcculls commented 2 years ago

Previously every call to provider.get() for a Sisu-managed Provider<T> resulted in a new binding lookup.

These extra lookups are unnecessary because Sisu will automatically update live lookups as injectors come and go. This is done to support dynamic maps/lists of beans, but it does mean we can cache binding lookups and re-use them for single providers as long as we only get instances via BeanEntry.getProvider().get().

Note: we can't use BeanEntry.getValue() when re-using binding lookups because it caches the instance, whereas here we always want to return a fresh bean instance.