io.github.amayaframework.di.ServiceProviderImpl Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of amaya-di Show documentation
Show all versions of amaya-di Show documentation
A framework responsible for monitoring and automating the dependency injection process.
package io.github.amayaframework.di;
import com.github.romanqed.jfunc.Exceptions;
import com.github.romanqed.jfunc.Function0;
final class ServiceProviderImpl implements ServiceProvider {
private final Repository repository;
ServiceProviderImpl(Repository repository) {
this.repository = repository;
}
@Override
public Repository getRepository() {
return repository;
}
@Override
@SuppressWarnings("unchecked")
public Function0 get(Artifact artifact) {
return (Function0) repository.get(artifact);
}
@Override
@SuppressWarnings("unchecked")
public Function0 get(Class type, Class>... generics) {
return (Function0) repository.get(new Artifact(type, generics));
}
@Override
@SuppressWarnings("unchecked")
public Function0 get(Class type) {
return (Function0) repository.get(new Artifact(type));
}
@Override
@SuppressWarnings("unchecked")
public T instantiate(Artifact artifact) {
var supplier = get(artifact);
if (supplier == null) {
return null;
}
return (T) Exceptions.suppress(supplier);
}
@Override
public T instantiate(Class type, Class>... generics) {
var supplier = get(type, generics);
if (supplier == null) {
return null;
}
return Exceptions.suppress(supplier);
}
@Override
public T instantiate(Class type) {
var supplier = get(type);
if (supplier == null) {
return null;
}
return Exceptions.suppress(supplier);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy