Wirebox standalone - how to cache mapped objects once autowired


I was wondering if there was a way to ask Wirebox to cache an
autowired instance of an object? This is *different* to caching the
CFC in the application scope.

Example, if I have a mapping e.g.

<cfset map("my.service").to("com.services.MyService") />

When I call wirebox.getInstance("my.service") I would like it to
autowire that the CFC the first time, and subsequent times it should
give me the a new instance (i.e. a copy) of the previously auto-wired

The idea is if I have a very busy page, each call to
wirebox.getInstance("my.service") doesn't incur that same autowiring
overhead - becuase my code and dependencies have not changed.

I hope that makes sense. Thanks in advance for any replies.


Sorry, I dropped this thread yesterday. I got super busy and forgot about it. :frowning:

To specifically answer your question, no WireBox cannot give you a NEW copy of your service that is already wired without having to wire it. That doesn't really even make sense since creating a new instance of the service fresh would require it to be wired and you probably don't want to go duplicating your service (with the ColdFusion duplicate() method) as that will make a costly deep copy of EVERY outgoing reference that service has.

Can you explain why you need a new copy of the service every time? Can't the service just be a singleton itself and every page request simply is handed a reference to the single instance of your service. Or is that what you wanted and I am just understanding you wrong?

To review, I'm suggesting that you not only persist the WireBox factory in a scope such as application, but I'm also suggesting that you persist your service as a singleton EITHER through WireBox's inScope("application") persistence, or WireBox's inCache() storage, or the most simple method of the asSingleton() setting. If written correct, your service should be thread-safe and be able to handle concurrent calls to its methods. In that scenario, your app will only ever have to create a single WireBox instance and a single service instance. If the service has instance data specific to a given method call that would preclude multi-threaded use, then it sounds more like a bean to me.



Hi Brad

I can understand how you might need to get something autowired each
time, but I can also understand how the autowired cfc dependencies
might never change. I guess I could use my service as a singleton, it
should be thread-safe.

The main issue was performance by the way, not that it's slow but
there is a lot going on with the autowiring each time.

Thanks for the feedback!