-
New Feature
-
Resolution: Fixed
-
Neutral
-
None
-
-
Yes
-
Empty show more show less
-
5.4 Sprint 1
Currently, we can't @Inject multiple implementations of a common type, e.g.:
@Inject
public SomeClientCode(Collection<Foo> allFoos) {
This is because Guice forces us to give a binding "key" to all components we register.
However, this Guice extension allows it: https://github.com/google/guice/wiki/Multibindings
We still have to "key" those bindings though. One still can't inject "collection of some arbitrary type", unless "arbitrary type" as been bound via multi-bindings. One way we could achieve this, is by annotating the types we want to "multi-bind"; at registration time, we look if the component we're registering has this annotation (directly or via its sub-types), and create multi-bindings for the type that has the annotations.
Here's a patch that does this
Use case: registries and callbacks. We have a bunch of places where components explicitly register themselves to make themselves known to others because of this. Concrete use-case: with new configuration mechanisms in 5.4, we'll have a "registry of registries" component, which needs to know about all registries in the system. With this feature, we don't need to invent a terse callback mechanism, and can't instead proceed on the "don't call us we'll call you" pattern that IoC is supposed to promote.
PS: I'm not entirely sure about the scoping of those components, and it's currently lacking any other test than "i've tried it in a live system and it worked".
PPS: Scope seems to work as expected - which may make things tricky (if "client" is not lazy-singleton, and one of the impls is lazy, it won't see it)
- is causing
-
MAGNOLIA-6538 Improve support IoC multi-binding
- Accepted
- is depended upon by
-
MAGNOLIA-6076 Make config by file optional
- Closed
-
MAGNOLIA-6086 Registry/RegistryFacade API - propose functionality and implementation improvements
- Closed
- mentioned in
-
Page Loading...