简体   繁体   English

重置活动后如何销毁单例?

[英]How to destroy singleton when activity is reset?

I use gwt 2.8 anf google-gin 2.12 我使用gwt 2.8和google-gin 2.12

I would like to inject some object into a deep custom com.google.gwt.user.client.ui.composite . 我想将一些对象注入到深度自定义com.google.gwt.user.client.ui.composite

For instance this composite may contain a panel which contains other UIBinded views which can contains other nested element... 例如,此复合材料可能包含一个面板,其中包含其他UIBinded视图,该视图可以包含其他嵌套元素...

DeepComposite
    \ APanel
        \ AnObjectToShare
        \ View1
        \ View2
            \ AnotherPanel
                \ AnObjectToShare
        \ View3
            \ AnObjectToShare

You can see in this hierarchy there is an AnObjectToShare I need to access at various level. 您可以在此层次结构中看到我需要在各个级别访问的AnObjectToShare

My first reflex was to inject it as Scope.SINGLETON . 我的第一个反应是将其作为Scope.SINGLETON注入。 But today I see it too intrusive, as if I run a new activity which initialize a new DeepComposite (which is the starting point of my g-in-jection context), my previous AnObjectToShare instance is reused. 但是今天,我看到它太麻烦了,好像我运行一个初始化新DeepComposite的新活动(这是我的g 注入上下文的起点)一样,我的以前的AnObjectToShare实例被重用了。

To resume I'm looking for a way to make my singletons to be singleton only on my current context. 要恢复,我正在寻找一种方法使我的单身人士仅在当前环境下成为单身人士。 Or a way to reset my singleton. 或重置我的单身人士的方法。 Or any other idea or workaround to resolve this issue. 或任何其他想法或解决方法来解决此问题。

Unfortunately, GIN doesn't support custom scopes; 不幸的是,GIN不支持自定义范围。 but maybe you could migrate to Dagger? 但也许您可以迁移到Dagger? (which would support your use case) (这将支持您的用例)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM