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

net.contextfw.web.application.internal.scope.WebApplicationScopedBeans Maven / Gradle / Ivy

package net.contextfw.web.application.internal.scope;

import java.util.HashMap;
import java.util.Map;

import com.google.inject.Key;

public class WebApplicationScopedBeans {

    private static volatile ThreadLocal currentInstance = new ThreadLocal();

    private Map, Object> beans = new HashMap, Object>();

    public Map, Object> getBeans() {
        return beans;
    }

    public static WebApplicationScopedBeans getCurrentInstance() {
        return currentInstance.get();
    }

    public void setAsCurrentInstance() {
        currentInstance.set(this);
    }

    public static void clearCurrentInstance() {
        currentInstance.set(null);
    }

    public static WebApplicationScopedBeans createNewInstance() {
        currentInstance.set(new WebApplicationScopedBeans());
        return currentInstance.get();
    }

    public  void seed(Class clazz, T value) {
        seed(Key.get(clazz), value);
    }

    public  void seed(Key key, T value) {
        beans.put(key, value);
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy