In my program, there is a place when I need to access a singleton resolved from a factory and attach to its event:
void MyMethod()
{
myFactory.Resolve<MySingleton>().DoWork += WorkMethod;
}
The problem is that MyMethod can be executed multiple times, but I want to attach to event only once (otherwise I'll get multiple calls). So I want to attach only when I wasn't attached before. It there anything nicier than
myFactory.Resolve<MySingleton>().DoWork -= WorkMethod;
myFactory.Resolve<MySingleton>().DoWork += WorkMethod;