Reuse Implemented Functionality
- 2 minutes to read
This topic describes how to add additional modules and business objects from an external library to extend the application’s functionality.
XAF Extra Modules
Follow the steps below to add the Validation module and set up validation rules for business objects.
In the Solution Explorer, right-click the SimpleProjectManager.Module.Blazor project and select Manage NuGet Packages. In the invoked NuGet Package Manager, choose the DevExpress 21.2 Local package source and install the DevExpress.ExpressApp.Validation and DevExpress.ExpressApp.Validation.Blazor NuGet packages.
Open the SimpleProjectManager.Module.Blazor\Module.cs file and add the following code to the Module constructor:
using DevExpress.ExpressApp.Validation; // ... namespace SimpleProjectManager.Module.Blazor { public sealed partial class SimpleProjectManagerBlazorModule : ModuleBase { public SimpleProjectManagerBlazorModule() { // ... RequiredModuleTypes.Add(typeof(ValidationModule)); } } }
Open the SimpleProjectManager.Module\BusinessObjects\Planning.cs file and apply the RuleCriteriaAttribute to the ProjectTask class:
using DevExpress.Persistent.Validation; // ... [RuleCriteria("EndDate >= StartDate", CustomMessageTemplate = "Start Date must be less than End Date")] public class ProjectTask : BaseObject { // ... }
Run the ASP.NET Core Blazor application and create several project tasks. The added module validates project tasks according to the specified settings.
Data Models from External Libraries
You can add a business class to your application from the Business Class Library. XAF generates UI elements according to this class’ structure. The following steps show how to add the Person class from the Business Class Library and create the Employee navigation item to display Person objects in a list.
Open the SimpleProjectManager.Module\Module.cs file and add the following code to the Module constructor:
using DevExpress.Persistent.BaseImpl; // ... namespace SimpleProjectManager.Module { public sealed partial class SimpleProjectManagerModule : ModuleBase { public SimpleProjectManagerModule() { // ... AdditionalExportedTypes.Add(typeof(Person)); } } }
Invoke the Model Editor for the SimpleProjectManager.Module project and navigate to the NavigationItems | Items | Planning | Items node. Create a new navigation item and set its Caption property to “Employee” and View to “Person_ListView”. Refer to the Add an Item to the Navigation Control topic for more information on how to add a navigation item.
Run the application. The navigation control shows the new item in the Planning section.
Note
You can also use third-party modules or create your own reusable modules for use in multiple XAF applications.