I have been repeatedly admonished for use of static calls in my Service Classes used in a Blazor Entity Framework App.
My problem is that I have Services that require interaction with other Services in a classic loop.
For example, the Computer Manager Service may need to access Account Information provided by the Account Manager, and the Account Manager may need access to information about Computers.
If I add the Computer Manager Service to the Account Manager and the Account Manager Service to the Computer Manager I get complaints about circular dependencies, which I understand but have no other good way to resolve.
I looked for a solution that did not involve exposing static methods, but did not find anything of consequence. Thus, I implemented a set of static methods that take in a DBContext Factory which supports creation of a DBContext inside the Static Method for use only in that method, and then it is disposed when the method is complete. I have verified that the dispose is taking place.
So this lead to an effort to partition the services in a more granular fashion and that produced a concrete example.
I broke out some of the Account Management functionality into a AccountUtilitiesService where I never do anything that requires the ComputerManagerService. However, one of the tasks the Account Utility Service needs to do is compute costs, which requires a call to the ComputerUtilitiesService to get the costs associated with the Computers on the Account. This creates a dependency loop. I have to get the Computer Costs from somewhere and really do not want to put that method into the Account Service as it is really associated with Computers...
But since the AccountUtilitiesService is the only place where a call to the ComputerCosts method is made, I decided to move it to that service which eliminated that issue. I should have this done soon, and then we will see if what I wrote below continues.
I am running into issues that are crashing the App Pool on the IIS Server with no visible error or debug output, and several people are insisting that the Static methods are likely the cause. OK, that may well be so but it leaves me with no means by which to do what I need to do.
So what code pattern is used when Services need to talk to each other for various reasons? How do we implement this in a manner that avoids static methods and avoids cross dependency issues?
Do I have to try to partition my classes in an even more granular manner - which feels like it violates other Coding Principles? That is the only thing that is looking even remotely viable, but I am not sure it will solve the problem as I am not entirely sure I can disconnect them. I will start looking at this now to see if I can find a solution in this context.
Are there any other solutions to this problem that I might explore?
andin there then you really need to justify why.