When and where to use dependency injection with Guice?

I recently attended a university course at Guice and saw a Google I / O video ad about it . In the video, they claim to use it in every Google project, including Wave, etc. I was wondering - is Guice really ubiquitous? Is this really required knowledge for Java programmers? Should I always use it on top of the factory?

thanks

+4
source share
2 answers

Is Guice ubiquitous? Is this really a must for Java programmers?

Outside of Google - no, not really. I am not saying that this is not a good product, it is simply not very widely used now. There are other, more robust frameworks that provide dependency injection, such as Spring or EJB. The main difference is that Guice injects dependencies.

Should I always use it on top of the factory?

Of course not. Injection injection is a useful template, but, as with all useful tools, there is a right and wrong time to use it.

+4
source

Guice is a dependency injection framework. When using Java, you should definitely consider the dependency injection (DI) framework. DI can save you a lot of boiler plate code for (web) security / authentication, transaction management, logging, database access and results in cleaner code.

Alternatively, you can consider Spring. Guice, or at least was easier to use, because it didn't rely too much on XML, but Spring caught up with the latest version (using annotations, javaconfig, etc.).

Well, in any case, use the DI framework because you have your own factory code, transaction boiler room code (transaction.start. Commit, finally .. etc.), singletones (e.g. static getInstance methods), etc. .

+5
source

Source: https://habr.com/ru/post/1315982/


All Articles