ISettings
The ISettings interface is used to populate the settings UI in Veva, where users can configure various aspects of the system. Any module which needs configuration from the user can provide it's own implementation of the ISettings interface and each implementation will render a new tab in the settings UI where the user can fill in information. Each ISettings implementation has a scope, which can be "global", "website" or "user". If the scope is "global", it will be shown in the global settings dialog in Veva. If the scope is "website", it will be shown under the website settings in the website UI in Veva, where each website has it's own set of configuration values. If the scope is "user", then it will be shown under the user profile UI in Veva, where each user has it's own set of configuration values.
Each implementation has to return a name, which is usually just the type name of the class. The RequiresAppRecycle bool determines if the settings require the web application to be restarted after each change. If this is true, Veva will show a notification to the user that changing the settings will not be reflected until after a restart of the web application. Finally there's the scope as mentioned above.
Then you simply need to add public properties to the class, marked with the [EditorBrowsable] attribute. Those properties will be reflected and shown to the user.
Interface declaration
public interface ISettings { string Name { get; } bool RequiresAppRecycle { get; } SettingsScope Scope { get; } }
Example
In this example we are looking at the GoogleMapsSettings class which is a part of the Lisa.Modules.Components.GoogleMaps module. This is where the user needs to specify an API key for the Google maps integration. This settings class has a scope of "Global" which means that it needs to be configured once for each instance of Veva.
[DisplayName("Google Maps Settings")] [HelpLink("https://developers.google.com/maps/documentation/embed/get-started#get_a_key", "How to get a Google Maps API key:", "")] public class GoogleMapsSettings : ISettings { public string Name => "GoogleMaps"; public bool RequiresAppRecycle => false; public SettingsScope Scope => SettingsScope.Global; [EditorBrowsable] [Description("A unique API key for your website domain")] [DisplayName("API key")] public string APIKey { get; set; } }
Registration
This is how the implementation is registered into the DI container in Veva, this should be done in your module config file (The class which implements IModule).
public void ConfigureServices(IServiceCollection services, IConfiguration configuration) { services.AddNamed<ISettings, GoogleMapsSettings>("GoogleMaps"); }
Using the settings in code
Accessing stored settings is easy. Take the following code as an example on how the Google Maps component access the API key from the stored settings.
First, you need to inject the ISettingsService into your component/class. In a class, it's done via the constructor. In a razor component such as the Google Maps component, it's done like this:
@inject ISettingsService _settingsService
Then, you simply need to call the .GetSettings<T>() method on the settings service, where T is the type (ISettings implementation) you want to retrieve. See the example below. Note that since the scope of this settings object we are retrieving is "Global", we pass in NULL for the website Id and user Id. Doing so tells the settings service to return a "global" object, not one for the specified website/user.
private string GetAPIKey() { var googleMapsSettings = _settingsService.GetSettings<GoogleMapsSettings>(null, null); if (googleMapsSettings != null) { return googleMapsSettings.APIKey; } return string.Empty; }