coldfusioncoldfusion-11application.cfcfw1

Creating FW/1 Service in application.cfc


I am trying to create call a service in application.cfc

The original code looked like

It is now

void function setupApplication() {

  ...
  application.objCCFRO  = new model.services.setting();
  application.stSetting = application.objCCFRO.loadini("standard.ini");

I am trying to convert it to

  application.stSetting = variables.beanFactory.getBean( "settingService" ).loadIni("standard.ini");

The documentation says

sometimes you need access to the bean factory directly (such as for obtaining a transient) and whilst you can get at it inside your controllers via variables.fw.getBeanFactory() it’s better to have the bean factory injected by declaring property beanFactory; (which can be used in both controllers and services), then you can call variables.beanFactory.getBean() whenevr [sic] you need a transient.

I need a transient when I run setupApplication()


Solution

  • Well, if you're using DI/1 with FW/1, you can set accessors="true" in your Application.cfc and then define property settingService;. This will make the service available, via variables.settingService, providing that DI/1 is managing that CFC.

    Your example call could then become: application.stSetting = variables.settingService.loadIni("standard.ini");