Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- container
- .AddNewExtension<Interception>()
- .Configure<Interception>()
- .AddPolicy("MyLoggingPolicy")
- .AddMatchingRule<CustomAttributeMatchingRule>(
- new InjectionConstructor(typeof(Abstractions.Attributes.LogAttribute), true))
- .AddCallHandler<LoggingHandler>(new ContainerControlledLifetimeManager())
- .Interception
- .Container
- .RegisterType<IFirstInterface>(new InjectionFactory((context) => FirstClassFactoryMethod()))
- .RegisterType<ISecondInterface>(new InjectionFactory((context) => SecondClassFactoryMethod()));
- [AttributeUsage(AttributeTargets.Method)]
- public class LogAttribute : Attribute { }
- public class LoggingHandler : ICallHandler
- {
- public int Order { get; set; }
- public IMethodReturn Invoke(IMethodInvocation input, GetNextHandlerDelegate getNext)
- {
- Console.WriteLine($"{DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss")} Started: {input.MethodBase.Name}");
- var result = getNext()(input, getNext);
- Console.WriteLine($"{DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss")} Completed: {input.MethodBase.Name}");
- return result;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement