tags:

views:

1177

answers:

3

There is a lot of AOP implementation in C#, VB.net. this is some of AOP Implementations:

  • Aspect.NET
  • LOOM.NET
  • Enterprise Library 3.0 Policy Injection Application Block
  • Puzzle.NAspect
  • AspectDNG
  • Aspect#
  • Compose*
  • PostSharp
  • Seasar.NET
  • DotSpect (.SPECT)
  • The Spring.NET Framework as part of its functionality
  • Wicca and Phx.Morph
  • SetPoint
  • An exhaustive analysis on AOSD solutions for.NET is available from Twente University
  • ...

What is the best implementation for AOP in .Net? What I should use?

+1  A: 

"Best" is subjective.

First, draw up a list of the features you need, your architecture, etc. Then look for options that do what you need, without introducing unnecessary complexity. For example, several are interface oriented: is your code currently interface oriented? If not, PostSharp might be a better choice (being weaved into the original classes). But of course, PostSharp can't be configured at runtime... horses for courses.

Marc Gravell
+1  A: 

I don't know about best, there are a lot of frameworks and not enough hours in the day to try them all.

I did use PostSharp and was pleasantly surprised how easy it is to get started with it.

I also looked into AOP with Castle Windsor and Spring.Net, the approach is different (runtime vs compile time). Mixing AOP and IoC seems to make sense. When you're not using one of these frameworks yet it's a lot more work to get started but don't let that stop you.

For new projects now I'd probably use Castle Windsor, but that's mostly because I'd also want to use IoC. If i had to quickly implement AOP into an existing code base I'd use PostSharp.

Mendelt
+8  A: 

I think that Castle Dynamic Proxy is the solution of choice if dynamic interception can handle your needs. This framework is used internally by a lot of other frameworks that want to offer AOP capabilities. Typically, most of existing IoC containers now provide some dynamic interception mechanisms (Spring.NET, Castle Windsor, StructureMap, etc.) If you already work with an IoC container, maybe it could be easier to look at what it proposes.

If dynamic interception can't address your needs (weaving sealed class, intercepting non-virtual call, etc.), then you certainly want static weaving. PostSharp is the reference in this domain.

Note that it also exists Linfu, that can be used to leverage both AOP fashions.

Romain Verdier
+1 on that if you want to do runtime AOP. +1 on PostSharp if you want post-compile time AOP
Krzysztof Koźmic