Skip to content

Add a setting

A setting is one Register call. The admin UI (for App-scoped settings) or the profile (for User-scoped) renders the control automatically.

Register it

csharp
SettingDefinitions.Register("Projects.AutoArchiveDays", typeof(int),
    scopes: [SettingScope.App], defaultValue: 90, category: "Projects");
  • scopes decides where it lives — App renders at /admin/settings, User on the profile, Tenant per tenant.
  • category groups it in the UI.
  • The type drives the control (bool → switch, int → number, a choice → dropdown).

To self-register from a slice, implement ISettingsContributor so there's no central list to edit.

Read it

Anywhere in a handler or service:

csharp
var days = await _settings.GetAsync<int>("Projects.AutoArchiveDays");

Resolution follows the User → Tenant → App cascade and is cached with tagged invalidation, so reads are cheap and changes take effect immediately.

Write it

csharp
await _settings.SetAsync("Projects.AutoArchiveDays", 30, SettingScope.App);

Dynamic options

For a choice setting whose options come from data (e.g. the list of roles), provide an ISettingOptionsProvider and the settings UI resolves the dropdown without hard-coding.

See Settings for the model.

NetForge Community is MIT-licensed. Pro is a commercial edition.