Uploaded image for project: 'Magnolia'
  1. Magnolia
  2. MAGNOLIA-6027

IoC: Support multi-binding

XMLWordPrintable

    • Icon: New Feature New Feature
    • Resolution: Fixed
    • Icon: Neutral Neutral
    • 5.4
    • None
    • core
    • Yes
    • 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)

        Acceptance criteria

              gjoseph Magnolia International
              gjoseph Magnolia International
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Created:
                Updated:
                Resolved: