[coldbox-3.5.1] Interceptors accessing wired objects

So I’m still working on a proof of concept to convince the bosses that CB is a great framework with which to start building a SaaS application. In the process, one of the things I have to commit to is to be able to code everything that their current system can “do”…not that we won’t rewrite it…but I made a commitment.

There is a routine by which the CGI scope is stuffed into a session variable because the values can actually be used but overridden in this application and I need to mimic that functionality. In my first stab at this I…

Created an interceptor so that on a session start it can grab the cgi scope and dump it into an object for later use.
Created a basic model to house the cgi scope variables using a single property of type struct and accessors set to true.

In the interceptor, I thought to use wirebox to get the mapped instance in the session scope for the cgi facade class.

It works up to a point…but continues to claim that “setcgiscope()” is not a method…

Error Type: Application : [N/A]
Error Messages: The method setcgiscope was not found in component C:\inetpub\wwwroot\td\model\system\CGIFacade.cfc.

So the two questions I have are:

  1. Does this seem a reasonable approach. If there is a simpler or smarter way to do this, great…I mean, I’ve been doing CF for a long long time so I know I can do it another way, but I to do it the CB way :slight_smile:
  2. Why is my accessor not working…am I overlooking something or have I don’t something wrong for injection that I don’t get yet?

The relevant items are below and this is not the first interceptor, class, mapping or injection I have done on this proof of concept

Wirebox Mapping
mapPath(“systemcgi”).to(“model.system.CGIFacade”).into(this.SCOPES.SESSION);

Interceptor

component extends=“coldbox.system.Interceptor” {
property name=“wirebox” inject=“wirebox”;
public void function preProcess(event, interceptData) {
wirebox.getInstance(“systemcgi”).setcgiscope(CGI);
};
}

CGIFacade model
component accessors=“true” {
property name=“cgiscope” type=“struct”;

CGIFacade function init(){
return this;
}
}

Thanks,

Mike

Mike,

The answer is yes, with ColdBox rather than inject the wirebox, inject the object instead.

So your code for your interceptor would look like this.

component extends=“coldbox.system.Interceptor” {
property name=" cgiObject " inject=“cgiObject”;
public void function preProcess(event, interceptData) {
cgiObject.setcgiscope(CGI);
};
}

Hopefully that will get you going…

So, from a session point of view, this works perfectly…but I thought I would test making a simple change to the wirebox mapping and scoping it as request. When I do this, I don’t see the (in your example below) cgiObject in the request scope output…it still seems to be sitting in session.

In the example you provided, cgiObject (the property) is now an instance of the class…but since the class is mapped in wirebox in the request scope, where is “cgiObject” the variable? More over, when working with interceptors, does it make more sense to avoid request scopes?

Now I’m pretty confused as to where things are sitting, when they are being instantiated and in what scope.

Mike,

Unless you specify the scope it is always variables that the object is saved too.

I was likely getting unnecessarily confused…I keep forgetting about event/rc/prc being used to move things around. Still learning.

thanks,
Mike