rodyon
11/02/2022, 10:32 AMREQUEST 1 rc.data = variables.blogService.list();
REQUEST 2 rc.data = variables.blogService.list();
I think if something like this happen in Lucee/Coldfusion, it would be abandoned somewhere around year 2000 as unusable platform. I'm not big on multithreading, but never got an issue you mentioned with cfml or fw/1 in years.Charles Robertson
11/02/2022, 11:30 AM<http://variables.blog|variables.blog>
, I am not so sure.
I mean, we are sometimes meant to lock down application variables and other bits of code that might spawn a race condition.
I just wondered whether this is one such example?rodyon
11/02/2022, 1:11 PMwebsolete
11/02/2022, 1:18 PMwebsolete
11/02/2022, 1:19 PMJim Priest
11/02/2022, 1:22 PMrodyon
11/02/2022, 1:36 PMCharles Robertson
11/02/2022, 1:57 PMproperty fooService;
My understanding is that because the actual controller component is in the application scope, everything inside the component, including properties, which are in the variables
scope, also persist.
You can see this when you dump out the application scope.
The point I am trying to make, is that any variable inside a service, in the variables
scope, is a singleton, as well.
This makes it vulnerable to being changed by more than one request.
If services were transients, each request would get given a new instance. In this case, there would be no problem, because each request would be given its own copy of all the variables inside each service.Charles Robertson
11/02/2022, 2:03 PMwebsolete
11/02/2022, 2:30 PMCharles Robertson
11/02/2022, 3:17 PMvariables
scope mutation inside a singleton.
I only used this approach, because I found it in an FW1 example application. And to be fair, the objective, within the example app, was very possibly correct and I corrupted it.
So, I’m going to remove the variables
scope variable and just return the list data from the page()
method.
Before:
function page(page){
// build variables.blogs struct from DB query
…
cfloop(query=local.qGetFile, startrow=local.startrow, endrow=local.endrow){
// add blog bean to variables.blogs
…
variables.blogs[local.qGetFile.File_ID] = blog;
}
}
After:
function page(page){
// build variables.blogs struct from DB query
…
local.pagedata = {
recordcount: local.recordcount,
list: {}
};
cfloop(query=local.qGetFile, startrow=local.startrow, endrow=local.endrow){
// add blog bean to variables.blogs
…
local.pagedata.list[local.qGetFile.File_ID] = blog;
}
return local.pagedata;
}
seancorfield
rc
or `local`/`var` scope variables only. The variables
scope of a controller should only be used to cache global state (like an in-memory copy of a fixed lookup table or some such) and should either be initialized in the constructor method init()
via dependency injection, or with careful locking as if dealing with application
scope.dfgrumpy
12/28/2022, 4:47 PMtmcneer
01/31/2023, 4:52 PMrodyon
02/03/2023, 5:29 PMjakobward
02/23/2023, 1:04 AMScott Conklin
04/05/2023, 9:59 PMpublic void function setupSession() {
// set up a default session
variables.userService.defaultUserSession();
}
function before( struct rc = {} ) {
// reset the application
if(structKeyExists(rc, 'resetApp')) {
userService.logout();
}
// user session data
rc["userSession"] = variables.userService.getUserSession();
}
I am getting
Original exception in onSessionStart
The action main.default failed.
Component [Application] has no accessible Member with name [USERSERVICE]
(expression)gundberg
04/26/2023, 5:13 PMMatt
05/01/2023, 9:09 PMRich Symons
05/05/2023, 6:32 PMadam.euans
05/10/2023, 11:30 AMpublic any function onSessionStart() {
setupRequestDefaults();
setupSessionWrapper();
}
Anders Lars
05/15/2023, 7:53 PMunhandledPaths
for all my existing stuff? Or can i hook up fw1 to an app.cfc in a subdir and just have that dir and below benefit from the framework?
And assuming running in a sub dir is fine, are there any other major complications tied to running it on a small part of a legacy site? Thanks!dfgrumpy
05/20/2023, 6:35 PMseancorfield
Anders Lars
06/21/2023, 5:49 PMspills
06/29/2023, 6:59 PMjamiejackson
07/07/2023, 6:42 PMsatauros
10/13/2023, 10:04 AMAnders Lars
10/31/2023, 9:46 PMDWilson
11/09/2023, 8:52 AM