I have 2 classes that have dependencies.
public class AuditManager
{
//set of methods
public static AuditManager Singleton= new AuditManager();
public int AuditEvent(int x){
Event event=new Event(x);
event.SaveToDB();
}
}
Also I have a class:
public class Event
{
int x;
//set of methods
public Event (int x)
{
this.x=x;
}
public User getUserOfEvent(int eventId){
User usr = Respository.Get(eventId);
Audit.Singleton.AuditEvent(usr.x); //circular dependency between Audit and event
return usr;
}
public int SaveToDB()
{
new EventDal(){id=x}.Save(); //EventDal is used a lot in more Entity-type classes
}
}
As you see, Audit uses classes like Event (responsibles of representing the model) And also , some actions in the model should be audited.
How is the best way to remove these circular dependencies?