Java – Guice abstractmodule installation method

What does the method install () in the abstractmodule class do? Can anyone explain to me? From the documents I read from Guice website, I can get:

Configure what binding is accurate? Bindings from installed modules or classes that call installation methods?

Solution

Installation allows combination: in its configuration method, foomodule may install fooservicemodule (for example) This will mean that syringes created only based on foomodule will include bindings and providers in foomodule and fooservicemodule

You may see an installation to split a module into logical submodules for ease of reading or testing, or you may see an installation of an advanced module to ensure its dependency configuration You can also use it to instantiate module instances with different constructor parameters (such as binding multiple data stores), or install automatically generated module instances, such as those created through factorymodulebuilder

Module combination can be a double-edged sword because repeated binding is not allowed: if your foomodule and barmodule both install the same dependent module, and the binding is not exact duplicates (for example, if the module instantiates an object in its configuration method), Guice will not be able to create any syringe for installing foomodule and barmodule because of repeated binding You can solve this problem before defining equals and hashcode on your modules, or make any module top-level by managing your combination, or install it in another module (but not run at the same time)

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>