
com.github.thorbenkuck.di.domain.provider.SingletonGenericIdentifiableProvider Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of wire-di-runtime-environment Show documentation
Show all versions of wire-di-runtime-environment Show documentation
Easy and simple di using annotation processors
The newest version!
package com.github.thorbenkuck.di.domain.provider;
import com.github.thorbenkuck.di.runtime.WireRepository;
import org.jetbrains.annotations.NotNull;
import java.util.function.Function;
class SingletonGenericIdentifiableProvider implements IdentifiableProvider {
@NotNull
private final Function creationFunction;
@NotNull
private final Class>[] wireTypes;
@NotNull
private final Class type;
private volatile T instance;
SingletonGenericIdentifiableProvider(
@NotNull final Function creationFunction,
@NotNull Class>[] wireTypes,
@NotNull Class type
) {
this.creationFunction = creationFunction;
this.type = type;
this.wireTypes = wireTypes;
}
@Override
@NotNull
public final Class> type() {
return type;
}
@Override
@NotNull
public final Class>[] wiredTypes() {
return wireTypes;
}
@Override
public final boolean isSingleton() {
return true;
}
@Override
@NotNull
public synchronized T get(@NotNull final WireRepository wiredRepository) {
if(instance == null) {
instance = creationFunction.apply(wiredRepository);
}
return instance;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy