Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@zihotki
Created April 6, 2016 12:40
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zihotki/93eb61131d898fa3f821d78ed3c9c221 to your computer and use it in GitHub Desktop.
Save zihotki/93eb61131d898fa3f821d78ed3c9c221 to your computer and use it in GitHub Desktop.
Autofac module to write to debug output component resolve and activation messages
public class LogRequestModule : Module
{
public int depth = 0;
protected override void AttachToComponentRegistration(IComponentRegistry componentRegistry,
IComponentRegistration registration)
{
registration.Preparing += RegistrationOnPreparing;
registration.Activating += RegistrationOnActivating;
//registration.Activated += RegistrationOnActivated;
base.AttachToComponentRegistration(componentRegistry, registration);
}
private void RegistrationOnActivated(object sender, ActivatedEventArgs<object> e)
{
Debug.WriteLine("{0}Activated {1}", GetPrefix(), e.Component.Activator.LimitType);
}
private string GetPrefix()
{
return new string('-', depth * 2);
}
private void RegistrationOnPreparing(object sender, PreparingEventArgs preparingEventArgs)
{
Debug.WriteLine("{0}Resolving {1}", GetPrefix(), preparingEventArgs.Component.Activator.LimitType);
depth++;
}
private void RegistrationOnActivating(object sender, ActivatingEventArgs<object> activatingEventArgs)
{
depth--;
Debug.WriteLine("{0}Activating {1}", GetPrefix(), activatingEventArgs.Component.Activator.LimitType);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment