Skip to main content
.NET Framework 4.6.2+

XafApplication.CreateObjectSpace(Type) Method

Creates an Object Space that supports a specific object type. Use this method overload if your application registers several ObjectSpaceProviders.

Namespace: DevExpress.ExpressApp

Assembly: DevExpress.ExpressApp.v24.2.dll

NuGet Package: DevExpress.ExpressApp

Declaration

public IObjectSpace CreateObjectSpace(
    Type objectType
)

Parameters

Name Type Description
objectType Type

A System.Type object that is the type of objects that will be supported by a created Object Space.

Returns

Type Description
IObjectSpace

An IObjectSpace object representing the created Object Space.

Remarks

Use the CreateObjectSpace method to create an Object Space in your application. You may require a new Object Space if, for example, you need to create a View.

The CreateObjectSpace(System.Type) method initially calls the XafApplication.CheckCompatibility method to check whether the versions of the application and its modules coincide with the corresponding versions in the database. Then, a new Object Space is created if the versions coincide. For instance, when a developer modifies the database while end-users are using this database, an exception is raised when an end-user tries to invoke a View. This exception will report that the database version is greater than the application’s version. You can override this behavior by handling the XafApplication.CustomCheckCompatibility event.

To create an Object Space, the XafApplication.ObjectSpaceProvider‘s IObjectSpaceProvider.CreateObjectSpace method is used. The type of the Object Space that will be created by this method depends on the type of the Object Space Provider:

To create the required Object Space Provider for your application, override the CreateDefaultObjectSpaceProvider method in your WinApplication and WebApplication descendants. By default, it is overridden to create an XPObjectSpaceProvider (see the XafApplication.ObjectSpaceProvider property description). Alternatively, you can handle the XafApplication.CreateCustomObjectSpaceProvider event.

Note

XAF uses the first registered Object Space Provider for the following purposes:

Ensure that NonPersistentObjectSpaceProvider is not the first registered Provider in your application.

Note that in applications with the Application Builder, you need to use the Application Builder’s ObjectSpaceProviders property to register Object Space Providers instead of the XafApplication.CreateDefaultObjectSpaceProvider method or XafApplication.CreateCustomObjectSpaceProvider event to register Object Space Providers. Refer to the following help topic for more information on how to do this: Integrate Application Builders into Existing Applications.

We strongly recommend this because the use of the XafApplication.CreateDefaultObjectSpaceProvider method and XafApplication.CreateCustomObjectSpaceProvider event conflicts with IObjectSpaceFactory and IObjectSpaceProviderFactory service usage.

This technique also improves performance of your application because the application instance is not created in this case.

When several Object Space Providers are passed to the XafApplication.ObjectSpaceProviders property, pass the objectType parameter to the CreateObjectSpace method to create an Object Space that supports a particular object type.

You can access the created Object Space by handling the XafApplication.ObjectSpaceCreated event.

To create a nested Object Space, use the XPObjectSpace.CreateNestedObjectSpace method.

The following example creates a List View and displays it via a PopupWindowShowAction.

using System;
using DevExpress.ExpressApp;
using DevExpress.ExpressApp.Actions;
using DevExpress.Persistent.Base;
using DevExpress.Persistent.BaseImpl;
// ...
public class ShowListViewController : WindowController {
    public ShowListViewController() {
        PopupWindowShowAction showListViewAction = new PopupWindowShowAction(this, "ShowListView",
            PredefinedCategory.Edit);
        showListViewAction.CustomizePopupWindowParams += ShowListViewAction_CustomizePopupWindowParams;
    }
    private void ShowListViewAction_CustomizePopupWindowParams(object sender, CustomizePopupWindowParamsEventArgs e) {
        Type objectType = typeof(Person);
        IObjectSpace newObjectSpace = Application.CreateObjectSpace(objectType);
        e.View = Application.CreateListView(newObjectSpace, objectType, true);
    }
}

The following code snippets (auto-collected from DevExpress Examples) contain references to the CreateObjectSpace(Type) method.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

See Also