On Sunday, July 7, 2013 7:16:09 AM UTC-4, Francis Galiegue wrote: > > There's nothing wrong with the builder pattern even if you're using > Guice. > > If the parameters don't change for the life of the application, but > you're > > writing something extensible, you might just have users pass a > > URLTransformerBuilder to your Module's constructor, and then build and > bind > > the result. > > > > That is what I am currently doing... In fact, with builders, my API > works pretty well, but DI has shed a new light on my design which > tells me, "not so good". Unlike DI, builders' products are "fixed". DI > allows to inject products on a finer level, easier; and due to the > evolution I envision, it is what I need. >
Well, the question is what the lifecycle of the objects are. One option is to write a Provider which gets injected the parameters you'll use in your builder, and then it can take care of running the builder and returning the result (I assume you have some sort of request scope or something for the things that change). If the parameters change between calls, it won't matter because (assume you bound the Provider using its class object) a new one will be created every time. Classes can just ask for a URLTransformer and not care about how it gets created. -Tim > > -- 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.
