Math コンポーネントを更新する方法を知っているクラス (MathController) があります。
そのクラスはヘルパー クラスを使用して、タイム スケジュールに基づいて、いつ更新をトリガーするかを決定します。
私がやりたいことは、IoC コンテナーにヘルパー クラスを追加することです。
現在、IoC は MathController を作成します。ヘルパー クラスは MathController からアクションを受け取る必要があるため、循環依存関係のシナリオに陥らずにそれを行う方法がわかりません。
これは、シナリオの例として私が作成したサンプルです。
void Main()
{
var mathController = new MathController();
}
class MathController
{
private readonly StateMonitor _stateMonitor;
public MathController()
{
_stateMonitor = new StateMonitor(RefreshMath);
_stateMonitor.Monitor();
}
public void RefreshMath()
{
Debug.WriteLine("Math has been refreshed");
}
}
class StateMonitor
{
private readonly Action _refreshCommand;
public StateMonitor(Action command)
{
_refreshCommand = command;
}
public void Monitor()
{
Debug.WriteLine("Start monitoring");
Thread.Sleep(5000);
Debug.WriteLine("Something happened, we should execute the given command");
_refreshCommand();
}
}