2010/1/24 Berlin Brown <[email protected]>: > This is a general design question. > > Should you use Guice dependency injection whenever you use the new > operator? Even within methods. > > For example, I have an application where I use guice for some of the > main object creation calls. But I haven't used it within some of the > methods > > For example, here is a method I was considering guice for: > > final DescriptiveStatistics stats = this.toReportStats > (this.stringUtils); > final DescriptiveStatistics wordSizeStats = > this.toReportStatsWordSize(this.stringUtils); > final ReportDocument noStopWordsReport = this.build(false); > final DescriptiveStatistics noStopWordsStats = > noStopWordsReport.toReportStats(this.stringUtils); > final DescriptiveStatistics noStopWordsWordSizeStats = > noStopWordsReport.toReportStatsWordSize > (this.stringUtils); > final Set<Map.Entry<String, Integer>> topWords = this.topWords > (this.getNumTopWords(), true, this.stringUtils); > > final ReportStatsDocument statsReport = new ReportStatsDocument > ( > this.getDocumentSize(), > this.isStopWords(), > stats, > wordSizeStats, > noStopWordsReport, > noStopWordsStats, > noStopWordsWordSizeStats, > topWords); > return statsReport; > > }
I think you can find your answer here: http://misko.hevery.com/2008/09/30/to-new-or-not-to-new/ I would suggest also following the references, they helped me a lot to understand many things when using Inversion of Control framework like Guice. -- 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.
