Additional info:
i see ‘MyService’ as just a soft reference to the parent ‘AbstractService’.
No, it’s not that, at all. The way I understand it, the “parent pattern” is so you don’t have to repeat yourself.
Since ‘AbstractService’ is the actual instance, it should be the one that is cached as a singleton.
No, AbstractService should NEVER be instantiated. It’s just a “design”.
Let’s use a more thorough example:
map(‘AbstractService’).to(‘some.cfc.never.instantiated’)
.initArg(name=‘arg1’, value=‘value1’)
.initArg(name=‘arg2’, value=‘value2’)
.initArg(name=‘arg3’, value=‘value3’)
.property(name=‘prop1’, value=‘prop1’)
.property(name=‘prop2’, value=‘prop2’)
.property(name=‘prop3’, value=‘prop3’)
Now, I have 27 services I want to do just like this. Most would be singletons, some would not.
map(‘ServiceA’).to(‘com.serviceA’).parent(‘AbstractService’).asSingleton()
map(‘ServiceB’).to(‘com.serviceB’).parent(‘AbstractService’).asSingleton()
map(‘ServiceC’).to(‘com.serviceC’).parent(‘AbstractService’); /// NOT a singleton
map(‘ServiceD’).to(‘com.serviceD’).parent(‘AbstractService’); /// NOT a singleton
This doesn’t work. NONE of them end up being a singleton, because (if it’s a bug?) I didn’t put .asSingleton() on the parent definition.
I would have to duplicate the existing ‘AbstractService’ definition and add:
map(‘AbstractServiceSingleton’).to(‘some.cfc.never.instantiated’)
.asSingleton()
.initArg(name=‘arg1’, value=‘value1’)
.and.so.on
In my opinion, you should be able to add the .asSingleton() or not to the parent definition. If you do not, but you provide it on the “child” definitions, it should read it there. In fact, if there were a feature of .asTransient(), I would expect it to override the .asSingleton() on the parent definition. At the minimum, I would expect that if you did not define the caching strategy on the parent, that it would certainly pick it up from the child definition.