While I am asking dumb questions... Application.cfc

31 views
Skip to first unread message

Gavin Baumanis

unread,
May 10, 2013, 2:47:34 AM5/10/13
to mach-ii-for...@googlegroups.com
Hi Everyone, 

I have an existing application that I am trying to implement Mach-II with.
So I already have an Application.cfc

Here is what I have done;

I have copied the mach-ii.cfc into the {AppRoot}
Application.cfc extends mach-ii

Where there is a matching method (Eg. onApplicationStart() )
I am calling super.onApplicationStart();
And have left the rest of the code that is in my original Application.cfc.

In Application.cfc I have Init() method that I call in the pseudo-constructor 
In that INIT() method I have all my application variables being set via;
this.name = '....';
this.datasource = '....';

etc...

the issue I am having is that none of my THIS variables are being created as application scoped variables.

I am obviously missing something - and I assume it is because I am extending the mach-ii framework.
(I haven't previously had an Application.cfc that was extending another CFC)

I am sure it is going to be one of those things where I slap myself for being so silly - but none the less - if could someone could point me in the right direction - I would really appreciate it!


As always - thanks - Gavin.

Dave Shuck

unread,
May 10, 2013, 2:02:59 PM5/10/13
to mach-ii-for...@googlegroups.com
Perhaps I am missing something, but typically things that are set in the 'this' scope in Application.cfc are not available in the application scope.  If you intend to set things in the application scope and are doing so outside of OnApplicationStart() which is inherently thread-safe (yes, I know you are calling init() from there, but it is exposed), I would take an approach similar to this within the body of your init():

<!--- warning...untested code below --->
<cfif !StructKeyExists(application, "appInitComplete")>
   <cflock name="#application.applicationName#_appinit" type="exclusive" timeout="5">
      <cfif !StructKeyExists(application, "appInitComplete")>
         <cfset application.foo = "bar" />
         <cfset application.bar = "foo" />
         <cfset application.appInitComplete = true />
      </cfif>
   </cflock>
</cfif>




--
--
To post to this group, send email to mach-ii-for...@googlegroups.com
For more options and to unsubscribe, visit this group at http://groups.google.com/group/mach-ii-for-coldfusion?hl=en
 
New (July 2012): We've moved to GitHub: https://github.com/Mach-II/Mach-II-Framework
---
You received this message because you are subscribed to the Google Groups "Mach-II for CFML" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mach-ii-for-coldf...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Gavin Baumanis

unread,
May 10, 2013, 7:48:02 PM5/10/13
to mach-ii-for...@googlegroups.com
Hi Dave,

Thanks for the reply....
Not sure what I am thinking at the moment.....

For some reason I was certain that variables set in the THIS scope of Applicaiton.cfc became application scoped variables, they don't.

I have just created a really simple Application.cfc and an index.cfm to dump the application scope, too.
And of course they aren't there.

Because I set the datasource in the THIS scope and never use the datasource attribute in a cfquery - and they work.
Same with ormSettings... they are set in the THIS scope and alll my ORM operations work correctly, too.

I genuinely thought that I had previously dumped the Application scope, too, and saw all the THIS items in there.
Obviously I was wrong though.

I actually do have application.XXX =  in onApplicationStart for the creation of all my singletons / service objects.
So I am not really sure what I was thinking!

To unsubscribe from this group and stop receiving emails from it, send an email to mach-ii-for-coldfusion+unsub...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages