Your very first aspect weaving with AspectDNG 15 Dec 2004



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.

// base.cs
namespace AspectDNG.Sample {

    public class EntryPoint {

        public static void Main() {
            System.Console.Write("World");
        }
    }
}

Now we can take a look to the aspect code :

// aspect.cs
namespace AspectDNG.Sample.Aspect {

    public class HelloAspect {

        [AspectDNG.InlineAtStart("* *.EntryPoint::Main(*)")]
        public void Hello() {
            System.Console.Write("Hello ");
        }

        [AspectDNG.InlineBeforeReturn("* *.EntryPoint::Main(*)")]
        public void Emphase() {
            System.Console.WriteLine(" !");
        }
    }
}
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.