My application loads all library assemblies located in its executing path and executes preknown methods against contained classes.
I now need to do the same with an assembly that references my application assembly. Is this possible and are there any negative implications that I should be aware of?
Master Assembly:
public abstract class TaskBase
{
public abstract void DoWork();
}
LoadAssemblyFromFile("Assembly0001.dll");
Assembly0001.Task1.DoWork();
Child Assemblies:
public sealed class Task1: MasterAssembly.TaskBase
{
public override void DoWork { /* whatever */ }
}
Yes, this is possible. As long as your master assembly doesn't reference the child assemblies, you should be fine. Otherwise, you'll have a circular dependency.
The master assembly will simply load the child assemblies and know nothing about them except that they implement an interface. That way, the master assembly doesn't need to reference the child assemblies.
No gotchas as far as I'm aware. We use this technique successfully for certain scenarios.
In my experience there is nothing wrong with this. In fact, MEF uses this technique in the form of AssemblyCatalog
(where your implementations are IN the master assembly) and DirectoryCatalog
(where the implementations of an interface are in assemblies in a specific directory).
Both can be used together in an AggregateCatalog
with no problems.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With