Config State Service

ConfigStateService is a singleton service, i.e. provided in root level of your application, and keeps the application configuration response in the internal store.

Before Use

In order to use the ConfigStateService you must inject it in your class as a dependency.

import { ConfigStateService } from '@abp/ng.core';

@Component({
  /* class metadata here */
})
class DemoComponent {
  constructor(private config: ConfigStateService) {}
}

You do not have to provide the ConfigStateService at module or component/directive level, because it is already provided in root.

Get Methods

ConfigStateService has numerous get methods which allow you to get a specific configuration or all configurations.

Get methods with "$" at the end of the method name (e.g. getAll$) return an RxJs stream. The streams are triggered when set or patched the state.

How to Get All Configurations

You can use the getAll or getAll$ method of ConfigStateService to get all of the applcation configuration response object. It is used as follows:

// this.config is instance of ConfigStateService

const config = this.config.getAll();

// or
this.config.getAll$().subscribe(config => {
   // use config here
})

How to Get a Specific Configuration

You can use the getOne or getOne$ method of ConfigStateService to get a specific configuration property. For that, the property name should be passed to the method as parameter.

// this.config is instance of ConfigStateService

const currentUser = this.config.getOne("currentUser");

// or
this.config.getOne$("currentUser").subscribe(currentUser => {
   // use currentUser here
})

On occasion, you will probably want to be more specific than getting just the current user. For example, here is how you can get the tenantId:

const tenantId = this.config.getDeep("currentUser.tenantId");

// or
this.config.getDeep$("currentUser.tenantId").subscribe(tenantId => {
   // use tenantId here
})

or by giving an array of keys as parameter:

const tenantId = this.config.getDeep(["currentUser", "tenantId"]);

FYI, getDeep is able to do everything getOne does. Just keep in mind that getOne is slightly faster.

How to Get a Feature

You can use the getFeature or getFeature$ method of ConfigStateService to get a feature value. For that, the feature name should be passed to the method as parameter.

// this.config is instance of ConfigStateService

const enableLdapLogin = this.config.getFeature("Account.EnableLdapLogin");

// or
this.config.getFeature$("Account.EnableLdapLogin").subscribe(enableLdapLogin => {
   // use enableLdapLogin here
})

For more information, see the features document.

How to Get a Setting

You can use the getSetting or getSetting$ method of ConfigStateService to get a setting. For that, the setting name should be passed to the method as parameter.

// this.config is instance of ConfigStateService

const twoFactorBehaviour = this.config.getSetting("Abp.Identity.TwoFactor.Behaviour");

// or
this.config.getSetting$("Abp.Identity.TwoFactor.Behaviour").subscribe(twoFactorBehaviour => {
   // use twoFactorBehaviour here
})

For more information, see the settings document.

State Properties

Please refer to ApplicationConfigurationDto type for all the properties you can get with getOne and getDeep. It can be found in the models.ts file.

Refresh App State

The RefreshAppState function is a method in the ConfigStateService service class that sends a request to a server to retrieve data and updates the internal state on the ConfigStateService. This function is responsible for refreshing the state of the service to reflect the latest configuration settings.

import { ConfigStateService} from '@abp/ng.core';

constructor( private configStateService: ConfigStateService) {
  this.configStateService.refreshAppState()
}

See Also

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.

In this document
Community Talks

Building Modular Monolith Applications Using .NET and ABP Framework

17 Oct, 17:00
Online
Register Now
Mastering ABP Framework Book
Mastering ABP Framework

This book will help you gain a complete understanding of the framework and modern web application development techniques.

Learn More