|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Question about Assembly.CreateInstance()I want a plugin interface for my application. I have my main app named App.exe I have a plugin interface assembly named PluginInterface.dll (defines IPluginInterface) I have a plugin implementation named PluginTest.dll (defines TestClass) In my application I simply do the following: Assembly myAssembly = Assembly.LoadFile( "PluginTest.dll" ); IPluginInterface plugin = (IPluginInterface)myAssembly.CreateInstance( "TestClass" ); plugin.Test() (one of the methods specified in the plugin interface). I compile the code and I get the following: MyApp.exe PluginInterface.dll PluginTest.dll If I delete PluginInterface, My code won't run. Is there a way to specify an interface w/o having to actually deploy a dll that just has an interface specification in it? Thanks, Brad On Feb 8, 7:30 pm, Brad Figler <bradfig***@gmail.com> wrote:
Show quote > Here is my setup: I believe that you can specify IPluginInterface within the MyApp.exe> > I want a plugin interface for my application. > > I have my main app named App.exe > I have a plugin interface assembly named PluginInterface.dll (defines > IPluginInterface) > I have a plugin implementation named PluginTest.dll (defines TestClass) > > In my application I simply do the following: > > Assembly myAssembly = Assembly.LoadFile( "PluginTest.dll" ); > IPluginInterface plugin = (IPluginInterface)myAssembly.CreateInstance( > "TestClass" ); > > plugin.Test() (one of the methods specified in the plugin interface). > > I compile the code and I get the following: > > MyApp.exe > PluginInterface.dll > PluginTest.dll > > If I delete PluginInterface, My code won't run. Is there a way to > specify an interface w/o having to actually deploy a dll that just has > an interface specification in it? > > Thanks, > > Brad project. Then, when you create your PluginTest.dll, you just have to reference the MyApp project. The only time you would need the shared middle dll is if you define a second interface that MyApp implements so your plugin has some idea about the application using it. Mike Mike wrote:
Show quote > On Feb 8, 7:30 pm, Brad Figler <bradfig***@gmail.com> wrote: Yeah, that is the "other" solution that I found during my time on google.>> Here is my setup: >> >> I want a plugin interface for my application. >> >> I have my main app named App.exe >> I have a plugin interface assembly named PluginInterface.dll (defines >> IPluginInterface) >> I have a plugin implementation named PluginTest.dll (defines TestClass) >> >> In my application I simply do the following: >> >> Assembly myAssembly = Assembly.LoadFile( "PluginTest.dll" ); >> IPluginInterface plugin = (IPluginInterface)myAssembly.CreateInstance( >> "TestClass" ); >> >> plugin.Test() (one of the methods specified in the plugin interface). >> >> I compile the code and I get the following: >> >> MyApp.exe >> PluginInterface.dll >> PluginTest.dll >> >> If I delete PluginInterface, My code won't run. Is there a way to >> specify an interface w/o having to actually deploy a dll that just has >> an interface specification in it? >> >> Thanks, >> >> Brad > > I believe that you can specify IPluginInterface within the MyApp.exe > project. Then, when you create your PluginTest.dll, you just have to > reference the MyApp project. The only time you would need the shared > middle dll is if you define a second interface that MyApp implements > so your plugin has some idea about the application using it. > > Mike > I don't necessarily want to do that because I have a bit of a funky setup (from a development point of view). The actual code that will use the plugin is a windows service. The service entry point simply launches thread(s) that actually do the work (and respond to the service manager requests). Well, the myApp.exe in the above example is actually a test harness that includes all of the code accept the entry point in to the service. This allows me to "run" my services in normal program space while developing/debugging. If I was to do that, I would have to put my plugin interface in my service.exe and I don't want to do that because I want my test harness to run independently of the service (and vice versa). Long story short, I will just deal with the additional DLL. Thanks for the response. Brad |
|||||||||||||||||||||||