Class: ObjectFactory
Defined in: core/src/ObjectFactory.ts:36
The ObjectFactory is a manager for creating objects based on registered
class types. This allows for the tracking of multiple instances of objects
so that references can be referenced by unique name.
Constructors
Constructor
new ObjectFactory(
config?,logger?):ObjectFactory
Defined in: core/src/ObjectFactory.ts:55
Parameters
config?
any
logger?
any
Returns
ObjectFactory
Properties
classes
readonlyclasses:Map<string,any>
Defined in: core/src/ObjectFactory.ts:38
A map for string fully qualified class names to their class types.
config
protectedconfig:any
Defined in: core/src/ObjectFactory.ts:41
The global application configuration object.
instances
readonlyinstances:Map<string,any>
Defined in: core/src/ObjectFactory.ts:44
A map for the unique name to the intance of a particular class type.
logger
protectedlogger:any
Defined in: core/src/ObjectFactory.ts:47
The application logging utility.
Methods
clear()
clear():
void
Defined in: core/src/ObjectFactory.ts:158
Deletes all instantiated objects.
Returns
void
clearAll()
clearAll():
void
Defined in: core/src/ObjectFactory.ts:166
Deletes all instantiated objects and registered class types.
Returns
void
destroy()
destroy(
objs?):Promise<void>
Defined in: core/src/ObjectFactory.ts:117
Destroys the specified objects. If undefined is passed in, all objects managed by the factory are destroyed.
Parameters
objs?
any
Returns
Promise<void>
getInitMethods()
getInitMethods(
obj):Function[]
Defined in: core/src/ObjectFactory.ts:248
Searches an object for one or more functions that implement a @Init decorator.
Parameters
obj
any
The object to search.
Returns
Function[]
The list of functions that implements the @Init decorator if found, otherwise undefined.
getInstance()
getInstance<
T>(nameOrType):T|undefined
Defined in: core/src/ObjectFactory.ts:282
Returns the object instance with the given unique name. Unique names take the form <ClassName>:<InstanceName>.
It is possible to only specifiy the <ClassName>, doing so will automatically look for the <ClassName>:default
instance or the first found instance of the given type.
Type Parameters
T
T
Parameters
nameOrType
any
The unique name or class type of the object to retrieve.
Returns
T | undefined
The object instance associated with the given name if found, otherwise undefined.
initialize()
initialize<
T>(obj):T|Promise<T>
Defined in: core/src/ObjectFactory.ts:175
Scans the given object for any properties with the @Inject decorator and assigns the correct values.
Type Parameters
T
T
Parameters
obj
any
The object to initialize with injected defaults
Returns
T | Promise<T>
newInstance()
newInstance<
T>(type,options?):T|Promise<T>
Defined in: core/src/ObjectFactory.ts:323
Creates a new instance of the class specified with the provided unique name or type and constructor arguments. If an existing object has already been created with the given name, that instance is returned, otherwise a new instance is created using the provided arguments.
Type Parameters
T
T
Parameters
type
any
The fully qualified name or type of the class to instantiate. If a type is given it's class name will be inferred via the constructor name.
options?
The options to use when instantiating the new class object.
Returns
T | Promise<T>
register()
register(
clazz,fqn?):void
Defined in: core/src/ObjectFactory.ts:403
Registers the given class type for the provided fully qualified name.
Parameters
clazz
any
The class type to register.
fqn?
string
The fully qualified name of the class to register. If not specified, the class name will be used.
Returns
void