Creating FW/1 Service in application.cfc

喜你入骨 提交于 2019-12-25 07:10:03

问题


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()


回答1:


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");



来源:https://stackoverflow.com/questions/32573438/creating-fw-1-service-in-application-cfc

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!