Back to Devexpress

XafApplication.ObjectSpaceCreated Event

expressappframework-devexpress-dot-expressapp-dot-xafapplication-b61afcaa.md

latest8.1 KB
Original Source

XafApplication.ObjectSpaceCreated Event

Occurs after an Object Space has been created via the XafApplication.CreateObjectSpace method.

Namespace : DevExpress.ExpressApp

Assembly : DevExpress.ExpressApp.v25.2.dll

NuGet Package : DevExpress.ExpressApp

Declaration

csharp
public event EventHandler<ObjectSpaceCreatedEventArgs> ObjectSpaceCreated
vb
Public Event ObjectSpaceCreated As EventHandler(Of ObjectSpaceCreatedEventArgs)

Event Data

The ObjectSpaceCreated event's data class is ObjectSpaceCreatedEventArgs. The following properties provide information specific to this event:

PropertyDescription
ObjectSpaceGets the Object Space.

Remarks

Note

This is a legacy event. In new applications, we recommend that you use the ObjectSpaceProviderEvents.OnObjectSpaceCreated event for most use case scenarios. Refer to the Usage Considerations section for details.

If you need to access the Object Space created for a particular View, handle the ObjectSpaceCreated event and use its ObjectSpaceCreatedEventArgs.ObjectSpace parameter.

Note that nested Object Spaces are created by the XPObjectSpace.CreateNestedObjectSpace method. So, the ObjectSpaceCreated event is not raised when a nested Object Space is created.

Usage Considerations

The XafApplication.ObjectSpaceCreated event fires only for Object Spaces that are created by an XAF Application and within the XAF Application context (for example, in an XAF Controller).

Keep in mind that XafApplication does not host the Object Space creation logic and instead uses the IObjectSpaceFactory service to create Object Spaces. Other services can also directly use IObjectSpaceFactory to create Object Spaces without communicating with XafApplication. In such cases, the ObjectSpaceProviderEvents.OnObjectSpaceCreated event fires when an Object Space is created, but the XafApplication.ObjectSpaceCreated event does not.

Adhere to the following recommendations to choose the correct event to use:

  • If you need to implement global logic that must be triggered by the creation of any IObjectSpace within the application, use ObjectSpaceProviderEvents.OnObjectSpaceCreated.
  • If logic that you want to implement operates on XAF Application elements (XAF Controllers, View UI elements, and so on), you may prefer to use XafApplication.ObjectSpaceCreated for convenience.

The following code snippets (auto-collected from DevExpress Examples) contain references to the ObjectSpaceCreated event.

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-CRUD-for-Non-Persistent-Objects-Stored-Remotely/CS/NonPersistentObjectsDemo.Module/NonPersistentObjectSpaceHelper.cs#L20

csharp
this.AdapterCreators = new List<Action<NonPersistentObjectSpace>>();
application.ObjectSpaceCreated += Application_ObjectSpaceCreated;
NonPersistentObjectSpace.UseKeyComparisonToDetermineIdentity = true;

XAF_Non-Persistent-Objects-Filtering-Demo/CS/EFCore/NonPersistentFilteringEF.Module/Module.cs#L34

csharp
private void Application_SetupComplete(object sender, EventArgs e) {
    Application.ObjectSpaceCreated += Application_ObjectSpaceCreated;
}

XAF_Non-Persistent-Objects-Reloading-Demo/CS/EFCore/NonPersReloadEF/NonPersReloadEF.Module/Module.cs#L35

csharp
private void Application_SetupComplete(object sender, EventArgs e) {
    Application.ObjectSpaceCreated += Application_ObjectSpaceCreated;
    NonPersistentObjectSpace.UseKeyComparisonToDetermineIdentity = true;

XAF_Non-Persistent-Objects-Edit-Linked-Persistent-Objects-Demo/CS/EFCore/NonPersistentEditEF/NonPersistentEditEF.Module/Module.cs#L35

csharp
private void Application_SetupComplete(object sender, EventArgs e) {
    Application.ObjectSpaceCreated += Application_ObjectSpaceCreated;
    NonPersistentObjectSpace.UseKeyComparisonToDetermineIdentity = true;

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

csharp
base.Setup(application);
application.ObjectSpaceCreated += Application_ObjectSpaceCreated;
// Manage various aspects of the application UI and behavior at the module level.

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

vb
Me.AdapterCreators = New List(Of Action(Of NonPersistentObjectSpace))()
AddHandler application.ObjectSpaceCreated, AddressOf Application_ObjectSpaceCreated
NonPersistentObjectSpace.UseKeyComparisonToDetermineIdentity = True

XAF_how-to-connect-different-data-models-to-several-databases-within-a-single-application/VB/CommonModule/CommonModule.vb#L36

vb
TryCast(application.Security, SecurityStrategy)?.RegisterXPOAdapterProviders(New SecurityPermissionsProviderDefault(application))
   AddHandler application.ObjectSpaceCreated , AddressOf Application_ObjectSpaceCreated
End Sub

See Also

XafApplication Class

XafApplication Members

DevExpress.ExpressApp Namespace