java - Can someone explain what com.google.inject does? -
I have declared a class with my constructor which was annotated with Then two questions: & lt; 1 & gt; What does & lt; 2 & gt; As the producer is never called directly, does the fact that it is commented with Google is a dependency injection library, so that you can create objects by expressing the relationship between them Are there. The objects are manufactured because they are demanded to create other items. You can also implement abstract classes or interfaces with different implementations by configuring Guice, which makes it useful for running or testing your code. Here's a very simple example (from one of my apps) I'm a Note that It declares that whenever I want It says that there should be only one connection pool data source. It also means that when I try to get an example of However, it does not stop here. Other things depend on I see how it is a big fan of Guice after reducing the need to start a bunch of things for me. In order to initialize the other things, I will ask for what I want, and POF! that sounds like. @Inject is. And I have not called a producer anywhere in the entire project.
@ Inject mean? (What does it do? Constructor is annotated with it?)
@Inject is anything to do with?
@Inject Builder and methods that determine the annotates are what many things need to initiate, there are also many other annotations that determine how the guide works but only Explanation of things is not enough; You also have to configure them.
MySQLDataTracker that requires a
MysqlConnectionPoolDataSource : < Pre>
public class MySQLDataTracker extends ExperimentDataTracker {@Inject Public MySQLDataTracker (MysqlConnectionPoolDataSource DS) {.. ..}}
MySQLDataTracker spreads
ExperimentDataTracker , an abstract class can be implemented in many ways. In my Guice bindings, I declare that
bind (ExperimentDataTracker.class) .to (MySQLDataTracker.class);
ExperimentDataTracker , a
MySQLDataTracker will be created. I also need to make sure that the required object for this construction is available, I declare a provider:
@Provides @Singleton MysqlConnectionPoolDataSource getMysqlCPDS () {return (some thingy i build ...); }
ExperimentDataTracker , then Guys needs to make it. If I was not above, then it would throw an error
ExperimentDataTracker Tracker = injector.getInstance (ExperimentDataTracker.class).
ExperimentDataTracker , then it is used to inject other objects in return, in fact only one call at the top level of my code
getInstance It does happen, which makes Guice very much everything, I do not have to write the
new statement anywhere.
Comments
Post a Comment