On Fri, Apr 11, 2014 at 12:58 PM, Donnie Carvajal wrote:

> I have an application with a root application.cfc and a subfolder for IVR
> access that also has an application.cfc which extends the root
> application.cfc.  There are certain Application variables that I only need
> in the IVR subfolder, so I added an onApplicationStart method to the
> subfolder application.cfc.  I'm running into an issue in my IVR access
> indicating that the IVR specific variables are not available.  This is
> because the root application.cfc ran before the sub and the
> onApplicationStart method in the sub application.cfc did not.
>
> Would you suggest putting all application variables in the Root
> onApplicationStart method or add a check in subfolder onRequest method for
> variables and call subfolder onApplicationStart if missing?
>
> Any best practices I'm missing?


Assuming that both App.cfc files share the same Application name, it's
really all one "application" regardless of which fires first. So you aren't
really getting much benefit from what it sounds like you are trying to do,
unless App.cfc is doing some other things too.

A few ways you could do this. Here are some ideas:

1) Use some sort of BeanFactory/Parent SubFactories to populate these
beans. DI/1 is a good one...

https://github.com/framework-one/di1

2) You could pull out some of the Application.cfc code and abstract it into
other files. Then you have the option to include things your IRV needs or
not, without extending. Mura CMS does this. Start at line 48/67/79 here to
see a few examples of how:

https://github.com/blueriver/MuraCMS/blob/develop/Application.cfc

3) I've used a very lightweight SingletonFactory.cfc before to create files
on demand. This is similar to some things DI/1 does but super dumbed down
and without the Dependency Injection part. you ask it for a CFC and it
optionally creates it if needed and stores it in the application scope. If
it's already in Application scope it just returns it.

A quick example is here:

https://gist.github.com/cameroncf/10487348

You call it something like this:

ivrSettings = createObject('component','path.to.model.SingletonFactory')
                      .init()
                      .getObject('path.to.model.IVR.Settings');

You can obviously abstract out some of that init code but that's
essentially how it's used in a one line example.

-Cameron

-- 
Cameron Childress
--
p:   678.637.5072
im: cameroncf
facebook <http://www.facebook.com/cameroncf> |
twitter<http://twitter.com/cameronc> |
google+ <https://profiles.google.com/u/0/117829379451708140985>


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Order the Adobe Coldfusion Anthology now!
http://www.amazon.com/Adobe-Coldfusion-Anthology/dp/1430272155/?tag=houseoffusion
Archive: 
http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:358323
Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/groups/cf-talk/unsubscribe.cfm

Reply via email to