Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Plugin to use its own app.config

I finally managed to build a working solution of a plugin architecture with help of some guys over here, but now a new problem arises.

My hosting application uses it's app.config file for some defaults for the executing assembly (which is a Windows Service).

Each plugin should be able to load it's own settings from a separate plugin settings file because the host shouldn't be made aware of the plugin settings. In the plugin project I added an app.config file as well (with some settings and a connection string) so that I can instantiate the Properties.Settings class and use it's properties in the plugin code.

The problem is when I change the settings in the app.config of the plugin (which is build as plugin.dll.config) I can't see those changes in the plugin itself, which still uses the design time settings.

Is there a way to load the app.config settings in each plugin so the generated Properties.Settings class will work? If not is there another way to load a app.config based settings file into the plugin? I'm planning on adding a LoadConfiguration method in the IPlugin interface so each plugin will load it's own settings.

like image 941
Erik Beijer Avatar asked May 08 '09 09:05

Erik Beijer


People also ask

Can I use app config in .net core?

Application configuration in ASP.NET Core is performed using one or more configuration providers. Configuration providers read configuration data from key-value pairs using a variety of configuration sources: Settings files, such as appsettings. json.

Is app config and web config are same?

When using Windows Forms or WPF etc, then you have the app. config which also stores ConnectionStrings. So yes they are similar but have different purposes.

Does app config get compiled?

Now you might be wondering what happens behind the scenes. Well, when you compile your application, the compiler actually copies the app. config file to the output folder, but gives it another name: When you start your application (ConsoleApp1.exe in our example), the matching config file will be loaded too.


2 Answers

Would something like ConfigurationManager.OpenMappedExeConfiguration help here? You can create a Configuration object reading in the values from a specific file.

like image 37
Colin Desmond Avatar answered Sep 20 '22 05:09

Colin Desmond


You're working against the architecture of app.config. You get one app.config file per executable (EXE, not DLL). The executable launches, creates its AppDomain, and then loads MyApp.exe.config. You can add app.config objects all you want in Visual Studio, but they are ignored for DLLs. I think what you want to do is manually copy the XML from the dll.config and paste it into the application level app.config. (I'm sure there's a way to automate this using TeamBuild or some such.) The overridden values will then be available to your Properties.Settings class.

like image 151
Mike Post Avatar answered Sep 22 '22 05:09

Mike Post