Skip to main content
All docs
V25.1
  • .NET 8.0+

    DevExpress v25.1 Update — Your Feedback Matters

    Our What's New in v25.1 webpage includes product-specific surveys. Your response to our survey questions will help us measure product satisfaction for features released in this major update and help us refine our plans for our next major release.

    Take the survey Not interested

    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.v25.1.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

    Use one of the following techniques to fill this collection.

    1. Handle the OnObjectSpaceCreated event in the Application Builder code in the application’s Startup.cs file.
    2. In the event handler, call the PopulateAdditionalObjectSpaces(IObjectSpaceProviderService, IObjectSpaceCustomizerService) method to populate the AdditionalObjectSpaces collection with all necessary Object Spaces.

    File: MySolution.Blazor.Server/Startup.cs, MySolution.Win/Startup.cs, MySolution.WebApi/Startup.cs

    using DevExpress.ExpressApp;
    //...
    builder.ObjectSpaceProviders.Events.OnObjectSpaceCreated = context => {
        CompositeObjectSpace compositeObjectSpace = context.ObjectSpace as CompositeObjectSpace;
        if (compositeObjectSpace != null) {
            if (!(compositeObjectSpace.Owner is CompositeObjectSpace)) {
                var objectSpaceProviderService = context.ServiceProvider.GetRequiredService<IObjectSpaceProviderService>();
                var objectSpaceCustomizerService = context.ServiceProvider.GetRequiredService<IObjectSpaceCustomizerService>();
                compositeObjectSpace.PopulateAdditionalObjectSpaces(objectSpaceProviderService, objectSpaceCustomizerService);
            }
        }
    }
    

    #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 OnObjectSpaceCreated event in the Application Builder code in the application’s Startup.cs file.
    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.

    File: MySolution.Blazor.Server/Startup.cs, MySolution.Win/Startup.cs, MySolution.WebApi/Startup.cs

    using DevExpress.ExpressApp;
    // ...
    builder.ObjectSpaceProviders.Events.OnObjectSpaceCreated = context => {
        var nonPersistentObjectSpace = context.ObjectSpace as NonPersistentObjectSpace;
        if (nonPersistentObjectSpace != null) {
            if (!nonPersistentObjectSpace.IsKnownType(typeof(Person), true)) {
                IObjectSpace additionalObjectSpace = context.ServiceProvider.GetRequiredService<IObjectSpaceFactory>()
                    .CreateObjectSpace<Person>();
                // Customize the additionally created Object Space.
                nonPersistentObjectSpace.AdditionalObjectSpaces.Add(additionalObjectSpace);
                nonPersistentObjectSpace.Disposed += (s2, e2) => {
                    additionalObjectSpace.Dispose();
                };
            }
        }
    };
    // ...
    
    See Also