I am looking for the simplest solution to allow our .Net EXE to call a DLL provided by a 3rd party. Here's the rub - that DLL calls into objects in our code.
One of the nice things in .Net is that an EXE can be used as an assembly in other project, like it's a DLL. My original idea was for them to import our EXE into their project and then call functions within.
I mocked that up and it works great, but the customer doesn't want it to work that way, they want to run our app and have it call their code, ideally provided in a DLL.
Now this would be trivial to do if their code didn't call ours, but in my attempts to make a project mocking this up I always run into circular reference issues. I know I can avoid all that with runtime support, but perhaps I am missing a simpler solution?
Extract the components that your customers need to interact with into their own assembly. This might even be just a single interface (let's call it
IPlugin
for the sake of conciseness, although I don't know whether your customers really write plugins).Now your customers implement this interface with a class in their DLL and copy that to your application's dir (in the easiest case).
Your application, might do the following on startup.
Assembly
class).Register
-method when neededwhen registering, the plugins could subscribe to events on your application, or your app could call their execute-method when needed.
This might require some additional work or even rework, but it's easily maintainable and simple. Depending on what you want to do, you can pass other classes/interfaces to the plugins when calling the methods on the interface. Imagine a class
Application
for instance, which implements an interfaceIApplication
, which is defined in the interface-dll. Now the plugins can call methods in your application, store a reference to it and do whatever you allow them to do in your interface definition.I hope this is better to understand than my first comment :-)
Cheers