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

com.github.rainbow.util.SpringInjector Maven / Gradle / Ivy

The newest version!
package com.github.rainbow.util;

import com.github.rainbow.property.SpringValueRegistry;
import com.google.inject.AbstractModule;
import com.google.inject.Guice;
import com.google.inject.Injector;
import com.google.inject.Singleton;

public class SpringInjector {
  private static volatile Injector s_injector;
  private static final Object lock = new Object();

  private static Injector getInjector() {
    if (s_injector == null) {
      synchronized (lock) {
        if (s_injector == null) {
          try {
            s_injector = Guice.createInjector(new SpringModule());
          } catch (Throwable ex) {
            throw ex;
          }
        }
      }
    }

    return s_injector;
  }

  public static  T getInstance(Class clazz) {
    try {
      return getInjector().getInstance(clazz);
    } catch (Throwable ex) {
      throw ex;
    }
  }

  private static class SpringModule extends AbstractModule {
    @Override
    protected void configure() {
      bind(PlaceholderHelper.class).in(Singleton.class);
      bind(SpringValueRegistry.class).in(Singleton.class);
    }
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy