I am happy to announce that today I got the AOP/1 framework to Alpha state (Version 0.1)! The AOP/1 framework was inspired from talking to a client that was using DI/1 and I was describing how good it would be to have the ability to intercept methods, as you can with ColdSpring's AOP, but with less definitions (BTW, I know that ColdSpring 2 has radically trimmed down the syntax, which is awesome!). The main issue I have had with ColdSpring's implementation is that it is a great concept but very difficult to describe using the vocabulary (Advisor, Advice, AfterReturningAdvice,NamedMethodPointcutAdvisor,ProxyFactoryBean to name a few) to people.
Another side of it was that I wanted a much simpler way to do this, without having to always resort to looking stuff up in the manual. So I give you AOP/1!
Let's take a simple example. Using AOP/1 is very similar to working with Inject One ( see: Getting Started with Inject One ), since it is just an extension of DI/1, you would first, define your bean factory:
<script src="https://gist.github.com/cybersonic/5877209.js"></script>
So far all the configuration is identical to DI/1. Let's take a concrete example. Let's say we have a service that reverses a string. This would be defined under /services/Reverse.cfc :
<script src="https://gist.github.com/cybersonic/5877193.js"></script>
All pretty simple so far! Let's go and get it a full example of using it:
<script src="https://gist.github.com/cybersonic/5877212.js"></script>
This would output:
!olleH
Everything is fine so far, but what if we want to intercept these calls? Well that is where AOP/1 does the hard work for you. All you have to define is a CFC (in your services if you like, or manually passing all the settings you want) with one or more of the following methods: before, after, around and onerror. In this case we have a before method defined in our BeforeInterceptor.cfc:
<script src="https://gist.github.com/cybersonic/5877213.js"></script>
Now all we need to do is as above, but just add the fact that we are intercepting:
<script src="https://gist.github.com/cybersonic/5877219.js"></script>
And that is it! Now all the method calls to the ReverseService will first call the BeforeInterceptor.before() method. So if we now call continue as before and do:
<script src="https://gist.github.com/cybersonic/5877229.js"></script>
We would now get:
!olleHerofeb
I hope this is a useful framework for people out there, and it allows them to do much more de-coupled development! I would also really like to thank Sean Corfield for allowing this project to under the framework-one family banner!
You can Fork it, Clone it or Download it over at Github
Tweet
comments powered by Disqus