Skip to main content
A newer version of this page is available. .
All docs
V20.2
.NET Framework 4.5.2+

CompositeObjectSpace.AdditionalObjectSpaces Property

Gets the list of Object Spaces used to handle objects that do not belong to the current Object Space. We recommend that you call the PopulateAdditionalObjectSpaces(XafApplication) method to populate this collection automatically.

Namespace: DevExpress.ExpressApp

Assembly: DevExpress.ExpressApp.v20.2.dll

NuGet Package: DevExpress.ExpressApp

Declaration

public IList<IObjectSpace> AdditionalObjectSpaces { get; }

Property Value

Type Description
IList<IObjectSpace>

An IList<T> collection of Object Spaces used to handle objects that do not belong to the current Object Space.

Exceptions

Type Description
InvalidOperationException

Cannot add the Object Space to the CompositeObjectSpace.AdditionalObjectSpaces collection because another Object Space for the same object types already exists.

Remarks

You can use one of the following ways to fill this collection.

  1. Handle the XafApplication.ObjectSpaceCreated event in a module or Controller.
  2. In the event handler, call the PopulateAdditionalObjectSpaces(XafApplication) method to populate the AdditionalObjectSpaces collection with all necessary Object Spaces.

The following example demonstrates how to do this in a platform-agnostic module (MySolution.Module/Module.cs(vb)):

using DevExpress.ExpressApp;
//...
public class MySolutionModule : ModuleBase {
    //...
    public override void Setup(XafApplication application) {
        base.Setup(application);
        application.ObjectSpaceCreated += Application_ObjectSpaceCreated;
    }
    private void Application_ObjectSpaceCreated(object sender, ObjectSpaceCreatedEventArgs e) {
        CompositeObjectSpace compositeObjectSpace = e.ObjectSpace as CompositeObjectSpace;
        if (compositeObjectSpace != null) {
            if (!(compositeObjectSpace.Owner is CompositeObjectSpace)) {
                compositeObjectSpace.PopulateAdditionalObjectSpaces((XafApplication)sender);
            }
        }
    }
}

Manually: Create Object Spaces and Add Them to the Collection

If you need to create an additional Object Space manually, follow the steps below:

  1. Handle the XafApplication.ObjectSpaceCreated event in a module or Controller.
  2. In the event handler, access NonPersistentObjectSpace and use its IsKnownType(Type, Boolean) method to ensure that the AdditionalObjectSpaces collection does not already include a compatible Object Space.

The following example demonstrates how to do this in a platform-agnostic module (MySolution.Module/Module.cs(vb)):

using DevExpress.ExpressApp;
//...
public class MySolutionModule : ModuleBase {
    //...
    public override void Setup(XafApplication application) {
        base.Setup(application);
        application.ObjectSpaceCreated += Application_ObjectSpaceCreated;
    }
    private void Application_ObjectSpaceCreated(object s, ObjectSpaceCreatedEventArgs e) {
        var nonPersistentObjectSpace = e.ObjectSpace as NonPersistentObjectSpace;
        if (nonPersistentObjectSpace != null) {
            if (!nonPersistentObjectSpace.IsKnownType(typeof(Person), true)) {
                IObjectSpace additionalObjectSpace = Application.CreateObjectSpace(typeof(Person));
                // customize the created additional Object Space
                nonPersistentObjectSpace.AdditionalObjectSpaces.Add(additionalObjectSpace);
                nonPersistentObjectSpace.Disposed += (s2, e2) => {
                    additionalObjectSpace.Dispose();
                };
            }
        }
    }
}
See Also