Application Settings. Access in Code
To access the value of the Setting Unit, use the IObjectSpace context and AppSettings service, which allows to get (set) the values from any Value Slice.
The code snippet below reads the value of the Key1 Setting Unit from the root Slice.
- c#
- VB
public class SomeBusinessLogicProvider
{
//...
public void SomeMethod()
{
//...
var rootSlice = objectSpace.AppSettings().RootSlice; // get root slice
var key1 = rootSlice.RootSettings.Folder1.Key1.Value; // get Key1 value from root slice
}
}
Public Class SomeBusinessLogicProvider
'...
Public Sub SomeMethod()
'...
Dim rootSlice = objectSpace.AppSettings().RootSlice ' get root slice
Dim key1 = rootSlice.RootSettings.Folder1.Key1.Value ' get Key1 value from root slice
End Sub
End Class
The next use case is to get a value from an arbitrary Value Slice. To do this, navigate to the target Slice Object by specifying a combination of all intermediate objects in a GetSlice() method.
The following code snippet demonstrates how to get the value of the Key1 Setting Unit, which corresponds to the obj2 object.
- c#
- VB
public class SomeBusinessLogicProvider
{
//...
public void SomeMethod()
{
//...
var slice = objectSpace.AppSettings().GetSlice(obj1, obj2); // get slice by key object
var key1 = slice.RootSettings.Folder1.Key1.Value; // get Key1 value from slice
}
}
Public Class SomeBusinessLogicProvider
'...
Public Sub SomeMethod()
'...
Dim slice = objectSpace.AppSettings().GetSlice(obj1, obj2) ' get slice by key object
Dim key1 = slice.RootSettings.Folder1.Key1.Value ' get Key1 value from slice
End Sub
End Class
In practical tasks often it is convenient to use the Current Slice. The concept of a Current Slice is to provide automatically a value that is relevant in the current moment. The most common use cases of the Current Slice are the root Slice or Slice Object, which corresponds to the current user (see Slices Design. Typical Scenarios). The developer has the ability to implement Current Slice in accordance with other specific requirements.
An example of obtaining the values from the Current Slice:
- c#
- VB
public class SomeBusinessLogicProvider
{
//...
public void SomeMethod()
{
//...
var currentSlice = objectSpace.AppSettings().CurrentSlice; // get current slice
var key1 = currentSlice.RootSettings.Folder1.Key1.Value; // get Key1 value from current slice
}
}
Public Class SomeBusinessLogicProvider
'...
Public Sub SomeMethod()
'...
Dim currentSlice = objectSpace.AppSettings().CurrentSlice ' get current slice
Dim key1 = currentSlice.RootSettings.Folder1.Key1.Value ' get Key1 value from current slice
End Sub
End Class
There is also an alternative way to get the value from the Current Slice:
- c#
- VB
public class SomeBusinessLogicProvider
{
//...
public void SomeMethod()
{
//...
var key1 = objectSpace.AppSettings().Root().Folder1.Key1.Value; // get Key1 value from current slice
}
}
Public Class SomeBusinessLogicProvider
'...
Public Sub SomeMethod()
'...
Dim key1 = objectSpace.AppSettings().Root().Folder1.Key1.Value ' get Key1 value from current slice
End Sub
End Class