Interface Scope

All Known Implementing Classes:
ScopedValueScope
Functional Interface:
This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.

@FunctionalInterface public interface Scope
Controls the lifecycle and sharing of instances produced by a Binding. A Scope wraps an unscoped ValueBinding and returns a new Binding that applies the scope's caching or sharing strategy.

Register custom scopes via InjectionFramework.bindScope(Class, Scope).

The built-in implementation is ScopedValueScope, which uses a ScopedValue to cache one instance per structured scope invocation.

Since:
Apr-2026
Author:
reed.vonredwitz
See Also:
  • Method Details

    • scope

      Binding<?> scope(ValueBinding<?> binding)
      Wraps the given unscoped ValueBinding in a scoped Binding. The returned binding may cache, share, or re-create instances according to the scope's strategy.

      The signature uses wildcards so that implementations may be expressed as lambdas. The framework guarantees that the returned Binding produces values that are assignment-compatible with the type represented by Binding.dependency().

      Parameters:
      binding - the unscoped ValueBinding whose ValueBinding.value() creates a fresh instance on each call
      Returns:
      a scoped Binding implementing this scope's instance lifecycle