Is Microsoft working on a solution for AOP in C#? What are the (real AOP) alternatives?
Bonus question: is Code Contracts a kind of AOP?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Most dependency injection frameworks in .net have the ability to use AOP techniques, I personally prefer Ninject and the Interceptor plugin as its simple to use and doesn’t require any class pollution with 3rd party attributes or anything.
That being said Spring.net, Castle Windsor and lots of other DI frameworks support the same principle with slightly different syntax and approaches, some are xml driven some are c# driven so you can have compile time safety.
One thing to think about is that most DI frameworks do this via class proxying, so they require your methods to be virtual and then at runtime it proxies your class method and you can intercept at that point. There are some other approaches such as IL weaving which is what PostSharp does, which can be faster than proxying, although I dont have any measurements to back that up.
Didn’t see the bonus question bit, for me I would say its not a clear cut answer, as it depends on how you use it, as generally you are using AOP as a way to separate your non functional concerns such as logging, transactions maybe validation from your source code, so you add this logic from the outside in, so ideally your source code has no knowledge of the AOP happening (although that’s not always the case if you are using some 3rd party attributes which will couple your source code to the AOP framework).
As code contracts can be written in-line with existing classes or hooked in via attributes or I believe can be fully injected at runtime, so much like logging concerns you could put them all into your classes but when using an AOP approach you wouldn’t. So for me Code Contracts are just a tool to enforce something, you can use it in an AOP fashion or you can just embed it in your code.