|
|||||
|
|||||
OverviewSamplesUser Reference DocumentationProject InformationMisc |
AOP
OverviewNanoContainer lets you configure aspects on components in a PicoContainer. You can configure aspects in Java, or using Groovy. Advice can be configured for all components in a container, using pointcuts, or advice can be applied to just one component. Advice objects may themselves have dependencies on other components, supplied by the container. NanoContainer uses dynaop to apply the aspects, provide pointcuts, etc. NanoContainer's approach to AOP is heavily influenced by dynaop, so you might want to check out the dynaop documentation for a good introduction to AOP. (It is possible to plug in your own AOP 'backend', if you prefer to use something besides dynaop.) AdviceTwo kinds of advice are supported, interceptors and mixins. An interceptor is invoked around method calls. Configuring AspectsFor the following examples, we'll use the following logging interceptor:
We'll also assume that we have a Java ConfigurationThe primary interface for configuring aspects in Java is
If we wanted to apply our interceptor to just one component, we could do the following:
Note that components and aspects can be registered in any order. An aspect can be registered before the component it applies to. In the example above, we could have reversed the two lines and registered the interceptor before the component. Container Supplied AdviceAdvice objects may themselves be components in the
With this in place, we could then register our
Pico will supply the Mixins are a special case. While you can register a mixin as an explicit component in the container, you usually don't want to. Applying the same mixin instance as advice to multiple components would in effect mean that multiple components would share the same base class object - sharing the same instances variables, etc. This is usually not a good thing. However, you may specify a mixin class that has dependencies on components in the container. The container will instantiate a new mixin object for each component that it applies the mixin to, but will satisfy any dependencies the mixin has from components in the container, using constructor injection. PointcutsNotice the use of the Groovy ConfigurationTo configure aspects using Groovy, use DynaopNanoContainerBuilder. This is probably the easiest and most expressive way to configure aspects. A Groovy configuration file might look something like this: An error occurred: http://svn.codehaus.org/picocontainer/java/nanocontainer/trunk/container/src/test/org/nanocontainer/script/groovy/GroovyNodeBuilderAopScriptedTestCase.groovy. The system administrator has been notified.
The example above shows a mixture of component scoped and container scoped advice, both interceptors and mixins. Again, note that the order in which things are registered does not matter. We could have registered container scoped advice before registering the components they apply to, or we could have registered advice dependencies such as For more information, see the NanoContainer documentation. Just substitute LimitationsComponents that have aspects applied to them must implement an interface. Advice is not applied to components registered via |
||||
|
Copyright 2003-2006 - The Codehaus. All rights reserved unless otherwise noted.
Powered by Atlassian Confluence
|
|||||