com.vaadin.flow.di.
Interface Lookup
-
All Known Implementing Classes:
public interface Lookup
Provides a way to discover services used by Flow (SPI).
A lookup instance may be created based on a service, see
of(Object, Class...)
. Several lookup instances may be combined viacompose(Lookup, Lookup)
method which allows to make a lookup instance based on a number of services. The resulting lookup instance may be used in internal Flow code to transfer data in the unified way which allows to change the available data types during the code evolution without changing the internal API (like arguments in methods and constructors).There is the "global" application
Lookup
instance and theVaadinContext
. It has one to one mapping and is available even before aDeploymentConfiguration
(andVaadinServlet
) is created. So this is kind of a singleton for a Web Application. As a consequence it provides and may return only web app singleton services. Dependency injection frameworks can provide an implementation for the applicationLookup
which manages instances according to the conventions of that framework.The application
Lookup
is similar to theInstantiator
class but aLookup
instance is available even before aVaadinService
instance is created (and as a consequence there is no yet anInstantiator
instance).This is the code which one may use to get the application
Lookup
instance:VaadinContext context = ...; Lookup lookup = context.getAttribute(Lookup.class);
This SPI is mostly for internal framework usage since
Instantiator
provides all required services for the application developer.Since:
Author:
Vaadin Ltd
See Also:
-
-
Method Summary
All Methods Modifier and Type Method and Description static Lookup
compose(Lookup lookup1, Lookup lookup2)
Make a composite lookup which contains the services from both
lookup1
andlookup2
.<T> T
lookup(Class<T> serviceClass)
Lookup for a service of the given type.
<T> Collection<T>
lookupAll(Class<T> serviceClass)
Lookup for all services by the provided
serviceClass
.static <T> Lookup
of(T service, Class<? super T>... serviceTypes)
Creates a lookup which contains (only) the provided
service
as instance of givenserviceTypes
.
-
-
-
Method Detail
-
lookup
<T> T lookup(Class<T> serviceClass)
Lookup for a service of the given type.
The
serviceClass
is usually an interface (though it doesn't have to be) and the returned value is some implementation of this interface.Type Parameters:
T
- a service typeParameters:
serviceClass
- a service SPI classReturns:
a service which implements the
serviceClass
, may benull
if no services are registered for this SPISee Also:
-
lookupAll
<T> Collection<T> lookupAll(Class<T> serviceClass)
Lookup for all services by the provided
serviceClass
.The
serviceClass
is usually an interface class (though it doesn't have to be) and the returned value is all implementations of this interface.Type Parameters:
T
- a service typeParameters:
serviceClass
- a service SPI classReturns:
all services which implement the
serviceClass
, if no services found an empty list is returned (sonull
is not returned)
-
of
@SafeVarargs static <T> Lookup of(T service, Class<? super T>... serviceTypes)
Creates a lookup which contains (only) the provided
service
as instance of givenserviceTypes
.This method may be used to create a temporary lookup which then can be used to extend an existing lookup via
compose(Lookup, Lookup)
.Type Parameters:
T
- the service typeParameters:
service
- the service objectserviceTypes
- the supertypes of the service which may be used to access the serviceReturns:
a lookup initialized with the given
service
-
compose
static Lookup compose(Lookup lookup1, Lookup lookup2)
Make a composite lookup which contains the services from both
lookup1
andlookup2
.lookup(Class)
method will return the service from the first lookup if it's not null and fallbacks to thelookup2
otherwise. So the first lookup takes precedence. The methodlookupAll(Class)
simply combines all the services from both lookups.The resulting lookup is intended to be a "temporary" (short living) lookup to extend an existing lookup with some additional data which is required only in some isolated object.
Parameters:
lookup1
- the first lookup to composelookup2
- the second lookup to composeReturns:
the composite lookup
-
-