Class BeanBag.BeanBuilder<T>

  • Type Parameters:
    T - the bean type
    Enclosing class:
    BeanBag

    public static final class BeanBag.BeanBuilder<T>
    extends Object
    A builder for an individual bean's configuration.
    • Method Detail

      • setPriority

        public BeanBag.BeanBuilder<T> setPriority​(int priority)
        Set the bean priority. Higher numbers have higher precedence. Users should normally configure beans with a priority of 0 or higher.
        Parameters:
        priority - the bean priority
        Returns:
        this builder (not null)
      • setName

        public BeanBag.BeanBuilder<T> setName​(String name)
        Set the bean name. Beans with no name have a name of the empty string "".
        Parameters:
        name - the bean name (must not be null)
        Returns:
        this builder (not null)
      • addAlias

        public BeanBag.BeanBuilder<T> addAlias​(String alias)
        Add another name that this bean can be identified by.
        Parameters:
        alias - the bean alias (must not be null)
        Returns:
        this builder (not null)
      • setSupplier

        public BeanBag.BeanBuilder<T> setSupplier​(BeanSupplier<T> supplier)
        Set the supplier for this bean. Setting a supplier will overwrite a supplier created via buildSupplier() (if any).
        Parameters:
        supplier - the supplier instance (must not be null)
        Returns:
        this builder (not null)
      • setInstance

        public BeanBag.BeanBuilder<T> setInstance​(T instance)
        Set the supplier for this bean to a literal instance. Setting a supplier will overwrite a supplier created via buildSupplier() (if any). The bean will be marked as a singleton.
        Parameters:
        instance - the bean instance (must not be null)
        Returns:
        this builder (not null)
      • buildSupplier

        public BeanBag.SupplierBuilder<T> buildSupplier()
        Construct a reflective supplier for this bean. Completing this builder will overwrite the supplier created via setSupplier(BeanSupplier) (if any).
        Returns:
        a new supplier builder (not null)
      • setSingleton

        public BeanBag.BeanBuilder<T> setSingleton​(boolean singleton)
        Set the singleton flag for this bean. A singleton is created in a scope which is global to a single container.
        Parameters:
        singleton - the value of the singleton flag
        Returns:
        this builder (not null)
      • addRestrictedTypes

        public BeanBag.BeanBuilder<T> addRestrictedTypes​(Collection<Class<? super T>> types)
        Restrict the types of this bean. The bean will only be able to be looked up using one of these types.
        Parameters:
        types - the restricted types (must not be null)
        Returns:
        this builder (not null)
      • build

        public BeanBag.Builder build()
        Commit this bean definition into the enclosing container builder.
        Returns:
        the container builder (not null)