SharpCrafters Forum – PostSharp and .NET classes

SharpCrafters Support Forum

        


PostSharp and .NET classes Expand / Collapse
Author
Message
Posted 2/16/2010 10:31:50 PM


Community Member
Hello! I am new in Aspect-Oriented programming so I would like to clear some things for myself. Tell me please if I can join aspects to classes in .NET assemblies. For example I need to raise OnExit in System.Net.HttpWebRequest.DoSubmitRequestProcessing which is private. Can I do this?
Post #3679
Posted 2/18/2010 7:34:14 AM


Gael Fraiteur

SharpCrafters
Hi,

You can't add aspects of this kind to classes that are not defined in the current project.
When you add aspects to methods of external assemblies, the aspects are executed only when the methods are invoked from the current project.

-gael
Post #3680
Posted 2/18/2010 7:49:28 AM


Community Member
Thank you for your answer Gael!

So. My application does Web Request using HTTPWebRequest and its private method is invoked. How can I join my aspect to System.Net.HttpWebRequest.DoSubmitRequestProcessing? Ues I need my aspect been executed after DoSubmitRequestProcessing done. Could you give a small example please.
Post #3681
Posted 2/18/2010 12:15:51 PM


Gael Fraiteur

SharpCrafters
Something like this:

[assembly: MyAspect(TargetAssemblies="System", TargetTypes="System.Net.HttpWebRequest", TargetMethods="DoSubmitRequestProcessing ")]

-gael
Post #3682
Posted 2/19/2010 3:31:25 PM


Community Member
I can not make working my solution.
My Program.cs contain lines:
Uri uri = new Uri("http://www.microsoft.com/");
req = WebRequest.Create(uri) as HttpWebRequest;
resp = req.GetResponse() as HttpWebResponse;

GetResponse invoke private method DoSubmitRequestProcessing.
I need to catch a moment then this method is invoked.

PostSharp can not do this because there is no direct call of DoSubmitRequestProcessing in my assembly. Maybe you can give me an advice how can I catch this moment? Maybe I should use other AOP implementation which uses dynamic proxies? Or there is a way to detect this moment using Reflection?

I need to modify Cookies before automatic redirection will be executed.
Post #3683
Posted 2/23/2010 12:28:42 PM


Gael Fraiteur

SharpCrafters
That's what I suspected.

PostSharp is only able to intercept direct calls to DoSubmitRequestProcessing from your assembly.

Dynamic proxies will not help; maximally a framework based on the profiling API.
Post #3989
« Prev Topic | Next Topic »


All times are GMT +1:00, Time now is 11:43am

Powered By InstantForum.NET v4.1.4 © 2010
Execution: 0.123. 7 queries. Compression Disabled.