问题
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 callvariables.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