Skip to content

Latest commit

 

History

History

docs

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Aspect Injector Docs

How it works

AspectInjector is a compile-time AOP framework which means that all required work is done at compile time. For example, before compilation your code looks like:

[Aspect(Scope.Global)]
[Injection(typeof(Log))]
class Log : Attribute
{
    [Advice(Kind.Before, Targets = Target.Method)]
    public void OnEntry([Argument(Source.Name)] string name)
    {
        Console.WriteLine($"Entering method {name}");
    }
}

class TestClass
{
    [Log]
    public void Do()
    {
        Console.WriteLine($"Done");
    }
}

Then when you hit F5, we pick up from there and change your assembly a bit, so it actually works like this:

[Aspect(Scope.Global)]
[Injection(typeof(Log))]
class Log : Attribute
{
    public static readonly Log __a$_instance;

    [Advice(Kind.Before, Targets = Target.Method)]
    public void OnEntry([Argument(Source.Name)] string name)
    {
        Console.WriteLine($"Entering method {name}");
    }

    static Log()
    {
        __a$_instance = new Log();
    }
}

internal class TestClass
{
    [Log]
    public void Do()
    {
        Log.__a$_instance.OnEntry("Do");
        Console.WriteLine("Done");
    }
}

Thus, there is no performance hit as often experienced with other runtime AOP frameworks.