The "Provider<LogFileEntry>" instance is injected in the constructor and set as an attribute of the LogFileTransactionLog object.
After, that depends on how is implemented the provider itself. When get() method is called, the provider implementation can return a new instance LogFileEntry, or always the same (quite strange in this case ?) What's your problem about that? Anthony MÜLLER 2009/8/14 zhaoyi <[email protected]> > > Can anyone help me on this? thanks. > > On Aug 10, 2:38 am, zhaoyi <[email protected]> wrote: > > I have read the article "Providers for multiple instances" in this > > linkhttp://code.google.com/p/google-guice/wiki/InjectingProviders. > > The example shown is: > > public class LogFileTransactionLog implements TransactionLog { > > > > private final Provider<LogFileEntry> logFileProvider; > > > > @Inject > > public LogFileTransactionLog(Provider<LogFileEntry> logFileProvider) > > { > > this.logFileProvider = logFileProvider; > > } > > > > public void logChargeResult(ChargeResult result) { > > LogFileEntry summaryEntry = logFileProvider.get(); > > summaryEntry.setText("Charge " + (result.wasSuccessful() ? > > "success" : "failure")); > > summaryEntry.save(); > > > > if (!result.wasSuccessful()) { > > LogFileEntry detailEntry = logFileProvider.get(); > > detailEntry.setText("Failure result: " + result); > > detailEntry.save(); > > } > > } > > > > There are two places to call logFileProvider.get() method. Are they > > return the same type of LogFileEntry? If they return different type of > > LogFileEntry, how does logFileProvider know which type is requested? > > > > thanks. > > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "google-guice" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/google-guice?hl=en -~----------~----~----~----~------~----~------~--~---
