RE: [coldbox:15047] Re: [wirebox 1.1.1] - Singleton question

I was looking at your post on my phone over lunch, but looking closer at it now, I see the following lines:

mapDirectory(’/model.repositories’).asSingleton();
mapDirectory(’/model.services’).asSingleton();

You shouldn’t chain “asSingleton()” after “mapDirectory()”. asSingleton() will only apply to the last mapping which was processed, not all the mappings created from that directory.

I would recommend going the route of adding the singleton=true annotation in all your singleton CFCs. Your only other option is to map them all explicitly by name.

On a side note, Luis, what do you think about enhancing the WireBox binder so that asSingleton() and other chainable methods would work with mapDirectory()? If we changed currentMapping
to be an array of mappings, then mapDirectory() could append each mapping it creates and methods like asSingletion(), asEagerInit() could apply themselves to each mapping in the array. Just a thought.

Thanks!

~Brad

Brad,

Thanks, I will go down the road of adding the singleton attribute to
my CFCs and let you know how it goes.

Brett

Brad,

Just updated the CFC's in my services and repositories directory to
include the singleton attribute and it worked beautifully. Thanks so
much for your help. My pages are loading at least ten times faster.

Brett

Most excellent news!

Thanks!

~Brad