PicoContainer
  1. PicoContainer
  2. PICO-55

Use PicoContainer as a factory of transient (unmanaged) objects.

    Details

    • Type: New Feature New Feature
    • Status: Closed Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: PicoContainer (Java)
    • Labels:
      None
    • Number of attachments :
      2

      Description

      e.g. using Scott's example...

      container.registerComponentImplementation(CompA.class);
      container.registerComponentImplementation(CompB.class);

      webworkAction = container.createComponentInstance(WebworkAction.class);

        Issue Links

          Activity

          Hide
          Zohar Melamed added a comment -

          Initial implementation

          Show
          Zohar Melamed added a comment - Initial implementation
          Zohar Melamed made changes -
          Field Original Value New Value
          Attachment createComponentInstance.zip [ 10978 ]
          Hide
          Aslak Hellesøy added a comment -

          This has a lot of duplicate code from DefaultComponentAdapter. It will have to be refactored so it doesn't duplicate any code before it can be applied.

          Show
          Aslak Hellesøy added a comment - This has a lot of duplicate code from DefaultComponentAdapter. It will have to be refactored so it doesn't duplicate any code before it can be applied.
          Hide
          Aslak Hellesøy added a comment -

          Aaargh. Never mind the last comment. I should learn to read patches in more detail before I comment. Looks good!

          Show
          Aslak Hellesøy added a comment - Aaargh. Never mind the last comment. I should learn to read patches in more detail before I comment. Looks good!
          Hide
          Thomas Heller added a comment -

          hi,

          shouldn't DefaultComponentAdapter be non caching by default and caching done this way instead of another base class?

          [code]

          public class InstanceCachingAdapter extends DecoratingComponentAdapter {

          private Object componentInstance = null;

          public InstanceCachingAdapter(ComponentAdapter delegate)

          { super(delegate); }

          public Object getComponentInstance(MutablePicoContainer container) throws PicoInitializationException, PicoIntrospectionException, AssignabilityRegistrationException, NotConcreteRegistrationException {
          // FIXME: sync by extra adapter or here?
          if (componentInstance == null)

          { componentInstance = super.getComponentInstance(container); }

          return componentInstance;
          }
          }

          [/code]

          thoughts?

          Show
          Thomas Heller added a comment - hi, shouldn't DefaultComponentAdapter be non caching by default and caching done this way instead of another base class? [code] public class InstanceCachingAdapter extends DecoratingComponentAdapter { private Object componentInstance = null; public InstanceCachingAdapter(ComponentAdapter delegate) { super(delegate); } public Object getComponentInstance(MutablePicoContainer container) throws PicoInitializationException, PicoIntrospectionException, AssignabilityRegistrationException, NotConcreteRegistrationException { // FIXME: sync by extra adapter or here? if (componentInstance == null) { componentInstance = super.getComponentInstance(container); } return componentInstance; } } [/code] thoughts?
          Hide
          Zohar Melamed added a comment -

          The things I'm not sure about:

          1. Should it be possible to both cache and create fresh instances of the same component class by calling register, followed by create/get?

          2. Should caching be the default?

          Show
          Zohar Melamed added a comment - The things I'm not sure about: 1. Should it be possible to both cache and create fresh instances of the same component class by calling register, followed by create/get? 2. Should caching be the default?
          Hide
          Zohar Melamed added a comment -

          As per disscusion today with Paul, a new patch that fixes a bug in the original patch- see testNewComponentInstancesNotCachedEvenIfClassIsRegisterd
          for details.

          This patch was diffed from HEAD and not from the previous patch.

          Show
          Zohar Melamed added a comment - As per disscusion today with Paul, a new patch that fixes a bug in the original patch- see testNewComponentInstancesNotCachedEvenIfClassIsRegisterd for details. This patch was diffed from HEAD and not from the previous patch.
          Zohar Melamed made changes -
          Attachment createComponentInstance-301003.zip [ 10985 ]
          Aslak Hellesøy made changes -
          Link This issue is depended upon by PICO-57 [ PICO-57 ]
          Hide
          Jon Tirsen added a comment -

          Ok, I've implemented this based on a simplication of Zohars patch. See TransientComponentAdapter and TransientComponentAdapterTestCase. I have not changed the PicoContainer-interface but instead getComponentInstance always returns a new instance if you use the TransientComponentAdapter. So the above example would be:
          container.registerComponentImplementation(CompA.class);
          container.registerComponentImplementation(CompB.class);
          container.registerComponent(new TransientComponentAdapter(WebworkAction.class, WebworkAction.class));

          webworkAction = container.getComponentInstance(WebworkAction.class); // will return new instance each call

          Show
          Jon Tirsen added a comment - Ok, I've implemented this based on a simplication of Zohars patch. See TransientComponentAdapter and TransientComponentAdapterTestCase. I have not changed the PicoContainer-interface but instead getComponentInstance always returns a new instance if you use the TransientComponentAdapter. So the above example would be: container.registerComponentImplementation(CompA.class); container.registerComponentImplementation(CompB.class); container.registerComponent(new TransientComponentAdapter(WebworkAction.class, WebworkAction.class)); webworkAction = container.getComponentInstance(WebworkAction.class); // will return new instance each call
          Jon Tirsen made changes -
          Status Unassigned [ 1 ] Closed [ 6 ]
          Resolution Fixed [ 1 ]

            People

            • Assignee:
              Unassigned
              Reporter:
              Zohar Melamed
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: