Application Settings. Typical Scenarios

Table of content:

  • Scenario 1. No Slices (root Slice only)
  • Scenario 2. One Slice
  • Scenario 3. Two Slices
  • Scenario 4. More than two Slices

Scenario 1. No Slices (root Slice only)

This scenario means that there will be only one root Slice. The root Slice is the Current Slice for any user, and all users have equal permissions to edit values in this Slice.

If the application does not use the security system with user authentication, the No Slices Scenario will be defined automatically. Also, this scenario can be specified via the Slices Designer in the static constructor of the module class:

  • c#
  • VB

static Module1()
{
  //...
  SettingsAccessor.CreateServiceInstance = xafApplication => new SettingsAccessorDesigner().CreateSettingsAccessor();
}

Shared Sub New()
  '...
  SettingsAccessor.CreateServiceInstance = Function(ByVal xafApplication) New SettingsAccessorDesigner().CreateSettingsAccessor()
End Sub

Scenario 2. One Slice

The scenario with a one Values Slice – this is the most common scenario. Most often Slice Basis Type is the type from Application.Security.UserType. The Current Slice is calculated for the user after authentication.

If the application uses a security system with user authentication, this scenario is automatically defined. Also, this scenario can be specified via the Slices Designer in the static constructor of the module class:

  • c#
  • VB

static Module1()
{
  SettingsAccessor.CreateServiceInstance = xafApplication => new SettingsAccessorDesigner<User>().SetupCurrentSlice(accessor =>
  {
    var currentUser = SecuritySystem.CurrentUser as User;
    if (currentUser != null)
      accessor.ObjectSpace.AppSettings().CurrentSlice(currentUser);
  }).CreateSettingsAccessor();
}

Shared Sub New()
  SettingsAccessor.CreateServiceInstance = Function(ByVal xafApplication)
    New SettingsAccessorDesigner(Of User)().SetupCurrentSlice(Sub(ByVal accessor)
      Dim currentUser = TryCast(SecuritySystem.CurrentUser, User)
      If currentUser IsNot Nothing Then
        accessor.ObjectSpace.AppSettings().CurrentSlice(currentUser)
      End If
    End Sub).CreateSettingsAccessor()
  End Function
End Sub

Scenario 3. Two Slices

The scenario with two Slices is much more rare than the scenario with a one Slice. For example, this scenario occurs if you intend to use Branches. In this case, the first Slice corresponds to the Branch type, and the second Slice corresponds to the type from Application.Security.UserType. The Current Slice is calculated after authentication and specifying the Branch. As a result, one user will access a different Setting Units with eigenvalues in the various Branches. Such a scenario can be specified via the Slices Designer:

  • c#
  • VB

static Module1()
{
  SettingsAccessor.CreateServiceInstance = xafApplication => new SettingsAccessorDesigner<Branch, UserWithBranch>().Slice1().Slice2(getName: slice => slice.SliceObject.UserName, getParentSliceObject: slice => slice.SliceObject.Branch, getSliceObjectsCriteria: slice => CriteriaOperator.Parse("Branch = ?", slice.SliceObject)).SetupCurrentSlice(accessor =>
  {
    var currentUser = SecuritySystem.CurrentUser as UserWithBranch;
    if (currentUser != null)
      accessor.ObjectSpace.AppSettings().CurrentSlice(currentUser.Branch, currentUser);
  }).CreateSettingsAccessor();
}

Shared Sub New()
  SettingsAccessor.CreateServiceInstance = Function(ByVal xafApplication)
    New SettingsAccessorDesigner(Of Branch, UserWithBranch)().Slice1().Slice2(getName := Function(ByVal slice) slice.SliceObject.UserName, getParentSliceObject := Function(ByVal slice) slice.SliceObject.Branch, getSliceObjectsCriteria := Function(ByVal slice) CriteriaOperator.Parse("Branch = ?", slice.SliceObject)).SetupCurrentSlice(Sub(ByVal accessor)
      Dim currentUser = TryCast(SecuritySystem.CurrentUser, UserWithBranch)
      If currentUser IsNot Nothing Then
        accessor.ObjectSpace.AppSettings().CurrentSlice(currentUser.Branch, currentUser)
      End If
    End Sub).CreateSettingsAccessor()
  End Function
End Sub

Scenario 4. More than two Slices

Use case that requires three or more Values Slices are extremely rare, but theoretically possible. For instance, suitable for use Slices structure where Slice Basis Types are Department, UserWithDepartment and State. Slices Designer allow to determine the Slices structure of any depth:

  • c#
  • VB

static Module1()
{
  SettingsAccessor.CreateServiceInstance = xafApplication => new SettingsAccessorDesigner<Department, UserWithDepartment, State>().Slice1().Slice2(getName: slice => slice.SliceObject.UserName, getParentSliceObject: slice => slice.SliceObject.Department, getSliceObjectsCriteria: slice => CriteriaOperator.Parse("Department = ?", slice.SliceObject)).Slice3().SetupCurrentSlice(accessor =>
  {
    var currentUser = SecuritySystem.CurrentUser as UserWithDepartment;
    if (currentUser != null)
      accessor.ObjectSpace.AppSettings().CurrentSlice(currentUser.Department, currentUser);
  }).CreateSettingsAccessor();
}

Shared Sub New()
  SettingsAccessor.CreateServiceInstance = Function(ByVal xafApplication)
    New SettingsAccessorDesigner(Of Department, UserWithDepartment, State)().Slice1().Slice2(getName := Function(ByVal slice) slice.SliceObject.UserName, getParentSliceObject := Function(ByVal slice) slice.SliceObject.Department, getSliceObjectsCriteria := Function(ByVal slice) CriteriaOperator.Parse("Department = ?", slice.SliceObject)).Slice3().SetupCurrentSlice(Sub(ByVal accessor)
      Dim currentUser = TryCast(SecuritySystem.CurrentUser, UserWithDepartment)
      If currentUser IsNot Nothing Then
        accessor.ObjectSpace.AppSettings().CurrentSlice(currentUser.Department, currentUser)
      End If
    End Sub).CreateSettingsAccessor()
  End Function
End Sub

In the code above was used the standard classes for one, two and three Slices. A more general use case requires to apply the First and Next methods and it allows to implement an arbitrary structure:

  • c#
  • VB

static Module1()
{
  SettingsAccessor.CreateServiceInstance = xafApplication => new SettingsAccessorDesigner<Department, UserWithDepartment, State>().First<Department>().Next<UserWithDepartment, Department>(getName: slice => slice.SliceObject.UserName, getParentSliceObject: slice => slice.SliceObject.Department, getSliceObjectsCriteria: slice => CriteriaOperator.Parse("Department = ?", slice.SliceObject)).Next<State, UserWithDepartment>().SetupCurrentSlice(accessor =>
  {
    var currentUser = SecuritySystem.CurrentUser as UserWithDepartment;
    if (currentUser != null)
      accessor.ObjectSpace.AppSettings().CurrentSlice(currentUser.Department, currentUser);
  }).CreateSettingsAccessor();
}

Shared Sub New()
  SettingsAccessor.CreateServiceInstance = Function(ByVal xafApplication)
    New SettingsAccessorDesigner(Of Department, UserWithDepartment, State)().First(Of Department)().[Next](Of UserWithDepartment, Department)(getName := Function(ByVal slice) slice.SliceObject.UserName, getParentSliceObject := Function(ByVal slice) slice.SliceObject.Department, getSliceObjectsCriteria := Function(ByVal slice) CriteriaOperator.Parse("Department = ?", slice.SliceObject)).[Next](Of State, UserWithDepartment)().SetupCurrentSlice(Sub(ByVal accessor)
      Dim currentUser = TryCast(SecuritySystem.CurrentUser, UserWithDepartment)
      If currentUser IsNot Nothing Then
        accessor.ObjectSpace.AppSettings().CurrentSlice(currentUser.Department, currentUser)
      End If
    End Sub).CreateSettingsAccessor()
  End Function
End Sub

Refer to the Slices Designer topic for details.