Handling Circular Dependencies in Scala with Dependency Injection Using MacWire
I'm updating my dependencies and I need help solving Does anyone know how to I'm working on a project and hit a roadblock....... I'm working with an scenario with circular dependencies while trying to set up dependency injection in my Scala project using MacWire (version 2.3.7). I have two classes, `UserService` and `NotificationService`, which reference each other. The `UserService` needs to send notifications when a user is created, and the `NotificationService` requires user information to customize the notifications. Here's a simplified version of my code: ```scala class UserService(notificationService: NotificationService) { def createUser(username: String): Unit = { // Logic to create a user println(s"User $username created") notificationService.sendNotification(username) } } class NotificationService(userService: UserService) { def sendNotification(username: String): Unit = { println(s"Notification sent to $username") } } ``` When I attempt to compile this, I get the following behavior: ``` behavior: Circular dependency detected: UserService depends on NotificationService, which depends on UserService ``` I've tried breaking the circular dependency by using lazy initialization in MacWire, but it hasn't worked as expected. I've also looked into using `trait` as an interface, but that doesn't seem to resolve the scenario either. Can anyone suggest a clean way to handle this circular dependency while adhering to best practices in Scala? Any insights would be greatly appreciated! I'm working on a API that needs to handle this. Any help would be greatly appreciated! I'd really appreciate any guidance on this. For context: I'm using Scala on CentOS. I'm working on a application that needs to handle this. Any feedback is welcome!