What you've described is not the same as what the original poster is asking
about. He want to use relative paths. You have created a simple factory, but
you still have to either know the full path to the target CFC (which is not
what he was wanting), or you have to have all your CFCs in a single folder
(which is not very easy to deal with if you have many components).
In any event, this simple factory might work fine if you have a simple
object model with limited dependencies. But for any large object model, is
very limiting since now any code using this has to be concerned about
creating all the objects you will use, with the proper arguments and the
proper dependencies resolved. ColdSpring solves all of these problems and
you only have to declare the paths to the components in one place: the
ColdSpring XML config file. Once that is done, you can use ColdSpring to
inject the CFCs into other CFCs that need to use them, or you can just call
getBean() on the ColdSpring bean factory to get back a reference to the
component.
Basically, instead of worrying about relative paths (for the original
poster) or having other parts of your application burdened with the
responsibility of properly creating the components and resolving their
dependencies (for Dominic), just define their locations in one place and let
ColdSpring do the work for you.
Also, just to be clear on the names, what you have here (getCFC()) is a
function, not a method. A function is standalone, while a method is invoked
on an object.
Hope this helps.
Brian
On Nov 16, 2007 10:48 AM, Dominic Watson <[EMAIL PROTECTED]>
wrote:
>
> I don't see why this is 'hacking' it at all. I also came up with something
> like this and I don't see why it is a problem. Indeed, our company does
> not
> host the websites that we create and removing any kind of responsibility
> of
> the system working from third parties is a bonus (we have to ask them to
> setup any mappings we want on a server, if things go wrong it can delay
> deployment 5 days or more).
>
> Could someone explain to me why I am wrong (this is a straight question
> and
> I quite expect to be convinced ;)?
>
> The udf I created looked something like this:
>
> <cffunction name="getCFC">
> <cfargument name="name">
> <cfargument name="method" default="init" required="false">
> <cfargument name="args" type="struct" required="false">
>
> <cfset var argNames = StructKeyArray(arguments.args)>
> <cfset var i = 0>
> <cfinvoke component="#arguments.name#" method="#arguments.method#"
> returnVariable="ret">
> <cfloop from="1" to="#arrayLen(argNames)#" index="i">
> <cfinvokeargument name="#argNames[i]#"
> value="#arguments.args[argNames[i]]#">
> </cfloop>
> </cfinvoke>
>
> <cfreturn ret>
> </cffunction>
>
>
> Just place the udf in a template in the same directory as your components
> and load the method into the application scope. Then call the method when
> ever you want to invoke a cfc, i.e.:
>
> <cfset myObj = application.getCFC("myCFC")> <!--- presuming myCFC.cfc has
> a
> method called init() that returns a value --->
>
>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Get involved in the latest ColdFusion discussions, product
development sharing, and articles on the Adobe Labs wiki.
http://labs/adobe.com/wiki/index.php/ColdFusion_8
Archive:
http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:293486
Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm
Unsubscribe:
http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4