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.v19.2.dll


public IObjectSpace CreateObjectSpace(
    Type objectType
Public Function CreateObjectSpace(
    objectType As Type
) As IObjectSpace


Name Type Description
objectType Type

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


Type Description

An IObjectSpace object representing the created Object Space.


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. XPObjectSpaceProvider creates an Object Space of the XPObjectSpace type. EFObjectSpaceProvider creates an Object Space of the EFObjectSpace type. 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.


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

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

When several Object Space Providers are passed to the XafApplication.ObjectSpaceProviders property (see How to: Use Both Entity Framework and XPO in a Single Application), 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",
        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);
See Also