de.leanovate.pragmatic.ioc.Injectors Maven / Gradle / Ivy
The newest version!
package de.leanovate.pragmatic.ioc;
import java.util.Optional;
import java.util.function.Supplier;
/**
* Collection of commonly used {@link de.leanovate.pragmatic.ioc.Injector}s.
*/
public class Injectors {
/**
* Create a singleton injector for a type.
*
* @param injectedClass the type to be injected
* @param supplier the supplier of the singleton instance (in production is is only invoked once)
* @param the type to be injected
* @return singleton injector for {@code T}
*/
public static Injector singleton(final Class injectedClass, final Supplier extends T> supplier) {
return new ScopedInjector<>(injectedClass, Optional.empty(), Scopes::getSingletonScope, supplier);
}
}