[coldbox-3.5.2] First AOP and what is NOT AVAILABLE to the CFC

The getController package method in the C:\data\htdocs\coldbox-352\system\web\services\ModuleService.cfc component cannot be accessed from C:\data\htdocs\tdcc\model\aspects\ModuleAccountRequirement.cfc.

I’ve created an AOP aspect. Woo Hoo. It worked in my initial tests, but as I expected to have access to some coldbox objects / settings, when I added things I use all over other classes, I encountered the above error when trying to inject the moduleService object.

The apsect (bound by regex to any handler in any module) is to be designed to:

  • check the current module being interacted with
  • check the sessionstorage object for a particular value (to see if an “account” is selected)
  • if the value is present, the access to the module (handler/action) is permitted
  • if the value is not present, the access is not permitted and the user is redirected to the home page

Of course, taking suggestions on better ways to do this, but my injection of the modelService (coldbox:moduleService) to get the current module AND to get the current event context fails. I initially take that to mean that at the time this class is instantiated in the process, the objects I need are not available.

Can someone clear up this assumption for me or tell me what I might be missing before I try to start hacking it? I supposed that the init() method could use some additional arguments and I could pass in the controller (not that I’m entirely certain of how to do that) but I would rather not (or more to the point, assumed I did not have to since I can properly inject sessionstorage and wirebox).


Mike Craig

Wow. So I found a very long thread from Ben Dalton and now see that in order to get much of this to work, I have to delay the DI a bit using providers. That was very helpful. What would be more helpful is to have this documented better in AOP. The example in the wiki is a good start but not very helpful when one of the obvious uses of an aspect is to determine if something should happen and if not, direct to what should (typically using setNextEvent and a messagebox (flash), as Ben’s initial problem indicated. I will try this out with providers instead and get some delayed DI going to see if I can get it to work. That thread was worth the read.


hmm…no, not what I expected, I don’t think. To provide some parent to module introspections, I opted to use a plugin in the module that I map for everyone to use and I’m not sure I want (or should) implement the provider interface to a plugin to support this…or should I?

Since it seemed from that discussion, noting but delaying the DI of certain objects into the aspect was required, I guess maybe that’s the only way I can go?


Got it figured out based on group threads for the most part. use provider to inject the message box because the plugins are not loaded at the time the aspect is instantiated.