Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I think your Something property is not getting set because singletons are instantiated when the application context is instantiated. When you call RegisterSingleton, the TestObject has already been created. The bean wiring is only done when a bean is created.</p> <p>You might be able to work around this problem by making the singleton instantiate lazily. That way it isn't instantiated until the first time it's requested. Hopefully, that's after you've registered the other singletons it needs.</p> <p>I don't know exactly what you're trying to accomplish, but if I wanted to change the wiring between some singleton beans at run time without making the beans aware of it, I would introduce some wrapper objects. Each wrapper would implement an interface and then just delegate all methods to its current target bean. To change the wiring, you just change the wrapper's target.</p> <p><strong>Update:</strong> as <a href="https://stackoverflow.com/questions/1371670/spring-registersingleton/1409554#1409554">yawn suggested</a>, Spring.NET has <a href="http://www.springframework.net/docs/1.3.0-RC1/reference/html/aop.html#aop-ts-swap" rel="nofollow noreferrer">hot-swappable target sources</a> that let you swap out the implementation of a bean at run time. Here's some sample code from the documentation that shows how to swap the bean implementation:</p> <pre><code>HotSwappableTargetSource swapper = (HotSwappableTargetSource) objectFactory.GetObject("swapper"); object oldTarget = swapper.swap(newTarget); </code></pre> <p>The XML definitions in the documentation look like this:</p> <pre><code>&lt;object id="initialTarget" type="MyCompany.OldTarget, MyCompany"&gt; &lt;/object&gt; &lt;object id="swapper" type="Spring.Aop.Target.HotSwappableTargetSource, Spring.Aop"&gt; &lt;constructor-arg&gt;&lt;ref local="initialTarget"/&gt;&lt;/constructor-arg&gt; &lt;/object&gt; &lt;object id="swappable" type="Spring.Aop.Framework.ProxyFactoryObject, Spring.Aop"&gt; &lt;property name="targetSource"&gt; &lt;ref local="swapper"/&gt; &lt;/property&gt; &lt;/object&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload