PDA

View Full Version : Applying AOP to a classes internal method calls


NolanEvans
08-08-2006, 08:29 PM
I have been using externally called aspects for quite some time now, however i was wondering how to weave a aspect in such that any internal call will also execute the aspect code.

I am trying to wrap a aspect around all methods in a class such that any call to the method, including an internal one will call the aspect.


public interface ConnectionInterface
{

string Reserve();

void Connect();

void Disconnect();

string StatusCheck(string number_string);
}
public class ASession_class : ConnectionInterface
{

public string Reserve()
{
Debug.WriteLine("I am going to reserve a number.");
helloworld(); //aspect should wrap this method too
return "9995551212";
}

private void helloworld()
{
}

public void Connect()
{
Debug.WriteLine("You are now connected.");
}

public void Disconnect()
{
Debug.WriteLine("You are now disconnected.");
}

public string StatusCheck(string number_string)
{
Debug.WriteLine("checked status for " + number_string);
return "SPARE";
}
}



So I want a aspect that intercepts the internal call to "helloworld", I have been trying to use "introductions", however I cannot get them to work. Is there an example of one out there?

Can this be done with Spring.NET's AOP platform?

Bruno Baia
08-09-2006, 12:39 PM
Hi,

Dynamic proxies are behind Spring.NET AOP features, and you can't proxy a private method using this technology.

A solution is to use a protected virtual method that you can proxy (overriding it), but unfortunately this is not possible today with Spring.NET that only uses Composition-based proxy.
It's possible with inheritance-based proxy which is planned for 1.2.


-Bruno

NolanEvans
08-09-2006, 06:06 PM
Okay, thanks for the reply.

lshinev
04-25-2007, 04:14 PM
Hello,

We are evaluating Spring. Net 1.1 preview 3 as part of our larger self defending objects approach to security. It seems to have great promise in simplifying our efforts, particularly AOP.

Are there any specific documented examples demonstrating your intended use of Introductions? I have searched the documentation, the included samples, the forums and the Web at large without specific success.

Thanks for your help,
Lee

Bruno Baia
04-26-2007, 01:21 PM
Hi,

Reference documentation :
12.3.2.5. Introduction advice (http://www.springframework.net/doc-latest/reference/html/aop.html#d0e7083)

An Introduction example has been added after 1.1 P3 release, donwload one of the latest nightly build (http://www.springframework.net/downloads/nightly/) and take a look to the Spring.AopQuickStart.Step6 example.

HTH,
Bruno