How to Use Correctly Object Space and Extensions to Access the Settings Values

This section provides additional guidance on how to use Application Settings in custom code. A common tasks associated with the Settings is to get the value and then modify it somehow. In general, it is important to understand that the system Object Space is not intended to be used as context for Settings storing.

For instance, the following statement will stop the functioning of the App Settings Service:

  • example

SettingsAccessor.Instance.ObjectSpace.Refresh()

Interactions with the Settings values require the same approach as for ordinary manipulations with persistent objects, i.e. the local Object Space is needed.

The code snippets below demonstrates how to get values for the ObjectSpace and UnitOfWork cases:

ObjectSpace

  • example

using (var objectSpace = Application.CreateObjectSpace())
  {
     var createEmpty = ((IModelEAMSettings)os.AppSettings().Root()).ExportImportSettings.CreateEmptyObject.Value;
  }

UnitOfWork

  • example

{
     var createEmpty = ((IModelEAMSettings)uow.Xafari().AppSettings().Root()).ExportImportSettings.CreateEmptyObject.Value;
  }

The extension methods can significantly improve the calling. The code snippet below implements these methods:

  • example

public static IModelEAMSettings EAMSettings(this IObjectSpace os)
  {
     return ((IModelEAMSettings)os.AppSettings().Root());
  }

  public static IModelEAMSettings EAMSettings(this UnitOfWork uow)
  {
     return ((IModelEAMSettings)uow.Xafari().AppSettings().Root());
  }

Now, you can get values in the following manner:

ObjectSpace

  • example

using (var objectSpace = application.CreateObjectSpace())
  {
     var createEmpty = objectSpace.EAMSettings().ExportImportSettings.CreateEmptyObject.Value;
  }

UnitOfWork:

  • example

using (UnitOfWork uow = XpoSessionDefault.CreateUnitOfWork())
  {
     var createEmpty = uow.EAMSettings().ExportImportSettings.CreateEmptyObject.Value;
  }

The modification of the Settings values is also similar to XPO techniques, i.e. you should call ObjectSpace.CommitChanges (or uow.CommitChanges()).