History of the best use of injection depend Google Guice framework [turn]

Guice is a lightweight developed by Google, based on Java5 (mainly using generics and annotations properties) dependency injection framework (IOC). Guice is very small and fast.

(Other dependency injection framework also Dagger, Spring)

 

Spring Framework relies injection is a household name, but in the actual development, we want to use dependency injection features convenient, but do not want to introduce the complexity of the Spring framework, how to do it?

With Google Guice, this problem will be simple, first introduced in your maven project in

<dependency>
	<groupId>com.google.inject</groupId>
	<artifactId>guice</artifactId>
	<version>4.0</version>
</dependency>

  

 

We use Guice to create a syringe Injector, then get the object you want from the Injector on it, Guice will automatically assemble dependency tree. Guice startup speed is very fast, in a large-scale applications, Guice assembling all the modules will never exceed 1s. Guice is a very clean dependency injection frame, which in addition to functions other than dependency injection, without any other non-related module functions.

Guice two most commonly used and notes that @Singleton @ Inject, Singleton represents objects built in a single embodiment, Inject represents the marked field will automatically Guice injection. In general these two annotation project generally more than 90% complete assembly work.

Guice need to instantiate an object, make sure that the corresponding object is instantiated with a default constructor.


Reference link: https: //www.jianshu.com/p/9ac108d14608

Guess you like

Origin www.cnblogs.com/1906859953Lucas/p/11220817.html