Inject Dependancy in application.cfc FW1

333 views Asked by At

I've an my test application in FW1. Currently I'm having test service and DAO. For example Model/services/test.cfc and Model/DAO/testDAO.Here I want set one of data on application.cfc. How I can inject some services / DAO in application cfc. I've tried to do that by following Creating FW/1 Service in application.cfc. But always facing the below issue.

enter image description here

I want call either my services/test.cfc or DAO / testDAO in my application cfc file. Give an idea of that and Thanks in advance !

2

There are 2 answers

1
James A Mohler On

In FW/1, Services go into each controller, not into application.cfc. You need to move them over there.

0
Tony Junkes On

Without seeing your code, there's a few things that seem incorrect here...

  1. As Bernhard stated, you need to declare properties immediately inside the component block.
  2. Make sure in your component declaration, you include accessors="true" attribute.
  3. Make sure you reference your service based on how you have DI/1 configured. I see you you have test.cfc in a services folder. I'm assuming for you to reference the property as testServices, you set DI/1 to map it this way. Otherwise, by convention, it would be accessed as either test or testService. See: Basic DI/1 Conventions
  4. I couldn't find the source to back this up but, I am 99% certain you will not be able to access your service/DAO from setupApplication(). It's sort of a chicken/egg approach.

You could make this call in one of the other life cycle methods such as before() or setupRequest(). Depending on your use-case however, I would rethink your approach. As James mentions in his answer, this is not a common order of operations. If you need data available on every request or access to a helper method for regular processing, I could see this working for you. Outside of that, unless you were really needing this service every time, you're better off isolating its injection to only the controllers requiring it in your application. It's ultimately hard to say without knowing your intention.