Gnommon
TTCTheo's Typesafe Cult
•Created by Gnommon on 6/17/2024 in #questions
Refactoring for Dependency Injection (Circular Dependecies)
Also: No i probably dont need a UserRepository but i wanted to keep the rest of the backend code clean and not have too many custom solutions for every single problem
5 replies
TTCTheo's Typesafe Cult
•Created by Gnommon on 6/17/2024 in #questions
Refactoring for Dependency Injection (Circular Dependecies)
Thank you! You bring up very good points.
The problem i had above is kinda solved now (haven't tested it yet). I realized the Auth Service does not really need the StructureService but rather the underlying repository so that should fix my problem of circular dependecy.
The reason why i want to add DI (and refactor everything to use DI not just parts, to have the code somewhat structured) is mainly for.
For example: I have a function for deleting structures. A user can delete a structure and the call could happen in multiple parts of the app. But only some of those calls also should send WebSocket notifications to other users to update their UI. There are other additional steps that could happen around the deletion of a structure.
For this kind of thing i envisioned using DI to simplify the code a bit but again, i just started this refactoring so i am not 100% sure on the approach yet.
Another example: One very big and complex function makes a bunch of DB calls. We have to test the entire functionality manually every time a slight change happens and therefore i wanted to make this function specifically more testable by injecting the DB calls with mocks instead of directly calling prisma.
5 replies