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

com.github.charlemaznable.varys.guice.VarysModular Maven / Gradle / Ivy

package com.github.charlemaznable.varys.guice;

import com.github.charlemaznable.configservice.ConfigModular;
import com.github.charlemaznable.httpclient.ohclient.OhModular;
import com.github.charlemaznable.varys.config.VarysConfig;
import com.github.charlemaznable.varys.impl.Query;
import com.google.inject.AbstractModule;
import com.google.inject.Module;
import com.google.inject.util.Providers;

import static com.github.charlemaznable.core.lang.Listt.newArrayList;

public final class VarysModular {

    private OhModular ohModular;

    public VarysModular() {
        this((VarysConfig) null);
    }

    public VarysModular(Class configClass) {
        this(new ConfigModular().bindClasses(configClass).createModule());
    }

    public VarysModular(VarysConfig configImpl) {
        this(new AbstractModule() {
            @Override
            protected void configure() {
                bind(VarysConfig.class).toProvider(Providers.of(configImpl));
            }
        });
    }

    public VarysModular(Module configModule) {
        this.ohModular = new OhModular(configModule).bindClasses(Query.class);
    }

    public VarysModular bindOtherClients(Class... otherClientClasses) {
        return bindOtherClients(newArrayList(otherClientClasses));
    }

    public VarysModular bindOtherClients(Iterable> otherClientClasses) {
        this.ohModular.bindClasses(otherClientClasses);
        return this;
    }

    public VarysModular scanOtherClientPackages(String... basePackages) {
        return scanOtherClientPackages(newArrayList(basePackages));
    }

    public VarysModular scanOtherClientPackages(Iterable basePackages) {
        this.ohModular.scanPackages(basePackages);
        return this;
    }

    public VarysModular scanOtherClientPackageClasses(Class... basePackageClasses) {
        return scanOtherClientPackageClasses(newArrayList(basePackageClasses));
    }

    public VarysModular scanOtherClientPackageClasses(Iterable> basePackageClasses) {
        this.ohModular.scanPackageClasses(basePackageClasses);
        return this;
    }

    public Module createModule() {
        return this.ohModular.createModule();
    }

    public  T getClient(Class ohClass) {
        return this.ohModular.getClient(ohClass);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy