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

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

package io.github.amayaframework.di;

import com.github.romanqed.jfunc.Function0;

import java.util.function.Function;

/**
 * An interface describing the read-only version of the repository - the artifact provider.
 * It is used inside the builder implementation when resolving artifacts.
 */
public interface ArtifactProvider extends Function> {

    /**
     * Gets the instantiator associated with the specified artifact.
     *
     * @param artifact the specified artifact
     * @return null or {@link Function0} instance
     */
    Function0 apply(Artifact artifact);

    /**
     * Gets the instantiator associated with the specified type.
     *
     * @param type the specified type
     * @param   service type
     * @return null or {@link Function0} instance
     */
    @SuppressWarnings("unchecked")
    default  Function0 apply(Class type) {
        return (Function0) apply(new Artifact(type));
    }
}