bdeline2
10/26/2022, 4:52 PMproperty name="mySetting" inject="coldbox:moduleSettings:_*mymodule*_:myTestSetting";
But is there some way to do something like this without actually hardcoding 'mymodule' or some other mechanism besides property injection?
My '_BaseComponent.cfc' is a component I use in multiple code bases and I copy it from one code base to another as needed (which isn't very much). I'm trying to help my future self out when I copy it and I forget to update the module name.bdw429s
10/26/2022, 5:00 PMbdw429s
10/26/2022, 5:00 PMbdw429s
10/26/2022, 5:01 PMbdw429s
10/26/2022, 5:02 PMgetMetaData( this ).name
bdw429s
10/26/2022, 5:03 PMbdw429s
10/26/2022, 5:04 PMComponentA.cfc
just has
component extends='_BaseComponent.cfc' {}
then that doesn't really helpbdw429s
10/26/2022, 5:06 PMproperty name="mySetting" inject="coldbox:moduleSettings:{thisModule}:myTestSetting";
and have WireBox somehow be aware of the module that the CFC requesting the injection lived inside of. cc/ @lmajanobdeline2
10/26/2022, 6:15 PMwil-shiftinsert
10/27/2022, 2:11 PMgetModuleSettings( module )
;wil-shiftinsert
10/27/2022, 2:17 PMwil-shiftinsert
10/27/2022, 2:21 PMproperty name="req" inject="coldbox:requestService";
//….
var mySetting = getModuleSettings( req.getContext().getCurrentModule() )["myTestSetting"];
bdeline2
10/27/2022, 2:23 PMwil-shiftinsert
10/27/2022, 2:25 PMwil-shiftinsert
10/27/2022, 2:29 PM_BaseComponent.cfc
, using wirebox, directly or are you extending it?wil-shiftinsert
10/27/2022, 2:57 PMvar mySetting = getModuleSettings( 'myModule' ).mySetting;
binder.map("myBaseComponent")
.to("#moduleMapping#.model._BaseComponent").property(
name="mySetting",
value=mySetting
)
Or you can do something simular with initArg if your setting is part of your constructor.
There’s no need to hardcode your setting in a injection, instead you should set this up in every module which is using your _BaseComponent
If you are using your base component multiple times in an application because you are using it in multiple modules, you have to make sure it will have a different alias in every module.bdeline2
10/27/2022, 6:31 PMwil-shiftinsert
10/27/2022, 6:36 PMbdeline2
10/27/2022, 6:37 PMbdeline2
10/27/2022, 8:59 PMbinder.mapDirectory(
packagePath="#moduleMapping#.models",
namespace="@#this.modelNamespace#",
influence=function(binder, path){
binder
.initArg(name='myTestSetting', value='xyzxyz')
.asSingleton()
;
}
);
bdeline2
10/27/2022, 8:59 PM