After some other distractions I’m now coming back on this requirement and have made some progress which I’d like to share plus I’ve hit an issue for which I’d like some help and guidance.
As I’m using ORM I have the following settings in my Application.cfc…
this.ormSettings.eventhandling = true; this.ormSettings.eventhandler = "model.ORMEventHandler";
…so, taking record updating as an example, in my model.ORMEventHandler.cfc I have a preUpdate(any submittedEntity, any persistedStruct) method. Within this method I determine what in the submitted entity has changed from the persisted entity (I can share this if anyone is interested) and assemble a struct of data that I want to record in my audit trail table.
Next I have created a custom LogBox AsyncDBAppender, referencing it in my Coldbox.cfc config, which accepts my audit data and inserts it into my audit trail table.
And all is good in the garden!
Except…
Getting LogBox injected into my model.ORMEventHandler component.
I tried…
property name="objLogbox" inject="logbox:logger:auditTrailLogger";
…but it didn’t work and I guess I get that as ColdBox can’t inject it as ColdBox hasn’t been instantiated when the EventHandler is called for the first time by the Application.cfc pseudo constructor.
I decided to take a look at the variables scope in the pseudo constructor region of the component and it said getController() existed but then I tried…
variables.objLogbox = variables.getController().getLogbox().getLogger("auditTrailLogger");
…that failed with…
Message: ColdBox Controller Not Found Detail: The coldbox main controller has not been initialized
…so I guess the pseudo constructor was lying.
The only way I can see that I can get LogBox is by calling it from within preUpdate() and any other method in the component like this…
var objLogbox = getLogger("auditTrailLogger");
If this is right, my only concern is how “expensive” calling getLogger() is in every method rather than referencing it once from the variables scope as I’m used to with injected properties.
Any opinions or differing approaches welcome.