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 |
---|---|---|
object |
Type | A System. |
#Returns
Type | Description |
---|---|
IObject |
An IObject |
#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:
- XPObjectSpaceProvider creates an Object Space of the XPObjectSpace type.
- EFCoreObjectSpaceProvider<TDbContext> creates an Object Space of the EFCoreObjectSpace 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.
Note
XAF uses the first registered Object Space Provider for the following purposes:
- To get Xaf
Application. and XafObject Space Provider Application. property values.Connection String - To pass this Provider as the Custom
Check ObjectCompatibility Event Args Space argument.Provider - To update an application.
Ensure that Non
Note that in applications with the Application Builder, you need to use the Application Builder’s ObjectXaf
method or Xaf
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 Xaf
method and Xaf
event conflicts with IObject
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);
}
}
#Related GitHub Examples
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.