Как насчет решения этой проблемы со следующей архитектурой:
IPlanContextReceiver
{
public object StateByWichPlanContextCanDeciceWhatToReturn get;
}
class SomeWindow : Window, IPlanContextReceiver
А в PlanContext вместо свойства Current у вас есть
public static PlanContext GetCurrent(IPlanContextReceiver receiver)
{
lock(contextSync) // be threadsafe if necessary
{
if(/*condition that checks receiver.StateByWichPlanContextCanDeciceWhatToReturn*/)
{
// context is valid for this receiver
// return the correct context from an internal store or similar
return Contexts["TheContextForCoolReceivers"];
}
else if(/*condition that checks receiver.StateByWichPlanContextCanDeciceWhatToReturn*/)
{
// context is valid for this receiver
// return the correct context from an internal store or similar
return Contexts["TheContextForUncoolReceivers"];
}
// no existing context is available for this receiver
return null;
}
}
Если вы снова сделаете его одиночным, GetCurrent
также может быть методом экземпляра. И вместо Метода это также может быть индексатор - это дело вкуса.
Кроме того, вам решать, что на самом деле StateByWichPlanContextCanDeciceWhatToReturn
. Он может быть таким же сложным, как несколько свойств, которые необходимо проверить, или может быть таким же простым, как строка, которую вы устанавливаете один раз для каждой группы контекста вашего окна.