Gnommon
TTCTheo's Typesafe Cult
•Created by Gnommon on 6/17/2024 in #questions
Refactoring for Dependency Injection (Circular Dependecies)
TLDR: I want to refactor my application for dependency injection and I am not sure how to. I started creating Classes for basically every resource / table in DB. They all contain functions related to the resource like this:
My Problem now is that my Auth Service depends on another Service which also depends on the AuthService partially.
This creates circular dependencies. Should I create more granular Services i.e. a service for every function? Set of functions based on the dependencies? Is my Repository per Resource approach wrong?
Context: I've been working on a project using the T3 Stack and until now everything was basically entirely written inside the tRPC routers. This has become a problem now that other people besides me might start working on the project, increasing complexity, code coupling / duplication, testing purposes and all the other reasons for refactoring for dependency injection. I started today and am still learning how to apply the SOLID principles and I figured that starting with DI would be the solution to my problem. So if you think I am approaching my problem in a wrong way or if i should focus on other principles first, please let me know your opinion as well!
If you want more info and more detailed code examples I will be gladly provide them.
5 replies