Skip to main content
A newer version of this page is available. .
All docs
V21.2

Access XafApplication, ObjectSpace, and Security System in Custom Endpoint Methods

  • 2 minutes to read

The IXafApplicationProvider interface provides access to XafApplication, the Object Space, and the Security System. Inject the IXafApplicationProvider interface into an Endpoint Controller to use IXafApplicationProvider members.

using DevExpress.ExpressApp;
using DevExpress.ExpressApp.Blazor.Services;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.OData.Routing.Controllers;

namespace MySolution.WebApi {
    [Route("api/[controller]")]
    [ApiController]
    [Authorize]
    public class CustomEndpointController : ControllerBase {
        IXafApplicationProvider applicationProvider;
        public CustomEndpointController(IXafApplicationProvider applicationProvider) {
            this.applicationProvider = applicationProvider;
        }
    }
}

Access XafApplication and ObjectSpace

Call the IXafApplicationProvider.GetApplication method to obtain XafApplication. To get the Object Space, use the XafApplication.CreateObjectSpace method. The code below creates an ObjectSpace instance for the Contact business object.

using DevExpress.ExpressApp;
using DevExpress.ExpressApp.Blazor.Services;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.OData.Routing.Controllers;
using MySolution.Module.BusinessObjects;

namespace MySolution.WebApi {
    [Route("api/[controller]")]
    [ApiController]
    [Authorize]
    public class CustomEndpointController : ControllerBase {
        IXafApplicationProvider applicationProvider;
        public CustomEndpointController(IXafApplicationProvider applicationProvider) {
            this.applicationProvider = applicationProvider;
        }
        [HttpGet]
        public IActionResult Get() {
            XafApplication application = applicationProvider.GetApplication();
            Type objectType = typeof(Contact);
            IObjectSpace newObjectSpace = application.CreateObjectSpace(objectType);
            // ...
            return Ok();
        }
        //...
    }
}

Access Security System

Use the XafApplication.Security property to access the Security System. The following code obtains the Security.UserId property:

using DevExpress.ExpressApp;
using DevExpress.ExpressApp.Blazor.Services;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.OData.Routing.Controllers;
using MySolution.Module.BusinessObjects;

namespace MySolution.WebApi {
    [Route("api/[controller]")]
    [ApiController]
    [Authorize]
    public class CustomEndpointController : ControllerBase {
        IXafApplicationProvider applicationProvider;
        public CustomEndpointController(IXafApplicationProvider applicationProvider) {
            this.applicationProvider = applicationProvider;
        }
        [HttpGet]
        public IActionResult Get() {
            XafApplication application = applicationProvider.GetApplication();
            var userId = application.Security.UserId; 
            // ...
            return Ok();
        }
        //...
    }
}
See Also