KB Article T590896
Visible to All Users

How to customize the Object Space behavior in XPO-based XAF applications

This article describes how to create a custom Object Space class and register the custom Object Space Provider for it. The following code examples are available starting with version 17.2.4.

1. Inherit XPObjectSpace and override one or more protected methods you want to customize, e.g., the DoCommit method.

C#
using DevExpress.ExpressApp.Xpo; using DevExpress.ExpressApp.DC; using DevExpress.ExpressApp.DC.Xpo; // ... public class CustomXPObjectSpace : XPObjectSpace { public CustomXPObjectSpace(ITypesInfo typesInfo, XpoTypeInfoSource xpoTypeInfoSource, CreateUnitOfWorkHandler handler) : base(typesInfo, xpoTypeInfoSource, handler) { } protected override void DoCommit() { // Write your custom code here, or override other methods. base.DoCommit(); } }
Visual Basic
Imports DevExpress.ExpressApp.Xpo Imports DevExpress.ExpressApp.DC Imports DevExpress.ExpressApp.DC.Xpo ' ... Public Class CustomXPObjectSpace Inherits XPObjectSpace Public Sub New(ByVal typesInfo As ITypesInfo, ByVal xpoTypeInfoSource As XpoTypeInfoSource, ByVal handler As CreateUnitOfWorkHandler) MyBase.New(typesInfo, xpoTypeInfoSource, handler) End Sub Protected Overrides Sub DoCommit() ' Write your custom code here, or override other methods. MyBase.DoCommit() End Sub End Class

2. Inherit XPObjectSpaceProvider, override the CreateObjectSpaceCore method  and return your CustomXPObjectSpace instance in this method.

C#
using System.Data; using DevExpress.ExpressApp; using DevExpress.ExpressApp.Xpo; // ... public class CustomXPObjectSpaceProvider : XPObjectSpaceProvider { public CustomXPObjectSpaceProvider(IXpoDataStoreProvider dataStoreProvider, bool threadSafe) : base(dataStoreProvider, threadSafe) { } public CustomXPObjectSpaceProvider(string connectionString, IDbConnection connection, bool threadSafe) : base(connectionString, connection, threadSafe) { } protected override IObjectSpace CreateObjectSpaceCore() { return new CustomXPObjectSpace(TypesInfo, XpoTypeInfoSource, () => CreateUnitOfWork(DataLayer)); } }
Visual Basic
Imports System.Data Imports DevExpress.ExpressApp Imports DevExpress.ExpressApp.Xpo ' ... Public Class CustomXPObjectSpaceProvider Inherits XPObjectSpaceProvider Public Sub New(ByVal dataStoreProvider As IXpoDataStoreProvider, ByVal threadSafe As Boolean) MyBase.New(dataStoreProvider, threadSafe) End Sub Public Sub New(ByVal connectionString As String, ByVal connection As IDbConnection, ByVal threadSafe As Boolean) MyBase.New(connectionString, connection, threadSafe) End Sub Protected Overrides Function CreateObjectSpaceCore() As IObjectSpace Return New CustomXPObjectSpace(TypesInfo, XpoTypeInfoSource, Function() CreateUnitOfWork(DataLayer)) End Function End Class

Note: If you use the  Integrated Mode of the Security System or the  Middle Tier Security, inherit*  *SecuredObjectSpaceProvider or  *MiddleTierServerObjectSpaceProvider instead of  *XPObjectSpaceProvider accordingly.

3. In the application project, edit the WinApplication.cs  (WinApplication.vb) or WebApplication.cs (WebApplication.vb) file. In the CreateDefaultObjectSpaceProvider method, add the CustomXPObjectSpaceProvider instance to the ObjectSpaceProviders  list:

C#
protected override void CreateDefaultObjectSpaceProvider(CreateCustomObjectSpaceProviderEventArgs args) { // ... args.ObjectSpaceProviders.Add(new CustomXPObjectSpaceProvider(args.ConnectionString, args.Connection)); }
C#
Protected Overrides Sub CreateDefaultObjectSpaceProvider(ByVal args As CreateCustomObjectSpaceProviderEventArgs) ' ... args.ObjectSpaceProviders.Add(New CustomXPObjectSpaceProvider(args.ConnectionString, args.Connection)) End Sub

See also:
T591324: How to customize the UnitOfWork behavior in XPO-based XAF applications

Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.