komal_sonigra
komal_sonigra

Reputation: 75

Class bound in gin singleton module, on switching browser tabs, always gets initialized

If I have a class bound in gin which is singleton as:

bind(SomeStore.class).in(Singleton.class);

While injecting this SomeStore class, it's instance always created new which is not supposed to be.

public class SomeStore {

    private HashMap<Integer, Serializable>  testMap;

    public SomeStore() {
    }

    public void addValue(Integer hashkey, Serializable serializable) {
        if (testMap == null)
            testMap = new HashMap<Integer, Serializable>();
        testMap.put(hashkey, serializable);
    }

    public Serializable getValue(Integer hashkey) {
        return testMap.get(hashkey);
    }
}

Does it remains singleton throughout the browser's different tabs, and even when the UI is reloaded. If not, what will be ideal solution to do so? What if I bound it in SessionScope?

Upvotes: 0

Views: 40

Answers (0)

Related Questions