NanoContainer
  1. NanoContainer
  2. NANO-155

Configure Lifecycle Methods Via Scripts

    Details

    • Type: Wish Wish
    • Status: Open Open
    • Priority: Minor Minor
    • Resolution: Unresolved
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: None
    • Labels:
      None
    • Number of attachments :
      0

      Description

      The problem:

      Component lifecycle events are powerful but require either:

      • Source code modification: ie an annotation or interface implementation.
      • Source code consistency (ie the reflection lifecycle strategy that looks for “stop” “start” and “dispose” events.

      What I would LIKE to do is be able to specify the lifecycle events in the nano config:

      //Contrived Example:

      container()

      { //Create a new “Bar” component that start ==’s Bar.begin() //stop == Bar.finish() //and dispose == Bar.destroy() component(class:org.example.foo.Bar start:”begin” stop:”finish” dispose:”destroy”); }

      In XML Land, it would probably look something like:

      <component stop="finish" start="begin" dispose="destroy" ....../>

        Activity

        Hide
        Paul Hammant added a comment -

        Michael,

        See how far you can get with writing a new LifecycleStrategy that either does begin/finish/destroy only or those and the default methods ...

        .. and inject that in like so :-

        container(new DefaultPicoContainer(new CustomLifecycleStrategy()))

        { component(class:org.example.foo.Foo); component(class:org.example.foo.Bar); }
        • Paul
        Show
        Paul Hammant added a comment - Michael, See how far you can get with writing a new LifecycleStrategy that either does begin/finish/destroy only or those and the default methods ... .. and inject that in like so :- container(new DefaultPicoContainer(new CustomLifecycleStrategy())) { component(class:org.example.foo.Foo); component(class:org.example.foo.Bar); } Paul
        Hide
        Jörg Schaible added a comment -

        container(new DefaultPicoContainer(new ReflectionLifecycleStrategy(new NullMonitor(), "begin", "finish", "destroy")))

        { component(class:org.example.foo.Foo); component(class:org.example.foo.Bar); }

        ... but if I understood Michael corectly, he would like to configure these methods indivual for the component.

        Show
        Jörg Schaible added a comment - container(new DefaultPicoContainer(new ReflectionLifecycleStrategy(new NullMonitor(), "begin", "finish", "destroy"))) { component(class:org.example.foo.Foo); component(class:org.example.foo.Bar); } ... but if I understood Michael corectly, he would like to configure these methods indivual for the component.
        Hide
        Michael Rimov added a comment -

        Yes, I would like to configure the methods for the individual component.

        For example, lets say that we want to have a NanoWar request container that at the beginning of the request phase registers a Hibernate Session. To me at least, ideally, I would have the Request-scoped container automatically dispose of the Hibernate Session object at the end of the request when the
        container itself is disposed of.

        Of course, the problem for Hibernate Session is that the method is "close()", not "dispose()". So it appears to me that we need some sort of ability to map what we call "dispose" to "Hibernate-ease" method of "close".

        IIRC Spring has something in its config file format that is similar to what I'm requesting, where you can specify that a bean's destroy method is called something else. I couldn't find sample code off the top of my head, but I'll go digging if we need further clarification.

        Does that make sense?
        -Mike

        Show
        Michael Rimov added a comment - Yes, I would like to configure the methods for the individual component. For example, lets say that we want to have a NanoWar request container that at the beginning of the request phase registers a Hibernate Session. To me at least, ideally, I would have the Request-scoped container automatically dispose of the Hibernate Session object at the end of the request when the container itself is disposed of. Of course, the problem for Hibernate Session is that the method is "close()", not "dispose()". So it appears to me that we need some sort of ability to map what we call "dispose" to "Hibernate-ease" method of "close". IIRC Spring has something in its config file format that is similar to what I'm requesting, where you can specify that a bean's destroy method is called something else. I couldn't find sample code off the top of my head, but I'll go digging if we need further clarification. Does that make sense? -Mike

          People

          • Assignee:
            Unassigned
            Reporter:
            Michael Rimov
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated: