CatalogStoreManager is provided as an Optional (but empty) binding in
CatalogManagerModule since it's required by the PluginManager.
In DynamicCatalogManagerModule we provide two bindings for the
CatalogStoreManager against the same Guice key which is invalid and
leads to failures like:
3) [Guice/BindingAlreadySet]: CatalogStoreManager was bound multiple times.
Bound at:
1 : DynamicCatalogManagerModule.setup(DynamicCatalogManagerModule.java:47)
\_ installed by: CatalogManagerModule -> DynamicCatalogManagerModule
2 : java.base/DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)
\_ installed by: CatalogManagerModule -> DynamicCatalogManagerModule
Learn more:
https://github.com/google/guice/wiki/BINDING_ALREADY_SET
Another issue is that the optional binder binds CatalogStoreManager to
itself which Guice also complains about:
1) [Guice/RecursiveBinding]: Binding points to itself. Key: CatalogStoreManager
at CatalogManagerModule.setup(CatalogManagerModule.java:31)
\_ installed by: CatalogManagerModule -> RealOptionalBinder
2) [Guice/RecursiveBinding]: Binding points to itself. Key: CatalogStoreManager
at DynamicCatalogManagerModule.setup(DynamicCatalogManagerModule.java:47)
\_ installed by: CatalogManagerModule -> DynamicCatalogManagerModule
This can be solved by introducing an interface for CatalogStoreManager
and binding against that but since we'll only ever have a single
implementation we don't need that. Instead Guice can satisfy optional
bindings using user-provided bindings too which allows us to simply
remove the setBinding on the optional binder.
From JavaDocs of `OptionalBinder`
(https://google.github.io/guice/api-docs/4.2/javadoc/com/google/inject/multibindings/OptionalBinder.html).
If neither setDefault nor setBinding are called, it will try to link to
a user-supplied binding of the same type. If no binding exists, the
optionals will be absent. Otherwise, if a user-supplied binding of that
type exists, or if setBinding or setDefault are called, the optionals
will return present if they are bound to a non-null value.