|
|
|
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?
|
|
|
|
|
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
|
|
|
|
|
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.
|
|
|
|
|
Gael Fraiteur
SharpCrafters
|
|
Something like this:
[assembly: MyAspect(TargetAssemblies="System", TargetTypes="System.Net.HttpWebRequest", TargetMethods="DoSubmitRequestProcessing ")]
-gael
|
|
|
|
|
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.
|
|
|
|
|
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.
|
|
|
|