Current filter:
                                You should refresh the page.
                                  • 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.

                                    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(); } }
                                    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.

                                    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)); } }
                                    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:

                                    protected override void CreateDefaultObjectSpaceProvider(CreateCustomObjectSpaceProviderEventArgs args) { // ... args.ObjectSpaceProviders.Add(new CustomXPObjectSpaceProvider(args.ConnectionString, args.Connection)); }
                                    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

                                0 Solutions

                                Creation Date Importance Sort by