BSF. Aop
. Net free Open source, static AOP weave (directly modify IL Intermediate language) framework, similar to POSTSHARP (charge);
Implement pre-and post-AOP facets and inotifypropertychanged injection methods.
Open Source Address: Https://git.oschina.net/chejiangyi/BSF.Aop
Open source QQ group:. NET open source basic services 238543768 Welcome to Exchange
Description:
- Static weaving implementations with almost the same performance as native code authoring.
- The project structure is extended from the BSF infrastructure, but DLL aspects are not dependent on BSF.dll and can be used independently.
- Project code is small (also on several types of files), the core functions of plug-in development, easy to third-party expansion, reading, debugging, together to improve.
- . NET AOP static weaving related to the free open-source project is less or no longer heard, it is hoped that the open source this piece of content, the same type of open source projects starting point and reference.
using Configuration
1) Project reference BSF.Aop.dll, reference Mono.Cecil.dll, reference Mono.Cecil.Pdb.dll.
2) project Start code add Aopstartloader.start (); a code.
(This code is used for automatic injection scanning and vs. Project Environment Auto-configuration, export related EXE files, etc.)
Note:
- Web project added in Application_Start
- WinForm Project added in Pragram.main
Automation configuration (default recommendation)
Build project, and then run the debug project directly.
Note:
- Aopstartloader.start (); This code first time the project runs error, because the AOP environment has not been automatically built, the first run and automatically set up successfully, the future runs are automatically injected.
- The packages is generated under the project by default. BSF. AOP "folder and inject" AOP run script "in the VS Project PostBuildEvent event, refer to the following" Manual configuration Content ".
Manual configuration (recommended if you are having problems)
1) Configure the AOP injection directory.
VS Project under new packages. BSF. The Aop directory, which contains bsf.aop.ilrun.exe,bsf.aop.dll,mono.cecil.pdb.dll,mono.cecil.dll files, respectively.
2) Configure the PostBuildEvent script.
WinForm Environment :
Open vs-"Project Properties-" PostBuildEvent, configure the AOP run script. Such as:
xcopy $ (OutDir) BSF. Aop.dll $ (ProjectDir) packages. BSF. aop\/y
Call "$ (ProjectDir) packages. BSF. AOP\BSF. Aop.ILRun.exe "MsgBox $ (TargetDir)
Web Environment :
Open vs-"Project Properties-" PostBuildEvent, configure the AOP run script. (OpenApi.Test.Web replaced with a specific project name) such as:
xcopy $ (solutiondir) \OPENAPI.TEST.WEB\BIN\BSF. Aop.dll $ (solutiondir) \openapi.test.web\packages. BSF. aop\/y
Call "$ (solutiondir) \openapi.test.web\packages. BSF. AOP\BSF. Aop.ILRun.exe "MsgBox $ (solutiondir) \openapi.test.web\bin\
using the Demo sample
1) Examples of pre-and post-Aop facets ( detailed reference BSF.Aop.Test project )
PublicClassaroundaoptest {[MYAROUNDAOP] [Attributeinfo (Des ="Test 2")]Publicvoid Method (Tempinfo info, out int b,int a=1) {a =222; b =3; System.Console.WriteLine ("Hello world!" +A); } }PublicStaticClassAroundAopTest2 {[Myaroundaop][attributeinfo (Des ="Test")]PublicStaticvoid Method2 (tempinfo info, int a =1) {a =222; System.Console.WriteLine ("Hello world!" + a); } }PublicClassMYAROUNDAOP:Aop.Attributes.Around.Aroundaopattribute {Public Myaroundaop () {}PublicOverridevoid before (Aroundinfo info) {var att = info. Method.CustomAttributes.ToList () [0]; Info. params["a"] =55; System.Console.WriteLine ("Before" + info. params[ "a"]); } public override void after ( Aroundinfo info) {System.Console.WriteLine ( "after" + info. Params[ "a"]); }} public class tempinfo {public int T1 {get; set; }} public class attributeinfo: system. Attribute {public string Des {get; set;} }
2) INotifyPropertyChanged example (the actual effect is not tested, refer to BSF.Aop.Test project in detail )
[NOTIFYPROPERTYCHANGEDAOP] User { set;}}
By car Jiangyi
"Open source". Net Aop (static weave) Framework BSF. Aop