How can I embed (attach) event handlers to .net events of instances created by the IoC Unity container ?
Example. I have a class that reports errors through a standard .net event:
class CameraObserver
{
public event Action<Exception> UnhandledException;
[...]
}
I have another class that is responsible for handling these events:
class CrashMonitor
{
public static void HandleException(Exception x)
{ ... }
}
What I would like to do is automatically insert a handler from CrashMonitor into each instance of CameraObserver, as in this pseudocode:
UnityContainer container = new UnityContainer();
container.RegisterInstance<Action<Exception>>(CrashMonitor.HandleException)
.RegisterType<CameraObserver>(new InjectionEvent(UnhandledException));
var observer = container.Resolve<CameraObserver>();
Unity? , , CameraObserver , . ( ). , [Dependency] , .