Creating a new customer module using DEM
A module is a logical collection of functionality and resources that is packaged
in a way that can be separately developed, tested, deployed, and integrated into
an application. A package can be one or more assemblies. Each module has a
central class that is responsible for initializing the module and integrating
its functionality into the application. That class implements the ModuleBase
class.
Note
Create new modules if you need to share functionality and resources between different mobile applications eg. adjusting business policy and regulatory to the region.
ModuleBase
Depending on the purpose of the module, it can register views into composite user interfaces, make additional services available to the application, or extend the application's functionality. The following code shows the minimum implementation for a module.
public class FoundationModule : ModuleBase
{
public override IEnumerable<ITypeInfo> RegisterUsecases()
{
List<ITypeInfo> useCases = new List<ITypeInfo>()
{
new ViewModelInfo(typeof(Usecases.Empty.EmptyViewModel)){ PageTypes = new Type[] { typeof(Usecases.Empty.EmptyPage) }, ShowLoading = false },
new ViewModelInfo(typeof(Usecases.Activate.ActivateViewModel)){
DisplayData = new ViewModelDisplayData(10, "activate", AllIcons.Arrowright), ViewType = ViewType.Prelogin, ShowLoading = false,
PageTypes = new Type[] { typeof(Usecases.Activate.ActivatePage), typeof(Usecases.Activate.CreateNewPinPage) }
},
...
new ViewModelInfo(typeof(Usecases.AuthorizeDialog.AuthorizeDialogViewModel)){ViewType = ViewType.Postlogin }
};
return useCases;
}
public override IEnumerable<ITypeInfo> RegisterWidgets()
{
List<ITypeInfo> widgets = new List<ITypeInfo>()
{
new WidgetInfo(typeof(Widgets.BannerAdWidget.BannerAdWidgetViewModel))
{ IsEnabled = true, Order = 100, CanChangeIsEnabled = false }
};
return widgets;
}
public override IEnumerable<ITypeInfo> RegisterServices()
{
List<ITypeInfo> services = new List<ITypeInfo>()
{
new AppServiceInfo<Services.DemoAuthenticationService, IAuthenticationService>() { IsSingleInstance = true },
...
new AppServiceInfo<Services.NavigationService, INavigationService>() { IsSingleInstance = true },
};
return services;
}
public override IEnumerable<ITypeInfo> RegisterResources()
{
List<ITypeInfo> resources = new List<ITypeInfo>()
{
new TranslationResourceInfo<FoundationModule>("AssecoSEE.DEM.Foundation.Data.textResources.csv")
{
Priority = 20
}
};
return resources;
}
}
Initializing Modules
After the modules load, they are initialized. This means an instance of this base module class is created and its Register methods are called. Initialization is the place to integrate the module with the application. Consider the following possibilities for module initialization:
Use RegisterUsecases
method to Register the module's views with the
application.
If your module is participating in user interface (UI) composition using view
discovery or view injection, your module will need to associate its views or
view models with the appropriate region name using RegisterWidget
. This allows
views to show up dynamically on dashboard or other visual regions within the
application.
Note
Module instance lifetime is short-lived by default. After the Initialize method is called during the loading process, the reference to the module instance is released. If you do not establish a strong reference chain to the module instance, it will be garbage collected. This behavior may be problematic to debug if you subscribe to events that hold a weak reference to your module, because your module just "disappears" when the garbage collector runs.
Register types with a dependency injection container using RegisterService
.
The module may register types for the application or other modules to use.
To register translation (localization) resources with the application use the
RegisterResources
For more information see