An Architect's View

CFML, Clojure, Software Design, Frameworks and more...

An Architect's View

TransferFactoryProxy

February 8, 2007 · 6 Comments

Update: this proxy is not needed to have a single instance of the Transfer factory shared between multiple Model-Glue applications. You can simply have an alias tag in each application that references the single transferFactory object in the parent factory:
<alias name="transferFactory" alias="ormService"/>
So why did I think this wouldn't work? I created a test case for parent / child bean factories and aliases, I put nothing but aliases in the child factories. ColdSpring couldn't find the aliases. I deduced (wrongly) that ColdSpring did not allow aliases in child factories to redefine beans in the parent factory. Silly me. Turns out that my test case uncovered a bug in ColdSpring: aliases only work if the factory contains at least one real bean. At least, that's what my test cases seem to show. I'm going to run this past the ColdSpring crew for confirmation.
Want to share a single instance of Transfer between multiple Model-Glue applications? Original code / post edited out. The definition of transferFactory is in your parent bean factory which you tell Model-Glue about by putting this line in your index.cfm:
<cfset ModelGlue_PARENT_BEAN_FACTORY = application.cs />
(assuming your overall Application.cfc is creating application.cs). All the Model-Glue apps share that Application.cfc and so they all have the same parent bean factory which contains the single instance of the Transfer factory object. Each Model-Glue app has its own proxy object that delegates an alias that refers to the single factory object.

Tags: coldfusion · coldspring · modelglue · orm

6 responses so far ↓

  • 1 Robb // Jan 10, 2007 at 6:39 PM

    Thank you for sharing this example. I plan to give this a try.

    Robb
  • 2 John Allen // Jan 10, 2007 at 8:34 PM

    THANK YOU!!!!
  • 3 Ken Dunnington // Jan 11, 2007 at 12:10 PM

    Thanks for this post, Sean, I've been thinking about using a parent bean factory lately and it's quite helpful to see a concrete example.
  • 4 Joe Rinehart // Jan 12, 2007 at 4:55 AM

    Hey Sean,

    Why not use a ColdSpring alias to point the alias &quot;ormService&quot; to the true (not proxy) Transfer in your parent bean factory, e.g.,

    &lt;alias alias=&quot;ormService&quot; name=&quot;nameOfTransferBeanInParentFactory&quot; /&gt;

    ?
  • 5 Sean Corfield // Jan 13, 2007 at 12:06 AM

    @Joe, because that wouldn't work :)

    Aliases only work within a single bean factory instance. You can't create an alias in a bean factory that references a bean in the parent bean factory.

    Now, as to whether or not it *should* work... I'll leave that up to Chris and Dave...
  • 6 Sean Corfield // Feb 8, 2007 at 9:19 PM

    It turns out that Chris says it *should* work but my test case failed - which is why I went the proxy route in the first place.

    Turns out my test case uncovers a bug in ColdSpring - if you have a factory that contains *only* &lt;alias&gt; tags, ColdSpring won't find any of them. You have to have at least one real &lt;bean&gt; in a factory for &lt;alias&gt; to work.

    So this whole proxy thing is actually bogus. You can just &lt;alias name=&quot;transferFactory&quot; alias=&quot;ormService&quot;/&gt;

Leave a Comment

Leave this field empty: