Google I/O 2009 - Big Modular Java with Guice
ฝัง
- เผยแพร่เมื่อ 8 ก.ย. 2024
- Google I/O 2009 - Big Modular Java with Guice
Dhanji R. Prasanna, Jesse Wilson
Learn how Google uses the fast, lightweight Guice framework to power some of the largest and most complex applications in the world. Supporting scores of developers, and steep testing and scaling requirements for the web, Guice proves that there is still ample room for a simple, type-safe and dynamic programming model in Java. This session will serve as a simple introduction to Guice, its ecosystem and how we use it at Google.
For presentation slides and all I/O sessions, please go to: code.google.com/events/io/sessions.html
14:30 till this point, they explain why to use DI in the first place
14:40 why Guice?
16:52 Bindings
24:15 Scopes
28:12 Defining injections
30:55 Injecting providers
32:45 Leveraging Guice
41:00 AOP
43:45 Introspection SPI
47:30 how to compose modules
"Wave uses guice, why aren't you". Yeah. That didn't age well.
@7:38 But if you are using JUnit (and it looks like you are), you can (and probably should) perform setup and tear down in the setUp and tearDown methods.
@4:15 Another way would be to have overridable (i.e. non-final) methods that return a Shortener (and another one that returns a Tweeter). That way, you can write a subclass that overrides those methods with their own implementations that return mocks, or whatever.
@eelakh
True, but javac don't so it depend on which compiler you use.
who is 2021 in?
guice-servlet module, seems to be like going back. we moved the configuration from servlet code to XML in early 2000 and now we are going back..
R.I.P Bob!! :(
RIP Bob Lee. :(
watching this in 2020
mood
Why Reinventing Spring?
Why reinventing inversion of control?
Reinventing Spring? Nah! They are reinventing Borland JBuilder.
Good presentation ! thanks
It would still have been a direct dependency, every class that goes into an if block has to be imported (i.e. loaded and initiated).
I think that the point there is that the setup and teardown are boilerplate, no matter if you do it manually or using the JUnit methods.
Using Guice you are supposed to not even need to setup and teardown.
"Google Wave uses it" loool!
Why reinventing Spring? there is nothing I saw in this video that could convince me to use Guice instead of Spring. And I'm not even talking about other Spring Projects...
because guice is typesafe and spring is not?
My post was a while ago, i dont really remember everything i saw about guice, but with proper ide support you have type safety even in your xmls... anyway thats not an argument to switch to anything else... spring provides not only DI it gives a lot of awesome technologies to develop serious enterprize apps... i doubt that with guice you could easily use spring security or spring data or any other component...
Vachagan Balayan i guess its a matter of preference. i like guice because it has modules that you could, in theory at least :P, reuse in other apps without copy+pasting the beans.xml. however spring is more of a "kitchen sink" framework, it has way more features compared to guice. it more like a eco-system where guice is more of a lib.
Spring is type safe.
github.com/google/guice/wiki/SpringComparison
great vid!
At around 7th minute Jesse says if you compile a module you have to compile everything that it depends on?!!! it's not true. Test for yourself if you don't believe me. Define a class and inside one of the methods call another class that you've defined compile it. Then see the time of creation of the class files. Then go back and change the dependent class and compile again. It will still work without needing to compile the other class again. IDEs also keep track of these dependencies
Soo pretty much this is a re-write of Spring.
@Deonex What do you mean? Im noob with Spring, and I discover this... jejej.
Hey guys - what do you think the junit setup/teardown methods are for... Not saying DI isn't needed, but your unit test makes a poor argument...
That's right! That is the Hollywood sign. Very good!
"Well Google wave uses it, so why aren't you?" Shhh!
Sorry, forgot to mention @13:54
Another good google guice tutorial at :
th-cam.com/play/PLp0ed20U4R4jknb4xYdhx3yJn5RhWECxn.html
Don't like that there is a dependency on Guice for the annotations (or is there?). Should default to use the constructor with the most parameters
Nope, he couldnt use else in this method, because text local variable can be changed in the first if block of code (see: text = shortener.shorten(text);).
Can you share the links to the presentation. The link mentioned above doesn't work.
Sriharsha C V ;
one question though, when you are configuring your depencies in a module, at the end of the line/tree, your leaf dependencies will always have to be classes with no argument constructors, correct? There is no way, that you can configure juice to just inject you a class depends on a Long, for example. You would have to wrap that long in some wrap long class with a no argument constructor, or something of the sort. So, for example, if the smsTwitter need a Locale as input, that would be the end.
one word : WELD
Why he didn't use "else" in the first code? =)
Both code blocks are intended to run.
@@jamesflames6987 my question from 13 years ago. Thank you! yes, the first if updates 'text'
24:34
I love Guice but don't quite like the infomercial style of making every other way look so ugly at the beginning of the video.
I thought it was shadow until I read your comment! Worst. Beard. Ever.
I used to have that kind of beard 😆
what stops them from creating with new TwitterFactory("mockTestSmsProviderUrl") and not dealing with ugly static methods that won't work in multi-threading environment anyway and will make them always to write a tearDown method to cleanup parameters passed via static method? (i'm talking about th-cam.com/video/hBVJbzAagfs/w-d-xo.htmlm20s example)
I thought Juice was spelled with a J not G.
GUICE. JUICE
GONE. JUNGLE
GET. JET
GATHER. JUSTICE
Maybe that's why my nickname is "JuiceMan" go figure, lol.
When we make discovery or invention, we should always give it a unique name, preferably a short memorable non-word, because most publications are read by machines these days. For example, "p53" is a far better gene name than "her" as the latter is likely to be filtered out by a stoplist of common words, missing out great opportunities of cancer cure discovery by machine learning. By the same token, "guice" is more googleable than "juice." Good job, Google!
Hollywood principle "don't call us, we'll call you."
Bollywood principle "call us, we won't call you. No balance dude!"
Haha... No offense, just a joke!