Wood-MSDN

I am going to create a dll proxy which can call multiple dll modules at the same time. Those dll modules have common interfaces defined, i.e. they all have interface foo1(), foo2(), etc for proxy to call.

In long term, additional dll modules can be created by other partners.

The question is how my proxy can know new dll modules are available to call Is there a plug-in concept so those dll modules can be plugged in to proxy Or should I ask end-user to load those dll modules everytime and submit the dll address to the proxy in run-time

What is the best way to do it

Your advice is appreciated.



Re: Visual C# Language Is there a way to plug-in or register dll modules so dll proxy can know their presence during run-time?

Ken_L

Do some reading on creating DLL Wrappers.

With a wrapper you can specify whether or not the dll is local, copied AND more importanly what version of the dll to use...

You just add the wrapper to the GAC and sign the assembly

This is advanced stuff!!!!






Re: Visual C# Language Is there a way to plug-in or register dll modules so dll proxy can know their presence during run-time?

Wood-MSDN

Today I have foo1 and foo2 dll modules for my dll proxy, tomorrow I will have foo3 dll modules for my dll proxy. Whenever I call the dll proxy from main, should I just let the dll proxy know the name of foo3 and it's available in GAC so my dll proxy can refer to it This is what I can think of, is there other or better way

Any pointers are apprciated.

Thanks.





Re: Visual C# Language Is there a way to plug-in or register dll modules so dll proxy can know their presence during run-time?

ericrtodd

How will your modules be deployed If the modules are deployed in the same directory as your controller, you can load each assembly in the directory, iterate through the exported types, and instantiate/call any classes that implement your plugin interface. If you are deploying to the GAC, then you would iterate through the assemblies in the AppDomain, then the above.





Re: Visual C# Language Is there a way to plug-in or register dll modules so dll proxy can know their presence during run-time?

Wood-MSDN

The deployment will be in the directory instead of putting them to GAC.

Is there any sample I can refer to

Thanks.





Re: Visual C# Language Is there a way to plug-in or register dll modules so dll proxy can know their presence during run-time?

ericrtodd

Looking for classes implementing IFooBar (which has one method: Initialize):

Code Block

DirectoryInfo directory;

directory = new FileInfo(new Uri(Assembly.GetExecutingAssembly().GetName().Codebase).LocalPath).Directory;

foreach(FileInfo file in directory.GetFiles()) {

Assembly assembly;

try {

assembly = Assembly.LoadFrom(file.FullName);

foreach(Type type in assembly.GetTypes()) {

if(typeof(IFooBar).IsAssignableFrom(type) && !type.IsAbstract) {

IFooBar fooBar = (IFooBar)Activator.CreateInstance(type);

fooBar.Initialize();

}

}

} catch {

continue;

}

}





Re: Visual C# Language Is there a way to plug-in or register dll modules so dll proxy can know their presence during run-time?

Peter Ritchie

ericrtodd wrote:

Looking for classes implementing IFooBar (which has one method: Initialize):

Code Block

DirectoryInfo directory;

directory = new FileInfo(new Uri(Assembly.GetExecutingAssembly().GetName().Codebase).LocalPath).Directory;

foreach(FileInfo file in directory.GetFiles()) {

Assembly assembly;

try {

assembly = Assembly.LoadFrom(file.FullName);

foreach(Type type in assembly.GetTypes()) {

if(typeof(IFooBar).IsAssignableFrom(type) && !type.IsAbstract) {

IFooBar fooBar = (IFooBar)Activator.CreateInstance(type);

fooBar.Initialize();

}

}

} catch {

continue;

}

}

That's pretty much the recommended approach. You can get a bit more complex and put your "add-ins" in a directory other than the current directory; but you'll have to deal with all that configuration information in your app.config.

Do you want to be able to support unloading these DLLs Or will the proxy simply act as if they have a reference to the DLL






Re: Visual C# Language Is there a way to plug-in or register dll modules so dll proxy can know their presence during run-time?

Wood-MSDN

Do you want to be able to support unloading these DLLs

Yes.

Perhaps this should be another question/thread -- what if the dll modules are COM i.e. probably need Interop, and different implementation

e.g. one directory contains only .Net dlls, another directory contains COM dlls, to make it distinghishable.

Thanks.





Re: Visual C# Language Is there a way to plug-in or register dll modules so dll proxy can know their presence during run-time?

ericrtodd

I believe that what you want will require the dynamic creation/destruction of AppDomains (you cannot unload a type from an Assembly, but you can unload an AppDomain that has an Assembly loaded).





Re: Visual C# Language Is there a way to plug-in or register dll modules so dll proxy can know their presence during run-time?

Peter Ritchie

Complete decoupling of assemblies is also required. This means you can never reference a type in the "add-in" assembly if you want to unload it (or it's AppDomain). This requires that you declare an interface (in a third assembly) that is used by the host that loads the add-in assemblies and the add-in assemblies must implement that interface in order for the host to communicate with the add-in assembly without pulling it into the main AppDomain. Without doing that you can't unload add-in assembly and there's not much point in creating a separate AppDomain (other than for security/sandboxing reasons; but you've made no mention of that).