Aspect.NET – an aspect-oriented programming tool for Microsoft.NET Vladimir O. Safonov Professor...

34
Aspect.NET – an aspect- oriented programming tool for Microsoft.NET Vladimir O. Safonov Professor of computer science, Head of laboratory St. Petersburg University [email protected]

Transcript of Aspect.NET – an aspect-oriented programming tool for Microsoft.NET Vladimir O. Safonov Professor...

Page 1: Aspect.NET – an aspect-oriented programming tool for Microsoft.NET Vladimir O. Safonov Professor of computer science, Head of laboratory St. Petersburg.

Aspect.NET – an aspect-oriented programming tool for

Microsoft.NET

Vladimir O. Safonov

Professor of computer science,

Head of laboratory

St. Petersburg University

[email protected]

Page 2: Aspect.NET – an aspect-oriented programming tool for Microsoft.NET Vladimir O. Safonov Professor of computer science, Head of laboratory St. Petersburg.

Vladimir Safonov, SSCLI Capstone Workshop, Redmond 2005

2

Aspect.NET project (granted by MSR in 2002 and 2004)

Goals: Develop a state-of-the-art aspect-oriented programming

(AOP) tool for Microsoft.NET, on top of Microsoft Phoenix, integrated with the latest Visual Studio (Whidbey) and working also in SSCLI/Rotor environment

Make AOP ubiquitous for Microsoft.NET software developers

Develop most adequate ways of representing aspects for Microsoft.NET

Lay the foundation for future research and development work on spreading AOP among Microsoft.NET users

Page 3: Aspect.NET – an aspect-oriented programming tool for Microsoft.NET Vladimir O. Safonov Professor of computer science, Head of laboratory St. Petersburg.

Vladimir Safonov, SSCLI Capstone Workshop, Redmond 2005

3

AOP origin and status

• Aspect-oriented programming (AOP) – a prospective software engineering paradigm based on a concept of cross-cutting concern whose implementation contains not only a related set of modules (“generalized procedure”), but also a set of tangled code fragments to be woven (inserted) into a target application

• Predecessor: Professor A. L. Fouxman (Rostov University, Russia), “Technological Aspects of Software Systems Development”, 1979

• Modern classicist of AOP: Professor Gregor Kiczales, University of British Columbia, Canada (AspectJ tool ~ AOP extension for Java)

Page 4: Aspect.NET – an aspect-oriented programming tool for Microsoft.NET Vladimir O. Safonov Professor of computer science, Head of laboratory St. Petersburg.

Vladimir Safonov, SSCLI Capstone Workshop, Redmond 2005

4

AOP basics

• Cross-cutting concern ~ a concern whose implementation cannot be made by a generalized procedure

• Examples ~ logging; security; MT-safety; implementation of a new source language construct in a compiler

• Aspect ~ implementation of a cross-cutting concern

• Weaving ~ applying an aspect to a target application (inserting new modules and definitions; inserting, replacing or deleting tangled pieces of code)

• Pointcut ~ a set of weaving rules for an aspect

• Join points ~ a set of concrete points in a target application subject to aspect weaving

• Benefits of AOP: make software development and maintenance easier, due to performing it in terms of aspects

Page 5: Aspect.NET – an aspect-oriented programming tool for Microsoft.NET Vladimir O. Safonov Professor of computer science, Head of laboratory St. Petersburg.

Vladimir Safonov, SSCLI Capstone Workshop, Redmond 2005

5

Our approach to AOP

• Make aspects multi-language (language agnostic), in accordance to .NET programming paradigm, as opposed to extending any concrete programming language by AOP constructs (as in AspectJ)

• Use a simple AOP meta-language Aspect.NET.ML to provide user-level AOP annotations to source code of compilation units

• Represent meta-information on aspects by custom attributes (AspectDef, AspectRef), to safely tie them to assemblies, to make them easily available to AOP tools, and to avoid updating any general .NET tools for the purpose of their “AOP-awareness”

• Use Phoenix to handle assemblies and to support weaving

• Develop Aspect.NET as a Whidbey add-in to closely integrate it to Microsoft.NET development tools, technologies and environments

Page 6: Aspect.NET – an aspect-oriented programming tool for Microsoft.NET Vladimir O. Safonov Professor of computer science, Head of laboratory St. Petersburg.

Vladimir Safonov, SSCLI Capstone Workshop, Redmond 2005

6

Compare to other approaches to AOP

• Language extensions of a specific (usually – Java) language for AOP (AspectJ)

• Multi-dimensional separations of concerns (IBM HyperJ)• Interceptors• XML files with AspectJ-like specifications (Weave.NET)• Dynamic aspects (similar to debugger breakpoints)• Our approach is easy-to-use, language-agnostic, and

integrated with the latest Microsoft technologies and tools (Whidbey and Phoenix)

• As far as we can judge, right now there is no other AOP tool so closely integrated to Microsoft development tools as our Aspect.NET

Page 7: Aspect.NET – an aspect-oriented programming tool for Microsoft.NET Vladimir O. Safonov Professor of computer science, Head of laboratory St. Petersburg.

Vladimir Safonov, SSCLI Capstone Workshop, Redmond 2005

7

Aspect.NET architecture

• Aspect.NET.ML converters (currently for C#) to definitions of AspectDef AOP attribute

• Aspect weaver:

Target assembly + Aspect assemblies -> Target assembly*

• Aspect editor + aspect GUI: locating aspects, coloring aspects, editing aspects, deleting aspects; integrated to Whidbey as add-in

• Aspect.NET .msi-based installer (checks where the Phoenix RDK is located on your machine)

• AspectRotor – a separate console version of Aspect.NET for Rotor environment

Page 8: Aspect.NET – an aspect-oriented programming tool for Microsoft.NET Vladimir O. Safonov Professor of computer science, Head of laboratory St. Petersburg.

Vladimir Safonov, SSCLI Capstone Workshop, Redmond 2005

8

Example: the Politeness aspect%aspect Politeness

public class Politeness

{

%modules

public static SayHello ()

{

System.Console.WriteLine(“Hello”);

}

public static SayBye ()

{

System.Console.WriteLine(“Bye”);

}

%rules

%before %call *

%action public static void SayHelloAction

{ Politeness.SayHello()}

%after %call *

%action public static void SayByeAction { Politeness.SayBye()}

Page 9: Aspect.NET – an aspect-oriented programming tool for Microsoft.NET Vladimir O. Safonov Professor of computer science, Head of laboratory St. Petersburg.

Vladimir Safonov, SSCLI Capstone Workshop, Redmond 2005

9

Example: Weaving Politeness

%to MyApplication %apply Politeness

(the same can be done by means of Aspect editor)

Page 10: Aspect.NET – an aspect-oriented programming tool for Microsoft.NET Vladimir O. Safonov Professor of computer science, Head of laboratory St. Petersburg.

Vladimir Safonov, SSCLI Capstone Workshop, Redmond 2005

10

Aspect.NET working screenshot

Page 11: Aspect.NET – an aspect-oriented programming tool for Microsoft.NET Vladimir O. Safonov Professor of computer science, Head of laboratory St. Petersburg.

Vladimir Safonov, SSCLI Capstone Workshop, Redmond 2005

11

Aspect coloring screenshot

Page 12: Aspect.NET – an aspect-oriented programming tool for Microsoft.NET Vladimir O. Safonov Professor of computer science, Head of laboratory St. Petersburg.

Vladimir Safonov, SSCLI Capstone Workshop, Redmond 2005

12

Aspect.NET status and perspectives• Aspect.NET implementation team (SPBU PhD and graduate

students: Dmitry Grigoryev, Mikhail Gratchev, Alexander Maslennikov, Oleg Romashin.)

• A working prototype of Aspect.NET on top of latest Phoenix (02/28/05) and Whidbey beta2 developed

• Aspect.NET installer/distribution developed• Working console version of Aspect.NET for Rotor environment

(AspectRotor) developed• Aspect.NET uploaded to MSDNAA Curriculum Repository Web

site• Perspectives: library of examples; further research on aspect-

oriented knowledge management and on aspectizing (aspect mining)

• Our desire is to get funding from Microsoft to continue our project, to make Aspect.NET a product to be shipped with the future versions of Visual Studio.NET

Page 13: Aspect.NET – an aspect-oriented programming tool for Microsoft.NET Vladimir O. Safonov Professor of computer science, Head of laboratory St. Petersburg.

Vladimir Safonov, SSCLI Capstone Workshop, Redmond 2005

13

Conferences and seminars where Aspect.NET project presented

• First MSR Rotor Workshop, Cambridge, July 2002• Rotor Workshop, University of Pisa, Italy, April 2003• Fault-tolerant Software and Hardware Systems Workshop,

Hasso-Plattner Institute, Potsdam, February 2004• Microsoft Academic Days, Moscow, April 2005• IEEE Regional Conference, St. Petersburg, May 2005• MSR Faculty Summit, Redmond, July 2005 (as part of the

Phoenix panel)• Now MSR Rotor Capstone Workshop, Redmond,

September 2005• Current plans (Sep 2005): submit a paper and talk on

Aspect.NET to the Fifth International AOSD Conference, Bonn, Germany, March 2006 (the “classical” AOP conference)

Page 14: Aspect.NET – an aspect-oriented programming tool for Microsoft.NET Vladimir O. Safonov Professor of computer science, Head of laboratory St. Petersburg.

Vladimir Safonov, SSCLI Capstone Workshop, Redmond 2005

14

Aspect.NET users, evaluators and those who sent feedback (Sep 2005)

• Microsoft Phoenix team – John Lefor, Shahrokh Mortazavi, Jim Hogg et al.• Mercury Interactive (www.mercury.com), contact person: Yaniv Bronstein• University in Brazil, contact person: Andrea Furtado• Highly appreciated the project (email feedback): Andreas Mauer, TRIA IT-consulting GmbH (

www.tria.de) John Fahring [email protected]

Page 15: Aspect.NET – an aspect-oriented programming tool for Microsoft.NET Vladimir O. Safonov Professor of computer science, Head of laboratory St. Petersburg.

Vladimir Safonov, SSCLI Capstone Workshop, Redmond 2005

15

Aspect.NET team’s creative contacts to other AOP R&D teams

• Gregor Kiczales, University of British Columbia

• Andreas Polze, Hasso-Plattner Institute, Potsdam, Germany

• Mark Eaddy, Professor A. Aho’s AOP intern in Phoenix team

• Donal Lafferty, Trinity College, Dublin, Ireland (Weave.NET project)

• Tihamer Levendovsky, Budapest Technical University, Hungary

• Andrea Furtado, University in Brazil

Page 16: Aspect.NET – an aspect-oriented programming tool for Microsoft.NET Vladimir O. Safonov Professor of computer science, Head of laboratory St. Petersburg.

Vladimir Safonov, SSCLI Capstone Workshop, Redmond 2005

16

Aspect.NET references1) http://aosd.net - The starting Web site on AOP

2) http://www.msdnaa.net/curriculum/?6219 – Aspect.NET&doc

3) Safonov V. O. Aspect.NET: a new approach to aspect-oriented programming. - .NET Developer’s Journal, 2003, #4.

4) Safonov V.O. Aspect.NET: concepts and architecture. - .NET Developer’s Journal, 2004, #10.

5) Safonov V.O., Grigoryev D.A. Aspect.NET: aspect-oriented programming for Microsoft.NET in practice. - .NET Developer’s Journal, 2005, # 7.

6) Safonov V.O., Grigoryev D.A. Aspect.NET – an aspect-oriented programming tool for Microsoft.NET. – Proceedings of St. Petersburg Regional IEEE conference, St. Petersburg, May 2005.

Page 17: Aspect.NET – an aspect-oriented programming tool for Microsoft.NET Vladimir O. Safonov Professor of computer science, Head of laboratory St. Petersburg.

Using Aspect.NET

Vladimir O. SafonovProfessor

St. Petersburg University

Page 18: Aspect.NET – an aspect-oriented programming tool for Microsoft.NET Vladimir O. Safonov Professor of computer science, Head of laboratory St. Petersburg.

Vladimir Safonov, SSCLI Capstone Workshop, Redmond 2005

18

Installing Aspect.NETPre-requisites:• 1) Microsoft Visual Studio 2005 beta 2 installed.• 2) Microsoft Phoenix RDK 02/28/05 Release installed

Notes:• Aspect.NET Framework has been tested under Microsoft

Visual Studio 2005 beta 2 and with assemblies written in C# only.

• To install Aspect.NET, run AspectNETFramework.msi and follow tips of the wizard.

• The installer copies core assemblies, deployment files as well as Phoenix binaries into the folder specified by the user.

Page 19: Aspect.NET – an aspect-oriented programming tool for Microsoft.NET Vladimir O. Safonov Professor of computer science, Head of laboratory St. Petersburg.

Vladimir Safonov, SSCLI Capstone Workshop, Redmond 2005

19

Starting Aspect.NET Framework• The Aspect.NET Framework add-in window appears every

time Visual Studio is started.

Page 20: Aspect.NET – an aspect-oriented programming tool for Microsoft.NET Vladimir O. Safonov Professor of computer science, Head of laboratory St. Petersburg.

Vladimir Safonov, SSCLI Capstone Workshop, Redmond 2005

20

How to create an aspect in Aspect.NET ML?• Aspect is a special VS C# project template.• So, please create a new project (say MAddNopCounter) specified with aspect template.

Page 21: Aspect.NET – an aspect-oriented programming tool for Microsoft.NET Vladimir O. Safonov Professor of computer science, Head of laboratory St. Petersburg.

Vladimir Safonov, SSCLI Capstone Workshop, Redmond 2005

21

How to create an aspect?• The wizard generates the simple aspect skeleton in aspect.an file, which is container for

aspect description written in Aspect.NET ML.• Сode the body of the aspect in the .an file, based on the skeleton generated by the

wizard.

Page 22: Aspect.NET – an aspect-oriented programming tool for Microsoft.NET Vladimir O. Safonov Professor of computer science, Head of laboratory St. Petersburg.

Vladimir Safonov, SSCLI Capstone Workshop, Redmond 2005

22

How to create an aspect?

• Click “Build Solution” button or execute “Rebuild All”. At this phase, the aspect.an.cs file is created to contain correct C# source code with ML annotations converted into the custom attribute AspectDef. Then, the standard C# compiler compiles it to the aspect assembly and places it into the debug folder (say MAddNopCounter.dll).

• One can weave this assembly as an aspect to his/her projects.

Page 23: Aspect.NET – an aspect-oriented programming tool for Microsoft.NET Vladimir O. Safonov Professor of computer science, Head of laboratory St. Petersburg.

Vladimir Safonov, SSCLI Capstone Workshop, Redmond 2005

23

Weaving aspects

• Open or Create new C# project in Visual Studio.• In Aspect.NET Framework click "Add Existing

Aspect Module" button on "Modules" tab to add Aspect assemblies. You can add multiple assemblies.

• Press "Find Joinpoints" button to find the join points in the currently active project.

• If join points have been found, Aspect.NET Framework switches to the "Aspects" tab. Here you can filter the joinpoints and browse them.

Page 24: Aspect.NET – an aspect-oriented programming tool for Microsoft.NET Vladimir O. Safonov Professor of computer science, Head of laboratory St. Petersburg.

Vladimir Safonov, SSCLI Capstone Workshop, Redmond 2005

24

Weaving aspects

• Use the checkboxes in the join points tree to enable or disable a join point. You can enable or disable groups of join points by checking or unchecking parent methods, classes and namespaces.

• You can click the join point to see its location in a source code.

• Pressing "Weave Aspects" button results in aspects weaving into the debug assembly of the current project.

• When weaving is finished , Aspect.NET Framework informs you where the target assembly is located.

Page 25: Aspect.NET – an aspect-oriented programming tool for Microsoft.NET Vladimir O. Safonov Professor of computer science, Head of laboratory St. Petersburg.

Vladimir Safonov, SSCLI Capstone Workshop, Redmond 2005

25

Weaving aspects• Visualization Tab represents program modules, with aspect actions

woven, as colored chart.

Page 26: Aspect.NET – an aspect-oriented programming tool for Microsoft.NET Vladimir O. Safonov Professor of computer science, Head of laboratory St. Petersburg.

Vladimir Safonov, SSCLI Capstone Workshop, Redmond 2005

26

Example of Weaving

• MAddNop is a basic sample included into Phoenix RDK to demonstrate its capabilities. It is a simple managed Phoenix based application to add nop's to an existing executable.

• Let’s change its behavior without touching source code and create an aspect MAddNopCounter to add some tracing.

• The aspect reports on starting Phoenix initialization process, prints Phoenix configuration state and counts the number of nop’s inserted to an executable.

Page 27: Aspect.NET – an aspect-oriented programming tool for Microsoft.NET Vladimir O. Safonov Professor of computer science, Head of laboratory St. Petersburg.

Vladimir Safonov, SSCLI Capstone Workshop, Redmond 2005

27

Step by Step playing with Aspect.NET

• Turn the MAddNop.cs file from \PhoenixRDK\src\Samples\maddnop into VS project named MAddNop.

• Lets weave our aspect to MAddNop project and check the results.

Page 28: Aspect.NET – an aspect-oriented programming tool for Microsoft.NET Vladimir O. Safonov Professor of computer science, Head of laboratory St. Petersburg.

Vladimir Safonov, SSCLI Capstone Workshop, Redmond 2005

28

Step by Step playing with Aspect.NET

• First of all load the source project into VS IDE.

Page 29: Aspect.NET – an aspect-oriented programming tool for Microsoft.NET Vladimir O. Safonov Professor of computer science, Head of laboratory St. Petersburg.

Vladimir Safonov, SSCLI Capstone Workshop, Redmond 2005

29

Step by Step playing with Aspect.NET• Load the MAddNopCounter assembly to the Aspects list.

Page 30: Aspect.NET – an aspect-oriented programming tool for Microsoft.NET Vladimir O. Safonov Professor of computer science, Head of laboratory St. Petersburg.

Vladimir Safonov, SSCLI Capstone Workshop, Redmond 2005

30

Step by Step playing with Aspect.NET• Click “Find Joinpoints” button and wait until the obtained points will

not be printed at Aspects tab.

Page 31: Aspect.NET – an aspect-oriented programming tool for Microsoft.NET Vladimir O. Safonov Professor of computer science, Head of laboratory St. Petersburg.

Vladimir Safonov, SSCLI Capstone Workshop, Redmond 2005

31

Step by Step playing with Aspect.NET• To weave the actions to the join points, click “Weave Aspects” button and

check the resulting assembly ~MAddNop.exe in the debug folder of your project.

• Lets try how it works on the testapp.exe shipped with PhoenixRDK. Copy testapp.exe and testapp.pdb from \PhoenixRDK\Applications\Tests into debug folder of MAddNop project.

• Run “~MAddNop.exe testapp.exe newapp.exe”and “MAddNop.exe testapp.exe newapp.exe”in the console to compare the behavior of the assembly with the aspect woven to that of the original assembly.

Page 32: Aspect.NET – an aspect-oriented programming tool for Microsoft.NET Vladimir O. Safonov Professor of computer science, Head of laboratory St. Petersburg.

Vladimir Safonov, SSCLI Capstone Workshop, Redmond 2005

32

Step by Step playing with Aspect.NET

• The result of executing two assemblies is presented below.

• As we can see, output of our new assembly is much more informative, as compared to the original assembly. No Phoenix source code touched to achieve this goal

Page 33: Aspect.NET – an aspect-oriented programming tool for Microsoft.NET Vladimir O. Safonov Professor of computer science, Head of laboratory St. Petersburg.

Vladimir Safonov, SSCLI Capstone Workshop, Redmond 2005

33

AspectRotor• The first Aspect.NET console version working in the Rotor

environment. Included into the Aspect.NET archive uploaded to the MSDNAA Web site

• A set of Perl scripts (please use ActivePearl 5.8.7) to initialize, to build and remember target applications and aspects, to select join points, to visualize the sources, to weave aspects, to run the original and the updated assemblies

• Uses Phoenix as well-as the add-in version, and the Rotor binaries shipped with the Phoenix RDK

• A simple comfortable menus in console mode provided for each step; it’s possible to undo and return back

• DEMO (IF TIME PERMITS…)

Page 34: Aspect.NET – an aspect-oriented programming tool for Microsoft.NET Vladimir O. Safonov Professor of computer science, Head of laboratory St. Petersburg.

Vladimir Safonov, SSCLI Capstone Workshop, Redmond 2005

34

Q & A