Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using application settings across assemblies

Tags:

c#

.net

plugins

I'm writing an application that includes a plugin system in a different assembly.

The problem is that the plugin system needs to get application settings from the main app (like the directory to look for plugins).

How is this done, or am I going about this the wrong way?

Edit: I was encouraged to add some details about how the plugin system works. I haven't completely worked that out and I've only just begun implementing it, but I basically went by this article.

like image 850
Brian Ortiz Avatar asked Nov 15 '08 22:11

Brian Ortiz


People also ask

Where are application settings stored?

User-scope settings are stored in the user's appdata folder. Application-scope settings are stored in C:\Users\My Name\AppData\Local\My_Company\. If your settings file doesn't contain any Application-scope settings, you won't have a company folder.

Where are .NET application settings stored?

Settings. settings is located in the My Project folder for Visual Basic projects and in the Properties folder for Visual C# projects. The Project Designer then searches for other settings files in the project's root folder. Therefore, you should put your custom settings file there.

What are application configurations?

An application configuration file is an XML file used to control assembly binding. It can redirect an application from using one version of a side-by-side assembly to another version of the same assembly. This is called per-application configuration.

What is the use of app config in C#?

By adding an application configuration file (app. config file) to a C# project, you can customize how the common language runtime locates and loads assembly files. For more information about application configuration files, see How the runtime locates assemblies (. NET Framework).


2 Answers

Let the main application get the plugin directory from the application settings and push it into the plugin system.

like image 152
EricSchaefer Avatar answered Oct 02 '22 22:10

EricSchaefer


Perhaps you could insert the configuration as an argument when creating the plugin?

//Get the configuration for the current appDomain
System.Configuration.Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);

//Create the plugin, and pass in the configuration
IPlugin myPlugin = new AlfaPlugin(config);

You'll probably need a reference to the System.Configuration assembly.

like image 37
Frode Lillerud Avatar answered Oct 02 '22 23:10

Frode Lillerud