[Logo] Mentawai Forum - Mentawai Web Framework
  [Search] Search   [Recent Topics] Recent Topics   [Members]  Member Listing   [Groups] Back to home page 
[Register] Register / 
[Login] Login 

Forum Read-Only! Check the new site and forum here!

Using Mentawai along with Guice  XML
Forum Index -> General Comments Go to Page: Previous  1, 2
Author Message
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

velo


[Avatar]

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
[Email] [MSN]
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

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!
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
Sven



Joined: 20/01/2008 05:53:15
Messages: 24
Offline

What do you think, Sergio?
 
Forum Index -> General Comments Go to Page: Previous  1, 2
Go to:   
Powered by JForum 2.1.6 © JForum Team