PDA

View Full Version : AOP without ProxyFactory


kerryr
12-23-2005, 01:52 AM
I've been examining your AOP implementation and I have a question.

From the examples it looks like I have to generate my target class using ProxyFactory. This is a problem for me as I also use an OR/Mapper which sometimes creates the classes for me.

Is there any way I can get this to work with Spring? Does Spring AOP work with OR/Mappers like NHibernate?

Thanks

Aleks Seovic
12-23-2005, 02:43 AM
Spring AOP will work with any class that implements one or more interfaces (interface is required for composition proxy at the moment), so as long as your target classes implement an interface, you will be able to create AOP proxy for them using either ProxyFactory, or prefferably ProxyFactoryObject definition in the Spring config file.

It's hard to provide a more complete answer without understanding exactly what you are trying to do. If you can provide some more details and an example, I can probably give you a better answer.

Regards,

Aleks

Rick Evans
12-23-2005, 10:30 AM
Hi

You will have to use Spring.NET's ProxyFactory directly (or via a ProxyFactoryObject definition) in order to use Spring.NET AOP... the ProxyFactory (and it's attendant proxies) are the underpinning of the whole Spring.NET AOP implementation.

I am conversant with Hibernate only, and have only a passing familiarity with NHibernate. A quick browse through the (NHibernate) source led me to the IInterceptor interface, which has a method on it called Instantiate(Type, string) which leads to me to think that that is the place where any Spring AOP proxification might be done. But I don't know how that would play out, 'cos of course NHibernate does it's own proxying to effect lazy-loading... I'll have to have more than a trivial browse through the source to give you a definitive answer there :?

Having said that, I gotta ask... one (typically) only persists domain objects (via ORM); one would not (typically) persist service objects, and in these days of the anaemic domain model (http://www.martinfowler.com/bliki/AnemicDomainModel.html), it's the service objects that (again typically) encapsulate the rich business logic that requires the application of enterprise services using AOP. I have, not as yet, encountered a scenario where I would want to proxify domain objects... feel free to share your particular use case :)

On the purely Hibernate side (I am sure the parallels apply to NHibernate), I have successfully used the Hibernate Interceptor strategy to inject collaborators into domain objects as they are loaded by a Session. Like Aleks says, can you provide some more concrete information about what aspects you are thinking of applying to your persistent objects?

Cheers
Rick

MNBob
12-28-2005, 06:18 PM
Rick,

Your response made me chuckle only because you were kind of enough to link (Anemic Domain Model) to a site that says not to do what many people are doing. :)

kerryr
01-03-2006, 03:24 AM
Hi,

Thanks (all) for the reply. I do have a (thin) service layer which co-ordinates actions on the domain objects.

I'm firstly looking to apply exception handling to this service layer, so in this case it's not a problem.

I'm also trying to find an auditing mechanism where I can automatically record changes made to a domain object. This could attach to the service layer, although I'd ideally like it to attach to the domain objects. This is something I haven't prototyped yet so my thinking is still a little muddled. AOP looks like a possible way of removing this concern - or at least reducing it to a few attributes or an xml file.

I'm not familiar with the Hibernate or NHibernate interceptors, although I'd prefer not to have to deal with them if possible. My head is getting full and my team have enough to learn with AOP/DI/IOC/ORM and .NET 2.0 :)

Cheers,
Kerry