Back to Devexpress

XafApplication.CreateObjectSpace(Type) Method

expressappframework-devexpress-dot-expressapp-dot-xafapplication-dot-createobjectspace-x28-system-dot-type-x29.md

latest12.1 KB
Original Source

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

NuGet Package : DevExpress.ExpressApp

Declaration

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

Parameters

NameTypeDescription
objectTypeType

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

|

Returns

TypeDescription
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:

Space ProviderObject Space
XPObjectSpaceProviderXPObjectSpace
EFCoreObjectSpaceProvider<TDbContext>EFCoreObjectSpace
SecuredObjectSpaceProviderSecuredXPObjectSpace
SecuredEFCoreObjectSpaceProvider<TDbContext>SecuredEFCoreObjectSpace
NonPersistentObjectSpaceProviderNonPersistentObjectSpace

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.

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.

csharp
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.

XAF_how-to-show-filter-dialog-before-listview/CS/EFCore/DialogBeforeListViewEF/DialogBeforeListViewEF.Blazor.Server/Controllers/BlazorShowFilterDialogController.cs#L29

csharp
protected void ShowFilterDialog(ListView listView) {
    NonPersistentObjectSpace nonPersistentObjectSpace = (NonPersistentObjectSpace)Application.CreateObjectSpace(typeof(ViewFilterContainer));
    IObjectSpace persistentObjectSpace = Application.CreateObjectSpace(typeof(ViewFilterObject));

XAF-search-objects-using-complex-criterion/CS/XPO/ComplexSearch/ComplexSearch.Module/Controllers/MyShowSearchController.cs#L14

csharp
private void MyAction1_CustomizePopupWindowParams(object sender, CustomizePopupWindowParamsEventArgs e) {
    var nonPersistentOS = Application.CreateObjectSpace(typeof(MySearchClass));
    var persistentOS = Application.CreateObjectSpace(typeof(Contact));

xaf-save-and-share-custom-view-settings/CS/EFCore/ViewSettingsEF/ViewSettingsEF.Module/Controllers/ViewVariantsController.cs#L68

csharp
CriteriaOperator criteria = CriteriaOperator.Parse("([ViewId] = ?) And ([IsShared] Or [OwnerId] is null Or [OwnerId] = ?)", View.Id, SecuritySystem.CurrentUserId.ToString());
IObjectSpace objectSpace = Application.CreateObjectSpace(typeof(SettingsStore));
var tst = objectSpace.GetObjects<SettingsStore>(criteria);

xaf-how-to-show-persistent-objects-in-a-non-persistent-objects-view/CS/EFCore/ComplexDialogEF/ComplexDialogEF.Module/Controllers/MyController.cs#L21

csharp
void action_CustomizePopupWindowParams(object sender, CustomizePopupWindowParamsEventArgs e) {
    IObjectSpace os = Application.CreateObjectSpace(typeof(OrderTemplate));
    e.Context = TemplateContext.PopupWindow;

xaf-custom-logon-parameters/CS/XPO/WinForms/CustomLogonXPOWin/CustomLogonXPOWin.Win/WinApplication.cs#L28

csharp
var application = (XafApplication)sender;
e.ObjectSpace = application.CreateObjectSpace(typeof(CustomLogonParameters));
CompositeObjectSpace nonPersistentObjectSpace = e.ObjectSpace as CompositeObjectSpace;

XAF_generate-a-sequential-number-for-a-persistent-object-within-a-database-transaction/VB/Demo.Module/Controllers/TestListViewController.vb#L27

vb
For j As Integer = 0 To 49
    Using os As IObjectSpace = Application.CreateObjectSpace(GetType(Demo.Module.BusinessObjects.Contact))
        Try

XAF-CRUD-for-Non-Persistent-Objects-Stored-Remotely/VB/NonPersistentObjectsDemo.Module/NonPersistentObjectSpaceHelper.vb#L46

vb
If Not npos.AdditionalObjectSpaces.Any(Function(os) os.IsKnownType(type)) Then
    Dim persistentObjectSpace As IObjectSpace = application.CreateObjectSpace(type)
    npos.AdditionalObjectSpaces.Add(persistentObjectSpace)

XAF_Non-Persistent-Objects-Reloading-Demo/VB/NonPersistentObjectsDemo.Module/Module.vb#L47

vb
If Not npos.AdditionalObjectSpaces.Any(Function(os) os.IsKnownType(GetType(BaseObject))) Then
    Dim persistentObjectSpace As IObjectSpace = Application.CreateObjectSpace(GetType(BaseObject))
    npos.AdditionalObjectSpaces.Add(persistentObjectSpace)

See Also

XafApplication Class

XafApplication Members

DevExpress.ExpressApp Namespace