Author |
Message |
![[Post New]](/templates/default/images/icon_minipost_new.gif) 06/02/2008 06:14:08
|
saoj
Joined: 01/07/2005 09:59:17
Messages: 2846
Location: Rio de Janeiro, RJ
Offline
|
The problem is, with the name from the action input alone Guice doesn't know what kind of class to instantiate.
I did not know about that. So GUICE cannot instantiate by name and it needs the class as well? hummmm
Maybe using the IoC like velo suggested is a way to go. It ties a name to an implementation and also has scopes. We would have a GuiceComponent, something like that.
ioc("myclass", guice(MyClass.class));
So when you do a input.getValue("myclass"), the MyClass class will be loaded by Guice.
|
Sergio Oliveira
|
|
 |
![[Post New]](/templates/default/images/icon_minipost_new.gif) 06/02/2008 06:19:21
|
velo
![[Avatar]](/images/avatar/7f39f8317fbdb1988ef4c628eba02591.jpg)
Joined: 16/02/2006 13:33:54
Messages: 1197
Location: Jaraguá do Sul - SC
Offline
|
Saoj...
The unique problem, today, to use Guice as the default Mentawai ioc is scope?
No workaround possible?
Maybe when can open an issue to they, when solved guice can become the default ioc on mentawai.
Or this is impossible?
VELO
|
_____________________________________
Mentawai Developer
"When the only tool you have is a hammer, everything looks like a nail"
http://en.wikipedia.org/wiki/Golden_hammer |
|
 |
![[Post New]](/templates/default/images/icon_minipost_new.gif) 06/02/2008 06:41:51
|
saoj
Joined: 01/07/2005 09:59:17
Messages: 2846
Location: Rio de Janeiro, RJ
Offline
|
I don't want to kill the Mentawai support for IOC. You question is non-sense.
I want to add full support to Guice.
This is not a government company, where for you to become the director, the director most go away!
We can support Guice and keep the Mentawai IoC support.
|
Sergio Oliveira
|
|
 |
![[Post New]](/templates/default/images/icon_minipost_new.gif) 07/02/2008 03:52:04
|
Sven
Joined: 20/01/2008 05:53:15
Messages: 24
Offline
|
saoj wrote:
I did not know about that. So GUICE cannot instantiate by name and it needs the class as well? hummmm
Yes! The Injector#createInstance() method only takes a class as an argument. The Injector then creates an instance of that class (or possibly a subclass if special configuration for this class has been set before).
saoj wrote:
Maybe using the IoC like velo suggested is a way to go. It ties a name to an implementation and also has scopes. We would have a GuiceComponent, something like that.
ioc("myclass", guice(MyClass.class));
So when you do a input.getValue("myclass"), the MyClass class will be loaded by Guice.
That looks good!
|
|
 |
![[Post New]](/templates/default/images/icon_minipost_new.gif) 07/02/2008 04:36:13
|
Sven
Joined: 20/01/2008 05:53:15
Messages: 24
Offline
|
I think the ApplicationManager should be extended by this method:
Code:
public GuiceComponent guice( Class<? extends Object> klass,
com.google.guice.Injector injector ) {
return new GuiceComponent( klass, injector );
}
or maybe this
Code:
public GuiceComponent ioc( String name, Class<? extends Object> klass,
com.google.guice.Injector injector ) {
GuiceComponent gc = new GuiceComponent( klass, injector );
addComponent( name, gc );
return gc;
}
The GuiceComponent class should look like this:
Code:
class GuiceComponent implements Component {
private Class<? extends Object> klass;
private Injector injector;
public GuiceComponent( Class<? extends Object> klass, Injector injector ) {
this.klass = klass;
this.injector = injector;
}
@Override
public Object getInstance() throws InstantiationException {
return injector.getInstance( klass );
}
}
Note: The code has not been tested! I just typed this into the forum editor
|
|
 |
![[Post New]](/templates/default/images/icon_minipost_new.gif) 16/02/2008 14:07:50
|
Sven
Joined: 20/01/2008 05:53:15
Messages: 24
Offline
|
What do you think, Sergio?
|
|
 |
|