hey, I meet the Stackoverflow Exception, and this ...
# koin
k
hey, I meet the Stackoverflow Exception, and this is my code
Copy code
single {
                TaskService(
                    database = get(),
                    taskGroupService = get(),
                    taskProjectService = get(),
                    tagService = get(),
                    subtaskService = get()
                )
            }

            single {
                TaskGroupService(
                    database = get(),
                    taskService = get()
                )
            }
how can I fix it ?
n
This is a cyclic dependence between TaskService and TaskGroupService.
TaskService
needs
TaskGroupService
, which in turns needs
TaskService
, which in turn needs
TaskGroupService
, etc... Try to extract the code that is needed by both your classes into a 3rd "standalone" class, which can be injected without issue in both
TaskService
and
TaskGroupService
k
sorry to be late, actually I have fix it with this code thank you for explaination
n
If your
TaskGroupService
still has the
TaskService
dependency, the issue (cyclic dependency) is still present, even if you avoided the crash by injecting lazily the
TaskGroupService
.
I would recommend you read more documentation about the core concepts of injection before you go any further or you will face many more issues and incomprehension later on. Sadly, the Koin documentation doesn't explain the "why" of injection, only the "how".
p
This the dilemma of egg and chicken. To get the chicken you need the egg. To get the egg you need the chicken. 🙃