• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

using CFCs statically without cfinvoke

New Here ,
May 30, 2006 May 30, 2006

Copy link to clipboard

Copied

We have a set of CFCs that we use as an application API.
Currently, the way I use them is by instantiating them in the application scope and then creating aliases (for shortened syntax) like this:
<cfobject name="Application.Company" component="components.company">
<cfset $Company = Application.Company>

and then in the application, I call methods like this:
<cfset qCompany = $Company.GetCompanyDetails(cmpid)>

-- All of the objects are intented to be used statically and have no instance data, but to use them like this, I've obviously having to create an instance (using CreateObject or cfobject).
-- The reason I don't use CFInvoke to call methods statically is because I think that it makes the code much more difficult to read.
-- The one concern I have of using the objects in the way that I am (by creating instances of them and putting those instances into application scope) is that if I forget to "var" any variables in a method, then I have just created "instance data" on the object, and things could get really tough to debug when unexpected behavior starts occurring in the application.

-- I 'm trying to find a solution to reference my CFCs, and then access them later statically without creating an instance at all. Has anyone ever come up with a solution for this?

-- As a "last resort", I could always create the objects in Request scope, but there's obviously some performance overhead there.

Any thoughts on this?
TOPICS
Advanced techniques

Views

465

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
May 30, 2006 May 30, 2006

Copy link to clipboard

Copied

I think <cfinvoke> is just what you should use. But If the code beautification is what you're after, you could write a wrapper User-Defined-Function (UDF) for the <cfinvoke> tag - just like cflib.org's many UDFs, that are meant to replace the corresponding tags. Put the wrapper functions in a separate file, and include it from your master template?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 30, 2006 May 30, 2006

Copy link to clipboard

Copied

On Tue, 30 May 2006 15:23:08 +0000 (UTC), Fernis wrote:

> I think <cfinvoke> is just what you should use.

There's a rather large performance hit when creating/destroying CFC
instances (one IS still created when doing a <cfinvoke>, it's just "killed"
immediately after use).

If your CFCs are just "bags o' functions" rather than being used to define
"objects", it might be an idea to forgo using CFCs, and just use UDFs (or
libraries of UDFs, as appropriate).

--
Adam

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 30, 2006 May 30, 2006

Copy link to clipboard

Copied

Thanks for the replies

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 30, 2006 May 30, 2006

Copy link to clipboard

Copied

LATEST
Thanks for the replies

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation