The Factory Object
The Factory object is an instance of the mmFactory class that implements the standard Gang-of-Four Factory pattern.
What is a Factory?
The main purpose of the Factory is to provide flexible class instantiation within MM .NET. It allows you to instantiate your own specialized components (such as the Database Manager, Form Manager, and so on), rather than the standard components that come with the Framework.For example, let's say you enhance the MM .NET Database Manager by creating a subclass and extending a few of its methods. Now you need to find the line of code in MM .NET that instantiates the Database Manager, and change it so it instantiates your custom manager instead. If MM .NET buried this line of code within a Framework method, you'd be out of luck. However, this single line of code has been surfaced in the CreateDatabaseManager method of the mmFactory class. All you have to do is override this single method and return an instance of your custom Database Manager. The steps outlined below detail exactly how this is done.
Factory Members
The Factory class contains a number of factory methods that create other manager objects. For example:- CreateApplicationLog
- CreateAppSettingsManager
- CreateDatabaseManager
- CreateFormManager
- CreateLanguageManager
- CreateSecurityManager
- CreateUserManager
Overriding Factory Methods
The beauty of the Factory object is you can override its factory methods when you want to replace an MM .NET manager object with your own custom object. Here are the steps you must take:Step 1: Create a Custom Manager Class
When creating a custom manager class to replace an MM .NET manager, you need to create a subclass of the MM .NET manager class and override its methods.For example, in C:
using OakLeaf.MM.Main.Managers; public class MyDataBaseManager : mmDatabaseManager, ImmDatabaseManager { public MyDataBaseManager(ImmAppSettingsManager appSettingsMgr, ImmUserManager userMgr) : base(appSettingsMgr, userMgr) { } }
And in VB .NET:
Imports OakLeaf.MM.Main.Managers Public Class MyDatabaseManager Inherits mmDatabaseManager Sub New(appSettingsMgr As ImmAppSettingsManager, userMgr As ImmUserManager) MyBase.New(appSettingsMgr, userMgr) End Sub End Class
Step 2: Override the Factory Method
In this step you need to override the factory method that creates the object you are interested in (a Factory class has already been added to your MM .NET projects).For example, in C#:
/// <summary> /// Application-Level factory /// </summary> public class Factory : mmFactory, ImmFactoryWPF { public override ImmDatabaseManager CreateDatabaseManager() { return new MyDataBaseManager(AppWPF.AppSettingsMgr, AppWPF.UserMgr); }
And in VB .NET:
''' <summary> ''' Application-Level Factory ''' </summary> Public Class Factory Inherits mmFactory Implements ImmFactoryWPF Public Overrides Function CreateDatabaseManager() As ImmDatabaseManager Return New MyDatabaseManager(AppWPF.AppSettingsMgr, AppWPF.UserMgr) End Function
Implementing a Generic Factory
The MM .NET Generic Factory class (mmFactoryGeneric) allows you to data drive your class instantiation. The mmFactoryGeneric class has a CreateObject() method that accepts a single classToken parameter that specifies which class is to be instantiated by the factory. The mmFactoryGeneric class performs a lookup in its associated Classes table using the classToken as a primary key value. The Classes table contains three fields--the ClassToken primary key field, the ClassName field, and the Assembly field:
When the CreateObject() method is called, mmFactoryGeneric looks up the specified class token in the ClassToken field. When the record is found, it uses the information in the ClassName field (which contains a fully qualified class name including namespace) and the Assembly field which contains the name of the assembly in which the class is located. It then uses reflection to instantiate an instance of the class and return a reference to it.
Creating the Generic Factory's Classes Table
If you are working with SQL Server or MSDE, you can run a script, MMClasses.sql, that automatically creates the Generic Factory's Classes table for you.To run this script:
- Launch the SQL Server Management Studio if you are using a newer version of SQL Server, or SQL Query Analyzer tool if you are using SQL Server 2000, and in the Connect to Server dialog, enter the connection information needed to connect to SQL Server, and then click Connect or OK.
- In the toolbar, click the Open button. In the Open File dialog, navigate to the \Program Files\MM .NET Framework 2026\MM .NET Framework Wizards\Scripts directory, select the mmClasses.sql file, and click the Open button.

This displays the MMClasses.sql script file in the Query window:

- Go towards the top of the script file and locate this command:
use Northwind
Change <Classes Database> to the name of your classes database. For example:
use MyDatabase
- To run the script, press F5, or select the Execute Query button from the toolbar.
When the script is finished executing, you should have the MM .NET Classes table in your database. Add a record to the Classes table for each class instantiation you want to data drive.
Adding Records to the Classes Table
When adding records to the Classes table, you need to specify:- A Token name
- A Class name (with a fully qualified namespace)
- An assembly name (with the dll extension)
So, for example:
ClassToken - OrderEntity
ClassName - OakLeaf.MM.NorthwindSample.Main.Business.OrderEntity
Assembly - OakLeaf.MM2026.NorthwindSample.Business.dll
Calling the Generic Factory's CreateObject()
After setting up the Generic Factory, it's easy to create an object by calling its CreateObject() method and passing a token. For example:
var myEntity = (ABusinessEntity)mmAppBase.GenericFactory.CreateObject("OrderEntity");
It makes sense to cast the returned object to some usable type, but it really only makes sense to cast it as a parent class up the hierarchy rather than the specific class that it actually is (otherwise, why are you using a Generic Factory?)
Specifying the Database
If your application has more than one database, you need to specify in which database the Classes tables is stored. To do this, add the ClassesDatabaseKey to the <appSettings> node of your application's configuration file and set the key value to the Classes database.For example:
<add key="ClassesDatabaseKey" value="Northwind" />
© (c) 2026 Oak Leaf Enterprises, Inc., 1996-2026 • Updated: 02/10/26
Comment or report problem with topic
