How do you organize your small reusable cffunctions?

后端 未结 6 1367
孤街浪徒
孤街浪徒 2020-11-30 06:19

I am reorganizing my ColdFusion directory structures and am curious about how experienced CF developers are organizing libraries of smaller cffunctions.

I am not as

6条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-11-30 06:32

    if you are using Application.cfc (if you are not i would strongly suggest migrating to it from Application.cfm - its very easy to do) you can build a baseComponent.cfc with all your UDF methods and have the Application.cfc inherit from baseComponent. then in the onRequestStart method set a variable called request.app=this;

    for the entiure request, you can then use request.app.methodname() to access the UDF. its very nice and simple way of handling UDFs

    also, if you like you can have all your cfcs inherit from the same baseComponent so that all your cfcs have those util functions as native methods. makes unit testing cfcs very easy because the cfcs dont need to reply on a passed (injected) reference to the UDf component, they are decedents of it!

    one challenge with this approach is that the extends attribute of a cfc cannot be an expression... so depending on how you package your components, this can be hard to implement. the easiest way to handle it is with a coldfusion mapping.

    hth Jon

提交回复
热议问题