Class: ObjectFactory
Defined in: service-core/src/ObjectFactory.ts:21
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.
Extends
ObjectFactory
Constructors
Constructor
new ObjectFactory(
config?,logger?):ObjectFactory
Defined in: service-core/src/ObjectFactory.ts:22
Parameters
config?
any
logger?
any
Returns
ObjectFactory
Overrides
CoreObjectFactory.constructor
Properties
classes
readonlyclasses:Map<string,any>
Defined in: service-core/node_modules/@rapidrest/core/dist/types/ObjectFactory.d.ts:22
A map for string fully qualified class names to their class types.
Inherited from
CoreObjectFactory.classes
config
protectedconfig:any
Defined in: service-core/node_modules/@rapidrest/core/dist/types/ObjectFactory.d.ts:24
The global application configuration object.
Inherited from
CoreObjectFactory.config
instances
readonlyinstances:Map<string,any>
Defined in: service-core/node_modules/@rapidrest/core/dist/types/ObjectFactory.d.ts:26
A map for the unique name to the intance of a particular class type.
Inherited from
CoreObjectFactory.instances
logger
protectedlogger:any
Defined in: service-core/node_modules/@rapidrest/core/dist/types/ObjectFactory.d.ts:28
The application logging utility.
Inherited from
CoreObjectFactory.logger
Methods
clear()
clear():
void
Defined in: service-core/node_modules/@rapidrest/core/dist/types/ObjectFactory.d.ts:43
Deletes all instantiated objects.
Returns
void
Inherited from
CoreObjectFactory.clear
clearAll()
clearAll():
void
Defined in: service-core/node_modules/@rapidrest/core/dist/types/ObjectFactory.d.ts:47
Deletes all instantiated objects and registered class types.
Returns
void
Inherited from
CoreObjectFactory.clearAll
destroy()
destroy(
objs?):Promise<void>
Defined in: service-core/node_modules/@rapidrest/core/dist/types/ObjectFactory.d.ts:39
Destroys the specified objects. If undefined is passed in, all objects managed by the factory are destroyed.
Parameters
objs?
any
Returns
Promise<void>
Inherited from
CoreObjectFactory.destroy
getInitMethods()
getInitMethods(
obj):Function[]
Defined in: service-core/node_modules/@rapidrest/core/dist/types/ObjectFactory.d.ts:59
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.
Inherited from
CoreObjectFactory.getInitMethods
getInstance()
getInstance<
T>(nameOrType):T|undefined
Defined in: service-core/node_modules/@rapidrest/core/dist/types/ObjectFactory.d.ts:67
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.
Inherited from
CoreObjectFactory.getInstance
initialize()
initialize<
T>(obj):Promise<T>
Defined in: service-core/src/ObjectFactory.ts:30
Scans the given object for any properties with the
Type Parameters
T
T
Parameters
obj
any
The object to initialize with injected defaults
Returns
Promise<T>
Inject
decorator and assigns the correct values.
Overrides
CoreObjectFactory.initialize
newInstance()
newInstance<
T>(type,options?):T|Promise<T>
Defined in: service-core/node_modules/@rapidrest/core/dist/types/ObjectFactory.d.ts:77
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?
InstanceOptions
The options to use when instantiating the new class object.
Returns
T | Promise<T>
Inherited from
CoreObjectFactory.newInstance
register()
register(
clazz,fqn?):void
Defined in: service-core/node_modules/@rapidrest/core/dist/types/ObjectFactory.d.ts:83
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
Inherited from
CoreObjectFactory.register