1

I have a windows service. The idea is to execute as many different tasks as possible. Lets say we have this IServicePart interface with Start() and Stop() methods. When the service starts it will search all assemblies in some directory and find all classes which implements IServicePart. Done, no problem.

The problem:

Assembly1.dll is a good candidate for IServicePart. But it needs a configuration. For example Assembly1.dll.config. Now I can copy/paste/rename the dll to task2.dll and task2.dll.config and create a second task for the service. Each of those plugins comes with 10-20 dll dependencies

1) The most obvious problem is how to load the configuration, because the service host's appDomain is different than assembly1 and task2.

2) I expect issues when I try to load the two IServiceParts when they depend on the same 3rd party assemblies

Solution 1 is to make a custom configuration and not use the app.config.

Solution 2 is to run each plugin in its own appDomain.

What are your suggestions.

Hope I explained this correctly

===================

reference: similar question here: Plugin to use its own app.config

Community
  • 1
  • 1
mynkow
  • 4,408
  • 4
  • 38
  • 65

1 Answers1

1

The way I've done this, involves having each plugin in its own app domain. However, the codebase property of those appdomains continue to point to the root directory where my service exe is located. This achieves two things:

  1. The many tertiary dependencies that the plugins have now don't need to be duplicated. For example, I can put my logger assembly in the root folder (with the service exe) and all the plugins can see it. This is great, because I neither wish to put my logger assembly into each plugin subdirectory, nor do I wish to use the GAC.

  2. All plugins now share the same app config (the same one used by the service exe). This is a good or bad thing, depending on your needs. But don't forget the configSource attribute, which can allow you to put specific config sections into seperate config files within your plugin subdirectories.

    Incidentally, I've been using MAF for my plugins.

Community
  • 1
  • 1
Brent Arias
  • 29,277
  • 40
  • 133
  • 234
  • nice. Can you share a sample how you run the plugins in new domain? Is MAF earlier version of MEF? – mynkow Jul 01 '11 at 23:30
  • Hey Brent. If you have time can you look at this: http://social.msdn.microsoft.com/Forums/en/csharpgeneral/thread/15760b47-1740-4129-9851-79fd506f903a Regards! – mynkow Jul 02 '11 at 16:12
  • @mynkow: I'm not sure what that issue is, but I know one of the most mysterious problems you might encounter with MAF is it's "pseudo strong-naming" behavior. MAF acts like each plugin is strong named. If the version of the AssemblyVersion of the plugin changes, and you don't reset the MAF plugin map, it will quietly not load the plugin (the version does not match what it was expecting). Just be aware of this, and you won't have any issues. – Brent Arias Jul 02 '11 at 19:30
  • What security do you apply when loading addins – mynkow Jul 02 '11 at 20:15