Announcing AOP/1

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:

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 :

All pretty simple so far! Let's go and get it a full example of using it:

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:

Now all we need to do is as above, but just add the fact that we are intercepting:

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:

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

del.icio.us Digg StumbleUpon Facebook reddit Google Bookmarks
  1. David Boyer

    #1 by David Boyer - June 28, 2013 at 4:25 AM

    Thanks Mark, this looks really interesting especially as I've been investigating AOP recently. Have you any plans to add some very basic example apps to the project, similar to how some are packaged with FW/1?
  2. Mark Drew

    #2 by Mark Drew - June 28, 2013 at 4:31 AM

    There is a basic run through the examples in the code, which are actually the test cases I used to develop the app (I should move them to MXUnit soon, I just had to do quick checks)

    I was thinking of doing an example content management application or something, It's one of those things isn't it? It's not ui or exciting but in my mind pretty awesome and useful.

    Any ideas welcome of course!
  3. Dominic Watson

    #3 by Dominic Watson - June 28, 2013 at 4:52 AM

    That looks really neat. Will / does the intercept method take more loose rules? i.e. apply the rule to any beans that end in "Service":

    beanFactory.intercept( "*Service", "BeforeInterceptor" );

    The old skool ColdSpring 1 way of AOC was definitely way too verbose. I suggested, 5 years ago, what appears to be being implemented in v2 now:

    http://fusion.dominicwatson.co.uk/2008/04/scatting-with-coldspring.html

    This looks far more sensible and, as you say, explainable! Nice one.
  4. Mark Drew

    #4 by Mark Drew - June 28, 2013 at 5:38 AM

    I am not sure if it does/can take loose rules, as the intercept() method will just do a getBean("Service") (in your example above), I would go with the rule that if you get a true from containsBean("Service") you can add the interceptor.

    I also added the ability to intercept certain methods:

    bf.intercept("Service", "MyInterceptor", "save,load")
  5. Marco Betschart

    #5 by Marco Betschart - June 28, 2013 at 6:01 AM

    Awesome!!!

    I'm very happy to see the simplicity approach of FW/1 and DI/1 now in a AOP framework! I've had the same feelings as you when I've used the AOP functionalities of ColdSpring in the past - that's why I've not used the power of AOP, as it was just not fun!

Comments are closed.

comments powered by Disqus