https://kotlinlang.org logo
#kodein
Title
# kodein
t

Tomas Kormanak

08/17/2022, 8:52 AM
Hi, I have a problem with
DependencyLoopException
We have a loop in dependencies which I think is alright in our case. We use construction injection (no DiAware interface). I was hoping that using a provider can solve it, but it seems not. Any ideas?
Copy code
bind<EventBus>
    ╔╩>bind<Set<out EventHandler<in Event>>>
    ║  ╚>bind<NotificationService>
    ║    ╚>bind<EventBus>
    ╚══════╝
Copy code
class LocalEventdBus: EventBus (
    handlerProvider: () -> Set<EventHandler<Event>>,
) {...}
Copy code
bindSingleton<EventBus> { LocalEventBus(provider()) }
r

romainbsl

08/19/2022, 11:29 AM
Let me rephrase your use case. You have a Super EventBus that can take handle multiple EventBus under the hood, maybe in order to broadcast the right event to the right handler ? So practically speaking, you need a least 2 different instances of EventBus. Assuming that LocalEventBus is your “Super” EventBus, how did you defined your provider ? Not important here, but you should use the instance function
bindSingleton<EventBus> { LocalEventBus(instance()) }
6 Views