Package com.netflix.governator.guice.bootstrap

Source Code of com.netflix.governator.guice.bootstrap.GovernatorBootstrap

package com.netflix.governator.guice.bootstrap;

import com.google.inject.Inject;
import com.google.inject.ProvisionException;
import com.netflix.governator.guice.BootstrapBinder;
import com.netflix.governator.guice.BootstrapModule;
import com.netflix.governator.guice.ModuleTransformer;
import com.netflix.governator.guice.PostInjectorAction;
import com.netflix.governator.guice.annotations.GovernatorConfiguration;

/**
* Implementation for the @GovernatorConfiguration main bootstrap class annotation
*/
public class GovernatorBootstrap implements BootstrapModule {

    private final GovernatorConfiguration config;
   
    @Inject
    public GovernatorBootstrap(GovernatorConfiguration config) {
        this.config = config;
    }
   
    @Override
    public void configure(BootstrapBinder binder) {
        if (config.enableAutoBindSingleton() == false)
            binder.disableAutoBinding();
        binder.inStage(config.stage());
        binder.inMode(config.mode());
       
        for (Class<? extends PostInjectorAction> action : config.actions()) {
            try {
                binder.bindPostInjectorAction().to(action);
            } catch (Exception e) {
                throw new ProvisionException("Error creating postInjectorAction '" + action.getName() + "'", e);
            }
        }
       
        for (Class<? extends ModuleTransformer> transformer : config.transformers()) {
            try {
                binder.bindModuleTransformer().to(transformer);
            } catch (Exception e) {
                throw new ProvisionException("Error creating postInjectorAction '" + transformer.getName() + "'", e);
            }
        }   
    }
}
TOP

Related Classes of com.netflix.governator.guice.bootstrap.GovernatorBootstrap

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.