[coldbox-3.5.0] getSetting, setSetting and wireBox

I have an app which currently has some hard-coded settings, that ideally I’d like to “convert” into dynamic settings. For instance, a list of banned IP addresses that are currently in Coldbox.cfc in my settings object (i.e bannedIPS: [“127.0.0.1”,127.0.0.2”]).

I’d like to move these out of coldbox.cfc, and build them automatically from afterConfigurationLoad inside an interceptor for example setSetting(“bannedIPS”,[“127.1.2.3”]).

The problem (obviously), is that these settings are already injected into my models, so a model that has is empty when I actually need it within the model later.

Is there a way to “refresh” these injected settings somehow? Or do I need to approach this in a different way?

Thanks,

Tom.

I would approach this another way.

Create a service that is injected instead, that can be a singleton if need be. And create two methods one for setting and getting the list, or whatever you need. Which should include setting the list and getting the list, as well as single ip address.

How you do this is up to you, but personally I would look at storing the information in the database. Then the service could grab the information based on a query of that IP, store all the IP’s in the service ( don’t recommend that), or what ever you need to do.

I would also imagine that your app has an Admin interface, in which you could then write a module or handler to then maintain this list if you need too, or you can just manually add them to the database if that is preferred.

The main problem is that these lists can grow very large over time, and what might start out with 1-10 now, could be hundreds in a few years time. So the notion of going for and storing in a database is probably a better solution.

Now when is the best place to fire something like this, I would do it on the onRequestStart rather than where you are attempting to do it. Then you get the current IP and do something like

badIPService.isBanned(ipAddress);

And the service then can do a lookup and return true or false, and then you can either throw and exception or override the event to a new handler to then display different content, or even point them to another website if you so desire.

Hi Andrew,

Sorry – I was just using bannedIPs as an example. That’s not what I’m doing, and the array in question isn’t going to get very big, but it varies from application to application, which is why I wanted to avoid hard-coding it…

Well if it is too avoiding hard coding, then the principle should still apply.

I run an interceptor (called ‘appInit’) that runs on afterAspectsLoad that basically calculates a lot of different things and then stuffs them into the CB cache. My models then just pull them out of the cache as needed.