diff --git a/packages/classes/src/lib/classes.ts b/packages/classes/src/lib/classes.ts index a61283476..4a324bc3f 100644 --- a/packages/classes/src/lib/classes.ts +++ b/packages/classes/src/lib/classes.ts @@ -29,6 +29,12 @@ export const classes: MapPluginInitializer = (errorHandler) => { const instanceStorage = new ClassInstanceStorage(); return { + instantiate = any>( + model: Constructible, + obj?: TModel + ) { + return instantiate(instanceStorage, metadataStorage, model, obj); + }, initializeMapping(source, destination, options?) { // If a mapping already exists, handle error and return; if (mappingStorage.has(source, destination)) { @@ -52,15 +58,12 @@ export const classes: MapPluginInitializer = (errorHandler) => { * ``` * `Foo#bar` is a nested constructible */ - const [destinationInstance, destinationNestedConstructible] = instantiate( - instanceStorage, - metadataStorage, - destination - ); + const [ + destinationInstance, + destinationNestedConstructible, + ] = this.instantiate(destination); - const [sourceInstance, sourceNestedConstructible] = instantiate( - instanceStorage, - metadataStorage, + const [sourceInstance, sourceNestedConstructible] = this.instantiate( source ); @@ -130,15 +133,8 @@ export const classes: MapPluginInitializer = (errorHandler) => { destinationObj?: TDestination ) { // Prepare the sourceInstance/destinationInstance with plain object sourceObj and destinationObj - const [sourceInstance] = instantiate( - instanceStorage, - metadataStorage, - source, - sourceObj - ); - const [destinationInstance] = instantiate( - instanceStorage, - metadataStorage, + const [sourceInstance] = this.instantiate(source, sourceObj); + const [destinationInstance] = this.instantiate( destination, destinationObj );