PicoContainer
  1. PicoContainer
  2. PICO-6

allow for lazy instantiation of components

    Details

    • Type: New Feature New Feature
    • Status: Closed Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 1.0-beta-2
    • Fix Version/s: 1.0-beta-2
    • Component/s: None
    • Labels:
      None
    • Number of attachments :
      0

      Description

      In webwork, we create a new XWorkPicoContainer for each request to handle request scoped components. As most actions will only need 1 or 2 components, it would be nice for the container to only instantiate the components that are required.

      Our ideal usage would be

      Object getComponent(Class componentType)

      where componentType can a registered or unregistered component. unregistered components would need to follow pico rules (only 1 constructor) and each argument in the constructor would need to be a registered pico component.

      Here's the code we're using now to do this:

      public Object createAction(Class componentType) {
      Constructor constructor = componentType.getConstructors()[0];
      Class[] parameters = constructor.getParameterTypes();
      Object[] args = new Object[parameters.length];

      try {
      for (int i = 0; i < parameters.length; i++)

      { Class param = parameters[i]; args[i] = this.getComponent(param); }

      return makeComponentInstance(componentType, constructor, args);
      } catch (PicoInvocationTargetInitailizationException e)

      { e.printStackTrace(); // och! }

      return null;
      }

        Issue Links

          Activity

          Aslak Hellesøy made changes -
          Field Original Value New Value
          Remaining Estimate 0 minutes [ 0 ]
          Original Estimate 0
          Affects Version/s 1.0-beta-1 [ 10144 ]
          Fix Version/s 1.0-beta-1 [ 10144 ]
          Affects Version/s 1.0-alpha-2 [ 10150 ]
          Aslak Hellesøy made changes -
          Fix Version/s 1.0 [ 10145 ]
          Fix Version/s 1.0-beta-1 [ 10144 ]
          Affects Version/s 1.0 [ 10145 ]
          Affects Version/s 1.0-beta-1 [ 10144 ]
          Aslak Hellesøy made changes -
          Status Unassigned [ 1 ] Assigned [ 2 ]
          Assignee Aslak Hellesoy [ rinkrank ]
          Aslak Hellesøy made changes -
          Status Assigned [ 2 ] In Progress [ 3 ]
          Aslak Hellesøy made changes -
          Affects Version/s 1.0-beta-2 [ 10217 ]
          Fix Version/s 1.0 [ 10145 ]
          Affects Version/s 1.0 [ 10145 ]
          Fix Version/s 1.0-beta-2 [ 10217 ]
          Aslak Hellesøy made changes -
          Resolution Fixed [ 1 ]
          Status In Progress [ 3 ] Closed [ 6 ]
          Jörg Schaible made changes -
          Link This issue is related to PICO-120 [ PICO-120 ]

            People

            • Assignee:
              Aslak Hellesøy
              Reporter:
              Matt Ho
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: