Class KeyScope<T>

java.lang.Object
io.inverno.mod.base.Scope<T>
io.inverno.mod.base.KeyScope<T>
Type Parameters:
T - the type of the scoped instances

public abstract class KeyScope<T> extends Scope<T>

A key scope is used to provide bean instances bound to an arbitrary key.

Since:
1.2
Author:
Jeremy Kuhn
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates a key scope.
  • Method Summary

    Modifier and Type
    Method
    Description
    final T
    get(Object key)
    Returns the instance bound to the specified key.
    protected void
    hookOnGet(T instance)
    Optional hook executed when an instance is retrieved.
    final void
    Removes the instance currently bound to the specified key.

    Methods inherited from class io.inverno.mod.base.Scope

    create

    Methods inherited from class java.lang.Object

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

    • KeyScope

      public KeyScope()
      Creates a key scope.
  • Method Details

    • hookOnGet

      protected void hookOnGet(T instance)

      Optional hook executed when an instance is retrieved.

      Parameters:
      instance - the instance
    • get

      public final T get(Object key)

      Returns the instance bound to the specified key.

      If no instance is bound to the key, a new instance is created and kept in the scope.

      Parameters:
      key - the key defining the scope of the instance
      Returns:
      the instance
    • remove

      public final void remove(Object key)

      Removes the instance currently bound to the specified key.

      Parameters:
      key - the key defining the scope of the instance