Filter by title
There is a newer version of this document!

Blazor UI: Settings

Blazor applications can reuse the same ISettingProvider service that is explained in the settings document.

ISettingProvider

ISettingProvider is used to get the value of a setting or get the values of all the settings.

Example usages in a simple service

public class MyService : ITransientDependency
{
    private readonly ISettingProvider _settingProvider;

    //Inject ISettingProvider in the constructor
    public MyService(ISettingProvider settingProvider)
    {
        _settingProvider = settingProvider;
    }

    public async Task FooAsync()
    {
        //Get a value as string.
        string setting1 = await _settingProvider.GetOrNullAsync("MySettingName");

        //Get a bool value and fallback to the default value (false) if not set.
        bool setting2 = await _settingProvider.GetAsync<bool>("MyBoolSettingName");

        //Get a bool value and fallback to the provided default value (true) if not set.
        bool setting3 = await _settingProvider.GetAsync<bool>(
            "MyBoolSettingName", defaultValue: true);
        
        //Get a bool value with the IsTrueAsync shortcut extension method
        bool setting4 = await _settingProvider.IsTrueAsync("MyBoolSettingName");
        
        //Get an int value or the default value (0) if not set
        int setting5 = (await _settingProvider.GetAsync<int>("MyIntegerSettingName"));

        //Get an int value or null if not provided
        int? setting6 = (await _settingProvider
                         .GetOrNullAsync("MyIntegerSettingName"))?.To<int>();
    }
}

Example usage in a Razor Component

@page "/"
@using Volo.Abp.Settings
@inject ISettingProvider SettingProvider
@code {
    protected override async Task OnInitializedAsync()
    {
        bool settingValue = await SettingProvider.GetAsync<bool>("MyBoolSettingName");
    }
}

See Also

Contributors


Last updated: November 18, 2020 Edit this page on GitHub

Was this page helpful?

Please make a selection.

To help us improve, please share your reason for the negative feedback in the field below.

Please enter a note.

Thank you for your valuable feedback!

Please note that although we cannot respond to feedback, our team will use your comments to improve the experience.

ABP Community Talks
Beyond WordPress: A Developer-Friendly CMS for .NET
28 Aug, 17:00
Online
Watch the Event
ABP Live Webinar
Webinar Calendar Webinar Calendar
Discover
ABP Platform
Register Now
Oct 01
Wednesday,
17:00 UTC
Boost Your Development
ABP Live Training
Packages
See Trainings
Mastering ABP Framework Book
The Official Guide
Mastering
ABP Framework
Learn More
Mastering ABP Framework Book