0

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 !

Kannan.P
  • 1,263
  • 7
  • 14
  • Move your `property` line right below the `component` statement in line 1 – Bernhard Döbler Feb 25 '19 at 13:00
  • Even if I'm move that in immediate next to the component mean while accessing the property in inside setupapplication() it's through the property variable is undefined. – Kannan.P Feb 25 '19 at 13:15

2 Answers2

1

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.

Tony Junkes
  • 735
  • 8
  • 16
0

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

James A Mohler
  • 11,060
  • 15
  • 46
  • 72
  • 1
    While I agree (the OP's scenario does not match a use-case), Application.cfc is treated as a controller in FW/1 so injecting some kind of "helper" service object is not too unreasonable. – Tony Junkes Feb 26 '19 at 14:56