This project has moved and is read-only. For the latest updates, please go here.

Export DLL Constructor called more than once

Dec 14, 2009 at 10:42 PM

I am just getting started on working with MEF and I have a weird problem. First off, I am unsure which "preview" I am using, but here is how I have my stuff setup (I most likely have my design incorrect, I am trying to shoehorn this into an existing application):


I have an application that is a windows service (I am just using it as a console app for now) and it imports DLLs (via MEF) that export the interface I wrote. This windows service is supposed to be as dynamic as possible, it will just load in a DLL and then tell it what port to use. That DLL can then choose  to receive data or send data.  Then I have 2 exported DLLs, 1 that receives data and one that processes the data. The first exported DLL simply receives data on some port and once the data comes in, it will tell a server (running on the machine) that data came in and it needs to update whoever is listening. That is where the second exported DLL comes in. It is listening for the notification from the first DLL and then it will process the data.


So basically, my windows service opens up and loads all the DLLs and sits there running. It basically is just hosting the DLLs to do all the work with the data coming in on the ports. My problem is that when the DLL (second one I described) gets notified that data came in on a port, it  calls the constructor and then processes the data. Which is fine because this is the first time it is being used, but once data comes in again, it recalls the constructor. I guess I am confused as to why it calls the constructor every time it is used. Ideally I want it loaded in once and then always loaded until the windows service is closed down.