com.vaadin.flow.di.

Interface Lookup

  • All Known Implementing Classes:

    LookupInitializer.LookupImpl


    public interface Lookup

    Provides a way to discover services used by Flow (SPI). Dependency injection frameworks can provide an implementation that manages instances according to the conventions of that framework.

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

    The Lookup instance and the VaadinContext 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.

    This is the code which one may use to get the 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:

    Instantiator

    • Method Summary

      All Methods
      Modifier and Type Method and Description
      <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.

    • 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 type

        Parameters:

        serviceClass - a service SPI class

        Returns:

        a service which implements the serviceClass, may be null if no services are registered for this SPI

        See Also:

        lookupAll(Class)

      • 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 type

        Parameters:

        serviceClass - a service SPI class

        Returns:

        all services which implement the serviceClass, if no services found an empty list is returned (so null is not returned)