I am facing an issue with a circular dependency reference error in a .net core web app. Whilst I think I understand the issue I can’t think of a work around to the problem I face, I’ve searched around and also don’t seem to find anyone else with the same issue.
This is the logic flow I’m trying to achieve: 1. Generic repository handling db CRUD operations. 2. Within this repository is a service that performs certain task based on the kind of db action taking place.
Example 1 A new record is inserted to the user table, there is a task that triggers a welcome email to the user.
Example 2 A lead is inserted to the database, there is a task that creates follow up task for a system admin.
The reason this is all handled in such a generic way is that I want to provide an interface for app admins to create/update these trigger tasks, hence in example 1 why I don’t just hard code an email to the user.
I’m using DI to resolve various services and the issue I have is as follows:
EntityFrameworkRepository implements IRepository
ITriggerService is injected into the EntityFrameworkRepository, the error is triggered because I then try to inject and resolve IRepository in the trigger service, even without this injection templateService also attempts to resolve IRepository in its own constructor as well. At the minute I just have the ITempalteService and IEmailerService coded but there will be lots of other ‘trigger actions services’ these will also be used throughout the code and other services so I don’t really want to change the design of these.
I recognise that this is bad design based on all the other people that have asked similar questions and the responses they received, what I can’t figure out is how to resolve/architect the correct solution to achieve the desired goal.
All suggestions welcome!