atomicobject / objection

A lightweight dependency injection framework for Objective-C
http://www.objection-framework.org
MIT License
1.85k stars 223 forks source link

Sharing singleton scope when deriving a new injector #81

Open StatusReport opened 9 years ago

StatusReport commented 9 years ago

We have a scenario where we want to derive a new injector from an existing one with additional modules when displaying a new view controller. The existing injector has singleton instances that are already cached within it, and we need to use the same instance of them in the new injector.

Currently, using withModuleOfType: will create a new injector with the same global context, but with new injection entries that will create new instances of the singletons upon request.

It makes sense to me that derives injectors will produce the same singletons of the original injector, since we want to inherit the behavior of the original injector, including its context. What do you think?

Additionally, if anyone got any idea on how to overcome this in a different, elegant way, I'd be happy to know.

jdewind commented 9 years ago

I agree with this change. Singletons typically imply state and I can understand the need to keep it between modules.

I'll create a branch to implement this.

Thank you.