Creates an instance of the class registered for the given base class and key.
If no registration is found, falls back to instantiating the base class itself — a
long-standing, deliberate behavior that legitimate consumers (notably BaseEntity) rely on.
This method therefore does NOT return null for an unregistered key, so if (instance)
is not a valid resolution-failure test. Use TryCreateInstance when you need to know
whether the key actually resolved.
Async version of CreateInstance that supports lazy loading. If no registration is found synchronously and lazy loaders are registered, attempts to load the missing module before retrying and creating the instance.
Falls back to instantiating the base class directly if no registration is found even
after lazy loading (same behavior as the sync CreateInstance) — including throwing when the
anchor base is marked @RequiresSubclass().
Returns all registrations for a given base class and key. If key is not provided, will return all registrations for the base class.
Optionalkey: string | nullReturns all registrations for a given base class whose Key matches the
provided regex (tested against the trimmed-but-original-case key). Use for
more nuanced discovery patterns than the prefix helper handles.
Returns all registrations for a given base class whose Key STARTS WITH the
provided prefix (case-insensitive, trimmed). Useful when registrations follow
a naming convention with a structured prefix (e.g. "<EntityName>:...").
Prefer GetAllRegistrationsByMetadata when the discriminating data is
structured — putting tuples in the key string is fragile.
Returns all registrations for a given base class whose attached Metadata
bag satisfies the predicate. Registrations with no metadata are passed
undefined to the predicate.
This is the recommended discovery path for structured per-registration
data (e.g. form-panel slots that filter by { entity, slot }). It avoids
the brittleness of encoding tuples into the Key string.
Returns the registration with the highest priority for a given base class and key. If key is not provided, will return the registration with the highest priority for the base class.
Optionalkey: string | nullAsync version of GetRegistration that supports lazy loading. If no registration is found synchronously and lazy loaders are registered, attempts to load the missing module before retrying the lookup.
The base class to look up
Optionalkey: string | nullOptional key to differentiate registrations
The matching ClassRegistration, or null if not found even after lazy loading
Returns all registrations that have the specified root class, regardless of what base class was used in the registration. This is useful for finding all registrations in a class hierarchy.
The root class to search for
Optionalkey: string | nullOptional key to filter results
Array of matching registrations
Use this method or the
A reference to the base class you are registering a sub-class for
A reference to the sub-class you are registering
A key can be used to differentiate registrations for the same base class/sub-class combination. For example, in the case of BaseEntity and Entity object subclasses we'll have a LOT of entries and we want to get the highest priority registered sub-class for a specific key. In that case, the key is the entity name, but the key can be any value you want to use to differentiate registrations.
Higher priority registrations will be used over lower priority registrations. If there are multiple registrations for a given base class/sub-class/key combination, the one with the highest priority will be used. If there are multiple registrations with the same priority, the last one registered will be used. Finally, if you do NOT provide this setting, the order of registrations will increment the priority automatically so dependency injection will typically care care of this. That is, in order for Class B, a subclass of Class A, to be registered properly, Class A code has to already have been loaded and therefore Class A's RegisterClass decorator was run. In that scenario, if neither Class A or B has a priority setting, Class A would be 1 and Class B would be 2 automatically. For this reason, you only need to explicitly set priority if you want to do something atypical as this mechanism normally will solve for setting the priority correctly based on the furthest descendant class that is registered.
If true, will not print a warning if the key is null or undefined. This is useful for cases where you know that the key is not needed and you don't want to see the warning in the console.
If true, will automatically register the subclass with the root class of the baseClass hierarchy. This ensures proper priority ordering when multiple subclasses are registered in a hierarchy. Defaults to false to preserve the original registration contract where classes are stored under the baseClass you specify.
Optionalmetadata: Record<string, unknown>Registers a lazy loader callback that will be called when a class registration cannot be found synchronously. Multiple loaders can be registered and will be called in order until one succeeds.
A function that receives (baseClassName, key) and returns a Promise
Explicit-result sibling of CreateInstance. Never throws for an unresolved key —
returns a ClassResolutionResult so the caller can branch on Resolved.
const res = MJGlobal.Instance.ClassFactory.TryCreateInstance<MyProvider>(MyProviderBase, key);
if (!res.Resolved || !res.Instance) {
LogError(`provider '${key}' did not resolve: ${res.Reason}`);
return; // skip — do NOT install a hollow base instance
}
use(res.Instance);
Explicit-result, lazy-loading-aware sibling of TryCreateInstance. Never throws for an unresolved key.
ClassFactory is used to register and create instances of classes. It is a singleton class that can be used to register a sub-class for a given base class and key. Do NOT directly attempt to instantiate this class, instead use the static Instance property of the MJGlobal class to get the instance of the ClassFactory for your application.