Skip to content

A simple AOP library written in C# for .NET Standard 2.0+

License

Notifications You must be signed in to change notification settings

highstreeto/SimplyAOP

Repository files navigation

SimplyAOP

License Build Status NuGet

SimplyAOP is a .NET library (.NET Standard 2.0+) which allows to use AOP concepts in a simple and straightforward way.

It doesn't use dynamic proxy to accomplish that. Instead the AOP target must invoke a specific method (Advice(...)) on the AspectWeaver to allow for aspects to kick in.

So SimplyAOP doesn't need to create the instance of the target class so it can be used were instance creation is handled externally (for example by WCF).

Goals

  • Be as simple as possible
    • No runtime or compile time instrumentation
  • Minimize reflection usage

Basic Example

var config = new AspectConfiguration();
config.AddAspect<MethodConsoleTraceAdvice>();

new Target(config).Foo(1, 15);

class Target : AspectWeaver.Class {
    Target(AspectConfiguration config) : base(config) {}

    bool Foo(int a, int b) {
        return Advice((a, b), req => {
            return a == b;
        });
    }
}

class MethodConsoleTraceAdvice : IBeforeAdvice {
    public string Name => "Method Console Trace";
    public void Before<TParam, TResult>(Invocation<TParam, TResult> invocation)
        => Console.WriteLine($"Method {invocation.MethodName}({invocation.Parameter}) begin");
}

For a more detailed example see SimplyAOP.Example or SimplyAOP.IoCExample

About

A simple AOP library written in C# for .NET Standard 2.0+

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages