Skip to content
A lightweight (Aspect Oriented Programming) AOP foundation
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.github/ISSUE_TEMPLATE
Aspekt.Bootstrap.Host
Aspekt.Bootstrap.Tasks
Aspekt.Bootstrap.Test
Aspekt.Bootstrap Implement bootstrap as MSBuild task Mar 3, 2019
Aspekt.Contracts
Aspekt.Foundation.Test
Aspekt.Logging.Test
Aspekt.Logging
Aspekt.Nuget
Aspekt.Target
Aspekt.Test
Aspekt
.editorconfig
.gitattributes
.gitignore
.travis.yml
Aspekt.sln
Aspekt.sln.DotSettings
CODE_OF_CONDUCT.md
CONTRIBUTING.md
LICENSE
PULL_REQUEST_TEMPLATE.md
README.md

README.md

[ASPeKT]

Build status

A lightweight (Aspect Oriented Programming) AOP foundation

Overview

Aspekt is a small AOP foundation library written in C#. Aspect Oriented Programming (AOP) allows to ease the pain associated with cross-cutting concerns. A cross-cutting concern is a pattern that gets across a program that cannot easily be factored into its own module. This raises the so called signal-to-noise ratio. One common cross cutting concern is logging, when logging entry/exit/exception of a function, the code becomes cluttered with log code and the intent can become lost. Aspekt addresses these concerns, by using attributes as annotation of functions. Like PostSharp aspect utilizes post processing of the .NET binaries, inserting the aspects post build. For ASPeKT this is done using Mono.Cecil.

Usage

The foundation of Aspekt is the base Aspect. In order to utilize Aspects, just derive from Aspekt.Aspect and implement the OnEntry, OnExit, OnException methods. Aspekt will only place the calls implemented on the class i.e. OnEntry, OnExit, OnException

class SampleAspect : Aspekt.Aspect
{
   public SampleAspect(String val)
   {
   }

   public void override OnEntry(MethodArgs ma)
   {
      // called before any existing code is ran
   }

   public void override OnExit(MethodArgs ma)
   {
     // called before ANY return statement
   }

   public void override OnException(MethodArgs ma, Exception e)
   {
     // called if existing codes excepts
   }
}

Aspekt re-writes methods in the following manner.

class Foo
{
    [SampleAspect("Some Value")]
    public void Bar(String s, int i)
    {
       MethodArgs ma = new MethodArgs("Bar", "Assembly.Foo.Bar(String s, int i)", new Arguments(new object[] { s, i }), this);
       SampleAspect sa = new SampleAspect("Some Value");
       sa.OnEntry(ma);
       try
       {
           // original code
           sa.OnExit(ma);
       }
       catch(Exception e)
       {
          sa.OnException(ma,e);
          throw;
       }
    }
}

Aspekt tries not alter or modify existing code, so if the IL contains multiple returns, Aspekt calls OnExit before each return.

If you're using NuGet to get ASPeKT, your project will have the appropriate post build steps. You can ignore anything below.

Since Aspekt works post compile, in order to use it you must run the Bootstrap application against your assembly.

> Aspekt.Bootstrap.Host [PathToAssembly] 

This will process the assembly and add in the aspects to their respective members.

You can’t perform that action at this time.