Advertisement
Guest User

Untitled

a guest
Sep 24th, 2017
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. container
  2. .AddNewExtension<Interception>()
  3. .Configure<Interception>()
  4. .AddPolicy("MyLoggingPolicy")
  5. .AddMatchingRule<CustomAttributeMatchingRule>(
  6. new InjectionConstructor(typeof(Abstractions.Attributes.LogAttribute), true))
  7. .AddCallHandler<LoggingHandler>(new ContainerControlledLifetimeManager())
  8. .Interception
  9. .Container
  10. .RegisterType<IFirstInterface>(new InjectionFactory((context) => FirstClassFactoryMethod()))
  11. .RegisterType<ISecondInterface>(new InjectionFactory((context) => SecondClassFactoryMethod()));
  12.  
  13. [AttributeUsage(AttributeTargets.Method)]
  14. public class LogAttribute : Attribute { }
  15.  
  16. public class LoggingHandler : ICallHandler
  17. {
  18. public int Order { get; set; }
  19.  
  20. public IMethodReturn Invoke(IMethodInvocation input, GetNextHandlerDelegate getNext)
  21. {
  22. Console.WriteLine($"{DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss")} Started: {input.MethodBase.Name}");
  23. var result = getNext()(input, getNext);
  24. Console.WriteLine($"{DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss")} Completed: {input.MethodBase.Name}");
  25. return result;
  26. }
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement