Settings

Overview

Every application that has settings in Fanray will have a class that implements the ISettings interface. For example, here is the CoreSettings class in Fan.

public class CoreSettings : ISettings
{
    /// <summary>
    /// Title of the blog. Default "Fanray".
    /// </summary>
    public string Title { get; set; } = "Fanray";

    /// <summary>
    /// Short description on what the blog is about. Default "A fanray blog".
    /// </summary>
    public string Tagline { get; set; } = "A fanray blog";

    /// <summary>
    /// Default theme "Clarity".
    /// </summary>
    public string Theme { get; set; } = "Clarity";

    /// <summary>
    /// Gets or sets the timezone id for the site. Default "UTC".
    /// </summary>
    public string TimeZoneId { get; set; } = "UTC";

    ...
}

The Meta Table

The Core_Meta table stores all settings for applications, plugins, widgets and themes. The table is pretty much a key value pair, the application settings are flattened out to have the settings class and property as keys.

Core_Meta table

Settings Service

Settings are retrieved and saved through ISettingService. Because settings are so essential to the system, they are cached upon retrival.

namespace Fan.Settings
{
    /// <summary>
    /// The settings service contract.
    /// </summary>
    public interface ISettingService
    {
        /// <summary>
        /// Returns a type of <see cref="ISettings"/>.
        /// </summary>
        /// <typeparam name="T">The derived <see cref="ISettings"/> type.</typeparam>
        /// <returns></returns>
        Task<T> GetSettingsAsync<T>() where T : class, ISettings, new();
        /// <summary>
        /// Creates or updates a Settings, if a particular setting exists then updates it, else inserts it.
        /// </summary>
        /// <typeparam name="T">The derived <see cref="ISettings"/> type.</typeparam>
        /// <param name="settings"></param>
        /// <returns></returns>
        Task<T> UpsertSettingsAsync<T>(T settings) where T : class, ISettings, new();
    }
}

Data
Storage