2012/1/17 egolan <[email protected]> > Hi, > I am working on a project, which is kind of batch one. > We are using dependency injection as the architecture, and it proved > very well. Everything (well, 90%) could be tested. > Up until now, everything (objects graph) was hooked and created > manually. > > Now I want to take it for the next level, and use Guice. > I've been reading and experimenting and want to implement it to the > real project. > > Below is how I think I should do things and also some examples and > questions. > Please provide any remarks. > > So, for any Integer, String, Long, I will use: > Names.bindProperties(binder(), properties); > > I have some classes that I must use the Singleton pattern, as I am > using a library that forces me to do so. > So this is what I thought of doing: > FooDAO fooDAO = FooDAO.getInstance(); > bind(FooDAO.class).toInstance(fooDAO); > > Instead of manually constructing a class: > FooFetchOperationsImpl fooFetchoperations = new > FooFetchOperationsImpl(fooDAO, genericQuery, bulkSizeFetch); > I am doing: > > > bind(IDataCollector.class).to(FooFetchOperationsImpl.class).asEagerSingleton(); > And here I have an problem, as FooFetchOperationsImpl actually > implements another interface (RecordsCounterOperations). > So I'll need to do something like: > > > bind(RecordsCounterOperations.class).to(FooFetchOperationsImpl.class).asEagerSingleton(); > > I also have something like this: > IProducerConsumerQueue<List<MpsData>> queue = new > ProducerConsumerQueue<List<MpsData>>(); > For this queue, I am not sure how to use Guice to create it. > I want it to be singleton. Maybe manually create and then use: > toInstance() ? > > And what about thread pool? > Here's the by-hand creation: > ExecutorService operationThreadPool = > Executors.newFixedThreadPool(numberOfThreadsForFooHandling); > How should I handle it with Guice? > > And this? > FutureJobsBuilder<List<FooMpsData>> futureJobsBuilder = new > CollectionFutureJobsBuilder<FooMpsData>(subCollectionSize); > FutureJobsBuilder is the interface and CollectionFutureJobsBuilder is > an implementation. > will > > > bind(FutureJobsBuilder.class).to(CollectionFutureJobsBuilder.class).asEagerSingleton(); > work? > Do I need to use TypeLiteral somewhere? > > I also have some classes that implements provider. > I can just bind them normally, and then they will be injected to where > they are needed, correct? > > Here's another example: > MpsRequestConvertor requestConvertor = new MpsRequestConvertor(); > MpsResponseConvertor responseConvertor = new > MpsResponseConvertor(matchConfidenceThreshold); > MpsServiceProvider serviceProvider = new > MpsServiceProvider(environment); > Provider<Producer<List<FooMpsData>, List<MpsData>>> > producerProvider = new MpsProducerProvider(requestConvertor, > responseConvertor, serviceProvider); > > So injecting them would be something like: > bind(MpsRequestConvertor.class).to(MpsRequestConvertor.class); // > singleton? > > use the eager singleton..?
> bind(MpsResponseConvertor.class).to(MpsResponseConvertor.class); // > singleton? > bind(MpsServiceProvider.class).to(MpsServiceProvider.class); // > singleton? > bind(producerProvider.class).to(MpsProducerProvider.class); // > singleton? > Here it clearly states: http://google-guice.googlecode.com/svn/trunk/javadoc/com/google/inject/Binder.html bind(Service.class).toProvider(ServiceProvider.class) > > > I am really exited using Guice and would love showing it to the team > and boss :) > I have in mind, that once I have grasp of everything, I will separate > this module to sub modules and hook everything up. > > Thank you very much for any help and assistance. > > Eyal > > -- > 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. > > -- 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.
