Ticket S39783
Visible to All Users

Performance - Make it possible to specify declared ModuleUpdater types for the ModuleBase descendant instead of looking for types within a module assembly

created 13 years ago
C#
public class DatabaseUpdater { ... private IList<ModuleUpdater> GetModuleUpdaters(IObjectSpace objectSpace, IList<IModuleInfo> versionInfoList) { List<ModuleUpdater> dbUpdaters = new List<ModuleUpdater>(); foreach(ModuleBase module in modules) { Version moduleVersionFromDB = GetModuleVersionFromDB(versionInfoList, module.Name); if(ForceUpdateDatabase || module.Version > moduleVersionFromDB) { // !!! Type[] updaterTypes = AssemblyHelper.GetTypes(module.GetType().Assembly, type => typeof(ModuleUpdater).IsAssignableFrom(type) && !type.IsAbstract && !type.IsGenericTypeDefinition); // !!! foreach(Type updaterType in updaterTypes) { if(updaterType.GetConstructor(new Type[] { typeof(IObjectSpace), typeof(Version) }) != null) { dbUpdaters.Add((ModuleUpdater)TypeHelper.CreateInstance(updaterType, objectSpace, moduleVersionFromDB)); } else { String errorMessage = String.Format("Unable to create an instance of the \"{0}\" type.\r\nThe type does not expose a constructor with the .ctor({1}, {2}) signature.", updaterType.FullName, typeof(IObjectSpace).FullName, typeof(Version).FullName); throw new ObjectCreatingException(updaterType, errorMessage, null); } } } } return dbUpdaters; }

There may be a GetDeclaredModuleUpdaterTypes method, pretty similar to existing GetDeclaredControllerTypes and GetDeclaredExportedTypes methods in the ModuleBase class.

Answers

created 13 years ago (modified 13 years ago)

Starting with 12.2, you can override (it is recommended for better performance) the GetModuleTypes method and create required ModuleUpdaters manually. If you do not override this method, XAF will look for ModuleUpdater descendants itself. This is required to avoid a breaking change in existing applications.
If your custom module is not supposed to provide any updates to the database, then override the method as follows:

C#
public override IEnumerable<ModuleUpdater> GetModuleUpdaters(IObjectSpace objectSpace, Version versionFromDB) { return ModuleUpdater.EmptyModuleUpdaters; }

All standard XAF modules and templates will follow these best practices as well.

    Comments (1)
    DevExpress Support Team 12 years ago

      The related documentation is published:
      ModuleBase.GetModuleUpdaters Method

      Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

      Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.