Class Module.Bean<T>

java.lang.Object
io.inverno.core.v1.Module.Bean<T>
Type Parameters:
T - the actual type of the bean
All Implemented Interfaces:
Supplier<T>
Enclosing class:
Module

protected abstract static class Module.Bean<T> extends Object implements Supplier<T>

Interface representing the lifecycle of a bean in a module.

Module.Bean instances are used within modules during initialization to perform dependency injection in order to defer the actual beans instantiation beans at module startup. Dependency cycles, missing dependencies and other issues related to dependency injection are normally raised at compile time.

A bean has to be registered in a module before it can be used.

Since:
1.0
Author:
Jeremy Kuhn
See Also:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected String
    The bean name.
    protected Module
    The module into which the bean is registered.
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    Bean(String name)
    Creates a bean with the specified name.
  • Method Summary

    Modifier and Type
    Method
    Description
    abstract void
    Creates the underlying bean instance
    abstract void
    Destroys the underlying instance.
    abstract T
    Returns the supplied bean instance.
    final T
    get()
    Returns the requested bean instance while making sure the enclosing module is active.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • parent

      protected Module parent
      The module into which the bean is registered.
    • name

      protected String name
      The bean name.
  • Constructor Details

    • Bean

      protected Bean(String name)

      Creates a bean with the specified name.

      Parameters:
      name - the bean name
  • Method Details

    • get

      public final T get() throws IllegalStateException

      Returns the requested bean instance while making sure the enclosing module is active.

      In case the enclosing module is not active but one of its ancestors is active, this method starts the enclosing module in order to start modules in their natural order. If no ancestor is active (ie. the enclosing module is not part of a module initialization process), an IllegalStateException is thrown.

      Specified by:
      get in interface Supplier<T>
      Throws:
      IllegalStateException - if the enclosing module is inactive and not part of a module initialization process.
    • doGet

      public abstract T doGet()

      Returns the supplied bean instance.

      Returns:
      a bean instance
    • create

      public abstract void create()

      Creates the underlying bean instance

    • destroy

      public abstract void destroy()

      Destroys the underlying instance.