Announcement Announcement Module
No announcement yet.
Parameterized Singleton problem Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Parameterized Singleton problem

    We have a lot of Object Managers in our existing code which manage objects based on parameters to a static factory method. For eg.
    Object obj1 = ObjectManager.getInstance("param1");
    Object obj2 = ObjectManager.getInstance("param2");
    The ObjectManager maintains one instance of the Object for each parameter value. In some cases the parameter is propagated to composite objects further down. The parameter value is decided at runtime.
    We are planning to use Spring mainly for plug-n-play and I'm trying to figure out if Spring has anything out-of-the-box for this.

    Would really appreciate if somebody could help me out on this one.
    -Rajesh A

  • #2
    Hi Rajesh

    Without further discourse from you on what you are trying to do, this may be a solution to your issue (as I perceive it).



    • #3

      Thanks for your reply. It looks good but it still needs configuring all possible services in the XML. I have some kind of a Singleton pool already present and I want to leverage that.
      From what I have investigated the AbstractBeanFactory class has a method getBean(String id, Object[] args). I tried to play around with it but it seems it just passes the parameter to a specified factory-method. Now the problem is if I have dependencies which also need this parameter I have to do that myself in the factory-method. Now here I lose the ability to configure the dependencies in the spring XML. And if I still want the ability to get the depencies out of the Spring Bean factory I'll have to implement BeanFactoryAware, which I dont want to do.
      Hope I'm making sense over here.

      Thanks again,
      -Rajesh A


      • #4
        I've done something similar to what you are talking about. However, I did find I needed to write a Spring specific factory class. Take a look at my posts in this thread. It might not be exactly what you are looking for, but its a start.

        I know you don't want to pollute your code with Spring specific stuff, but at some point not everything can be accomplished in the XML. You need a little bit of Spring-specific Java to help you along.

        Perhaps you can post a little bit of how you want your stuff to work, I can see how my example can be adapted to your example.