XAS. AppModules

Introduction

AppModule is a XAF module whose sole task is to configure the application, specify the required modules, set initial parameters, etc. These modules are in demand both by the target application and by the individual components of the system to perform specialized tasks.

XAS is an auxiliary tool that accompanies the main target business application. In general, it is always necessary to take into account that support of the main application will require extra utilities, applications, services, etc. Here we are talking about solutions to the enterprise class, designed for the tens and hundreds of business users, many branches and corresponding amounts of data. Such side tasks may includes a system administration, data synchronization, remote computing, batch data processing, etc. When designing a modules of such a complex system, it is desirable to define a unified approach that will provide convenience and safety while using together the additional tools and the main application. This topic describes the approach to the formation of a set of application modules based on the foregoing wishes.

Concept

All modules of the application can be divided into 5 groups:

  • Platform agnostic modules;
  • Windows Forms specific modules;
  • ASP.NET specific modules (for Web applications);
  • MVC specific modules;
  • Configuration modules which implements the XAS features for the certain application.

Depending on what platforms are supported, the application can contain up to 5 AppModules:

  1. <app_name>.AppModule is a platform agnostic AppModule;
  2. <app_name>. AppModule.Win is for the Win version of the application.
  3. <app_name>. AppModule.Web is for the Web version of the application;
  4. <app_name>. AppModule.Mvc is for the MVC version of the application;
  5. <app_name>. AppModule.Cfg is intended to support XAS.

The names of AppModules are formed according to the rule below.

  • The first part <app_name> is the name of the application. Ex.: Xafari.BCDemo, Galaktika.EAM.3.2;
  • The second part describes the form of the component (it is always "AppModule");
  • The third part is the platform. If the platform is not specified, the module is platform agnostic. Suffixes “Win”, “Web”, “Mvc” indicate the platform. The "Cfg" module is intended for XAS, it provides some extra logic to configure the system.

Each AppModule is responsible for loading the all modules of its group.

<app_name>.AppModule.Cfg is a module designed special for XAS. It is mandatory that the Cfg-module contains references to all modules which are required in the XAS only, not in the app itself. These modules provide functionality that allows the XAS to configure some component of the system. For example, there is a mechanism of importing data, import functions are available to the user in the main app. And the different settings of this mechanism should be modified via the XAS. The implementation of this concept require to place all logic related to import settings into the Amm.ImportData.Cfg module (for instance). The reference to the module should be added to Amm.AppModule.Cfg. After that, it becomes possible to adjust import functions in the XAS.

Each tool that is a part of a larger system loads only the required AppModules. All needed system modules are specified in the AppModule. Such approach allows creating universal utilities that can operate with different applications. AppModules help the utilities in automatic tuning to interact with a particular application.

The AppModules should set all the initial parameters of the application instance and prepare it for full life cycle. So, any heir of XafApplication, which loads its own AppModules, should become a fully operational system.

An application instance configuration includes:

  • Security System initialisation and customization (as needed);
  • Specifying the value of the XafApplication.ApplicationName property;
  • Specifying the Object Space Provider type;
  • Other customizations.

All code executing the functions from the list above in the application class (WinApplication or WebApplication subclass) should be deleted.

Note

To see the presented concepts in action, examine the BCDemo application installed with Xafari. By default, the source code is installed in %PUBLIC%\Documents\Xafari Framework vXX.X.XXXX Demos\BCDemo\CS.

xas_8

xas_1

Example

The code snippet below demonstrates the platform agnostic AppModule in the BCDemo application.

  • c#
  • VB

public sealed partial class DemoAppModule : ModuleBase
{
  private readonly SecurityStrategyComplex _securityStrategy;
  public DemoAppModule()
  {
  var authentication = new AuthenticationActiveDirectory();
  authentication.CreateUserAutomatically = true;
  authentication.LogonParametersType = null;
  _securityStrategy = new SecurityStrategyComplex(typeof(SecuritySystemUser), typeof(SecuritySystemRole), authentication);
}
public override void Setup(XafApplication application)
{
  base.Setup(application);
  Application.ApplicationName = ConfigurationManager.AppSettings["ApplicationName"];
  Application.Security = _securityStrategy;
  Application.CustomizeLanguagesList += Application_CustomizeLanguagesList;
  Application.CreateCustomObjectSpaceProvider += Application_CreateCustomObjectSpaceProvider;
  Application.DatabaseVersionMismatch += DemoAppWindowsFormsApplication_DatabaseVersionMismatch;
}
private void DemoAppWindowsFormsApplication_DatabaseVersionMismatch(object sender, DatabaseVersionMismatchEventArgs e)
{
  e.Updater.Update();
  e.Handled = true;
}
private void Application_CreateCustomObjectSpaceProvider(object sender, CreateCustomObjectSpaceProviderEventArgs e)
{
  if (e.ObjectSpaceProvider == null)
  {
    var app = (XafApplication)sender;
    var security = (SecurityStrategy)app.Security;
    e.ObjectSpaceProvider = new SecuredObjectSpaceProvider(security, e.ConnectionString, e.Connection);
  }
}
private void Application_CustomizeLanguagesList(object sender, CustomizeLanguagesListEventArgs e)
{
  string userLanguageName = Thread.CurrentThread.CurrentUICulture.Name;
  if (userLanguageName != "en-US" && e.Languages.IndexOf(userLanguageName) == -1)
  {
    e.Languages.Add(userLanguageName);
  }
}
}

Public Partial NotInheritable Class DemoAppModule
  Inherits ModuleBase
  Private ReadOnly __securityStrategy As SecurityStrategyComplex
  Public Sub New()
    Dim authentication = New AuthenticationActiveDirectory()
    authentication.CreateUserAutomatically = True
    authentication.LogonParametersType = Nothing
    __securityStrategy = New SecurityStrategyComplex(GetType(SecuritySystemUser), GetType(SecuritySystemRole), authentication)
  End Sub
  Public Overrides Sub Setup(ByVal application As XafApplication)
    MyBase.Setup(application)
    Application.ApplicationName = ConfigurationManager.AppSettings("ApplicationName")
    Application.Security = __securityStrategy
    Application.CustomizeLanguagesList += Application_CustomizeLanguagesList
    Application.CreateCustomObjectSpaceProvider += Application_CreateCustomObjectSpaceProvider
    Application.DatabaseVersionMismatch += DemoAppWindowsFormsApplication_DatabaseVersionMismatch
  End Sub
  Private Sub DemoAppWindowsFormsApplication_DatabaseVersionMismatch(ByVal sender As Object, ByVal e As DatabaseVersionMismatchEventArgs)
    e.Updater.Update()
    e.Handled = True
  End Sub
  Private Sub Application_CreateCustomObjectSpaceProvider(ByVal sender As Object, ByVal e As CreateCustomObjectSpaceProviderEventArgs)
    If e.ObjectSpaceProvider Is Nothing Then
      Dim app = CType(sender, XafApplication)
      Dim security = CType(app.Security, SecurityStrategy)
      e.ObjectSpaceProvider = New SecuredObjectSpaceProvider(security, e.ConnectionString, e.Connection)
    End If
  End Sub
  Private Sub Application_CustomizeLanguagesList(ByVal sender As Object, ByVal e As CustomizeLanguagesListEventArgs)
    Dim userLanguageName As String = Thread.CurrentThread.CurrentUICulture.Name
    If userLanguageName <> "en-US" AndAlso e.Languages.IndexOf(userLanguageName) = -1 Then
      e.Languages.Add(userLanguageName)
    End If
  End Sub
End Class

See also: