com.vaadin.flow.di.
Interface Instantiator
All Superinterfaces:
All Known Implementing Classes:
Delegate for discovering, creating and managing instances of various types used by Flow. Dependency injection frameworks can provide an implementation that manages instances according to the conventions of that framework.
VaadinService
will by default use ServiceLoader
for finding
an instantiator implementation. If not found DefaultInstantiator
will
be used. It is possible to override this mechanism by overriding
VaadinService.createInstantiator()
.
Since:
1.0
Author:
Vaadin Ltd
-
Method Summary
Modifier and TypeMethodDescription<T extends Component>
TcreateComponent
(Class<T> componentClass) Creates an instance of a component by its
componentClass
.default <T extends HasElement>
TcreateRouteTarget
(Class<T> routeTargetType, NavigationEvent event) Creates an instance of a navigation target or router layout.
static Instantiator
Gets the instantiator to use for the given UI.
default Class<?>
getApplicationClass
(Class<?> clazz) Return the application-defined class for the given class: usually simply the given class, but the original class in case of a runtime generated subclass.
default Class<?>
getApplicationClass
(Object instance) Return the application-defined class for the given instance: usually simply the class of the given instance, but the original class in case of a runtime generated subclass.
default Stream<DependencyFilter>
getDependencyFilters
(Stream<DependencyFilter> serviceInitFilters) Processes the available dependency filters.
default I18NProvider
Get the I18NProvider if one has been defined.
default Stream<IndexHtmlRequestListener>
getIndexHtmlRequestListeners
(Stream<IndexHtmlRequestListener> indexHtmlRequestListeners) Processes the available Index HTML request listeners.
default MenuAccessControl
Get the MenuAccessControl.
<T> T
getOrCreate
(Class<T> type) Provides an instance of any given type, this is an abstraction that allows to make use of DI-frameworks from add-ons.
Gets all service init listeners to use.
-
Method Details
-
getServiceInitListeners
Stream<VaadinServiceInitListener> getServiceInitListeners()Gets all service init listeners to use. In addition to listeners defined in some way native to a specific instantiator, it is also recommended to support the default
ServiceLoader
convention. This can be done by including the items fromDefaultInstantiator.getServiceInitListeners()
in the returned stream.Returns:
stream of service init listeners, not
null
-
getIndexHtmlRequestListeners
default Stream<IndexHtmlRequestListener> getIndexHtmlRequestListeners(Stream<IndexHtmlRequestListener> indexHtmlRequestListeners) Processes the available Index HTML request listeners. This method can supplement the set of Index HTML request listeners provided by
VaadinServiceInitListener
implementations.The default implementation returns the original listeners without changes.
Parameters:
indexHtmlRequestListeners
- a stream of Index HTML request listeners provided by service init listeners, notnull
Returns:
a stream of all Index HTML request listeners to use, not
null
-
getDependencyFilters
Processes the available dependency filters. This method can supplement the set of dependency filters provided by
VaadinServiceInitListener
implementations.The default implementation returns the original handlers without changes.
The order of the filters inside the stream defines the order of the execution of those listeners by the
UidlWriter.createUidl(UI, boolean)
method.Parameters:
serviceInitFilters
- a stream of dependency filters provided by service init listeners, notnull
Returns:
a stream of all dependency filters to use, not
null
-
getOrCreate
Provides an instance of any given type, this is an abstraction that allows to make use of DI-frameworks from add-ons.
How the object is created and whether it is being cached or not is up to the implementation.
Type Parameters:
T
- the type of the instance to createParameters:
type
- the instance type to create, notnull
Returns:
an instance of the given type
-
getApplicationClass
Return the application-defined class for the given instance: usually simply the class of the given instance, but the original class in case of a runtime generated subclass.
Parameters:
instance
- the instance to checkReturns:
the user-defined class
-
getApplicationClass
Return the application-defined class for the given class: usually simply the given class, but the original class in case of a runtime generated subclass.
Parameters:
clazz
- the class to checkReturns:
the user-defined class
-
createComponent
Creates an instance of a component by its
componentClass
.Type Parameters:
T
- the component typeParameters:
componentClass
- the instance type to create, notnull
Returns:
the created instance, not
null
-
get
Gets the instantiator to use for the given UI.
Parameters:
ui
- the attached UI for which to find an instantiator, notnull
Returns:
the instantiator, not
null
-
getI18NProvider
Get the I18NProvider if one has been defined.
Returns:
I18NProvider instance
-
getMenuAccessControl
Get the MenuAccessControl.
Returns:
MenuAccessControl instance
-