Hello!
If you don't know Aspect#, please visit http://aspectsharp.sourceforge.net/
I though this one would be incredible complicated, as it involved the
replacement of IProxyFactory implementation but it was not that difficult.
Please note that Castle has an interceptor framework
[http://www.castleproject.org/containerdocs/interceptors], so I had to mix
the aspect# interceptor chain with the Castle interceptor chain. The
approach was simple: the Aspect# chain is one step in the castle interceptor
chain. I hope people can understand the design, I re-read the paragraph, and
its not much clear at all :-\
With this integration one can use the configuration related to the Aspect#
facility to act on the components on the container. For example, follows the
configuration:
<configuration>
<facilities>
<facility id="aspectsharp">
<![CDATA[
import Castle.Facilities.AspectSharp.Tests.Components in
Castle.Facilities.AspectSharp.Tests
import Castle.Facilities.AspectSharp.Tests.Interceptors in
Castle.Facilities.AspectSharp.Tests
interceptors [ "key" : LoggerTraceInterceptor ]
mixins [ "key" : SecurityMixin ]
aspect ProtocolHandlerLogger for [
assignableFrom(IProtocolHandler) ]
include "key"
pointcut method(*)
advice("key")
end
end
// You can define as many aspect as you want here...
]]>
</facility>
</facilities>
</configuration>
So in this case, each component on the container that is assignable from
IProtocolHandler will use the LoggerTraceInterceptor.
They also have a mixin (SecurityMixin).
One fake implementation of IProtocolHandler:
public class MessengerProtocolHandler : IProtocolHandler
{
public MessengerProtocolHandler()
{
}
public void Handle(String contents)
{
}
}
--> Note that the Handle method is not virtual! :-)
This is a snippet from one of the test cases, by the way, so here is the
code:
XmlConfigurationStore store = new
XmlConfigurationStore("../aop_castle_config.xml");
WindsorContainer container = new WindsorContainer( store );
container.AddFacility( "aspectsharp", new AspectSharpFacility() );
// Logger implementation
container.AddComponent( "logger", typeof(ILogger), typeof(MemoryLogger) );
// AopAlliance interceptors
container.AddComponent( "log4netinterceptor",
typeof(LoggerTraceInterceptor) );
// Protocol handlers
container.AddComponent( "protocolhandler.miranda",
typeof(IProtocolHandler), typeof(MirandaProtocolHandler) );
container.AddComponent( "protocolhandler.messenger",
typeof(IProtocolHandler), typeof(MessengerProtocolHandler) );
// using...
ILogger logger = (ILogger) container[ typeof(ILogger) ];
Assert.AreEqual( 0, logger.Contents.Length );
IProtocolHandler handler = (IProtocolHandler)
container[ "protocolhandler.miranda" ];
handler.Handle( "contents" );
handler = (IProtocolHandler) container[ "protocolhandler.messenger" ];
handler.Handle( "contents" );
Assert.AreEqual( "Entering Handle Leaving Handle Entering Handle Leaving
Handle ",
logger.Contents );
The code can be found here
http://svn.digitalcraftsmen.com.br/svn/castle/trunk/Facilities/AspectSharp/Castle.Facilities.AspectSharp/
Its only 5 small classes, the test cases took more time to write... :-\
TDD my arse! :-(
More at
http://svn.digitalcraftsmen.com.br/svn/castle/trunk/Facilities/AspectSharp/
I'm looking forward to working on
- ActiveRecord facility
- MyXAML facility (http://www.myxaml.com/)
--
Cheers,
hammett
http://www.digitalcraftsmen.com.br/~hammett
|