import { InstanceContainer } from '../core/validator.interface' ; import { defaultContainer } from '../core/defaultContainer' ; import { clone , merge } from '../services/entity.service' ; export function instanceProvider ( instanceFunc , entityObject ? ) { let instance = defaultContainer . get ( instanceFunc ) ; let prototype = entityObject ? entityObject . __proto__ : getInstance ( instanceFunc , [ ] ) . __proto__ ; if ( prototype . __proto__ ) { let isLoop = false ; do { isLoop = prototype . __proto__ . constructor != Object ; if ( isLoop ) { let extendClassInstance = defaultContainer . get ( prototype . __proto__ . constructor ) ; instance = merge ( clone ( instance ) , clone ( extendClassInstance ) ) ; prototype = prototype . __proto__ ; } } while ( isLoop ) ; } return instance ; } export function getInstance ( model , objectArguments ) { let classInstance = Object . create ( model . prototype ) ; try { model . apply ( classInstance , objectArguments ) ; } catch ( ex ) { classInstance = Reflect . construct ( model , objectArguments ) ; } return classInstance ; }