Interface Instantiator

All Superinterfaces:
Serializable
All Known Implementing Classes:
DefaultInstantiator, SpringInstantiator

public interface Instantiator extends Serializable
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 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 from DefaultInstantiator.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, not null
      Returns:
      a stream of all Index HTML request listeners to use, not null
    • getDependencyFilters

      default Stream<DependencyFilter> getDependencyFilters(Stream<DependencyFilter> serviceInitFilters)
      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, not null
      Returns:
      a stream of all dependency filters to use, not null
    • getOrCreate

      <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.

      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, not null
      Returns:
      an instance of the given type
    • createRouteTarget

      default <T extends HasElement> T createRouteTarget(Class<T> routeTargetType, NavigationEvent event)
      Creates an instance of a navigation target or router layout. This method is not called in cases when a component instance is reused when navigating.
      Type Parameters:
      T - the route target type
      Parameters:
      routeTargetType - the instance type to create, not null
      event - the navigation event for which the instance is created, not null
      Returns:
      the created instance, not null
    • createComponent

      <T extends Component> T createComponent(Class<T> componentClass)
      Creates an instance of a component by its componentClass.
      Type Parameters:
      T - the component type
      Parameters:
      componentClass - the instance type to create, not null
      Returns:
      the created instance, not null
    • get

      static Instantiator get(UI ui)
      Gets the instantiator to use for the given UI.
      Parameters:
      ui - the attached UI for which to find an instantiator, not null
      Returns:
      the instantiator, not null
    • getI18NProvider

      default I18NProvider getI18NProvider()
      Get the I18NProvider if one has been defined.
      Returns:
      I18NProvier instance