Presentation is loading. Please wait.

Presentation is loading. Please wait.

Aspect.NET — aspect-oriented toolkit for Microsoft.NET based on Phoenix and Whidbey Dmitry Grigoriev, PhD student Vladimir O. Safonov, Senior Member, IEEE,

Similar presentations


Presentation on theme: "Aspect.NET — aspect-oriented toolkit for Microsoft.NET based on Phoenix and Whidbey Dmitry Grigoriev, PhD student Vladimir O. Safonov, Senior Member, IEEE,"— Presentation transcript:

1 Aspect.NET — aspect-oriented toolkit for Microsoft.NET based on Phoenix and Whidbey Dmitry Grigoriev, PhD student Vladimir O. Safonov, Senior Member, IEEE, professor Mikhail Gratchev, PhD student Alexander Maslennikov, PhD student Saint-Petersburg State University

2 Aspect.NET, Pilsen, May 20062 Introduction to AOP (part 1) Aspect-oriented programming (AOP) is an attempt to solve the problems of development complex software. Each of software modules (classes, methods, procedures, etc.) solves some definite logically independent task (event logging, authentification, security, assertions,..). To use new modules in our product, we need to inject their calls into the sources.

3 Aspect.NET, Pilsen, May 20063 Introduction to AOP (part 2) As a result we have a lot of tangled code in our sources. What shall we do when we decide to remove or modify such a cross-cutting concern or add another one?

4 Aspect.NET, Pilsen, May 20064 Introduction to AOP (part 3) AOP suggests: “Let’s remove them from sources and weave directly to binaries instead, according to our rules described in special language” Approaches: Extend an existing language (AspectJ, Aspect#)  Need special compiler for every language version. Dynamic execution (hooks at definite points of execution) (Loom.NET, RAIL)  Don’t know what kind of code is currently executing.  Low performance -Static weaving into assemblies (Aspect.NET) High performance Resulting code could be examined explicitly (Reflector) A lot of existing.NET tools can work with resulting assemblies

5 Aspect.NET, Pilsen, May 20065 Aspect.NET goals Aspect.NET is an aspect-oriented tool that allows you to define some functionality by specific aspect units and weave them into your assemblies. So, the cross-cutting concerns appear to be structured into aspects which makes the code clearer. Aspect.NET is implemented as Visual Studio.NET 2005 (Whidbey) add-in, to use AOP technology in a comfortable manner, alongside with using ubiquitous VS.NET software development features.

6 Aspect.NET, Pilsen, May 20066 Aspect.NET Overview Let’s turn cross-cutting concerns into separate standalone units (classes), referred to as aspects. Aspect contain: Data (fields) Modules (aspect’s methods ) Actions (public methods to be called at specially defined join points of target code) Weaving rules (Determine the set of join points) Generally, aspect is a class whose methods are annotated by specific AOP weaving attributes.

7 Aspect.NET, Pilsen, May 20067 Aspect.NET ML Aspect definition is specified in a simple meta- language – Aspect.NET.ML. Meta-language allows you to describe a set of desired join-points and reuse such declarations for other aspects (ruleset). Then special converter turns it into.NET class source code, with meta-language annotations represented as custom attributes. This aspect class is compiled into an assembly by a common use.NET Framework compiler.

8 Aspect.NET, Pilsen, May 20068 Aspect Library (DLL) %aspect Test//ML language public class Test { %modules private static void TestRun() { WriteLine(”test”); } %rules Aspect.ML Converter C# Compiler public class Test: Aspect//Attribute annotation { [AspectAction(“%before %call Write*")] public static void TestRunAction() { Test.TestRun(); }

9 Aspect.NET, Pilsen, May 20069 Aspect.NET ML Example %aspect Politeness public class Politeness { %modules private static void SayScanningHello() { Console.WriteLine("Welcome to Aspect.NET scanning system!"); } %rules %before %call *SomeMethod %action public static void SayScanningHelloAction() { Politeness.SayScanningHello(); } }// Politeness

10 Aspect.NET, Pilsen, May 200610 Custom attributes (example) public class Politeness: Aspect { private static void SayScanningHello() { Console.WriteLine("Welcome to Aspect.NET scanning system!"); } [AspectAction(“%before %call *SomeMethod”)] public static void SayScanningHelloAction() { Politeness.SayScanningHello(); } }// Politeness

11 Aspect.NET, Pilsen, May 200611 Current Aspect.NET ML expressive power (1/3) Can inject actions before, after or instead call instructions Actions have full access to the woven context through the properties of base Aspect class: Object This;\\this keyword Object TargetObject;\\p.TargetMethod(..); MemberInfo TargetMemberInfo; \\TargetMethod as MethodInfo Type WithinType;\\this.GetType(); MethodBase WithinMethod;\\this.CurrentMethod(); string SourceFilePath;\\*.cs filepath string SourceFileLine.\\source line number And more…

12 Aspect.NET, Pilsen, May 200612 Current Aspect.NET ML expressive power (2/3) Weaving rules are specified by a mask and a regular expression. %before %call Namespace.Class.MethodName or %before %call *MethodName Signature filtering. %instead %call static public void *Method(float, string,..)

13 Aspect.NET, Pilsen, May 200613 Current Aspect.NET ML expressive power (3/3) Arguments capturing AspectAction(“%after %call *Method(int) && args(arg[1])”) static public void MethodAction(int i) { Console.WriteLine({0}, i); } Additional restrictions on join points placement %within(*SomeType) %withincode(*SomeMethod) %instead %call *Method && %within(*MyType) && %!withincode(*.ctor)

14 Aspect.NET, Pilsen, May 200614 Introducing Aspect.NET Framework Design Compiler Application Source Code Aspect Library Aspect Source Code Aspect.NET.ML Converter Application Weaver User Target Application Aspect.NET Framework

15 Aspect.NET, Pilsen, May 200615 Examples of Weaving Target application – BankManagement system static void Main(string[] args) { BankAccount acc1 = new BankAccount(); acc1.deposit(20);//apply aspects here acc1.withdraw(20);//apply aspects here } BankAccountContractAspect – Design by Contract: Invariant, Pre & Post checks of BankManagement.Deposit() and BankManagement.withdraw(); UsageLicensingAspect – checks permissions of current machine to perform these operations.

16 Aspect.NET, Pilsen, May 200616

17 Aspect.NET, Pilsen, May 200617 Class Diagram

18 Aspect.NET, Pilsen, May 200618 Filtering discovered joinpoints

19 Aspect.NET, Pilsen, May 200619 Decompiled Results BankAccount account1 = new BankAccount(); Aspect.InternalSetArgsTypes("float"); Aspect.InternalSetMemberName("BankManagement.BankAccount.deposit"); Aspect.InternalSetTargetObject(account1); UsageLicensingAspect.DepositWrapper(20f);\\instead of \\account1.deposit(20) Aspect.InternalSetArgsTypes("float"); Aspect.InternalSetMemberName("BankManagement.BankAccount.withdraw“) Aspect.InternalSetTargetObject(account1); UsageLicensingAspect.WithdrawWrapper(20f); \\instead of \\account1. withdraw(20) Console.WriteLine("Final balance is {0}", account1.Balance);

20 Aspect.NET, Pilsen, May 200620 Microsoft Phoenix Reflection is very poor for instrumenting MSIL assemblies (even in.NET 2.0). Microsoft Phoenix is a framework for building compilers and a wide range of tools for program analysis, optimization, and testing. Phoenix provides high level instructions for MSIL code. Phoenix tools can be implemented as compiler phases. Phoenix lets work with debug information instead of addressing unmanaged COM interfaces DIA. So we use it. We are collaborating with Phoenix developers at Microsoft Research (the project supported by MSR).

21 Aspect.NET, Pilsen, May 200621 AOP problems and our approach Comprehension Must be able to predict behavior (Aspect.NET: View join points in source) Must be easy to understand (Aspect.NET: Easy meta- language) Integration into existing tools and software processes (Aspect.NET: Nice add-in to Visual Studio) Debuggability Source-level debugging is critical (Aspect.NET: we are planning this feature) Testing AOP introduces new fault models (Aspect.NET: Unit testing within VS) Evolution Performance (Aspect.NET: Static weaving gives minimal overhead)

22 Aspect.NET, Pilsen, May 200622 Q&A Where to find? http://www.msdnaa.net/curriculum/?id=6334


Download ppt "Aspect.NET — aspect-oriented toolkit for Microsoft.NET based on Phoenix and Whidbey Dmitry Grigoriev, PhD student Vladimir O. Safonov, Senior Member, IEEE,"

Similar presentations


Ads by Google