Package com.vaadin.flow.di
Interface Instantiator
- All Superinterfaces:
Serializable
- All Known Implementing Classes:
DefaultInstantiator
,SpringInstantiator
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 itscomponentClass
.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 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.<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 defaultServiceLoader
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 byVaadinServiceInitListener
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 byVaadinServiceInitListener
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 create- Parameters:
type
- the instance type to create, notnull
- Returns:
- an instance of the given type
-
createComponent
Creates an instance of a component by itscomponentClass
.- Type Parameters:
T
- the component type- Parameters:
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:
- I18NProvier instance
-