Interface BeanRegistry

All Superinterfaces:
Service
All Known Implementing Classes:
DefaultBeanRegistry

@Incubating public interface BeanRegistry extends Service
Represents a bean registry used to lookup components by name and type. The BeanRegistry extends the Service contract, allowing it to be exposed via the service registry to any service easily.
Author:
Chris Cranford
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    add(String name, Class<?> type, Object bean)
    Adds a bean to the registry.
    void
    add(String name, Object bean)
    Adds a bean to the registry, resolving the class type from the bean instance.
    <T> Set<T>
    findByType(Class<T> type)
    Finds all beans that are registered by the specified type.
    <T> Map<String,T>
    Finds all beans that are registered with the specified type.
    <T> T
    lookupByName(String name, Class<T> type)
    Lookup a specific bean by its name and type.
    void
    remove(String name)
    Remove a bean from the registry by name.
  • Method Details

    • findByType

      <T> Set<T> findByType(Class<T> type)
      Finds all beans that are registered by the specified type.
      Parameters:
      type - the class type to lookup
      Returns:
      set of all beans found, may be empty, never null
    • findByTypeWithName

      <T> Map<String,T> findByTypeWithName(Class<T> type)
      Finds all beans that are registered with the specified type.
      Parameters:
      type - the class type to lookup
      Returns:
      map of bean instances with their mapping register names, may be empty, never null
    • lookupByName

      <T> T lookupByName(String name, Class<T> type)
      Lookup a specific bean by its name and type.
      Parameters:
      name - the bean name to find
      type - the bean type to find
      Returns:
      the bean or null if the bean could not be found
    • add

      void add(String name, Class<?> type, Object bean)
      Adds a bean to the registry.
      Parameters:
      name - the bean name the instance should be registered with, should not be null
      type - the bean class type, should not be null
      bean - the bean instance, should not be null
    • add

      void add(String name, Object bean)
      Adds a bean to the registry, resolving the class type from the bean instance.
      Parameters:
      name - the bean name the instance should be registered with, should not be null
      bean - the bean instance, should not be null
    • remove

      void remove(String name)
      Remove a bean from the registry by name.
      Parameters:
      name - the bean name