[Mono-list] How to do code injection with .NET

Lluis Sanchez lluis@ideary.com
Thu, 20 Feb 2003 22:25:40 +0100


Hi,

You can do it using ContextBoundObjects. Using ContextAttribute you can
create message sinks through which will flow all method calls. You then can
intercept a call to an object and make whatever check you want. However, it
only works with calls between contexts.

Unfortunately, it doesn't work in mono yet, but soon will :-)

Lluis.

----- Original Message -----
From: Philippe Lavoie
To: mono-list@ximian.com
Sent: Thursday, February 20, 2003 6:05 PM
Subject: [Mono-list] How to do code injection with .NET


Hi,

I've been reading a little about Aspect Oriented Design. And it seems
objects inheriting from ContextBoundObject allow you to do that, although
with some limitation, i.e. the framework only work with a context per class
maximum (I couldn't find a way to have a new context for every method call
inside the same class).

I was wondering if I could do something like in J2EE, i.e.

  [Priviledge("EditProfile")]
  public void EditMethod(){
     ...
  }

The above would in turn inject code inside the method that would be like

public void EditMethod(){
  if(! ContextUtils.GetPriviledgeContext().HasPriviledge("EditProfile")){
     throw Security("Insufficient priviledge");
  }
  ...
}


Is there a way at compile time (or runtime) to do this with mono (or
MS.NET)?

Thanks

Phil