Settings
With Confinity’s settigns app you can define configurations for your modules and apps that can be set by admins through a UI. The configuration data will be persisted to the database and you can obtain it through the options pattern. Since settings are based on ConfinityContent, you can create very flexible forms for your authors.
Register Settings
To define new settings you just create a new class which inherits from SettingsEntry.
public sealed class MyRocketSettings : SettingsEntry
{
public int Height { get; set; }
public EntityRef<Asset>? Image { get; set; }
}
In your module configuration you register your settings with an editor and optionally a description and an icon.
public void AddModule(IModuleContext module)
{
module.Configure.RegisterSettings<MyRocketSettings>("Default Rocket Settings")
.Key("default-rocket-key")
.Editor(form =>
{
form.AddTab(tab =>
{
tab.AddInput(p => p.Height);
tab.AddSelectAsset<MyRocketSettings>(p => p.Image);
});
});
}
Obtain Settings
You can obtain settings through DI by injecting ISettings<T>.
public class FoobarRocket
{
private readonly MyRocketSettings _rocketSettings;
public FoobarRocket(ISettings<MyRocketSettings> settings)
{
_rocketSettings = settings.CurrentValue;
}
public void StartRocket()
{
//do stuff with _rocketSettings
int height = _rocketSettings.Height;
}
}