简体   繁体   English

杜松子酒注入和从异步服务读取配置

[英]gin inject and read config from async service

i have got module and this module only read config from server via async callbacK: 我有模块,该模块仅通过异步callbacK从服务器读取配置:

@Singleton
public class Config {

private ConnectionSettings connectionSettings;

@Inject
protected Config(final MainRPCAsync mainRpc) {  

      configureConnection(mainRpc);
}

private void configureConnection(MainRPCAsync mainRpc) {

    Log.debug("****Configure connection..");

    mainRpc.getConfig(new AsyncCallback<Configuration>() {

        @Override
        public void onSuccess(Configuration result) {
            Log.debug("-----------Get config");
                                 //initialize configuration settings

            });             

        }

    });

and next this class Config is injected to another module but when i need to get configSettings from that module i get only null .... 然后将此类Config注入到另一个模块,但是当我需要从该模块获取configSettings时,我只会得到null ...。

and in log console i read info that line Log.debug("-----------Get config"); 在日志控制台中,我读取了Log.debug("-----------Get config");行的信息Log.debug("-----------Get config"); show info after all ... 毕竟显示信息...

Its possible be sure that connection settings will be initialized by rpc async before injection that class to another module ? 是否有可能确保在将该类注入到另一个模块之前,将通过rpc async初始化连接设置?

I have the same need. 我有同样的需求。 I want to pass the result into a widget created with GIN. 我想将结果传递到使用GIN创建的小部件中。

UPDATE I resolved with Assisted Injection. 更新我通过辅助注射解决了。 So, I create my widget into success method of async service, and I use the result for create my widget. 因此,我将小部件创建为异步服务的成功方法,然后将结果用于创建小部件。

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

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