Your very first aspect weaving with AspectDNG 1
After almost one year and a half, AspectDNG is still under heavy development.
One of the last exciting features is the full rewriting of the weaving engine. Please
thanks Thomas Gil for his work. The weaving engine is now much more faster,
and written in full C# (no more XSLT processing).
The 0.6.1 version of AspectDNG, available both on sourceforge and in the CVS,
introduce a new, and much more simple way of describing all the joinpoints using
Custom Attributes. Don’t be desappointed, let’s write a simple exemple.
Let’s write an Hello World, AspectDNG’s way.
<span class="rem">// base.cs</span>
<span class="kwrd">namespace</span> AspectDNG.Sample {
<span class="kwrd">public</span> <span class="kwrd">class</span> EntryPoint {
<span class="kwrd">public</span> <span class="kwrd">static</span> <span class="kwrd">void</span> Main() {
System.Console.Write(<span class="str">"World"</span>);
}
}
}
Now we can take a look to the aspect code :
<span class="rem">// aspect.cs</span>
<span class="kwrd">namespace</span> AspectDNG.Sample.Aspect {
<span class="kwrd">public</span> <span class="kwrd">class</span> HelloAspect {
[AspectDNG.InlineAtStart(<span class="str">"* *.EntryPoint::Main(*)"</span>)]
<span class="kwrd">public</span> <span class="kwrd">void</span> Hello() {
System.Console.Write(<span class="str">"Hello "</span>);
}
[AspectDNG.InlineBeforeReturn(<span class="str">"* *.EntryPoint::Main(*)"</span>)]
<span class="kwrd">public</span> <span class="kwrd">void</span> Emphase() {
System.Console.WriteLine(<span class="str">" !"</span>);
}
}
}
Pretty simple isn’t it ? Every meta-aspect inside AspectDNG has its own Custom Attribute.
So you don’t have to write the whole XML descriptor as you used to. By doing it this way, you introduce a dependency
between your aspects, and AspectDNG, but I’m sure it is not the worth thing you’ve ever written.
Moreover, if you want to keep your aspects clean, you can still use the good old XML way.
Much more “pure”, but a little painfull. By the way, take a look to the new jointpoint syntax that will be translated
in a xpath query. User-friendly no ? But just take a look at the process, here is a console dump:jbe@monkey:~/Devel/weave $ ls aspect.cs AspectDNGAttributes.dll AspectDNG.exe base.cs jbe@monkey:~/Devel/weave $ mcs base.cs jbe@monkey:~/Devel/weave $ mcs aspect.cs -r:AspectDNGAttributes.dll -t:library jbe@monkey:~/Devel/weave $ mono base.exe World jbe@monkey:~/Devel/weave $ mono AspectDNG.exe -dw base.exe aspect.dll jbe@monkey:~/Devel/weave $ mono base.exe Hello World ! jbe@monkey:~/Devel/weave $
AspectDNG is not ended. I’m currently rewriting the base layer. I think I may post about this new library in one or two week. This should be very exciting. By getting rid of Rail, we should increase weaving speed, and improve ILML completeness. One of the other point is the lack of documentation, you have to read the tests included in AspectDNG to see the whole thing. We are discussing about how this documentation will be written.
By the way, as you can see in the console dump, Mono is working better and better… Of course it works with Microsoft’s Framework too.
Some links :
Edit : Renaud sent me a mail indicating that it works on OS X too, thanks to Mono.
The screenshot.
Trackbacks
Use the following link to trackback from your own site:
http://www.evain.net/blog/articles/trackback/3
Bon ben moi qui demandais tout le temps le support de mono je peux que vous féliciter pour cette nouvelle version que je vais enfin pouvoir utiliser sous mon linux :)
Encore bravo