Object instantiation notification, AppDomain, Reflection

G

Guest

I am inquiring about the feasability of being able to determine when an
object of a certain type is instantiated.

I have a base type that I want to be able to determine when each instance is
created in an assembly. Can this be done using Reflection or AppDomain?

I'm trying to detect these instances automatically for some security settings.
Any help would be greatly appreciated.
 
J

John Saunders

Dave L said:
I am inquiring about the feasability of being able to determine when an
object of a certain type is instantiated.

I have a base type that I want to be able to determine when each instance
is
created in an assembly. Can this be done using Reflection or AppDomain?

I'm trying to detect these instances automatically for some security
settings.
Any help would be greatly appreciated.

You could put this checking code in the default constructor of the base
type, couldn't you?

John Saunders
 
G

Guest

The ultimate goal would to put something in the constructor of the base class
so that I could hook into the assembly from an outside security module that
would look for or monitor this "something" in the base class constructor or
just detect when an object of the base class type is created in any assembly.

I don't want to probe the assembly for an object reference to the base class
type, I want the instantiation of the base class to be discovered
automatically in the monitored assembly.
 
J

John Saunders

Dave L said:
The ultimate goal would to put something in the constructor of the base
class
so that I could hook into the assembly from an outside security module
that
would look for or monitor this "something" in the base class constructor
or
just detect when an object of the base class type is created in any
assembly.

I don't want to probe the assembly for an object reference to the base
class
type, I want the instantiation of the base class to be discovered
automatically in the monitored assembly.

Ok, let's break this down a bit.

You have a "security module" that wants to monitor things. You've got a base
class which is the base type for all of the things to be monitored, am I
right?

I presume that you want the "security module" to be able to run in a
separate AppDomain from the instances of the classes derived from the base?
The "security module" should be able to monitor instances from multiple
AppDomains? Possibly even from remote AppDomains?

Have you looked into the System.Management namespace? This sounds a lot like
WMI.

John Saunders
 
J

John Saunders

Dave L said:
The ultimate goal would to put something in the constructor of the base
class
so that I could hook into the assembly from an outside security module
that
would look for or monitor this "something" in the base class constructor
or
just detect when an object of the base class type is created in any
assembly.

I don't want to probe the assembly for an object reference to the base
class
type, I want the instantiation of the base class to be discovered
automatically in the monitored assembly.

P.S. See
http://msdn.microsoft.com/library/e...frameworkapplicationswithsystemmanagement.asp

John Saunders
 
G

Guest

Yes, you have the senario correct. I will have this security module (.dll)
running by the host application (.exe) that needs to monitor other known
modules (.dll's) in the scope of the AppDomain, and look for instantiations
of this particular base type. Then apply some permissions to the base types
interface on whether or not the current user has permission to use this base
type.

I'm not familiar with System.Management and I will read more, thanks for
your help John.
 
J

John Saunders

Dave L said:
Yes, you have the senario correct. I will have this security module
(.dll)
running by the host application (.exe) that needs to monitor other known
modules (.dll's) in the scope of the AppDomain, and look for
instantiations
of this particular base type. Then apply some permissions to the base
types
interface on whether or not the current user has permission to use this
base
type.

I'm not familiar with System.Management and I will read more, thanks for
your help John.

If they're all going to be in the same AppDomain, then they should be able
to communicate with static objects exposed by static properties. You can
even create static events. Your security module could listen for a
NewInstanceConstructing event from the base class, which could pass the
constructor parameters to the event. If you derive the EventArgs from
CancelEventArgs, the security module would be able to set e.Cancel = true to
tell the base class not to permit the instanitation.

It also seems to me that you could do something with remoting, I'm just not
quite sure what.

John Saunders

P.S. Of course, remember that if you're going to use static data, you have
to protected it from multi-threaded access.
 
G

Guest

I can't believe I overlooked static events. This solution worked perfectly
for this application, thanks John.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top