When you register binding you can subscribe on the three events.

  • OnActivating - execute callback method before binding activated.
  • OnActivated - execute callback method after binding activated.
  • OnDisposed - execute callback method after binding disposed.

Example:

var injector = new MugenInjector();
injector.Bind<IEmpty>().To<Empty>()
        .OnActivating(context => Console.WriteLine("Service type for activating {0}", context.Service))
        .OnActivated(o => Console.WriteLine("Activated object {0}", o))
        .OnDisposed(binding => Console.WriteLine("Disposed binding {0}", binding));

//Executed two event OnActivating and OnActivated
var empty = injector.Get<IEmpty>();
//Execute OnDisposed method
injector.Unbind<IEmpty>();

The interface Injector contains event that occurs after the disposed of the container.

Example:

var injector = new MugenInjector();
injector.Disposed += injector1 => Console.WriteLine("Disposed injector {0}", injector1);
injector.Dispose();

Last edited Apr 5, 2012 at 2:26 PM by VVS0205, version 2

Comments

No comments yet.