Announcement Announcement Module
Collapse
No announcement yet.
Prototype scope and injected dictionary object Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Prototype scope and injected dictionary object

    Hi,

    I came across something that I'm not able to understand by myself,
    so I'm coming here to tell what my (simple) problem is and maybe find out a solution.

    I'm setting up an MVC implementation using the scope prototype on the various involved objects as I will need more instances of my mvc setup. I'm resolving my dependencies with injections.

    I am using a dictionary to pass to the controller a map (key, value) of command objects.
    The controller and the commands have scope set to prototype. A new instance of the controller is actually created when I require for it. The problem is that for the commands (and all their dependencies) i keep receiving the same instances even if they (and their dependencies) have prototype scope.

    I tried to move one command out of the dictionary (using array I have the same problem) and I saw that a new instance in this case is created when required. In my design the command is injected in the controller so when the controller is created the command is created too. I would like to inject a map of commands (or an array of them) keeping the prototype scope.

    I hope I'm have been clear as my idea is pretty simple.

    I would apologize if ever I am using things not in the proper way.

    Any advice appreciated!

    Thanks
    Regards

    Rod

  • #2
    If your map doesn't have the scope prototype it is going to be reused.

    Comment


    • #3
      I would imagine so. Is there the way on the <dictionary /> to tell it to use scope prototype? Because i didn't find it....


      thanks

      Comment


      • #4
        I have no clue what that tag does or is so I'm not able to help you there.

        One question I have is qhy do you need multiple instances of the controller?! For some reason it looks to complex...

        Comment


        • #5
          I agree with you that is looks complex but probably my application requires that.

          The application I'm working on needs to be able to open more instances of same (let's say) modules. This means that this modules will have to run simultaneously having their own state (the model) but still sharing main domain objects (singleton injected).

          I have been able to implement this design by asking to the context to give me a new "module" object (using prototype scope) when I need to. Prototype scooped dependencies are instantiated in the same time constituting its mvc stack.

          It seems to work but the <dictionary /> was keeping holding the same objects instead of allowing the creation of new instances...

          I tried also the multiple contexts approach but it seemed to me more complex to manage.
          Still I will have to change something if the dictionary has not prototype scope.

          Thanks for any advice or observation.


          Rod

          Comment


          • #6
            Then again why would you need multiple controller instances if the only thing that is different is them odel?! Store/scope the model in the request/session and you should be good to go, without resorting to make all your beans prototype scoped.

            Comment


            • #7
              Your point is valid. Actually in (theory before the implementation) the controller should just route the requests and should be a reusable instance in this case.
              One model per each "module instance" is ok and needed, but how do you route the requests to the correct model using a single controller instance? If the controller is one for all views (I have multiple instances running together), how do you choose the right model to be worked on?

              Anyway I think the point is valid and I will try to work on it as well.

              Cheers

              Comment

              Working...
              X