PDA

View Full Version : AOP first steps...


dfed
08-17-2005, 02:36 PM
Hi all!
I think that AOP is a great thing! :))
I read an example, all work but my question is:
How can I intercept some invocations of all instances of concret interface?
And an example, if possible :oops:
Thanks a lot!

Rick Evans
08-17-2005, 04:16 PM
Hiya Dmitrij

I think AOP is great too :) I'll gladly give you an example if you tell me what you want to use as a discriminator for the invocations.

So given this rather arbitrary interface...

public interface Foo
{
void Execute(string processId);

string FindHandle (long handleId);
}

I take it your question then is how to intercept only certain invocations of these methods on a proxied instance of an implementation class? Do you mean that you want a dynamic style pointcut that matches only when say, the value of the 'processId' parameter of the Execute method starts with, mmm, let's say the string value 'bingo'? Is this what you are looking for?

If you post a snippet of your codebase such as the interface that you are proxying, and describe under what conditions you would like to have advice apply to intercepted invocations, then I (or one of the other devs) will post an example.

Ciao
Rick

dfed
08-18-2005, 07:58 AM
Hi Rick! :)

I try to remake a transaction manager in my project.

This is the interface which I want to proxy, invocations of his methods I want to intercept:


public interface ITemplate
{
void delete( Entity entity );
Entity load( Type entityClass, long id );
IList loadAll( Type entityClass );
Entity saveOrUpdate( Entity entity );
}
and the next interface, this is the transaction manager:

public interface ITransactionManager
{
void beginTransaction();
void commitTransaction();
void rollbackTransaction();
}
So I want to intercept invocations of methods of ITemplate interface, begin transaction, after commit and if an some exception throws do roolback.