Often when creating Telligent Community plugins they require some kind of configuration. Luckily this is easily achieved using the IConfigurablePlugin interface. Similar to other plugins, this requires you to provide a Name and Description property and well as an Initialize method. Additionally you must implement ConfigurationOptions which defines the details of the properties that can be configured, as well as the Update method. We will use the Update method to set the configured properties to a field so we can easily access the configured values from elsewhere in our plugin.
The below is an example of a plugin I created using the configuration from an Azure Insights metrics tracking plugin for Telligent Community. It allows for two configuration values; the Insights Instrumentation Key and a checkbox to set if events are logged.
You can then see how we are retrieving these properties in the Initialize method. There are several helper methods that handle casting the value to the desired type e.g. GetBool().
Another kind of configurable plugin is the IRequiredConfigurationPlugin plugin. It builds on the previous example with the slight difference that the based on the logic you define, the plugin will only be enabled if the required configuration is provided. In the Azure Insights plugin for example, it doesn’t make sense for the plugin to be enabled and run if no Instrumentation Key is provided. Without this, the plugin wouldn’t be able to send the data to the Insights service.
Below is another example where we are instead implementing IRequiredConfigurationPlugin and additionally providing an implementation for IsConfigured. In this example we are only validting that the Instrumentation Key is provided, but you could additionally check other properties too or different combinations based on your desired logic.
Using these two plugins your plugins can easily allow for many different kings of configuration using various data types and you can control the valifation to ensure the required values are set before your plugin is active (regardless if the plugin has been enabled in the admin console). You can see the code for these examples on GitHub: https://github.com/RichMercer/Telligent.Examples/tree/master/Telligent.Examples/Plugins