[coldspring-users] contamination of singleton beans across multiple sites that share common code

3 views
Skip to first unread message

meatn2veg

unread,
May 12, 2010, 12:29:26 PM5/12/10
to ColdSpring-Users, adrian...@idg.co.uk
Hi all
I have the following issue

Shared set of CFCs under /sharedcomponents/A.cfc
Some of these shared cfcs inherit from cfcs per site e.g. site1/
components/AbstractA.cfc

A.cfc extends AbstractA.cfc to get bespoke per site information

In the config for coldspring we create singletons of A.cfc

So for 2 sites with coldspring they will create A.cfc via a coldspring
bean call, which would/should create a bean that is A.cfc extending
the site specific Abstract.cfc.

There are no errors but if we have another site
site2/components/AbstractA.cfc
and site1 is initialised first it get the content in site2's
AbstractA.cfc.

Confused?

Basically its like coldspring says I already have a bean with path /
sharedcomponents/A.cfc so when site2 wants its version of its A bean
it gets the same singleton as site1 is using? Does coldspring store
singelton instances against hases of thier file paths.
The above 2 sites share the same jvm.

Thanks

--
You received this message because you are subscribed to the Google Groups "ColdSpring-Users" group.
To post to this group, send email to coldspri...@googlegroups.com.
To unsubscribe from this group, send email to coldspring-use...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/coldspring-users?hl=en.

Barney Boisvert

unread,
May 12, 2010, 12:59:58 PM5/12/10
to coldspri...@googlegroups.com
If I understand correctly, this is a CF issue, not a ColdSpring one.
CF only compiles a CFC when the underlying *.cfc file changes, and
inheritance is expressed in the compilation phase. So a given CFC can
only be represented by a single inheritance hierarchy at any given
time.

To put that another way, the pathing for AbstractA.cfc is considered
at compile time, not at runtime. Since the difference between the
sites is only available at runtime, it's "too late" for the compiler
to be able to deal with it.

You'll need to split up your code, at least to the point where you
don't have common code extending application-specific code.

cheers,
barneyb
--
Barney Boisvert
bboi...@gmail.com
http://www.barneyb.com/

Brian Kotek

unread,
May 12, 2010, 1:03:40 PM5/12/10
to coldspri...@googlegroups.com
Hmm, well first, I'm not sure how that design works. If sharedcomponents/A.cfc extends the site-specific site1/components/AbstractA.cfc, then A.cfc isn't a "shared component". A.cfc will ALWAYS extend site1/AbstractA.cfc. So I'm not really sure what you're trying to do there. Do you have multiple sharedcomponents/ folders, where A.cfc extends from site1's AbstractA.cfc in one, and extends site2's AbstractA.cfc in another?

Aside from that, ColdSpring stores beans in the application scope, so the first thing I would confirm is that the two sites have separate application scopes. You also need to make sure that this isn't some pathing issue. CF searches custom tag paths, mappings, etc. and once it finds a match, it stops. So if these somehow share the same path or mapping, then you'll have problems.

Hope that helps,

Brian

Doug Boude

unread,
May 12, 2010, 2:06:57 PM5/12/10
to coldspri...@googlegroups.com
Just as a general thought, perhaps rather than take the inheritance route you could approach it either from an aggregation/composition approach, injecting the appropriate instance-specific object. Or call this an opportunity to utilize the Decorator pattern and simply decorate your A.cfc appropriately after it's been delivered by CS. Also, perhaps you could refactor things to the point where your instance-specific A.cfc behaves differently based on post-creation setup methods, and totally avoid the need to have instance-specific CFCs? Just thinking out loud.

Doug

Sean Corfield

unread,
May 12, 2010, 8:52:00 PM5/12/10
to coldspri...@googlegroups.com
I'm pretty sure Barney's right here: presumably you're using a mapping
in your extends= attribute and you are trying to dynamically set
mappings in each site's Application.cfc? As Barney says, the CFC is
compiled (using the active mapping at the time) and then ColdFusion is
done - and that compiled version is used for the next site and so on,
regardless of the mapping.

FWIW, you could do this on Railo because, unlike Adobe ColdFusion, it
allows for each site to have a completely isolated web context (but
within a single JVM / server instance) and compiles files per-context.
So site1 and site2 could share source code but would be treated
completely separately for compilation and runtime purposes. That said,
I think you'd be better off refactoring to use composition instead of
inheritance here with the per-site information / object passed in at
construction time - like Doug suggested.
--
Sean A Corfield -- (904) 302-SEAN
Railo Technologies, Inc. -- http://getrailo.com/
An Architect's View -- http://corfield.org/

"If you're not annoying somebody, you're not really alive."
-- Margaret Atwood

Hem Talreja

unread,
May 12, 2010, 11:46:12 PM5/12/10
to coldspri...@googlegroups.com
The only time i have received this message was when I was initializing a set of CFC's
and dependency injection was happening as constructor arguments,
essentially multiple components needed the same component for init.


Easy solution is to use property injection (accessors) instead of constructor arguments

Recommendation

1. Verify you have two different Applications (1 per site)
2. If you have dependency injection happening as constructor arguments (init method) refactor to use property injection (set<BeanName>)


Thanks
-Hem
Reply all
Reply to author
Forward
0 new messages