com.vaadin.flow.di.
Interface Lookup
All Known Implementing Classes:
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 via
compose(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 the
VaadinContext
. It has one to one mapping and is available even before
a DeploymentConfiguration
(and VaadinServlet
) 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 application Lookup
which manages instances according to the conventions of that framework.
The application Lookup
is similar to the Instantiator
class
but a Lookup
instance is available even before a
VaadinService
instance is created (and as a consequence there is no
yet an Instantiator
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
Modifier and TypeMethodDescriptionstatic Lookup
Make a composite lookup which contains the services from both
lookup1
andlookup2
.<T> T
Lookup for a service of the given type.
<T> Collection<T>
Lookup for all services by the provided
serviceClass
.static <T> Lookup
Creates a lookup which contains (only) the provided
service
as instance of givenserviceTypes
.
-
Method Details
-
lookup
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
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
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
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
-