Just a minor nitpick. This isn't a real circular dependency, as the idea that "this is something only A
could do" is faulty. All B
really knows is that "this is something that only someone else can do". It may be true that only A
can do it, but that isn't known to B
.
Anyhow, a simple example would be this:
In assembly B
:
public interface ISomething
{
void PerformAction();
}
public class ActionManager
{
public void DoSomething(ISomething something)
{
something.PerformAction();
}
}
In assembly A
(which references B
):
public class ActionPerformer : ISomething
{
public void PerformAction()
{
...
}
}
public class Program
{
public static void Main()
{
ActionManager manager = new ActionManager();
ActionPerformer performer = new ActionPerformer();
manager.DoSomething(performer);
}
}
In short, this example demonstrates code that (after full polymorphic resolution) has A
call into B
, then B
calling back into A
.