An AOP (Aspect-Oriented Programming
) library that allows to implement aspects utilizing a fluent API. fluentAOP is primarily designed to simplify the adoption and use of AOP in .NET. It does not require XML files, attributes or any other kind of configuration. In contrast to most AOP implementations, its interception semantics exclusively rely on strongly-typed method definitions and a fluent API.
AOP in one line of code
An example is worth a thousand words...
// Note: line indented to improve readability
var foo = new Proxy<Foo>()
.Target( new Foo() )
.InterceptMethod ( f => f.Go() )
.OnBefore(()=> Console.Write(“Hello World!”) )
// Result: every time Go() is called a “Hello World!” message is previously printed.
Take a look at the QuickStart
for more examples.
fluentAOP: A simple way to introduce AOP in .NET applications
The aim of this project is not to offer the most complete AOP implementation or the richest interception semantics. fluentAOP is an attempt to simplify the adoption and use of AOP in .NET applications.
In order to achieve this goal fluentAOP offers:
- Strongly-typed syntax. Interception semantics are based on strongly-typed method definitions, which permit to develop aspects taking advantage of features like: auto-completion, refactoring, compile-time errors, etc.
- No configuration. fluentAOP tries to simplify AOP implementation by favoring convention over configuration. As a result, no configuration of any kind is ever required to build aspects. However, some conventions take place to make this possible.
- Minimum learning-curve. In order to get started with fluentAOP no previous experience with this or any other AOP implementation is required. No need to know or understand AOP terminology, which is not always very intuitive. By looking at some examples developers can figure out how to intercept calls and modularize their own applications.
- Methods as first-class elements. Utilizing dynamic proxies to implement AOP typically results in having to model aspects as interceptors. Such interceptors are commonly associated with objects no with methods. Therefore, the developer is responsible for providing the logic to break down object interception into method interception. fluentAOP alleviates this disparity by providing a true method-oriented approach.
- Non-intrusive. Using fluentAOP can result in a clean and well-modularized implementation of AOP. Advices are modeled as POCOs. They do not need any type of decoration, configuration or type hierarchy to compose aspects. Indeed, any advice implementation can be easily reused out of the scope of fluentAOP.
Take a look at the QuickStart
for some examples.
fluentAOP does not depend on any compile-time process to introduce aspects. Rather, it relies on Proxi (Proxy Interface
) to perform runtime IL-weaving. Proxi is a light-weight library that makes possible to generate runtime-built proxies (also known as dynamic proxies) using different providers. To know more about the Proxi project visit its website
What types of proxies does fluentAOP support?
- Interface Proxy. It implements an interface as its base type and utilizes composition to delegate calls to its target object. Any method or property exposed by the interface can be intercepted.
- Class Proxy. It extends a class and overrides its virtual methods and properties to provide interception. Any method or property exposed as virtual in the extended type can be intercepted.
- Non-Target Proxy. It does not require a target object and its base type can be abstract (class or interface). Any method or property exposed by its base type can be individually implemented on runtime.
What types of advices does fluentAOP support?
- OnBefore. It always runs before the target method execution.
- OnInvoke. It runs instead of the target method execution.
- OnAfter. It runs after the target method execution, but only if it does not throw.
- OnCatch. It runs after the target method execution, but only if it throws.
- OnFinally. It always runs after the target method execution. But OnAfter and OnCatch advices always run first if they exist.
- OnReturn. It runs right before the proxy method execution is over. OnFinally advice runs first if it exist.
How does fluentAOP compare with other AOP frameworks?
Like any other AOP implementation, based on runtime-built proxies, fluentAOP only supports a subset of AOP:
- Interception has to be defined around method or property calls: on entry, on exit or on exception.
- Only virtual or interface members (methods or properties) can be intercepted.
Does fluentAOP support property-based interception?
Yes, property and method interception are supported. Are non-target proxies supported?
Yes, it is possible to build proxies without having to provide a target object.What do I need to utilize fluentAOP?
Where can I get the source code for this project?
- Download the latest release from this website.
- Select 'Add Reference...' on your Visual Studio project.
- Locate and select: fluentAOP.dll and Proxi.dll.
You can get it from here
.Any idea on how to improve this project?
Please contact me