The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

Orlando80 (4) [Avatar] Offline
#1
Hi,
my favourite way to implement AOP at the moment is using dynamic proxy. Reading the book, I found you always use .CreateClassProxy and to use virtual methods in the target class. Maybe you should point out you can also work with non virtual methods using the composition of objects in DP calling CreateInterfaceProxyWithTarget<>. This will allow to intercept methods that are not virtual.
Any reason you don't like it?
matthew.groves (46) [Avatar] Offline
#2
Re: DynamicProxy with non virtual method
Hmm, I'm not sure why I did that. I'll look into it.

Thanks,

Matt
Orlando80 (4) [Avatar] Offline
#3
Re: DynamicProxy with non virtual method
Ok, let me know you impressions. Maybe it may have slightly more overhead at runtime, but if you are composing your object tree with a IoC container (like castle windsor) it just happens once.

Message was edited by:
Orlando80
matthew.groves (46) [Avatar] Offline
#4
Re: DynamicProxy with non virtual method
Very strange, because in a later chapter (which hasn't been released yet), I use CreateInterfaceProxyWithTargetInterface.

What I think happened is that I used CreateClassProxy early on because it's simpler code, but the text around that example makes it sound like this is the only way. Thank you for pointing this out, I will make the appropriate changes.
Orlando80 (4) [Avatar] Offline
#5
Re: DynamicProxy with non virtual method
you're welcome, I hope to read more chapters soon smilie
it's a really interesting topic and I'm going to have a talk about it soon so I'm really appreciating your point of view.
Orlando80 (4) [Avatar] Offline
#6
Re: DynamicProxy with non virtual method
BTW ... after reading the threading chapter (I appreciate it's just a demo code but I don't like too much using threads this way, it can be misleading ) I started thinking about the new async/await features of c# 4.5 to handle threading, do you think we can see it as a built in aspect?
matthew.groves (46) [Avatar] Offline
#7
Re: DynamicProxy with non virtual method
I don't think async/await can be used in that way (at least, I haven't seen it yet). Check out this blog post from Gael Fraiteur (creator of PostSharp) about async/await as related to PostSharp/AOP: http://www.sharpcrafters.com/blog/post/C-50-asyncawait-vs-PostSharp.aspx

Technically, async/await aren't necessarily related to threading, but rather non-blocking asynchronous programming. But async/await may be better for many situations than an AOP threading aspect (assuming you are able to use C# 5).

You could switch to use Task instead of Thread in the threading aspect. I've actually added this to the chapter already (not released yet). And one of the main points is that you can switch threading APIs by only changing one class (the threading aspect), thus following the Single Responsibility Principle.