What is a good utility for Guice Mapbinder?

I saw how it was used, but I'm not sure if use was a good example of using usecase. Do you have any idiomatic examples of using Guice Mapbinder ? (Cases when Mapbinder is really the right tool to solve the problem)

+4
source share
2 answers

Offline, this seems like a smart way to create a registry of time-based implementations of a common interface. Try to choose one of many plugins / modes / regardless of the command line or configuration file: the desired injection cannot be known at compile time. MapBinder provides easy viewing at runtime without resorting to type switching.

+3
source

I use it extensively in the Guts-GUI . You can look, in particular, at the ResourceModule , where it is used to display the right ResourceConverter<T> for a given type T :

 Map<TypeLiteral<?>>, ResourceConverter<?>> 

MapBinder is created directly in the Resources helper class.

Thus, any module can add its own resource converters for its own types, for example. MessageModule adds its own converters.

I also used it as a Map<Integer, WindowProcessor>> in the WindowsModule to define an ordered list of WindowProcessor , which will be applied one after another to the newly created window.

Again, this allows the various modules to insert their own processor into the list applied to each window: ResourceModule uses it to add the ability to automatically inject i18n resources into windows.

+1
source

All Articles