lundi 17 février 2020

C# get unreferenced assemblies

The problem

I'm working on a project with a plugin like system. The project structure is defined as follows:

- Solution
    - Project A (Cli)
    - Project B (Core logic)
    - Project C (Plugin)

Project A is the startup project, Project B contains the core logic and Project C is a plugin, which implements an interface in project B. Project A only has a reference to Project B and Project C only has a reference to Project B.

To visualize:
visualization

Since I do not reference Project C from Project B (and do not instantiate the class directly), code like AppDomain.CurrentDomain.GetAssemblies() (inside Project B) does not return Project C.

However, once I do (from Project B): var MyImplementation = new MyImplementation(), AppDomain.CurrentDomain.GetAssemblies() does return the assembly, since it's known and loaded at runtime as I instantiated the class MyImplementation explicitly from code.

The question

From Project B, I want to get all assemblies which implement a specific interface from Project B and instantiate them.

So, how do I get these (seemingly) unknown assemblies to get loaded at runtime?





Aucun commentaire:

Enregistrer un commentaire