如何在引导后注入Session/User对象?

dis*_*ame 5 java gwt gwt-platform gwtp

有些示例会将不同类型的对象注入演示者,但我无法找到解释如何完成此操作的示例.

Bootstrap-Code示例中,它们正在注入例如SecurityDelegate对象.

同样在Gatekeeper示例中,我看到正在注入的东西,例如MyGatekeeper,但这是如何完成的?

我想要的是首先检查用户是否登录,然后创建一个CurrentSession对象或类似的东西.但是我怎么能传递/注入这个对象呢?

目前我正在初始化一个单身对象CurrentUser,这是一种丑陋的imho.我想让GWTP支持运行,但是怎么样?


以这个CurrentSession被注入网守的例子为例:

@DefaultGatekeeper
public class LoggedInGatekeeper implements Gatekeeper {
    private final CurrentSession currentSession;

    @Inject
    LoggedInGatekeeper(CurrentSession currentSession) {
        this.currentSession = currentSession;
    }

    @Override
    public boolean canReveal() {
        return currentSession.isLoggedIn();
    }
}
Run Code Online (Sandbox Code Playgroud)

我怎么CurrentSession在这里注射?

Ste*_*ORT 0

这是一个解释如何使用 Gatekeeper 的教程:http://dev.arcbees.com/gwtp/tutorials/tutorial-part2.html

在 Gin 的模块中将 CurrentSession 的类(本教程中的 CurrentUser )声明为 Singleton,如下所示:

public class YourGinModule extends AbstractGinModule {

    @Override
    protected void configure() {
        bind( CurrentSession.class ).in ( Singleton.class );
        ...
    }

}
Run Code Online (Sandbox Code Playgroud)

在这里您可以找到在客户端使用 GWTP Gatekeeper 并在服务器端使用 Spring Security 的另一个示例: https: //github.com/imrabti/gwtp-spring-security