如何在引导后注入会话/用户对象? [英] How to inject Session/User object after bootstrapping?
问题描述
在< a href =http://dev.arcbees.com/gwtp/get-started/Bootstrap-Code.html =nofollow> Bootstrap-Code 例如他们正在注入例如一个 SecurityDelegate
对象。
同样在网守例如我看到注入的东西,例如 MyGatekeeper
,但这是怎么完成的?
我想要先检查用户是否登录,然后创建一个 CurrentSession
对象或类似的东西。但我怎样才能通过/注入这个对象?
目前我正在初始化一个单例对象 CurrentUser
which是一种丑陋的imho。我希望获得GWTP支持,但如何?
以 CurrentSession
被注入关守:
$ b
@DefaultGatekeeper
public class LoggedInGatekeeper实现Gatekeeper {
private final CurrentSession currentSession;
@Inject
LoggedInGatekeeper(CurrentSession currentSession){
this.currentSession = currentSession;
@Override
public boolean canReveal(){
return currentSession.isLoggedIn();
$ b $ p $如何注入 CurrentSession
在这里? 解决方案下面是一个教程,介绍如何使用Gatekeeper: http://dev.arcbees.com/gwtp/tutorials/tutorial-part2.html
在你的杜松子酒模块中声明CurrentSession的类(本教程中的CurrentUser)为Singleton,如下所示:
public class YourGinModule extends AbstractGinModule {
@Override
protected void configure(){
bind(CurrentSession.class).in(Singleton.class);
...
}
}
在这里你可以找到另一个例子,在客户端使用GWTP Gatekeeper,在服务器端使用Spring Security: https:// github.com/imrabti/gwtp-spring-security
There are examples where different kinds of objects are getting injected into a presenter, but I can't find an explanation how this can be done.
In the Bootstrap-Code example they are injecting e.g. a SecurityDelegate
object.
Also in the Gatekeeper example I see things being injected, e.g. MyGatekeeper
, but how is this done?
What I want is to first check if the user is logged in and then create a CurrentSession
object or something like this. But how can I pass/inject this object around?
At the moment I am initializing a singleton object CurrentUser
which is kind of ugly imho. I would like to get the GWTP support running, but how?
Take this example of the CurrentSession
being injected into the gatekeeper:
@DefaultGatekeeper
public class LoggedInGatekeeper implements Gatekeeper {
private final CurrentSession currentSession;
@Inject
LoggedInGatekeeper(CurrentSession currentSession) {
this.currentSession = currentSession;
}
@Override
public boolean canReveal() {
return currentSession.isLoggedIn();
}
}
How do I inject CurrentSession
here?
解决方案 Here is a tutorial that explains how to use Gatekeeper : http://dev.arcbees.com/gwtp/tutorials/tutorial-part2.html
Declare CurrentSession's class ( CurrentUser in the tutorial ) as Singleton in your Gin's module like below :
public class YourGinModule extends AbstractGinModule {
@Override
protected void configure() {
bind( CurrentSession.class ).in ( Singleton.class );
...
}
}
Here you can find another example using GWTP Gatekeeper on client side and Spring Security on server side : https://github.com/imrabti/gwtp-spring-security
这篇关于如何在引导后注入会话/用户对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!