Extendind/hooking system dll's

  • Thread starter Thread starter yairinbal
  • Start date Start date
Y

yairinbal

Hello,

I am looking for a way to extend system classes (specifically I'm
talking about data provider connection classes such as
System.Data.SqlConnection, System.Data.OracleConnection).

What I need is to add custom pre-processing before call to some of teh
methods. I would like to minimize the code changes of the application
that uses these classes.

The problem is that these system classes are defnied as sealed so I
cannot simply extend them.

Do you have any idea how can I extended these classes and more
generally how can I hook system classes?

Regards,
Yair
 
* (e-mail address removed) wrote, On 22-7-2007 16:08:
Hello,

I am looking for a way to extend system classes (specifically I'm
talking about data provider connection classes such as
System.Data.SqlConnection, System.Data.OracleConnection).

What I need is to add custom pre-processing before call to some of teh
methods. I would like to minimize the code changes of the application
that uses these classes.

The problem is that these system classes are defnied as sealed so I
cannot simply extend them.

Do you have any idea how can I extended these classes and more
generally how can I hook system classes?

Regards,
Yair

You could 'wrap' them. Implement IDBConnection, put a SqlConnection in
your class as private field and forward every call & property. This
also gives you a nice processing point.

Jesse
 
* (e-mail address removed) wrote, On 22-7-2007 16:08:











You could 'wrap' them. Implement IDBConnection, put a SqlConnection in
your class as private field and forward every call & property. This
also gives you a nice processing point.

Jesse- Hide quoted text -

- Show quoted text -

Hi,
I thought about that idea but I found the following drawbacks:

1. The database specific classes (e.g. SqlConnection,
OracleConnecitoon) may have database specific methods and wrapping
IDBConnection may cause loss of functionallity
2. My applicaiton currently work with SqlConneciton/OracleConection
classes. Since the new class is not superclass of these classes, I
cannot move it as arguments to methods that expect it. I could
implement casting and returning the private field but doing so will
bypass my wrapping.

What I am acutally need as a way to "bypass" the sealed...

Do you have any ideas?

Yair
 
Yair,

Quite simply, if the class is sealed, then you can't do anything. The
best thing you could do in the case of the provider classes is implement the
interface classes that all data providers use (IDbCommand, IDbConnection)
and code your app to use those. Then, you can basically host instances of
the sealed database classes inside of your interface implementations, and
perform the calls as you wish).

I am curious, what kind of interception do you need to perform?
 
Yair,

Quite simply, if the class is sealed, then you can't do anything. The
best thing you could do in the case of the provider classes is implement the
interface classes that all data providers use (IDbCommand, IDbConnection)
and code your app to use those. Then, you can basically host instances of
the sealed database classes inside of your interface implementations, and
perform the calls as you wish).

I am curious, what kind of interception do you need to perform?

--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)




I am looking for a way to extend system classes (specifically I'm
talking about data provider connection classes such as
System.Data.SqlConnection, System.Data.OracleConnection).
What I need is to add custom pre-processing before call to some of teh
methods. I would like to minimize the code changes of the application
that uses these classes.
The problem is that these system classes are defnied as sealed so I
cannot simply extend them.
Do you have any idea how can I extended these classes and more
generally how can I hook system classes?
Regards,
Yair- Hide quoted text -

- Show quoted text -

Hi,

I guess that the solution you suggested will require mass code change.
For example - if currently my connection object is defined as
OracleConnection, I'll now have to change it to MyConnection.

I needed to add transparent logging capabiliies to the Open() of
DbConnection method. I wanted it to work with the need to change all
may apps.

Yair
 
Yair,

Instead of changing everything, why not just have a function that needs
to be called in order to open a connection which will do the logging? Then
change all the calls to open to use your method? This would require much
less code change IMO.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Yair,

Quite simply, if the class is sealed, then you can't do anything.
The
best thing you could do in the case of the provider classes is implement
the
interface classes that all data providers use (IDbCommand, IDbConnection)
and code your app to use those. Then, you can basically host instances
of
the sealed database classes inside of your interface implementations, and
perform the calls as you wish).

I am curious, what kind of interception do you need to perform?

--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)




I am looking for a way to extend system classes (specifically I'm
talking about data provider connection classes such as
System.Data.SqlConnection, System.Data.OracleConnection).
What I need is to add custom pre-processing before call to some of teh
methods. I would like to minimize the code changes of the application
that uses these classes.
The problem is that these system classes are defnied as sealed so I
cannot simply extend them.
Do you have any idea how can I extended these classes and more
generally how can I hook system classes?
Regards,
Yair- Hide quoted text -

- Show quoted text -

Hi,

I guess that the solution you suggested will require mass code change.
For example - if currently my connection object is defined as
OracleConnection, I'll now have to change it to MyConnection.

I needed to add transparent logging capabiliies to the Open() of
DbConnection method. I wanted it to work with the need to change all
may apps.

Yair
 
Yair,

Instead of changing everything, why not just have a function that needs
to be called in order to open a connection which will do the logging? Then
change all the calls to open to use your method? This would require much
less code change IMO.

--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)




Yair,
Quite simply, if the class is sealed, then you can't do anything.
The
best thing you could do in the case of the provider classes is implement
the
interface classes that all data providers use (IDbCommand, IDbConnection)
and code your app to use those. Then, you can basically host instances
of
the sealed database classes inside of your interface implementations, and
perform the calls as you wish).
I am curious, what kind of interception do you need to perform?
--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Hello,
I am looking for a way to extend system classes (specifically I'm
talking about data provider connection classes such as
System.Data.SqlConnection, System.Data.OracleConnection).
What I need is to add custom pre-processing before call to some of teh
methods. I would like to minimize the code changes of the application
that uses these classes.
The problem is that these system classes are defnied as sealed so I
cannot simply extend them.
Do you have any idea how can I extended these classes and more
generally how can I hook system classes?
Regards,
Yair- Hide quoted text -
- Show quoted text -

I guess that the solution you suggested will require mass code change.
For example - if currently my connection object is defined as
OracleConnection, I'll now have to change it to MyConnection.
I needed to add transparent logging capabiliies to the Open() of
DbConnection method. I wanted it to work with the need to change all
may apps.
Yair- Hide quoted text -

- Show quoted text -

Hi,

What I wanted to do is to take existing applications and without the
need to modify and re-compile them to override the Open(). Optimally,
if I have a conneciton string in Web.Config that points to a data
provider - if I coould only modify the XML to a new wrapper provider
it would be the best.

Yair
 
I can understand that, but considering you have coded against the
concrete classes instead of the interface/abstract base classes in the
System.Data namespace (and sub-namespaces), that's impossible. You are
going to have to modify your code.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Yair,

Instead of changing everything, why not just have a function that
needs
to be called in order to open a connection which will do the logging?
Then
change all the calls to open to use your method? This would require much
less code change IMO.

--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)




On Jul 23, 4:49 am, "Nicholas Paldino [.NET/C# MVP]"
Yair,
Quite simply, if the class is sealed, then you can't do anything.
The
best thing you could do in the case of the provider classes is
implement
the
interface classes that all data providers use (IDbCommand,
IDbConnection)
and code your app to use those. Then, you can basically host
instances
of
the sealed database classes inside of your interface implementations,
and
perform the calls as you wish).
I am curious, what kind of interception do you need to perform?
I am looking for a way to extend system classes (specifically I'm
talking about data provider connection classes such as
System.Data.SqlConnection, System.Data.OracleConnection).
What I need is to add custom pre-processing before call to some of
teh
methods. I would like to minimize the code changes of the
application
that uses these classes.
The problem is that these system classes are defnied as sealed so I
cannot simply extend them.
Do you have any idea how can I extended these classes and more
generally how can I hook system classes?
Regards,
Yair- Hide quoted text -
- Show quoted text -

I guess that the solution you suggested will require mass code change.
For example - if currently my connection object is defined as
OracleConnection, I'll now have to change it to MyConnection.
I needed to add transparent logging capabiliies to the Open() of
DbConnection method. I wanted it to work with the need to change all
may apps.
Yair- Hide quoted text -

- Show quoted text -

Hi,

What I wanted to do is to take existing applications and without the
need to modify and re-compile them to override the Open(). Optimally,
if I have a conneciton string in Web.Config that points to a data
provider - if I coould only modify the XML to a new wrapper provider
it would be the best.

Yair
 

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

Back
Top