[dev] Cyclic dependencies in binders

Chuck Hagenbuch chuck at horde.org
Mon May 17 01:58:11 UTC 2010


Quoting Jan Schneider <jan at horde.org>:

> There's a problem with creating binders for objects with cyclic dependencies.
>
> I'm currently refactoring Horde_Alarm, and it depends on  
> Horde_Notification if displaying alarms as notifications.  
> Horde_Notification OTOH depends on Horde_Alarm because it triggers  
> the alarm system before displaying notifications, so that it can  
> push any new alarms on the stack right before.
>
> Theoretically I would have two binders and both use the injector to  
> get the other object. But this obviously leads to an endless loop.
>
> Any ideas how to solve this?

I'd use a factory that created the dependency directly. Factories can  
create objects outside of the injector - that's their purpose - and  
that should solve the cycle.

-chuck


More information about the dev mailing list