InstanceSupplier Type — spring-boot Architecture
Architecture documentation for the InstanceSupplier type/interface in BootstrapRegistry.java from the spring-boot codebase.
Entity Profile
Source Code
core/spring-boot/src/main/java/org/springframework/boot/bootstrap/BootstrapRegistry.java lines 99–163
@FunctionalInterface
interface InstanceSupplier<T> {
/**
* Factory method used to create the instance when needed.
* @param context the {@link BootstrapContext} which may be used to obtain other
* bootstrap instances.
* @return the instance or {@code null}
*/
@Nullable T get(BootstrapContext context);
/**
* Return the scope of the supplied instance.
* @return the scope
*/
default Scope getScope() {
return Scope.SINGLETON;
}
/**
* Return a new {@link InstanceSupplier} with an updated {@link Scope}.
* @param scope the new scope
* @return a new {@link InstanceSupplier} instance with the new scope
*/
default InstanceSupplier<T> withScope(Scope scope) {
Assert.notNull(scope, "'scope' must not be null");
InstanceSupplier<T> parent = this;
return new InstanceSupplier<>() {
@Override
public @Nullable T get(BootstrapContext context) {
return parent.get(context);
}
@Override
public Scope getScope() {
return scope;
}
};
}
/**
* Factory method that can be used to create an {@link InstanceSupplier} for a
* given instance.
* @param <T> the instance type
* @param instance the instance
* @return a new {@link InstanceSupplier}
*/
static <T> InstanceSupplier<T> of(@Nullable T instance) {
return (registry) -> instance;
}
/**
* Factory method that can be used to create an {@link InstanceSupplier} from a
* {@link Supplier}.
* @param <T> the instance type
* @param supplier the supplier that will provide the instance
* @return a new {@link InstanceSupplier}
*/
static <T> InstanceSupplier<T> from(@Nullable Supplier<T> supplier) {
return (registry) -> (supplier != null) ? supplier.get() : null;
}
}
Source
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free