Guice creates a "dependency graph" that's really mapping from keys to classes (or instances [or providers]). When you request a dependency such as:
injector.getInstance(RealBillingService.class); The key is simply the type "RealBillingServices.class". Guice will create an instance of it and inject its dependencies (and any transitive dependencies). The only time a proxy is created is if Guice's AOP functionality is being used. In this case, they create a super class (at runtime using cglib) of whatever RealBillingServices.class maps to. The intercepted methods are overridden in order to intercept method calls. On Monday, February 10, 2014 7:15:41 AM UTC-8, Bhuvan Gupta wrote: > > I was going through the google guice and then i thought about how it > might be working. > > So This is my theory on how property injector might be working. > > Guice first wants us to create a injector and pass all the binding > information > to it. > > Injector injector = Guice.createInjector(new BillingModule()); > > *code snippets from google guice > page<https://code.google.com/p/google-guice/wiki/GettingStarted> > > OK at this point i can think that there is a class with all the > information of binding. > > and when we do > > injector.getInstance(RealBillingService.class); > > Here we do the trick. > > injector will return a proxy instance for the real RealBillingService object > and when we call a > > method of RealBillingService object, proxy instance invocation handler > uses reflection to > > figure out the properties to inject and fullfill it based on the > information passed during the creation of injector. > > *QUESTION* > > This is the way i suppose, the guice works. If i am wrong, what would be > the actual way by which 'Guice'achieve it ? > > If this is the way guice work then Guice always returns the proxy object and > the user code always makes call on the proxy objects. is this true ? > -- You received this message because you are subscribed to the Google Groups "google-guice" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/google-guice. For more options, visit https://groups.google.com/groups/opt_out.
