Created
April 6, 2016 12:40
-
-
Save zihotki/93eb61131d898fa3f821d78ed3c9c221 to your computer and use it in GitHub Desktop.
Autofac module to write to debug output component resolve and activation messages
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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