The first time AOP was attached with the DEMO, which is currently only for learning and cannot be used in the production environment. aopdemo
GIT Code address: https://git.oschina.net/ruanjianfeng/Ruan.Framework.Core
The demo code is as follows:
1 public class ConsoleTimeAttribute : ApectBaseAttribute 2 { 3 public override void Before(ApectContext apectContext) 4 { 5 apectContext.SetCorrelationObject(DateTime.Now); 6 Console.WriteLine($"Before > Method:{apectContext.MethodName} > {DateTime.Now}"); 7 } 8 9 public override void After(ApectContext apectContext)10 {11 Console.WriteLine($"Before > Method:{apectContext.MethodName} > {DateTime.Now}");12 Console.WriteLine($"CorrelationObject > {(DateTime)apectContext.CorrelationObject}");13 }14 }
First, the feature class that inherits ApectBaseAttribute will be used;
1 public interface ITest2 {3 [ConsoleTime] // added feature monitoring 4 void Say (string message); 5}
public class Test : ITest { private readonly string _init; public Test(string init) { _init = init; } public void Say(string message) { Console.WriteLine($"init : {_init} || message : {message}"); } }
How to Use AOP
Var type = ApectProxyBuilder. buildType <ITest> (typeof (Test); ITest test = (ITest) Activator. createInstance (type, "OK"); test. say ("what to Say ");
If IOC is used in combination, you can only provide learning at present. There is still a lack of returned values for the execution methods in the AOP proxy class, and only the AOP processing of non-inherited interface classes.
If you have any questions or problems, please contact us more and use them in the production environment later.