NConcern Code
NConcern is a .NET Runtime AOP (Aspect-Oriented Programming) Framework
Brought to you by:
virtuoze
| File | Date | Author | Commit |
|---|---|---|---|
| NConcern | 2016-12-23 |
|
[2412c3] Implicit joinpoint correction and testing prepa... |
| LICENSE | 2016-12-15 |
|
[381c1a] MIT |
| README.md | 2016-12-15 |
|
[ce14eb] README |
NConcern is a .NET runtime AOP (Aspect-Oriented Programming) lightweight framework written in C# that reduces tangling caused by cross-cutting concerns. Its role is to introduce Aspect-Oriented Programming paradigm with a minimum cost to maximize quality and productivity.
NConcern AOP Framework is based on code injection at runtime.
An aspect represents a set of features related to a specific concern. The role of an aspect is to provide advices for method. It can be added and removed at runtime.
An advice is the code added by an aspect to complete a method. It can be implemented using delegate, expression or CIL generation.
I want to trace my service calls with "Console.WriteLine".
My services are OperationContract typed (WCF service)
[assembly: System.Diagnostics.Debuggable(true, true)]
[ServiceContract]
public class Calculator
{
[OperationContract]
public int Add(int a, int b)
{
return a + b;
}
}
static public class Tracer
{
static public void Trace(MethodInfo method, object[] arguments)
{
Console.WriteLine("{0}({1})", method.Name, string.Join(", ", arguments));
}
}
public class Logging : IAspect
{
public IEnumerable<IAdvice> Advise(MethodInfo method)
{
yield return Advice.Basic.Before((instance, arguments) =>
{
Tracer.Trace(method, arguments);
});
}
}
var services = new Func<MethodInfo, bool>(method =>
{
return method.IsDefined(typeof(OperationContractAttribute), true);
});
Aspect.Weave<Logging>(services);
Aspect.Release<Logging>(services);