All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.github.amayaframework.di.ServiceProviderImpl Maven / Gradle / Ivy

Go to download

A framework responsible for monitoring and automating the dependency injection process.

There is a newer version: 2.2.0
Show newest version
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