468,251 Members | 1,478 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,251 developers. It's quick & easy.

Performance when dynamically loading assembly to do plugins in Web Services

Hi,

I'm currently writing a Web Services that interacts with a database.
To allow me to use not just one database provider (for example, I
could use MS Access, SQL Server or MySQL), the Web Service dynamically
loads up an assembly that implements an Interface I called IDatabase.

To load the assembly and create an object, I wrote this function:

private IDatabase LoadDatabasePlugin( string assemblyFile, string
objectType )
{
IDatabase dbLogic = null;
Assembly assembly;
Type type;

try
{
// Try loading the specified assembly.
assembly = Assembly.LoadFrom(assemblyFile);
if (assembly != null)
{
// Get the object type we want.
type = assembly.GetType( objectType );
if( type != null )
{
// Create an instance of the object.
dbLogic = (IDatabase)Activator.CreateInstance(type);
}
}
}
catch
{
return null;
}
return dbLogic;
}

where "assemblyFile" is the assembly file ("d:\dbmsaccess.dll") and
"objectType" is the class I want to create
("MyProject.Database.Logic").

This works fine, when I change the DLL file name, the new assembly
code get loaded and I can which from MSAccess to MSSQLserver without
problem and without recompiling my Web Service.

My concerns is this: what performance problems can I have as I get
thousands of simultanious users accessing my Web Service? Does
calling Assembly.LoadFrom() actually loads the file on each call? Or
does .Net checks if it's not already loaded? I'm trying to find a way
to do a check before calling LoadFrom() in case the DLL is already
loaded.

Please, tell me if this whole approach of dynamically loading the
assembly is OK, and how I can improve it so that I don't get slowdowns
as more users query the Web Service.

Thanks for your time,

Benjamin
Nov 16 '05 #1
1 4711
Benjamin,

You shouldn't have to do this. The assembly can only be loaded once,
and the Assembly will not be loaded a second time. The assembly will be
loaded until the app-domain exits.

The code you have should be fine.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Benjamin" <be************@hotmail.com> wrote in message
news:3f**************************@posting.google.c om...
Hi,

I'm currently writing a Web Services that interacts with a database.
To allow me to use not just one database provider (for example, I
could use MS Access, SQL Server or MySQL), the Web Service dynamically
loads up an assembly that implements an Interface I called IDatabase.

To load the assembly and create an object, I wrote this function:

private IDatabase LoadDatabasePlugin( string assemblyFile, string
objectType )
{
IDatabase dbLogic = null;
Assembly assembly;
Type type;

try
{
// Try loading the specified assembly.
assembly = Assembly.LoadFrom(assemblyFile);
if (assembly != null)
{
// Get the object type we want.
type = assembly.GetType( objectType );
if( type != null )
{
// Create an instance of the object.
dbLogic = (IDatabase)Activator.CreateInstance(type);
}
}
}
catch
{
return null;
}
return dbLogic;
}

where "assemblyFile" is the assembly file ("d:\dbmsaccess.dll") and
"objectType" is the class I want to create
("MyProject.Database.Logic").

This works fine, when I change the DLL file name, the new assembly
code get loaded and I can which from MSAccess to MSSQLserver without
problem and without recompiling my Web Service.

My concerns is this: what performance problems can I have as I get
thousands of simultanious users accessing my Web Service? Does
calling Assembly.LoadFrom() actually loads the file on each call? Or
does .Net checks if it's not already loaded? I'm trying to find a way
to do a check before calling LoadFrom() in case the DLL is already
loaded.

Please, tell me if this whole approach of dynamically loading the
assembly is OK, and how I can improve it so that I don't get slowdowns
as more users query the Web Service.

Thanks for your time,

Benjamin

Nov 16 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Christoph Haas | last post: by
1 post views Thread by M.H.Paravresh | last post: by
13 posts views Thread by bjarne | last post: by
6 posts views Thread by Pete Davis | last post: by
3 posts views Thread by Michael Gaillez | last post: by
2 posts views Thread by brian.gabriel | last post: by
reply views Thread by NPC403 | last post: by
reply views Thread by kermitthefrogpy | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.