Skip to main content

Register a Built-in XAF Module

  • 6 minutes to read

XAF includes a number of ready-to-use built-in modules. This topic describes how to register a built-in module in a new or existing XAF application.

Register a Built-in XAF Module in an Existing .NET Application

  1. Install the NuGet package that contains the module.
  2. Navigate to the MyApplication.Blazor.Server\Startup.cs (Blazor) or MyApplication.Win\Startup.cs (WinForms) file and call the module-related Add* method to register the module.

The following code samples register Reports, Dashboards, and Office modules in the application.

public class Startup {
   // ...
   public void ConfigureServices(IServiceCollection services) {
         // ...
         services.AddXaf(Configuration, builder => {
            // ...
            builder.Modules
               .AddReports(/*...*/)
               .AddDashboards(/*...*/)
               .AddOffice(/*...*/)
            // ...
         });
   }
}
Display the list of module NuGet packages and AddModule methods
Module NuGet Packages Module-Related Methods
Audit Trail Module DevExpress.ExpressApp.AuditTrail.EFCore
DevExpress.ExpressApp.AuditTrail.Xpo
AddAuditTrailEFCore
AddAuditTrailXpo
Business Class Library Customization Module DevExpress.ExpressApp.Objects AddBusinessClassLibraryCustomization
Chart Module DevExpress.ExpressApp.Chart.Win AddCharts (WinForms)
Clone Object Module DevExpress.ExpressApp.CloneObject
DevExpress.ExpressApp.CloneObject.Xpo
AddCloning
ConditionalAppearance DevExpress.ExpressApp.ConditionalAppearance AddConditionalAppearance
Dashboards Module DevExpress.ExpressApp.Dashboards.Blazor
DevExpress.ExpressApp.Dashboards.Win
AddDashboards (Blazor)
AddDashboards (WinForms)
File Attachments Module DevExpress.ExpressApp.FileAttachment.Blazor
DevExpress.ExpressApp.FileAttachment.Win
AddFileAttachments (Blazor)
AddFileAttachments (WinForms)
KPI Module DevExpress.ExpressApp.Kpi AddKpi (WinForms)
Multi-Tenancy (Data per Tenant) Module DevExpress.ExpressApp.MultiTenancy.Blazor.EFCore
DevExpress.ExpressApp.MultiTenancy.Blazor.XPO
DevExpress.ExpressApp.MultiTenancy.Win.EFCore
DevExpress.ExpressApp.MultiTenancy.Win.XPO
AddMultiTenancy (EF Core Blazor)
AddMultiTenancy (XPO Blazor)
AddMultiTenancy (EF Core WinForms)
AddMultiTenancy (XPO WinForms)
Notifications Module DevExpress.ExpressApp.Notifications.Blazor
DevExpress.ExpressApp.Notifications.Win
AddNotifications (Blazor)
AddNotifications (WinForms)
Office Module DevExpress.ExpressApp.Office.Blazor
DevExpress.ExpressApp.Office.Win
AddOffice (Blazor)
AddOffice (WinForms)
Pivot Chart Module DevExpress.ExpressApp.PivotChart.Win AddPivotChart (WinForms)
Pivot Grid Module DevExpress.ExpressApp.PivotGrid.Win AddPivotGrid (WinForms)
Reports V2 Module DevExpress.ExpressApp.ReportsV2.Blazor
DevExpress.ExpressApp.ReportsV2.Win
AddReports (Blazor)
AddReports (WinForms)
Scheduler Module DevExpress.ExpressApp.Scheduler.Blazor
DevExpress.ExpressApp.Scheduler.Win
AddScheduler (Blazor)
AddScheduler (WinForms)
Script Recorder Module DevExpress.ExpressApp.ScriptRecorder.Win AddScriptRecorder (WinForms)
State Machine Module DevExpress.ExpressApp.StateMachine AddStateMachine
TreeList Editors Module DevExpress.ExpressApp.TreeListEditors.Win AddTreeListEditors (WinForms)
Validation Module DevExpress.ExpressApp.Validation.Blazor
DevExpress.ExpressApp.Validation.Win
AddValidation (Blazor)
AddValidation (WinForms)
View Variants Module DevExpress.ExpressApp.ViewVariantsModule AddViewVariants

Register a Module in the Module Project

You can use the ModuleBase.RequiredModuleTypes property to specify required dependencies for your module. XAF loads these dependent modules with the current module. Follow the steps below to register additional modules in the Module project:

  1. Install the NuGet package that contains the module to register.
  2. Add additional modules to the RequiredModuleTypes list in the MyApplication.Module\Module.cs file.
public sealed class _MyApplicationModule : ModuleBase {
   //...
   public _MyApplicationModule() {
      InitializeComponent();
      this.RequiredModuleTypes.Add(typeof(DevExpress.ExpressApp.SystemModule.SystemModule));
      this.RequiredModuleTypes.Add(typeof(DevExpress.ExpressApp.ReportsV2.ReportsModuleV2));
      this.RequiredModuleTypes.Add(typeof(DevExpress.ExpressApp.Dashboards.DashboardsModule));
      this.RequiredModuleTypes.Add(typeof(DevExpress.ExpressApp.Office.OfficeModule));
      // ...
   }
}
Display the list of module types and NuGet packages

Add a Built-in XAF Module in a New .NET Application

You can add modules to your application when you use the Template Kit to create a new XAF solution. Select modules in the Additional Modules section.

XAF Template Kit Additional Modules section

.NET Framework

Register the Additional Module in the Module Project

In an existing module project, you can register an extra module that will be loaded with the current module.

  1. Add a reference to the additional module assembly.
  2. In the module project’s constructor (declared in the Module.cs file by default), add the additional module to the ModuleBase.RequiredModuleTypes list.
public sealed class MySolutionModule : ModuleBase {
   //...
   public MySolutionModule() {
      InitializeComponent();
      this.RequiredModuleTypes.Add(typeof(MyCustomModule.CustomModule));
   }
}

Register the Additional Module in the Application Project

In the application project, you can register the additional module as follows.

  1. Add a reference to the additional module assembly.
  2. Add an instance of the additional module to the XafApplication.Modules list. For example, you can add it to the WinApplication/WebApplication descendant constructor.
public MySolutionWinApplication() {
      InitializeComponent();
      this.Modules.Add(new MyCustomModule.CustomModule());
}

Register a Dynamically Loaded Module

You can register additional modules that will be loaded dynamically by their names when required.

To register a dynamically loaded module, pass the additional module’s name to the XafApplication.Setup method. The Setup method has overloads that take the moduleAssemblies parameter - a string array that specifies module assembly names to be loaded.

For instance, you can use this method to load modules listed in the application configuration file. Refer to the Add a Module to the Application Configuration File section to see the example.

Add a Module to the Application Configuration File

This approach allows third-parties to plug-in their own modules without recompiling your application. Please note that third-party modules may contain insecure code that overrides security restrictions, modifies your business logic, etc. That is why adding modules from the configuration file is disabled by default. Enable it in a trusted environment only.

In a WinForms application, edit the Program.cs (Program.vb) file.

static class Program {
   static void Main() {
      //...
      MySolutionWindowsFormsApplication winApplication = new MySolutionWindowsFormsApplication();
      //...
      winApplication.Setup("MySolution", winApplication.ConnectionString, 
         ConfigurationManager.AppSettings["Modules"].Split(';'));
      winApplication.Start();
      //...
   }
   //...
}

In an ASP.NET Web Forms application, edit the Global.asax.cs (Global.asax.vb) file.

public class Global : System.Web.HttpApplication {
   protected void Session_Start(object sender, EventArgs e) {
      WebApplication.SetInstance(Session, new MySolutionWebApplication());
      //...
      WebApplication.Instance.Setup("MySolution", WebApplication.Instance.ConnectionString, 
         ConfigurationManager.AppSettings["Modules"].Split(';'));
      WebApplication.Instance.Start();
   }
   //...
}

You can now add a module assembly name to the modules list in the application configuration file (App.config and/or Web.config).

<configuration>
    <appSettings>
        <add key="Modules" value="MySolution.MyCustomModule" />
    </appSettings>
</configuration>

Here, MySolution.MyCustomModule is a custom module assembly name.

Note

If the module to be added includes the Entity Framework DbContext, register the EFCoreObjectSpace provider for it at the module level. Then, override the ModuleBase.Setup method, and handle the XafApplication.CreateCustomObjectSpaceProvider event.

Use the Module Designer or Application Designer

In an existing XAF solution, start the Application Designer or Module Designer. Drag the required module from the Toolbox to the Designer’s Required Modules / Modules section.

Tutorial_EM_Lesson_5_1

Modules Shipped With XAF are available in the DX.25.1: XAF Modules tab of the Toolbox.

You can register a custom module declared in an external library in the Toolbox; drag a registered module to the Application or Module Designer. For details, refer to the following topic: How to: Add Items to the Toolbox.

See Also