java - How to inject a implementation that takes some value in its constructor in Guice? -


i have following implementation trying inject in guice

`public class client{     private final database db;     public client(database db){       this.db = db     }  }  class someclass{    private client client;     @inject    public someclass(client client){      this.client = client;    }  }` 

this injection code injector guice = guice.injector(); guice.getinstance(someclass.class);

but keep on getting error:

could not find suitable constructor in hello.package.helloworld.client. classes must have either 1 (and one) constructor annotated @inject or zero-argument constructor not private

how inject class takes parameter?

the error text quite explicit: haven't used @inject on constructor of client.

so idea make so:

public class client{    private final database db;    @inject   public client(database db){      this.db = db    }  } 

and if don't know database, want create it, consider using guice's assisted injection, creates factory you.


Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -