Package org.eclipse.sisu.inject
package org.eclipse.sisu.inject
Dynamic bean lookup across multiple injectors.
The BeanLocator
lets you lookup and keep watch for bean implementations;
it does this by processing binding information from one or more BindingPublisher
s, such as injectors.
You can add or remove BindingPublisher
s using the MutableBeanLocator
view; any existing watchers or returned collections are updated to reflect the latest binding information.
DefaultBeanLocator
will automatically add any injectors it's bound in by virtue
of an injected setter. This makes it easy to share across multiple injectors with a simple instance binding:
Module locatorModule = new AbstractModule() { private final DefaultBeanLocator locator = new DefaultBeanLocator(); @Override protected void configure() { bind( DefaultBeanLocator.class ).toInstance( locator ); } }; Injector injectorA = Guice.createInjector( new WireModule( locatorModule, spaceModuleA ) ); // adds injectorA to locator Injector injectorB = Guice.createInjector( new WireModule( locatorModule, spaceModuleB ) ); // adds injectorB to locatorIf you want to use a
DefaultBeanLocator
in a given injector, but don't want that injector
added automatically, wrap the locator inside a provider to hide the injected setter from Guice:
bind( DefaultBeanLocator.class ).toProvider( Providers.of( locator ) );By default all bindings in an injector are separated into two partitions (default vs non-default) and ranked according to their sequence number. This is so bindings from multiple injectors can be interleaved to keep default components prioritized before non-default, while still maintaining an overall ordering between injectors. To override the default bind your own
RankingFunction
:
bind( RankingFunction.class ).to( MyRankingFunction.class );
-
ClassDescriptionBinding source locations can implement this interface to supply annotations to the
BeanLocator
.Finds and tracks bean implementations annotated withQualifier
annotations.Publisher ofBinding
s to interestedBindingSubscriber
s.Subscriber ofBinding
s from one or moreBindingPublisher
s.DefaultMutableBeanLocator
that locates qualified beans across a dynamic group ofBindingPublisher
s.SimpleRankingFunction
that partitions qualified bindings into two main groups.PlaceholderClass
; postpones classloading until absolutely necessary.Provider
backed by aDeferredClass
.Utility methods for dealing with changes in the Guice 4.0 SPI.Legacy<S>Deprecated.Limited support for migrating legacy types.Utility methods for dealing with container logging and recovery.MutableBeanLocator
that finds and tracks bindings across zero or moreBindingPublisher
s.Assigns eachBinding
a rank according to some function; higher ranks take precedence over lower ranks.Utility methods for dealing withSoftReference
collections.Utility methods for dealing with annotated sources.Utility methods for dealing with generic type arguments.Utility methods for dealing withWeakReference
collections.